Merge "heat: convert open to context manager"
[yardstick.git] / run_tests.sh
1 #!/bin/bash
2
3 ##############################################################################
4 # Copyright (c) 2015 Ericsson AB and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
11
12 # Run yardstick's flake8, unit, coverage, functional test
13
14 getopts ":f" FILE_OPTION
15
16 run_flake8() {
17     echo "Running flake8 ... "
18     logfile=test_results.log
19     if [ $FILE_OPTION == "f" ]; then
20         flake8 yardstick > $logfile
21     else
22         flake8 yardstick
23     fi
24
25     if [ $? -ne 0 ]; then
26         echo "FAILED"
27         if [ $FILE_OPTION == "f" ]; then
28             echo "Results in $logfile"
29         fi
30         exit 1
31     else
32         echo "OK"
33     fi
34 }
35
36 get_external_libs() {
37     cd $(dirname ${BASH_SOURCE[0]})
38     TREX_DOWNLOAD="https://trex-tgn.cisco.com/trex/release/v2.05.tar.gz"
39     TREX_DIR=$PWD/trex/scripts
40     if [ ! -d "$TREX_DIR" ]; then
41         rm -rf ${TREX_DOWNLOAD##*/}
42         if [ ! -e ${TREX_DOWNLOAD##*/} ] ; then
43             wget -nv $TREX_DOWNLOAD
44         fi
45         tar xf ${TREX_DOWNLOAD##*/}
46         pushd .
47         rm -rf trex && mkdir -p trex
48         mv v2.05 trex/scripts
49         rm -rf v2.05.tar.gz
50         touch "$PWD/trex/scripts/automation/trex_control_plane/stl/__init__.py"
51         popd
52     fi
53     echo "Done."
54     export PYTHONPATH=$PYTHONPATH:"$PWD/trex/scripts/automation/trex_control_plane"
55     export PYTHONPATH=$PYTHONPATH:"$PWD/trex/scripts/automation/trex_control_plane/stl"
56     echo $PYTHONPATH
57 }
58
59 run_tests() {
60     echo "Get external libs needed for unit test"
61     get_external_libs
62
63     echo "Running unittest ... "
64     if [ $FILE_OPTION == "f" ]; then
65         python -m unittest discover -v -s tests/unit > $logfile 2>&1
66     else
67         python -m unittest discover -v -s tests/unit
68     fi
69
70     if [ $? -ne 0 ]; then
71         if [ $FILE_OPTION == "f" ]; then
72             echo "FAILED, results in $logfile"
73         fi
74         exit 1
75     else
76         if [ $FILE_OPTION == "f" ]; then
77             echo "OK, results in $logfile"
78         fi
79     fi
80 }
81
82 run_coverage() {
83     source tests/ci/cover.sh
84     run_coverage_test
85 }
86
87 run_functional_test() {
88
89     mkdir -p .testrepository
90     python -m subunit.run discover tests/functional > .testrepository/subunit.log
91
92     subunit2pyunit < .testrepository/subunit.log
93     EXIT_CODE=$?
94     subunit-stats < .testrepository/subunit.log
95
96     if [ $EXIT_CODE -ne 0 ]; then
97         exit 1
98     else
99         echo "OK"
100     fi
101 }
102
103 export PYTHONPATH='yardstick/vTC/apexlake'
104
105 run_flake8
106 run_tests
107 run_coverage
108 run_functional_test