run.sh revision 7000eb00
1#!/usr/bin/env bash
2
3source odl_utils.sh
4
5TESTS_DIR=tests
6
7function 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
21export CFG_METHOD=vat
22source config.sh
23
24verbose=0
25
26while [ $# -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
52done
53
54### begin script
55
56failed_tcs=()
57count=0
58failed_num=0
59passed_num=0
60
61start_time=`date +%s`
62
63# sudo?
64if [[ $(id -u) != 0 ]]; then
65  echo "Superuser privileges needed!"
66  exit 1
67fi
68
69# check whether ODL is running
70check_odl_running
71
72
73# count tests
74test_num=`ls -l "$TESTS_DIR"/test_* | wc -l`
75disabled_num=`ls -l "$TESTS_DIR"/disabled_test_* | wc -l`
76manual_num=`ls -l "$TESTS_DIR"/manual_test_* | wc -l`
77
78echo
79echo "Running VPP lite test suite."
80echo
81echo "Config method: $CFG_METHOD"
82echo
83
84for test_case in "$TESTS_DIR"/test_*
85do
86  let "count=$count + 1"
87
88  # run the test case
89  base_name=`basename -a "$test_case"`
90  printf "*** %2d/%d : %-48s" $count $test_num "$base_name"
91  logger "*** test start $base_name"
92
93  if [ $verbose -ne 0 ] ; then
94    "$test_case"
95  else
96    "$test_case" &> /dev/null
97  fi
98  rc=$?
99
100  if [ $rc -ne 0 ] ; then
101    printf "failed!\n"
102    failed_tcs+=("$test_case")
103    let "failed_num=$failed_num + 1"
104  else
105    printf "passed.\n"
106    let "passed_num=$passed_num + 1"
107  fi
108  logger "*** test end $base_name: result: $rc"
109  sleep 1
110done
111
112end_time=`date +%s`
113runtime=$((end_time-start_time))
114
115echo
116echo "------------------------------------------------------"
117echo "Runtime: " `date -u -d @${runtime} +"%M min %S sec"`
118echo
119
120if [ $failed_num -eq 0 ]; then
121  echo "All tests have passed."
122else
123  echo "List of failed test cases:"
124  for tc in "${failed_tcs[@]}"
125  do
126    echo "$tc"
127  done
128fi
129
130echo
131if [ $disabled_num -ne 0 ] ; then
132  echo "Skipped tests: " $disabled_num
133fi
134
135if [ $manual_num -ne 0 ] ; then
136  echo "Manual tests: " $manual_num
137fi
138
139echo
140echo "------------------------------------------------------"
141
142### end script
143