Move tests: functional/
[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         python -m unittest discover -v -s yardstick/tests/unit >> $logfile 2>&1
33     else
34         python -m unittest discover -v -s tests/unit
35         python -m unittest discover -v -s yardstick/tests/unit
36     fi
37
38     if [ $? -ne 0 ]; then
39         if [ $FILE_OPTION == "f" ]; then
40             echo "FAILED, results in $logfile"
41         fi
42         exit 1
43     else
44         if [ $FILE_OPTION == "f" ]; then
45             echo "OK, results in $logfile"
46         fi
47     fi
48 }
49
50 run_coverage() {
51     source $COVER_DIR_NAME/cover.sh
52     run_coverage_test
53 }
54
55 run_functional_test() {
56
57     mkdir -p .testrepository
58     python -m subunit.run discover yardstick/tests/functional > .testrepository/subunit.log
59
60     subunit2pyunit < .testrepository/subunit.log
61     EXIT_CODE=$?
62     subunit-stats < .testrepository/subunit.log
63
64     if [ $EXIT_CODE -ne 0 ]; then
65         exit 1
66     else
67         echo "OK"
68     fi
69 }
70
71 if [[ $opts =~ "--unit" ]]; then
72     run_tests
73 fi
74
75 if [[ $opts =~ "--coverage" ]]; then
76     run_coverage
77 fi
78
79 if [[ $opts =~ "--functional" ]]; then
80     run_functional_test
81 fi
82
83 if [[ -z $opts ]]; then
84     echo "No tests to run!!"
85     echo "Usage: run_tests.sh [--unit] [--coverage] [--functional]"
86     exit 1
87 fi