Merge "ansible: disable Extra cloud image kernel stub"
[yardstick.git] / tools / 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 unit, coverage, functional test
13
14 getopts ":f" FILE_OPTION
15 opts=$@ # get other args
16
17 # don't write .pyc files this can cause odd unittest results
18 export PYTHONDONTWRITEBYTECODE=1
19
20 PY_VER="py$( python --version | sed 's/[^[:digit:]]//g' | cut -c-2 )"
21 export PY_VER
22
23 COVER_DIR_NAME="./tools/"
24 export COVER_DIR_NAME
25
26 run_tests() {
27     echo "Get external libs needed for unit test"
28
29     echo "Running unittest ... "
30     if [ $FILE_OPTION == "f" ]; then
31         python -m unittest discover -v -s tests/unit > $logfile 2>&1
32         if [ $? -ne 0 ]; then
33             echo "FAILED, results in $logfile"
34             exit 1
35         fi
36         python -m unittest discover -v -s yardstick/tests/unit >> $logfile 2>&1
37     else
38         python -m unittest discover -v -s tests/unit
39         if [ $? -ne 0 ]; then
40             exit 1
41         fi
42         python -m unittest discover -v -s yardstick/tests/unit
43     fi
44
45     if [ $? -ne 0 ]; then
46         if [ $FILE_OPTION == "f" ]; then
47             echo "FAILED, results in $logfile"
48         fi
49         exit 1
50     else
51         if [ $FILE_OPTION == "f" ]; then
52             echo "OK, results in $logfile"
53         fi
54     fi
55 }
56
57 run_coverage() {
58     source $COVER_DIR_NAME/cover.sh
59     run_coverage_test
60 }
61
62 run_functional_test() {
63
64     mkdir -p .testrepository
65     python -m subunit.run discover yardstick/tests/functional > .testrepository/subunit.log
66
67     subunit2pyunit < .testrepository/subunit.log
68     EXIT_CODE=$?
69     subunit-stats < .testrepository/subunit.log
70
71     if [ $EXIT_CODE -ne 0 ]; then
72         exit 1
73     else
74         echo "OK"
75     fi
76 }
77
78 if [[ $opts =~ "--unit" ]]; then
79     run_tests
80 fi
81
82 if [[ $opts =~ "--coverage" ]]; then
83     run_coverage
84 fi
85
86 if [[ $opts =~ "--functional" ]]; then
87     run_functional_test
88 fi
89
90 if [[ -z $opts ]]; then
91     echo "No tests to run!!"
92     echo "Usage: run_tests.sh [--unit] [--coverage] [--functional]"
93     exit 1
94 fi