xref: /aosp_15_r20/external/igt-gpu-tools/scripts/run-tests.sh (revision d83cc019efdc2edc6c4b16e9034a3ceb8d35d77c)
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
25ROOT="`dirname $0`"
26ROOT="`readlink -f $ROOT/..`"
27IGT_CONFIG_PATH="`readlink -f ${IGT_CONFIG_PATH:-$HOME/.igtrc}`"
28RESULTS="$ROOT/results"
29PIGLIT=`which piglit 2> /dev/null`
30
31if [ -z "$IGT_TEST_ROOT" ]; then
32	paths=("$ROOT/build/tests/test-list.txt"
33	       "$ROOT/tests/test-list.txt")
34	for p in "${paths[@]}"; do
35		if [ -f "$p" ]; then
36			echo "Found test list: \"$p\""
37			IGT_TEST_ROOT=$(dirname "$p")
38			break
39		fi
40	done
41fi
42
43if [ -z "$IGT_TEST_ROOT" ]; then
44	echo "Error: test list not found."
45	echo "Please build tests to generate the test list or use IGT_TEST_ROOT env var."
46	exit 1
47fi
48
49IGT_TEST_ROOT="`readlink -f ${IGT_TEST_ROOT}`"
50
51function download_piglit {
52	git clone https://anongit.freedesktop.org/git/piglit.git "$ROOT/piglit"
53}
54
55function run_piglit # as-root <args>
56{
57	local need_root=$1
58	shift
59	local sudo
60
61	export IGT_TEST_ROOT IGT_CONFIG_PATH
62
63	if [ "$need_root" -ne 0 -a "$EUID" -ne 0 ]; then
64		sudo="sudo --preserve-env=IGT_TEST_ROOT,IGT_CONFIG_PATH"
65	fi
66
67	$sudo $PIGLIT "$@"
68}
69
70function print_help {
71	echo "Usage: run-tests.sh [options]"
72	echo "Available options:"
73	echo "  -d              download Piglit to $ROOT/piglit"
74	echo "  -h              display this help message"
75	echo "  -l              list all available tests"
76	echo "  -r <directory>  store the results in directory"
77	echo "                  (default: $RESULTS)"
78	echo "  -s              create html summary"
79	echo "  -t <regex>      only include tests that match the regular expression"
80	echo "                  (can be used more than once)"
81	echo "  -T <filename>   run tests listed in testlist"
82	echo "                  (overrides -t and -x)"
83	echo "  -v              enable verbose mode"
84	echo "  -x <regex>      exclude tests that match the regular expression"
85	echo "                  (can be used more than once)"
86	echo "  -R              resume interrupted test where the partial results"
87	echo "                  are in the directory given by -r"
88	echo "  -n              do not retry incomplete tests when resuming a"
89	echo "                  test run with -R"
90	echo ""
91	echo "Useful patterns for test filtering are described in the API documentation."
92}
93
94while getopts ":dhlr:st:T:vx:Rn" opt; do
95	case $opt in
96		d) download_piglit; exit ;;
97		h) print_help; exit ;;
98		l) LIST_TESTS="true" ;;
99		r) RESULTS="$OPTARG" ;;
100		s) SUMMARY="html" ;;
101		t) FILTER="$FILTER -t $OPTARG" ;;
102		T) FILTER="$FILTER --test-list $OPTARG" ;;
103		v) VERBOSE="-v" ;;
104		x) EXCLUDE="$EXCLUDE -x $OPTARG" ;;
105		R) RESUME="true" ;;
106		n) NORETRY="--no-retry" ;;
107		:)
108			echo "Option -$OPTARG requires an argument."
109			exit 1
110			;;
111		\?)
112			echo "Unknown option: -$OPTARG"
113			print_help
114			exit 1
115			;;
116	esac
117done
118shift $(($OPTIND-1))
119
120if [ "x$1" != "x" ]; then
121	echo "Unknown option: $1"
122	print_help
123	exit 1
124fi
125
126if [ "x$PIGLIT" == "x" ]; then
127	PIGLIT="$ROOT/piglit/piglit"
128fi
129
130if [ ! -x "$PIGLIT" ]; then
131	echo "Could not find Piglit."
132	echo "Please install Piglit or use -d to download Piglit locally."
133	exit 1
134fi
135
136if [ "x$LIST_TESTS" != "x" ]; then
137	run_piglit 0 print-cmd --format "{name}" igt
138	exit
139fi
140
141if [ "x$RESUME" != "x" ]; then
142	run_piglit 1 resume "$RESULTS" $NORETRY
143else
144	mkdir -p "$RESULTS"
145	run_piglit 1 run igt --ignore-missing -o "$RESULTS" -s $VERBOSE $EXCLUDE $FILTER
146fi
147
148if [ "$SUMMARY" == "html" ]; then
149	run_piglit 0 summary html --overwrite "$RESULTS/html" "$RESULTS"
150	echo "HTML summary has been written to $RESULTS/html/index.html"
151fi
152