Merge changes from topics 'add_factor_testcase_tx_pkt_size', 'add_posca_test_suite_fr...
[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 posca)
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          "-posca")
42              SUITE_PREFIX=$SUITE_PREFIX_CONFIG/posca/testcase_cfg
43          ;;
44     esac
45
46     TEST_CASE=$2
47
48     #find all the test case yaml files first
49     find $SUITE_PREFIX -name "*yaml" > /tmp/all_testcases.yaml
50     all_testcases_insuite=`cat /tmp/all_testcases.yaml | awk -F '/' '{print $NF}' | awk -F '.' '{print $1}'`
51     all_testcases=(${all_testcases_insuite})
52
53     if [ "${TEST_CASE}" != "" ]; then
54        testcase_exec=(${TEST_CASE// /})
55        for i in "${testcase_exec[@]}"; do
56            if [[ " ${all_testcases[*]} " != *" $i "* ]]; then
57                error "unknown test case: $i. available test cases are: ${all_test_cases[@]}"
58            fi
59        done
60        info "tests to execute: ${TEST_CASE}."
61     else
62        error "lack of testcase name"
63     fi
64 }
65 function run_test(){
66
67     test_suite=$1
68     echo "Running test suite $test_suite"
69
70     case $test_suite in
71         "rubbos")
72             info "Running rubbos test suite"
73             test_file="/home/opnfv/bottlenecks/testsuites/rubbos/testsuite_story/rubbos_story1"
74             if [[ -f $test_file ]]; then
75                 testcases=($(cat $test_file))
76             else
77                 error "no rubbos test suite file"
78             fi
79             for i in "${testcases[@]}"; do
80                 #check if the testcase is legal or not
81                 check_testcase -rubbos $i
82                 #adjust config parameters, different test suite has different methods, take rubbos as an example
83                 #run test case, different test suite has different methods
84                 file=${BASEDIR}/testsuites/rubbos/testcase_cfg/${i}.yaml
85                 python /home/opnfv/bottlenecks/testsuites/rubbos/run_rubbos.py -c $file
86             done
87         ;;
88         "vstf")
89             info "Running vstf test suite"
90             test_file="/home/opnfv/bottlenecks/testsuites/vstf/testsuite_story/vstf_story1"
91             if [[ -f $test_file ]]; then
92                 testcases=($(cat $test_file))
93             else
94                 error "no vstf test suite file "
95             fi
96             for i in "${testcases[@]}"; do
97                 #check if the testcase is legal or not
98                 check_testcase -vstf $i
99                 #adjust config parameters
100                 #run test case
101                 file=${BASEDIR}/testsuites/vstf/testcase_cfg/${i}.yaml
102                 python /home/opnfv/bottlenecks/testsuites/vstf/run_vstf.py -c $file
103             done
104         ;;
105         "posca")
106             info "Running posca test suite"
107             test_file="/home/opnfv/bottlenecks/testsuites/posca/testsuite_story/posca_factor_test"
108             if [[ -f $test_file ]]; then
109                 testcases=($(cat $test_file))
110             else
111                 error "no posca test suite file "
112             fi
113             for i in "${testcases[@]}"; do
114                 #check if the testcase is legal or not
115                 check_testcase -posca $i
116                 #adjust config parameters
117                 #run test case
118                 file=${BASEDIR}/testsuites/posca/testcase_cfg/${i}.yaml
119                 python /home/opnfv/bottlenecks/testsuites/posca/run_posca.py -c $file
120             done
121         ;;
122     esac
123 }
124
125 while [[ $# > 0 ]]
126     do
127     key="$1"
128     case $key in
129         -h|--help)
130             echo "$usage"
131             exit 0
132             shift
133         ;;
134         -r|--report)
135             report="-r"
136         ;;
137         -s|--suite)
138             SUITE="$2"
139             shift
140         ;;
141         *)
142             echo "unkown option $1 $2"
143             exit 1
144         ;;
145      esac
146      shift
147 done
148
149 BASEDIR=`dirname $0`
150 source ${BASEDIR}/common.sh
151
152 #check the test suite name is correct
153 if [ "${SUITE}" != "" ]; then
154     suite_exec=(${SUITE//,/ })
155     for i in "${suite_exec[@]}"; do
156         if [[ " ${arr_test_suite[*]} " != *" $i "* ]]; then
157             error "unkown test suite: $i"
158         fi
159     done
160     info "Tests to execute: ${SUITE}"
161 fi
162
163 # Source credentials
164 info "Sourcing Credentials openstack.creds to run the tests.."
165 source /home/opnfv/bottlenecks/config/openstack.creds
166
167 #run tests
168 if [ "${SUITE}" != "" ]; then
169     for i in "${suite_exec[@]}"; do
170         run_test $i
171     done
172 fi