svn commit: r234259 - projects/net80211_testsuite/wtap/001

Monthadar Al Jaberi monthadar at FreeBSD.org
Sat Apr 14 00:40:33 UTC 2012


Author: monthadar
Date: Sat Apr 14 00:40:32 2012
New Revision: 234259
URL: http://svn.freebsd.org/changeset/base/234259

Log:
  * Modified so that the test script returns 0 on success otherwise failure,
  which is returned in teardown();
  * Added info() routine that should be used instead of calling echo directly;
  * Modified loggin format to print the number of the test on each log line;
  * Modified loggin output to print the name of the test and date of running
  the test;
  * Modified run() so that it print either "ALL TEST PASSED" or how many test
  failed with which ones;
  * Modified teardown() to explicitly unlink the wtap simulator visibility
  between the nodes;
  * Changed how the script parses the command line arguments, and add 'all'
  flag that equals to 'setup run teardown';
  
  Approved by: adrian (mentor)

Modified:
  projects/net80211_testsuite/wtap/001/test.sh

Modified: projects/net80211_testsuite/wtap/001/test.sh
==============================================================================
--- projects/net80211_testsuite/wtap/001/test.sh	Sat Apr 14 00:40:13 2012	(r234258)
+++ projects/net80211_testsuite/wtap/001/test.sh	Sat Apr 14 00:40:32 2012	(r234259)
@@ -5,8 +5,14 @@
 # + vis_map - to setup the visibility map between wtap instances
 # + vimage - to configure/destroy vtap nodes
 
-# The number of nodes to test
+# The name of the test that will be printed in the begining
+TEST_NBR="001"
+TEST_NAME="4 nodes in a line topology"
+
+# Return value from this test, 0 success failure otherwise
+TEST_RESULT=127
 
+# The number of nodes to test
 NBR_NODES=4
 
 # The subnet prefix
@@ -14,10 +20,15 @@ IP_SUBNET="192.168.2."
 
 cmd()
 {
-	echo "*** " $*
+	echo "***${TEST_NBR}*** " $*
 	$*
 }
 
+info()
+{
+	echo "***${TEST_NBR}*** " $*
+}
+
 descr()
 {
 	cat <<EOL
@@ -47,10 +58,14 @@ EOL
 
 setup()
 {
+	# Initialize output file
+	info "TEST: ${TEST_NAME}"
+	info `date`
+
 	# Create wtap/vimage nodes
 	for i in `seq 1 ${NBR_NODES}`; do
 		wtap_if="`expr $i - 1`"
-		echo "Setup: vimage $i - wtap$wtap_if"
+		info "Setup: vimage $i - wtap$wtap_if"
 		cmd vimage -c $i
 		cmd wtap c $wtap_if
 	done
@@ -64,7 +79,7 @@ setup()
 		cmd vis_map a $j $i
 	done
 
-	# What's this do?
+	# Makes the visibility map plugin deliver packets to resp. dest.
 	cmd vis_map o
 
 	# Create each wlan subinterface, place into the correct vnet
@@ -82,28 +97,48 @@ setup()
 
 run()
 {
+	NBR_TESTS=0 NBR_FAIL=0
+
 	# Test connectivity from each node to each other node
 	for i in `seq 1 ${NBR_NODES}`; do
 		for j in `seq 1 ${NBR_NODES}`; do
 			if [ "$i" != "$j" ]; then
 				# From vimage '$i' to vimage '$j'..
-				echo "* Checking ${i} -> ${j}.."
+				info "Checking ${i} -> ${j}.."
+				NBR_TESTS="`expr ${NBR_TESTS} + 1`"
 				# Return after a single successful packet
 				cmd jexec $i ping -q -t 5 -c 5 \
 				    -o ${IP_SUBNET}${j}
 
 				if [ "$?" = "0" ]; then
-					echo "CHECK: ${i} -> ${j}: SUCCESS"
+					info "CHECK: ${i} -> ${j}: SUCCESS"
 				else
-					echo "CHECK: ${i} -> ${j}: FAILURE"
+					info "CHECK: ${i} -> ${j}: FAILURE"
+					NBR_FAIL="`expr ${NBR_FAIL} + 1`"
 				fi
 			fi
 		done
 	done
+	if [ $NBR_FAIL = 0 ]; then
+		info "ALL TESTS PASSED"
+		TEST_RESULT=0
+	else
+		info "FAILED ${NBR_FAIL} of ${NBR_TESTS} TESTS"
+	fi
 }
 
 teardown()
 {
+	cmd vis_map c
+	# Unlink all links
+	# XXX: this is a limitation of the current plugin,
+	# no way to reset vis_map without unload wtap.
+	n="`expr ${NBR_NODES} - 1`"
+	for i in `seq 0 ${n}`; do
+		j="`expr ${i} + 1`"
+		cmd vis_map d $i $j
+		cmd vis_map d $j $i
+	done
 	n="`expr ${NBR_NODES} - 1`"
 	for i in `seq 0 ${n}`; do
 		vnet="`expr ${i} + 1`"
@@ -114,30 +149,50 @@ teardown()
 		cmd wtap d ${wtap_if}
 		cmd vimage -d ${i}
 	done
+	exit ${TEST_RESULT}
 }
 
-case $1 in
-	'setup')
-		setup
-		exit 0
-	;;
-	'run')
-		run
-		exit 0
-	;;
-	'teardown')
-		teardown
-		exit 0
-	;;
-	'descr')
-		descr
-		exit 0
-	;;
-	*)
-		echo "$0 {setup | run | teardown | descr}"
-		exit 127
-	;;
-esac
+EXEC_SETUP=0
+EXEC_RUN=0
+EXEC_TEARDOWN=0
+while [ "$#" -gt "0" ]
+do
+	case $1 in
+		'all')
+			EXEC_SETUP=1
+			EXEC_RUN=1
+			EXEC_TEARDOWN=1
+		;;
+		'setup')
+			EXEC_SETUP=1
+		;;
+		'run')
+			EXEC_RUN=1
+		;;
+		'teardown')
+			EXEC_TEARDOWN=1
+		;;
+		'descr')
+			descr
+			exit 0
+		;;
+                *)
+			echo "$0 {all | setup | run | teardown | descr}"
+			exit 127
+		;;
+        esac
+        shift
+done
+
+if [ $EXEC_SETUP = 1 ]; then
+	setup
+fi
+if [ $EXEC_RUN = 1 ]; then
+	run
+fi
+if [ $EXEC_TEARDOWN = 1 ]; then
+	teardown
+fi
 
 exit 0
 


More information about the svn-src-projects mailing list