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