scripts: Add capability to resume interrupted run-tests.sh session
[platform/upstream/intel-gpu-tools.git] / scripts / run-tests.sh
1 #!/bin/bash
2 #
3 # Copyright © 2014 Intel Corporation
4 #
5 # Permission is hereby granted, free of charge, to any person obtaining a
6 # copy of this software and associated documentation files (the "Software"),
7 # to deal in the Software without restriction, including without limitation
8 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 # and/or sell copies of the Software, and to permit persons to whom the
10 # Software is furnished to do so, subject to the following conditions:
11 #
12 # The above copyright notice and this permission notice (including the next
13 # paragraph) shall be included in all copies or substantial portions of the
14 # Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 # IN THE SOFTWARE.
23
24
25 ROOT="`dirname $0`"
26 ROOT="`readlink -f $ROOT/..`"
27 IGT_TEST_ROOT="$ROOT/tests"
28 RESULTS="$ROOT/results"
29 PIGLIT=`which piglit 2> /dev/null`
30
31 if [ ! -d "$IGT_TEST_ROOT" ]; then
32         echo "Error: could not find tests directory."
33         exit 1
34 fi
35
36 if [ ! -f "$IGT_TEST_ROOT/single-tests.txt" ]; then
37         echo "Error: test list not found."
38         echo "Please run make in the tests directory to generate the test list."
39 fi
40
41 SINGLE_TEST_LIST=`cat "$IGT_TEST_ROOT/single-tests.txt" | sed -e '/TESTLIST/d' -e 's/ /\n/g'`
42 MULTI_TEST_LIST=`cat "$IGT_TEST_ROOT/multi-tests.txt" | sed -e '/TESTLIST/d' -e 's/ /\n/g'`
43
44 function download_piglit {
45         git clone git://anongit.freedesktop.org/piglit "$ROOT/piglit"
46 }
47
48 function print_help {
49         echo "Usage: run-tests.sh [options]"
50         echo "Available options:"
51         echo "  -d              download Piglit to $ROOT/piglit"
52         echo "  -h              display this help message"
53         echo "  -l              list all available tests"
54         echo "  -r <directory>  store the results in directory"
55         echo "                  (default: $RESULTS)"
56         echo "  -s              create html summary"
57         echo "  -t <regex>      only include tests that match the regular expression"
58         echo "                  (can be used more than once)"
59         echo "  -v              enable verbose mode"
60         echo "  -x <regex>      exclude tests that match the regular expression"
61         echo "                  (can be used more than once)"
62         echo "  -R              resume interrupted test where the partial results"
63         echo "                  are in the directory given by -r"
64         echo ""
65         echo "Useful patterns for test filtering are described in tests/NAMING-CONVENTION"
66 }
67
68 function list_tests {
69         echo "$SINGLE_TEST_LIST"
70         for test in $MULTI_TEST_LIST; do
71                 SUBTESTS=`"$IGT_TEST_ROOT/$test" --list-subtests`
72                 for subtest in $SUBTESTS; do
73                         echo "$test/$subtest"
74                 done
75         done
76 }
77
78 while getopts ":dhlr:st:vx:R" opt; do
79         case $opt in
80                 d) download_piglit; exit ;;
81                 h) print_help; exit ;;
82                 l) list_tests; exit ;;
83                 r) RESULTS="$OPTARG" ;;
84                 s) SUMMARY="html" ;;
85                 t) FILTER="$FILTER -t $OPTARG" ;;
86                 v) VERBOSE="-v" ;;
87                 x) EXCLUDE="$EXCLUDE -x $OPTARG" ;;
88                 R) RESUME="true" ;;
89                 :)
90                         echo "Option -$OPTARG requires an argument."
91                         exit 1
92                         ;;
93                 \?)
94                         echo "Unknown option: -$OPTARG"
95                         print_help
96                         exit 1
97                         ;;
98         esac
99 done
100 shift $(($OPTIND-1))
101
102 if [ "x$1" != "x" ]; then
103         echo "Unknown option: $1"
104         print_help
105         exit 1
106 fi
107
108 if [ "x$PIGLIT" == "x" ]; then
109         PIGLIT="$ROOT/piglit/piglit"
110 fi
111
112 if [ ! -x "$PIGLIT" ]; then
113         echo "Could not find Piglit."
114         echo "Please install Piglit or use -d to download Piglit locally."
115         exit 1
116 fi
117
118 if [ "x$RESUME" != "x" ]; then
119         sudo IGT_TEST_ROOT="$IGT_TEST_ROOT" "$PIGLIT" resume "$RESULTS"
120 else
121         mkdir -p "$RESULTS"
122         sudo IGT_TEST_ROOT="$IGT_TEST_ROOT" "$PIGLIT" run igt "$RESULTS" $VERBOSE $EXCLUDE $FILTER
123 fi
124
125 if [ "$SUMMARY" == "html" ]; then
126         "$PIGLIT" summary html --overwrite "$RESULTS/html" "$RESULTS"
127         echo "HTML summary has been written to $RESULTS/html/index.html"
128 fi