adjust project directories
[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/testsuite/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
82             done
83         ;;
84         "vstf")
85             info "Running vstf test suite"
86             test_file="/home/opnfv/bottlenecks/testsuite/vstf/testsuite_story/vstf_story1"
87             if [[ -f $test_file ]]; then
88                 testcases=($(cat $test_file))
89             else
90                 error("no vstf test suite file ")
91             fi
92             for i in "${testcases[@]}"; do
93                 #check if the testcase is legal or not
94                 check_testcase -vstf $i
95                 #adjust config parameters
96                 #run test case
97             done
98         ;;
99     esac
100 }
101
102 while [[ $# > 0 ]]
103     do
104     key="$1"
105     case $key in
106         -h|--help)
107             echo "$usage"
108             exit 0
109             shift
110         ;;
111         -r|--report)
112             report="-r"
113         ;;
114         -s|--suite)
115             SUITE="$2"
116             shift
117         ;;
118         *)
119             echo "unkown option $1 $2"
120             exit 1
121         ;;
122      esac
123      shift
124 done
125
126 BASEDIR=`dirname $0`
127 source ${BASEDIR}/common.sh
128
129 #check the test suite name is correct
130 if [ "${SUITE}" != "" ]; then
131     suite_exec=(${SUITE//,/ })
132     for i in "${suite_exec[@]}"; do
133         if [[ " ${arr_test_suite[*]} " != *" $i "* ]]; then
134             error "unkown test suite: $i"
135         fi
136     done
137     info "Tests to execute: ${SUITE}"
138 fi
139
140 #run tests
141 if [ "${SUITE}" != "" ]; then
142     for i in "${suite_exec[@]}"; do
143         run_test $i
144     done
145 fi