run.sh revision 51b44223
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 [vh]"
15  echo
16  echo "  -v : verbose output"
17  echo "  -h : show help"
18}
19
20verbose=0
21
22while [ $# -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
32done
33
34### begin script
35
36failed_tcs=()
37count=0
38failed_num=0
39passed_num=0
40
41start_time=`date +%s`
42
43# check whether ODL is running
44if [ "`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
49fi
50
51# sudo?
52if [[ $(id -u) != 0 ]]; then
53  echo "Superuser privileges needed!"
54  exit 1
55fi
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