run_test.sh revision 21121578
1#! /bin/bash
2
3# readme section---------------------------------------------------------------
4
5# usage: /bin/bash run_test.sh [-46lrh]
6#
7# Run all tests using nctxrx.sh. Report stored and printed
8# after tests were done. For details about options run
9# script with -h (help)
10#
11# User needs to specify following environment variables:
12#  ETH_DEV	- ethernet device to be used on SUT by DPDK
13#  REMOTE_HOST	- ip/hostname of DUT
14#  REMOTE_IFACE	- interface name for the test-port on DUT
15#  LOCAL_MAC	- MAC address used by DPDK
16#  L4FWD_PATH	- path to l4fwd app binary
17# Optional envirenment variables:
18#  L4FWD_FECORE	- core on which l4fwd frontend should run
19#  L4FWD_BECORE	- core on which l4fwd backend should run
20
21# options which can be changed by user-----------------------------------------
22
23# reorder settings
24reorder_min=4
25reorder_max=9
26reorder_step=5
27
28# loss settings
29loss_min=0
30loss_max=20
31loss_step=20
32
33# file for results storage
34DIR=$(dirname $0)
35result=${DIR}/result.out
36echo -e "Test\t\tProtocol\tFile\t\t\tStatus\tTime" > ${result}
37
38# how many times test file should be send during tests
39nb=3
40
41# variables used by script-----------------------------------------------------
42
43# option parsing variables
44run_loss=0
45run_reorder=0
46use_ip4=0
47use_ip6=0
48
49# track number of tests which have failed
50error_count=0
51
52SECONDS=0
53
54# functions and calls----------------------------------------------------------
55
56usage()
57{
58	echo -e "Usage:"
59	echo -e "\t$0 [-alr46h]"
60	echo -e "Options:"
61	echo -e "\t-a Run all tests"
62	echo -e "\t-l Perform loss tests"
63	echo -e "\t-r Perform reorder tests"
64	echo -e "\t-4 Use IPv4/TCP"
65	echo -e "\t-6 Use IPv6/TCP"
66	echo -e "\t-h Display this help"
67	echo -e "Info:"
68	echo -e "\tOptions [4/6] may be used together."
69}
70
71while getopts ":alr46h" opt
72do
73	case $opt in
74		a)
75			run_loss=1
76			run_reorder=1
77			;;
78		l)
79			run_loss=1
80			;;
81		r)
82			run_reorder=1
83			;;
84		4)
85			use_ip4=1
86			;;
87		6)
88			use_ip6=1
89			;;
90		h)
91			usage
92			exit 0
93			;;
94		?)
95			echo "Invalid option"
96			usage
97			exit 127
98			;;
99	esac
100done
101
102# check if tests to perform are specified
103if [[ ${run_loss} -eq 0 && ${run_reorder} -eq 0 ]]
104then
105	echo -e "Error: No tests specified\n"
106	usage
107	exit 127
108fi
109
110# check if IP protocol was specified
111if [[ ${use_ip4} -eq 0 && ${use_ip6} -eq 0 ]]
112then
113	echo -e "Error: No IP protocol specified\n"
114	usage
115	exit 127
116fi
117
118# get number of tests to perform
119if [[ ${run_reorder} -eq 1 ]]
120then
121	nb_of_reorder=$(( $(( ${reorder_max} - ${reorder_min} )) \
122		/ ${reorder_step} + 1 ))
123else
124	nb_of_reorder=0
125fi
126
127if [[ ${run_loss} -eq 1 ]]
128then
129	nb_of_loss=$(( $(( ${loss_max} - ${loss_min} )) / ${loss_step} + 1 ))
130else
131	nb_of_loss=0
132fi
133
134if [[ ${use_ip4} -eq 1 && ${use_ip6} -eq 1 ]]
135then
136	multiply=2
137else
138	multiply=1
139fi
140
141nb_of_tests=$(( $(( ${nb_of_loss} + ${nb_of_reorder} )) * ${multiply} ))
142tests_performed=0
143
144echo "Number of tests to run: ${nb_of_tests}"
145
146# add intermediary data into result file
147gather_data()
148{
149	test_case=$1
150	test_value=$2
151	protocol=$3
152
153	length=$(expr length "${test_case} ${test_value}")
154	if [[ ${length} -lt 8 ]]
155	then
156		tab="\t\t"
157	else
158		tab="\t"
159	fi
160
161	# add protocol used in test case which was invoked
162	sed -i "s_.*_${protocol}\t\t&_" ${result}.tmp
163	# add description of test case which was invoked (in first line)
164	sed -i "1 s_.*_${test_case} ${test_value}${tab}&_" ${result}.tmp
165	# add blank space to be aligned with first row
166	sed -i "1 ! s_.*_\t\t&_" ${result}.tmp
167	# add empty line befor each major test case
168	sed -i "1 s_.*_\n&_" ${result}.tmp
169	cat ${result}.tmp >> ${result}
170	rm -f ${result}.tmp
171}
172
173# run all tests
174while [[ ${use_ip4} -ne 0 || ${use_ip6} -ne 0 ]]
175do
176	#set protocol to be used in this round of tests
177	if [[ ${use_ip4} -eq 1 ]]
178	then
179		proto="ipv4"
180	elif [[ ${use_ip6} -eq 1 ]]
181	then
182		proto="ipv6"
183	fi
184
185	# check if reorder tests should be run
186	if [[ ${run_reorder} -eq 1 ]]
187	then
188		# run test for all specified reorder values
189		for reorder in $(seq ${reorder_min} \
190				${reorder_step} \
191				${reorder_max})
192		do
193			/bin/bash ${DIR}/nctxrx.sh \
194				-p ${proto} \
195				-n ${nb} \
196				-r ${reorder} \
197				-o ${result}.tmp \
198				-v
199
200			# check test status
201			st=$?
202			if [[ ${st} -eq 0 ]]
203			then
204				echo -e "\nTest for reorder: ${reorder}\t[OK]"
205			else
206				echo -e "\nTest for reorder: $reorder}\t[FAIL]"
207				error_count=$(expr ${error_count} + 1)
208			fi
209
210			# gather results
211			gather_data "Reorder" ${reorder} ${proto}
212			tests_performed=$(( ${tests_performed} + 1 ))
213			echo -e "\n[PROGRESS] ${tests_performed} out of \
214${nb_of_tests} done\n"
215		done
216	fi
217
218	# check if loss tests should be run
219	if [[ ${run_loss} -eq 1 ]]
220	then
221		# run test for all specified reorder values
222		for loss in $(seq ${loss_min} ${loss_step} ${loss_max})
223		do
224			/bin/bash ${DIR}/nctxrx.sh \
225				-p ${proto} \
226				-n ${nb} \
227				-l ${loss} \
228				-o ${result}.tmp \
229				-v
230
231			# check test status
232			st=$?
233			if [[ ${st} -eq 0 ]]
234			then
235				echo -e "\nTest for loss: ${loss}\t[OK]"
236			else
237				echo -e "\nTest for loss: ${loss}\t[FAIL]"
238				error_count=$(expr ${error_count} + 1)
239			fi
240
241			# gather results
242			gather_data "Loss" ${loss} ${proto}
243			tests_performed=$(( ${tests_performed} + 1 ))
244			echo -e "\n[PROGRESS] ${tests_performed} out of \
245${nb_of_tests} done\n"
246		done
247	fi
248
249	# mark that tests were done for one of the protocols
250	if [[ ${use_ip4} -eq 1 ]]
251	then
252		use_ip4=0
253	elif [[ ${use_ip6} -eq 1 ]]
254	then
255		use_ip6=0
256	fi
257done
258
259if [[ ${error_count} -eq 0 ]]
260then
261	echo -e "\nAll tests have ended successfully" >> ${result}
262else
263	echo -e "\n${error_count} tests have failed" >> ${result}
264fi
265
266if [[ $SECONDS -gt 60 ]]
267then
268	let "minutes=SECONDS/60"
269	let "seconds=SECONDS%60"
270	echo "All tests completed in $minutes minute(s) and $seconds second(s)"\
271		>> ${result}
272else
273	echo "All tests completed in $SECONDS second(s)" >> ${result}
274fi
275
276# print report after all tests were done
277echo -e "Report\n"
278cat ${result}
279