2cf54c708534d87dc7c459434496b30115621035
[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 # don't write .pyc files this can cause odd unittest results
17 export PYTHONDONTWRITEBYTECODE=1
18
19 run_flake8() {
20     echo "Running flake8 ... "
21     logfile=test_results.log
22     if [ $FILE_OPTION == "f" ]; then
23         flake8 yardstick > $logfile
24     else
25         flake8 yardstick
26     fi
27
28     if [ $? -ne 0 ]; then
29         echo "FAILED"
30         if [ $FILE_OPTION == "f" ]; then
31             echo "Results in $logfile"
32         fi
33         exit 1
34     else
35         echo "OK"
36     fi
37 }
38
39
40 run_tests() {
41     echo "Get external libs needed for unit test"
42
43     echo "Running unittest ... "
44     if [ $FILE_OPTION == "f" ]; then
45         python -m unittest discover -v -s tests/unit > $logfile 2>&1
46     else
47         python -m unittest discover -v -s tests/unit
48     fi
49
50     if [ $? -ne 0 ]; then
51         if [ $FILE_OPTION == "f" ]; then
52             echo "FAILED, results in $logfile"
53         fi
54         exit 1
55     else
56         if [ $FILE_OPTION == "f" ]; then
57             echo "OK, results in $logfile"
58         fi
59     fi
60 }
61
62 run_coverage() {
63     source tests/ci/cover.sh
64     run_coverage_test
65 }
66
67 run_functional_test() {
68
69     mkdir -p .testrepository
70     python -m subunit.run discover tests/functional > .testrepository/subunit.log
71
72     subunit2pyunit < .testrepository/subunit.log
73     EXIT_CODE=$?
74     subunit-stats < .testrepository/subunit.log
75
76     if [ $EXIT_CODE -ne 0 ]; then
77         exit 1
78     else
79         echo "OK"
80     fi
81 }
82
83 export PYTHONPATH='yardstick/vTC/apexlake'
84
85 run_flake8
86 run_tests
87 run_coverage
88 run_functional_test