bugfix: docker ci workflow bugfix
[bottlenecks.git] / run_tests.sh
1 #!/bin/bash
2 ##############################################################################
3 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 usage="Script to run the tests in bottlenecks auto.
12
13 usage:
14     bash $(basename "$0") [-h|--help] [-s <test suite>]
15
16 where:
17     -h|--help         show the help text
18     -r|--report       push results to DB(true by default)
19     -s|--suite        run specific test suite
20       <test suite>    one of the following:
21                             rubbos, vstf
22
23 examples:
24     $(basename "$0")
25     $(basename "$0") -s rubbos"
26
27 report=true
28
29 arr_test_suite=(rubbos vstf)
30
31 function check_testcase(){
32
33     check_suite="$1"
34     case $check_suite in
35          "-rubbos")
36              $SUITE_PREFIX=$SUITE_PREFIX_CONFIG/rubbos/testcase_cfg
37          ;;
38          "-vstf")
39              $SUITE_PREFIX=$SUITE_PREFIX_CONFIG/vstf/testcase_cfg
40          ;;
41     esac
42
43     TEST_CASE=$2
44
45     #find all the test case yaml files first
46     find $SUITE_PREFIX -name "*yaml" > /tmp/all_testcases.yaml
47     all_testcases_insuite=`cat /tmp/all_testcases.yaml | awk -F '/' '{print $NF}' | awk -F '.' '{print $1}'`
48     all_testcases=(${all_testcases_insuite})
49
50     if ["${TEST_CASE}" != ""]; then
51        testcase_exec=(${TEST_CASE// /})
52        for i in "${testcase_exec[@]}"; do
53            if [[ " ${all_test_cases[*]} " != *" $i "* ]]; then
54                error "unknown test case: $i. available test cases are: ${all_test_cases[@]}"
55            fi
56        done
57        info "tests to execute: ${TEST_CASE}."
58     else
59        error "lack of testcase name"
60     fi
61 }
62 function run_test(){
63
64     test_suite=$1
65     echo "Running test suite $test_suite"
66
67     case $test_suite in
68         "rubbos")
69             info "Running rubbos test suite"
70             test_file="/home/opnfv/bottlenecks/testsuites/rubbos/testsuite_story/rubbos_story1"
71             if [[ -f $test_file ]]; then
72                 testcases=($(cat $test_file))
73             else
74                 error("no rubbos test suite file ")
75             fi
76             for i in "${testcases[@]}"; do
77                 #check if the testcase is legal or not
78                 check_testcase -rubbos $i
79                 #adjust config parameters, different test suite has different methods, take rubbos as an example
80                 #run test case, different test suite has different methods
81                 file={$BASEDIR}/testsuites/rubbos/testcase_cfg/{$i}.yaml
82                 python /home/opnfv/bottlenecks/testsuites/rubbos/run_rubbos.py -c $file
83             done
84         ;;
85         "vstf")
86             info "Running vstf test suite"
87             test_file="/home/opnfv/bottlenecks/testsuite/vstf/testsuite_story/vstf_story1"
88             if [[ -f $test_file ]]; then
89                 testcases=($(cat $test_file))
90             else
91                 error("no vstf test suite file ")
92             fi
93             for i in "${testcases[@]}"; do
94                 #check if the testcase is legal or not
95                 check_testcase -vstf $i
96                 #adjust config parameters
97                 #run test case
98             done
99         ;;
100     esac
101 }
102
103 while [[ $# > 0 ]]
104     do
105     key="$1"
106     case $key in
107         -h|--help)
108             echo "$usage"
109             exit 0
110             shift
111         ;;
112         -r|--report)
113             report="-r"
114         ;;
115         -s|--suite)
116             SUITE="$2"
117             shift
118         ;;
119         *)
120             echo "unkown option $1 $2"
121             exit 1
122         ;;
123      esac
124      shift
125 done
126
127 BASEDIR=`dirname $0`
128 source ${BASEDIR}/common.sh
129
130 #check the test suite name is correct
131 if [ "${SUITE}" != "" ]; then
132     suite_exec=(${SUITE//,/ })
133     for i in "${suite_exec[@]}"; do
134         if [[ " ${arr_test_suite[*]} " != *" $i "* ]]; then
135             error "unkown test suite: $i"
136         fi
137     done
138     info "Tests to execute: ${SUITE}"
139 fi
140
141 #run tests
142 if [ "${SUITE}" != "" ]; then
143     for i in "${suite_exec[@]}"; do
144         run_test $i
145     done
146 fi