[PATCH v2] hwsim tests: reduce duplication in startup code

Johannes Berg johannes
Wed Oct 30 09:56:14 PDT 2013


From: Johannes Berg <johannes.berg at intel.com>

Instead of hard-coding four different cases, use variables
(and printf) to reduce the duplication.

Signed-hostap: Johannes Berg <johannes.berg at intel.com>
---
 tests/hwsim/start.sh | 39 +++++++++++++++++----------------------
 1 file changed, 17 insertions(+), 22 deletions(-)

diff --git a/tests/hwsim/start.sh b/tests/hwsim/start.sh
index b44f7b8..034db2b 100755
--- a/tests/hwsim/start.sh
+++ b/tests/hwsim/start.sh
@@ -7,6 +7,8 @@ HAPD=$DIR/../../hostapd/hostapd
 WLANTEST=$DIR/../../wlantest/wlantest
 HLR_AUC_GW=$DIR/../../hostapd/hlr_auc_gw
 
+DATE=`date +%s`
+
 if [ -z "$LOGDIR" ] ; then
     LOGDIR=$DIR/logs
 fi
@@ -20,16 +22,25 @@ fi
 
 if [ "$1" = "concurrent" ]; then
     CONCURRENT=y
+    CONCURRENT_ARGS="-N -Dnl80211 -ista%d -c $DIR/sta-dummy.conf"
     shift
 else
     unset CONCURRENT
+    CONCURRENT_ARGS=
 fi
 
 if [ "$1" = "valgrind" ]; then
     VALGRIND=y
+    VALGRIND_WPAS="valgrind --log-file=$LOGDIR/$DATE-valgrind-wlan%d"
+    VALGRIND_HAPD="valgrind --log-file=$LOGDIR/$DATE-valgrind-hostapd"
+    # why chmod?
+    chmod a+rx $WPAS
+    chmod a+rx $HAPD
     shift
 else
     unset VALGRIND
+    VALGRIND_WPAS=
+    VALGRIND_HAPD=
 fi
 
 if [ "$1" = "trace" ]; then
@@ -48,31 +59,15 @@ if [ "$CONCURRENT" = "y" ]; then
     sudo iw wlan2 interface add sta2 type station
 fi
 mkdir -p $LOGDIR
-DATE=`date +%s`
 sudo ifconfig hwsim0 up
 sudo $WLANTEST -i hwsim0 -c -d > $LOGDIR/$DATE-hwsim0 &
 sudo tcpdump -ni hwsim0 -s 2500 -w $LOGDIR/$DATE-hwsim0.dump > $LOGDIR/$DATE-tcpdump 2>&1 &
-if [ "$VALGRIND" = "y" ]; then
-    for i in 0 1 2; do
-	chmod a+rx $WPAS
-	if [ "$CONCURRENT" = "y" ]; then
-	    sudo valgrind --log-file=$LOGDIR/$DATE-valgrind-wlan$i $WPAS -g /tmp/wpas-wlan$i -G$GROUP -Dnl80211 -iwlan$i -c $DIR/p2p$i.conf -N -Dnl80211 -ista$i -c $DIR/sta-dummy.conf -ddKt$TRACE > $LOGDIR/$DATE-log$i &
-	else
-	    sudo valgrind --log-file=$LOGDIR/$DATE-valgrind-wlan$i $WPAS -g /tmp/wpas-wlan$i -G$GROUP -Dnl80211 -iwlan$i -c $DIR/p2p$i.conf -ddKt$TRACE > $LOGDIR/$DATE-log$i &
-	fi
-    done
-    chmod a+rx $HAPD
-    sudo valgrind --log-file=$LOGDIR/$DATE-valgrind-hostapd $HAPD -ddKt -g /var/run/hostapd-global -G $GROUP -ddKt > $LOGDIR/$DATE-hostapd &
-else
-    for i in 0 1 2; do
-	if [ "$CONCURRENT" = "y" ]; then
-	    sudo $WPAS -g /tmp/wpas-wlan$i -G$GROUP -Dnl80211 -iwlan$i -c $DIR/p2p$i.conf -N -Dnl80211 -ista$i -c $DIR/sta-dummy.conf -ddKt$TRACE > $LOGDIR/$DATE-log$i &
-	else
-	    sudo $WPAS -g /tmp/wpas-wlan$i -G$GROUP -Dnl80211 -iwlan$i -c $DIR/p2p$i.conf -ddKt$TRACE > $LOGDIR/$DATE-log$i &
-	fi
-    done
-    sudo $HAPD -ddKt -g /var/run/hostapd-global -G $GROUP -ddKt > $LOGDIR/$DATE-hostapd &
-fi
+for i in 0 1 2; do
+    sudo $(printf -- "$VALGRIND_WPAS" $i) $WPAS -g /tmp/wpas-wlan$i -G$GROUP -Dnl80211 -iwlan$i -c $DIR/p2p$i.conf \
+         $(printf -- "$CONCURRENT_ARGS" $i) -ddKt$TRACE > $LOGDIR/$DATE-log$i &
+done
+sudo $VALGRIND_HAPD $HAPD -ddKt -g /var/run/hostapd-global -G $GROUP -ddKt > $LOGDIR/$DATE-hostapd &
+
 sleep 1
 sudo chown $USER $LOGDIR/$DATE-hwsim0.dump
 if [ "x$VALGRIND" = "xy" ]; then
-- 
1.8.4.rc3




More information about the Hostap mailing list