aa0a29833fe1c4f81844943061de0eac8033662f
[one.git] / tests / data_plane / vpp_lite_topo / run.sh
1 #!/usr/bin/env bash
2
3 source config.sh
4 source odl_utils.sh
5
6 TESTS_DIR=tests
7
8 function help
9 {
10   echo "Run all ONE tests"
11   echo
12   echo This must be run with superuser privileges.
13   echo "Usage:"
14   echo " ./run.sh [vh]"
15   echo
16   echo "  -v : verbose output"
17   echo "  -h : show help"
18 }
19
20 verbose=0
21
22 while [ $# -gt 0 ] ; do
23   arg=$1
24   shift
25
26   if [ $arg == "-v" ]; then
27     verbose=1
28   elif [ $arg == "-h" ] ; then
29     help
30     exit 0
31   fi
32 done
33
34 ### begin script
35
36 failed_tcs=()
37 count=0
38 failed_num=0
39 passed_num=0
40
41 start_time=`date +%s`
42
43 # check whether ODL is running
44 if [ "`curl -X DELETE \
45   "http://${ODL_IP}:${ODL_PORT}/restconf/config/odl-mappingservice:mapping-database" \
46    -u ${ODL_USER}:${ODL_PASSWD} -s -o /dev/null -w "%{http_code}"`" != 200 ] ; then
47   echo "ODL is not running!"
48   exit 1
49 fi
50
51 # sudo?
52 if [[ $(id -u) != 0 ]]; then
53   echo "Superuser privileges needed!"
54   exit 1
55 fi
56
57 # count tests
58 test_num=`ls -l "$TESTS_DIR"/test_* | wc -l`
59
60 echo
61 echo "Running VPP lite test suite."
62 echo
63
64 for test_case in "$TESTS_DIR"/test_*
65 do
66   let "count=$count + 1"
67
68   # run the test case
69   base_name=`basename -a "$test_case"`
70   printf "*** %2d/%d : %-45s" $count $test_num "$base_name"
71
72   if [ $verbose -ne 0 ] ; then
73     "$test_case"
74   else
75     "$test_case" &> /dev/null
76   fi
77   rc=$?
78
79   if [ $rc -ne 0 ] ; then
80     printf "failed!\n"
81     failed_tcs+=("$test_case")
82     let "failed_num=$failed_num + 1"
83   else
84     printf "passed.\n"
85     let "passed_num=$passed_num + 1"
86   fi
87   sleep 1
88 done
89
90 end_time=`date +%s`
91 runtime=$((end_time-start_time))
92
93 echo
94 echo "------------------------------------------------------"
95 echo "Runtime: " `date -u -d @${runtime} +"%M min %S sec"`
96 echo
97
98 if [ $failed_num -eq 0 ]; then
99   echo "All tests have passed."
100 else
101   echo "List of failed test cases:"
102   for tc in "${failed_tcs[@]}"
103   do
104     echo "$tc"
105   done
106 fi
107
108 echo "------------------------------------------------------"
109
110 ### end script