run.sh revision 4543d282
1#!/usr/bin/env bash
2
3source config.sh
4source odl_utils.sh
5
6TESTS_DIR=tests
7
8function 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 [vhc]"
15  echo
16  echo "  -v : verbose output"
17  echo "  -c : clean"
18  echo "  -h : show help"
19}
20
21verbose=0
22
23while [ $# -gt 0 ] ; do
24  arg=$1
25  shift
26
27  if [ $arg == "-v" ]; then
28    verbose=1
29  elif [ $arg == "-h" ] ; then
30    help
31    exit 0
32  elif [ $arg == "-c" ] ; then
33    clean_all
34    exit 0
35  fi
36done
37
38### begin script
39
40failed_tcs=()
41count=0
42failed_num=0
43passed_num=0
44
45start_time=`date +%s`
46
47# sudo?
48if [[ $(id -u) != 0 ]]; then
49  echo "Superuser privileges needed!"
50  exit 1
51fi
52
53# check whether ODL is running
54check_odl_running
55
56
57# count tests
58test_num=`ls -l "$TESTS_DIR"/test_* | wc -l`
59
60echo
61echo "Running VPP lite test suite."
62echo
63
64for test_case in "$TESTS_DIR"/test_*
65do
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
88done
89
90end_time=`date +%s`
91runtime=$((end_time-start_time))
92
93echo
94echo "------------------------------------------------------"
95echo "Runtime: " `date -u -d @${runtime} +"%M min %S sec"`
96echo
97
98if [ $failed_num -eq 0 ]; then
99  echo "All tests have passed."
100else
101  echo "List of failed test cases:"
102  for tc in "${failed_tcs[@]}"
103  do
104    echo "$tc"
105  done
106fi
107
108echo "------------------------------------------------------"
109
110### end script
111