From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Gibson To: passt-dev@passt.top Subject: [PATCH 04/12] test: More robust wait for pasta/passt to be ready Date: Fri, 23 Sep 2022 17:20:30 +1000 Message-ID: <20220923072038.1667106-5-david@gibson.dropbear.id.au> In-Reply-To: <20220923072038.1667106-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============3474504744096159850==" --===============3474504744096159850== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable When we start passt or pasta, it may take a short time to be ready to handle packets, especially if running under valgrind. We have a number of semi-arbitrary fixed sleeps to account for this. We can do this more robustly by exploiting the fact that pasta/passt doesn't write its pidfile until it's ready to go, so if we wait for the pidfile to be created, we can proceed with confidence. Signed-off-by: David Gibson --- test/lib/setup | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/test/lib/setup b/test/lib/setup index 7e3f6c3..dee7b46 100755 --- a/test/lib/setup +++ b/test/lib/setup @@ -54,7 +54,9 @@ setup_passt() { context_run passt "make clean" context_run passt "make valgrind" context_run_bg passt "valgrind --max-stackframe=3D$((4 * 1024 * 1024)) --tr= ace-children=3Dyes --vgdb=3Dno --error-exitcode=3D1 --suppressions=3Dtest/val= grind.supp ./passt ${__opts} -f -t 10001 -u 10001 -P ${STATESETUP}/passt.pid" - sleep 5 + + # pidfile isn't created until passt is listening + wait_for [ -f "${STATESETUP}/passt.pid" ] =20 GUEST_CID=3D94557 context_run_bg qemu './qrap 5 qemu-system-$(uname -m)' \ @@ -99,7 +101,9 @@ setup_pasta() { [ ${TRACE} -eq 1 ] && __opts=3D"${__opts} --trace" =20 context_run_bg passt "./pasta ${__opts} -f -t 10002 -T 10003 -u 10002 -U 10= 003 -P ${STATESETUP}/passt.pid ${__target_pid}" - sleep 1 + + # pidfile isn't created until pasta is ready + wait_for [ -f "${STATESETUP}/passt.pid" ] } =20 # setup_passt_in_ns() - Set up namespace (with pasta), run qemu and passt in= to it @@ -129,7 +133,7 @@ setup_passt_in_ns() { [ ${TRACE} -eq 1 ] && __opts=3D"${__opts} --trace" =20 context_run_bg pasta "./pasta ${__opts} -t 10001,10002,10011,10012 -T 10003= ,10013 -u 10001,10002,10011,10012 -U 10003,10013 -P ${STATESETUP}/pasta.pid $= {NSHOLDER} ${STATESETUP}/ns.hold hold" - sleep 1 + wait_for [ -f "${STATESETUP}/pasta.pid" ] __ns_pid=3D$(${NSHOLDER} ${STATESETUP}/ns.hold pid) =20 context_setup_nsenter qemu "-t ${__ns_pid} -U -n -p --preserve-credentials" @@ -155,7 +159,7 @@ setup_passt_in_ns() { context_run passt "make" context_run_bg passt "./passt -f ${__opts} -t 10001,10011,10021,10031 -u 1= 0001,10011,10021,10031 -P ${STATESETUP}/passt.pid" fi - sleep 5 + wait_for [ -f "${STATESETUP}/passt.pid" ] =20 GUEST_CID=3D94557 context_run_bg qemu './qrap 5 qemu-system-$(uname -m)' \ @@ -226,7 +230,7 @@ setup_two_guests() { [ ${TRACE} -eq 1 ] && __opts=3D"${__opts} --trace" =20 context_run_bg passt_1 "./passt -P ${STATESETUP}/passt_1.pid -f ${__opts} -= t 10001 -u 10001" - sleep 1 + wait_for [ -f "${STATESETUP}/passt_1.pid" ] =20 __opts=3D [ ${PCAP} -eq 1 ] && __opts=3D"${__opts} -p ${LOGDIR}/passt_2.pcap" @@ -234,6 +238,7 @@ setup_two_guests() { [ ${TRACE} -eq 1 ] && __opts=3D"${__opts} --trace" =20 context_run_bg passt_2 "./passt -P ${STATESETUP}/passt_2.pid -f ${__opts} -= t 10004 -u 10004" + wait_for [ -f "${STATESETUP}/passt_2.pid" ] =20 GUEST_1_CID=3D94557 context_run_bg qemu_1 './qrap 5 qemu-system-$(uname -m)' \ --=20 2.37.3 --===============3474504744096159850==--