tests: Reduce duplication in startup code

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

Signed-hostap: Johannes Berg <johannes.berg@intel.com>
This commit is contained in:
Johannes Berg 2013-10-30 19:43:59 +02:00 committed by Jouni Malinen
parent 0b1faa8bf1
commit 95194219df

View file

@ -7,6 +7,8 @@ HAPD=$DIR/../../hostapd/hostapd
WLANTEST=$DIR/../../wlantest/wlantest WLANTEST=$DIR/../../wlantest/wlantest
HLR_AUC_GW=$DIR/../../hostapd/hlr_auc_gw HLR_AUC_GW=$DIR/../../hostapd/hlr_auc_gw
DATE=`date +%s`
if [ -z "$LOGDIR" ] ; then if [ -z "$LOGDIR" ] ; then
LOGDIR=$DIR/logs LOGDIR=$DIR/logs
fi fi
@ -20,16 +22,24 @@ fi
if [ "$1" = "concurrent" ]; then if [ "$1" = "concurrent" ]; then
CONCURRENT=y CONCURRENT=y
CONCURRENT_ARGS="-N -Dnl80211 -ista%d -c $DIR/sta-dummy.conf"
shift shift
else else
unset CONCURRENT unset CONCURRENT
CONCURRENT_ARGS=
fi fi
if [ "$1" = "valgrind" ]; then if [ "$1" = "valgrind" ]; then
VALGRIND=y VALGRIND=y
VALGRIND_WPAS="valgrind --log-file=$LOGDIR/$DATE-valgrind-wlan%d"
VALGRIND_HAPD="valgrind --log-file=$LOGDIR/$DATE-valgrind-hostapd"
chmod a+rx $WPAS
chmod a+rx $HAPD
shift shift
else else
unset VALGRIND unset VALGRIND
VALGRIND_WPAS=
VALGRIND_HAPD=
fi fi
if [ "$1" = "trace" ]; then if [ "$1" = "trace" ]; then
@ -48,31 +58,15 @@ if [ "$CONCURRENT" = "y" ]; then
sudo iw wlan2 interface add sta2 type station sudo iw wlan2 interface add sta2 type station
fi fi
mkdir -p $LOGDIR mkdir -p $LOGDIR
DATE=`date +%s`
sudo ifconfig hwsim0 up sudo ifconfig hwsim0 up
sudo $WLANTEST -i hwsim0 -c -d > $LOGDIR/$DATE-hwsim0 & 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 & 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 for i in 0 1 2; do
chmod a+rx $WPAS sudo $(printf -- "$VALGRIND_WPAS" $i) $WPAS -g /tmp/wpas-wlan$i -G$GROUP -Dnl80211 -iwlan$i -c $DIR/p2p$i.conf \
if [ "$CONCURRENT" = "y" ]; then $(printf -- "$CONCURRENT_ARGS" $i) -ddKt$TRACE > $LOGDIR/$DATE-log$i &
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 done
chmod a+rx $HAPD sudo $VALGRIND_HAPD $HAPD -ddKt -g /var/run/hostapd-global -G $GROUP -ddKt > $LOGDIR/$DATE-hostapd &
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
sleep 1 sleep 1
sudo chown $USER $LOGDIR/$DATE-hwsim0.dump sudo chown $USER $LOGDIR/$DATE-hwsim0.dump
if [ "x$VALGRIND" = "xy" ]; then if [ "x$VALGRIND" = "xy" ]; then