[PATCH v2] tests: Store the correct PID in hostapd-test.pid file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The hwsim's start.sh script spawns hostapd process using "sudo".
Since sudo forks a child process, $! holds the pid of sudo itself.
Fix that by storing the PID of the child process instead.
Since in VM "sudo" is replaced with a dummy script, pass an additional
argument to run-all.sh and start.sh scripts to indicate that they are
running inside a VM.

Signed-off-by: Andrei Otcheretianski <andrei.otcheretianski@xxxxxxxxx>
---
 tests/hwsim/run-all.sh   |  9 ++++++++-
 tests/hwsim/start.sh     | 15 ++++++++++++++-
 tests/hwsim/vm/inside.sh |  2 +-
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/tests/hwsim/run-all.sh b/tests/hwsim/run-all.sh
index 5cf56a9..94aa190 100755
--- a/tests/hwsim/run-all.sh
+++ b/tests/hwsim/run-all.sh
@@ -39,6 +39,7 @@ unset RUN_TEST_ARGS
 unset BUILD
 unset BUILD_ARGS
 unset CODECOV
+unset VM
 while [ "$1" != "" ]; do
 	case $1 in
 		-v | --valgrind | valgrind)
@@ -71,6 +72,12 @@ while [ "$1" != "" ]; do
 		-h | --help)
 			usage
 			;;
+		-V | --vm)
+			shift
+			echo "$0: running inside a VM"
+			VM=VM
+			;;
+
 		*)
 			RUN_TEST_ARGS="$RUN_TEST_ARGS$1 "
 			shift
@@ -108,7 +115,7 @@ if [ ! -z "$BUILD" ]; then
     fi
 fi
 
-if ! ./start.sh $VALGRIND $TRACE channels=$NUM_CH; then
+if ! ./start.sh $VM $VALGRIND $TRACE channels=$NUM_CH; then
 	if ! [ -z "$LOGBASEDIR" ] ; then
 		echo "Could not start test environment" > $LOGDIR/run
 	fi
diff --git a/tests/hwsim/start.sh b/tests/hwsim/start.sh
index 038426c..77e9791 100755
--- a/tests/hwsim/start.sh
+++ b/tests/hwsim/start.sh
@@ -71,6 +71,12 @@ done
 sed "s/group=admin/group=$GROUP/;s%LOGDIR%$LOGDIR%g" "$DIR/auth_serv/as.conf" > "$LOGDIR/as.conf"
 sed "s/group=admin/group=$GROUP/;s%LOGDIR%$LOGDIR%g" "$DIR/auth_serv/as2.conf" > "$LOGDIR/as2.conf"
 
+unset VM
+if [ "$1" = "VM" ]; then
+    VM="y"
+    shift
+fi
+
 if [ "$1" = "valgrind" ]; then
     VALGRIND=y
     VALGRIND_WPAS="valgrind --log-file=$LOGDIR/valgrind-wlan%d"
@@ -121,7 +127,14 @@ sudo $(printf -- "$VALGRIND_WPAS" 5) $WPAS -g /tmp/wpas-wlan5 -G$GROUP \
     -ddKt$TRACE -f $LOGDIR/log5 &
 sudo $VALGRIND_HAPD $HAPD -ddKt$TRACE -g /var/run/hostapd-global -G $GROUP -f $LOGDIR/hostapd &
 HPID=$!
-echo $HPID > $LOGDIR/hostapd-test.pid
+
+if [ -z "$VM" ]; then
+    # Sleep a bit, otherwise pgrep may run before the child is forked
+    sleep 0.1
+    pgrep -P $HPID > $LOGDIR/hostapd-test.pid
+else
+    echo $HPID > $LOGDIR/hostapd-test.pid
+fi
 
 if [ -x $HLR_AUC_GW ]; then
     cp $DIR/auth_serv/hlr_auc_gw.milenage_db $LOGDIR/hlr_auc_gw.milenage_db
diff --git a/tests/hwsim/vm/inside.sh b/tests/hwsim/vm/inside.sh
index 30b9387..c97a284 100755
--- a/tests/hwsim/vm/inside.sh
+++ b/tests/hwsim/vm/inside.sh
@@ -113,7 +113,7 @@ else
 	dbus-daemon --config-file=$TESTDIR/vm/dbus.conf --fork
 
 	cd $TESTDIR
-	./run-all.sh $(cat /tmp/host$ARGS) </dev/ttyS0 >/dev/ttyS0 2>&1
+	./run-all.sh --vm $(cat /tmp/host$ARGS) </dev/ttyS0 >/dev/ttyS0 2>&1
 	if test -d /sys/kernel/debug/gcov ; then
 		cp -ar /sys/kernel/debug/gcov /tmp/logs/
 		# these are broken as they're updated while being read ...
-- 
2.7.4


_______________________________________________
Hostap mailing list
Hostap@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/hostap



[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux