Introduce an option for testing binary API
[one.git] / tests / data_plane / vpp_lite_topo / run.sh
1 #!/usr/bin/env bash
2
3 source odl_utils.sh
4
5 TESTS_DIR=tests
6
7 function help
8 {
9   echo "Run all ONE tests"
10   echo
11   echo This must be run with superuser privileges.
12   echo "Usage:"
13   echo " ./run.sh [vhc] [--config-method vat|cli]"
14   echo
15   echo "  -v : verbose output"
16   echo "  -c : clean"
17   echo "  -h : show help"
18   echo "  --config-method : select configuration method. Default is VAT."
19 }
20
21 export CFG_METHOD=vat
22 source config.sh
23
24 verbose=0
25
26 while [ $# -gt 0 ] ; do
27   arg=$1
28   shift
29
30   if [ $arg == "-v" ]; then
31     verbose=1
32   elif [ $arg == "-h" ] ; then
33     help
34     exit 0
35   elif [ $arg == "-c" ] ; then
36     clean_all
37     exit 0
38   elif [ $arg == "--config-method" ] ; then
39     type=$1
40     shift
41     if [ $type != "vat" -a $type != "cli"  ] ; then
42       echo "ERROR: expected one of 'cli' or 'vat' "
43       help
44       exit 1
45     fi
46     export CFG_METHOD=$type
47   else
48     echo "parse error"
49     help
50     exit 1
51   fi
52 done
53
54 ### begin script
55
56 failed_tcs=()
57 count=0
58 failed_num=0
59 passed_num=0
60
61 start_time=`date +%s`
62
63 # sudo?
64 if [[ $(id -u) != 0 ]]; then
65   echo "Superuser privileges needed!"
66   exit 1
67 fi
68
69 # check whether ODL is running
70 check_odl_running
71
72
73 # count tests
74 test_num=`ls -l "$TESTS_DIR"/test_* | wc -l`
75
76 echo
77 echo "Running VPP lite test suite."
78 echo
79 echo "Config method: $CFG_METHOD"
80 echo
81
82 for test_case in "$TESTS_DIR"/test_*
83 do
84   let "count=$count + 1"
85
86   # run the test case
87   base_name=`basename -a "$test_case"`
88   printf "*** %2d/%d : %-45s" $count $test_num "$base_name"
89
90   if [ $verbose -ne 0 ] ; then
91     "$test_case"
92   else
93     "$test_case" &> /dev/null
94   fi
95   rc=$?
96
97   if [ $rc -ne 0 ] ; then
98     printf "failed!\n"
99     failed_tcs+=("$test_case")
100     let "failed_num=$failed_num + 1"
101   else
102     printf "passed.\n"
103     let "passed_num=$passed_num + 1"
104   fi
105   sleep 1
106 done
107
108 end_time=`date +%s`
109 runtime=$((end_time-start_time))
110
111 echo
112 echo "------------------------------------------------------"
113 echo "Runtime: " `date -u -d @${runtime} +"%M min %S sec"`
114 echo
115
116 if [ $failed_num -eq 0 ]; then
117   echo "All tests have passed."
118 else
119   echo "List of failed test cases:"
120   for tc in "${failed_tcs[@]}"
121   do
122     echo "$tc"
123   done
124 fi
125
126 echo "------------------------------------------------------"
127
128 ### end script