run.sh revision 5089c812
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`
75
76echo
77echo "Running VPP lite test suite."
78echo
79echo "Config method: $CFG_METHOD"
80echo
81
82for test_case in "$TESTS_DIR"/test_*
83do
84  let "count=$count + 1"
85
86  # run the test case
87  base_name=`basename -a "$test_case"`
88  printf "*** %2d/%d : %-48s" $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
106done
107
108end_time=`date +%s`
109runtime=$((end_time-start_time))
110
111echo
112echo "------------------------------------------------------"
113echo "Runtime: " `date -u -d @${runtime} +"%M min %S sec"`
114echo
115
116if [ $failed_num -eq 0 ]; then
117  echo "All tests have passed."
118else
119  echo "List of failed test cases:"
120  for tc in "${failed_tcs[@]}"
121  do
122    echo "$tc"
123  done
124fi
125
126echo "------------------------------------------------------"
127
128### end script
129