blob: 8285ba62d8292e32c78a660cd0707d4138bdc5e5 [file] [log] [blame]
Petri Latvala9fe6ea92017-09-25 12:34:02 +03001#!/bin/bash
Thomas Wood1a0ae512014-10-16 17:29:55 +01002#
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# Check that command line handling works consistently across all tests
26#
27
Petri Latvala31749742017-03-21 11:47:34 +020028# top_builddir is not set during distcheck. Distcheck executes this
29# script in the directory where the built binaries are so just use '.'
30# as the directory if top_builddir is not set.
31
32tests_dir="$top_builddir"
33if [ -z "$tests_dir" ]; then
34 tests_dir="."
Chris Wilson7213c3e2016-08-24 09:24:33 +010035fi
36
Petri Latvala31749742017-03-21 11:47:34 +020037# Manually running this script is possible in the source root or the
38# tests directory.
39
Chris Wilson7213c3e2016-08-24 09:24:33 +010040fail () {
41 echo "FAIL: $1"
42 exit 1
43}
Thomas Wood1a0ae512014-10-16 17:29:55 +010044
Daniel Vetterf0243a72017-09-06 10:02:52 +020045check_test ()
46{
47 local test
48
49 test=$1
50
Thomas Wood1a0ae512014-10-16 17:29:55 +010051 if [ "$test" = "TESTLIST" -o "$test" = "END" ]; then
Daniel Vetterf0243a72017-09-06 10:02:52 +020052 return
Thomas Wood1a0ae512014-10-16 17:29:55 +010053 fi
54
Petri Latvala31749742017-03-21 11:47:34 +020055 testname="$test"
56 if [ -x "$tests_dir/$test" ]; then
57 test="$tests_dir/$test"
58 else
59 # Possibly a script, not found in builddir but in srcdir
60 if [ -x "$srcdir/$test" ]; then
61 test="$srcdir/$test"
62 else
63 fail "Cannot execute $test"
64 fi
Thomas Wood1a0ae512014-10-16 17:29:55 +010065 fi
66
67 echo "$test:"
68
69 # check invalid option handling
70 echo " Checking invalid option handling..."
Chris Wilson7213c3e2016-08-24 09:24:33 +010071 ./$test --invalid-option 2> /dev/null && fail $test
Thomas Wood1a0ae512014-10-16 17:29:55 +010072
73 # check valid options succeed
74 echo " Checking valid option handling..."
Chris Wilson7213c3e2016-08-24 09:24:33 +010075 ./$test --help > /dev/null || fail $test
Thomas Wood1a0ae512014-10-16 17:29:55 +010076
77 # check --list-subtests works correctly
78 echo " Checking subtest enumeration..."
Thomas Woodf0516f32015-01-28 16:30:54 +000079 LIST=`./$test --list-subtests`
80 RET=$?
81 if [ $RET -ne 0 -a $RET -ne 79 ]; then
Chris Wilson7213c3e2016-08-24 09:24:33 +010082 fail $test
Thomas Woodf0516f32015-01-28 16:30:54 +000083 fi
84
85 if [ $RET -eq 79 -a -n "$LIST" ]; then
Chris Wilson7213c3e2016-08-24 09:24:33 +010086 fail $test
Thomas Woodf0516f32015-01-28 16:30:54 +000087 fi
88
89 if [ $RET -eq 0 -a -z "$LIST" ]; then
Petri Latvalafa5dc962017-03-21 14:05:04 +020090 # Subtest enumeration of kernel selftest launchers depends
91 # on the running kernel. If selftests are not enabled,
92 # they will output nothing and exit with 0.
Petri Latvala3ee83cf2017-08-14 12:51:52 +030093 if [ "$testname" != "drv_selftest" -a "$testname" != "drm_mm" ]; then
Petri Latvalafa5dc962017-03-21 14:05:04 +020094 fail $test
95 fi
Thomas Wood1a0ae512014-10-16 17:29:55 +010096 fi
97
98 # check invalid subtest handling
99 echo " Checking invalid subtest handling..."
Chris Wilson7213c3e2016-08-24 09:24:33 +0100100 ./$test --run-subtest invalid-subtest > /dev/null 2>&1 && fail $test
Daniel Vetterf0243a72017-09-06 10:02:52 +0200101}
102
103TESTLISTFILE="$tests_dir/test-list.txt"
104if [ ! -r "$TESTLISTFILE" ]; then
105 tests_dir="tests"
106 TESTLISTFILE="$tests_dir/test-list.txt"
107fi
108
109TESTLIST=`cat $TESTLISTFILE`
110if [ $? -ne 0 ]; then
111 echo "Error: Could not read test lists"
112 exit 99
113fi
114
Petri Latvala9fe6ea92017-09-25 12:34:02 +0300115if [ -n "$1" ] ; then
Daniel Vetterf0243a72017-09-06 10:02:52 +0200116 check_test $1
117 exit 0
118fi
119
120for test in $TESTLIST; do
121 check_test $test
Thomas Wood1a0ae512014-10-16 17:29:55 +0100122done