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# Check that command line handling works consistently across all tests 26# 27 28# 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="." 35fi 36 37# Manually running this script is possible in the source root or the 38# tests directory. 39 40fail () { 41 echo "FAIL: $1" 42 exit 1 43} 44 45check_test () 46{ 47 local test 48 49 test=$1 50 51 if [ "$test" = "TESTLIST" -o "$test" = "END" ]; then 52 return 53 fi 54 55 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 65 fi 66 67 echo "$test:" 68 69 # check invalid option handling 70 echo " Checking invalid option handling..." 71 ./$test --invalid-option 2> /dev/null && fail $test 72 73 # check valid options succeed 74 echo " Checking valid option handling..." 75 ./$test --help > /dev/null || fail $test 76 77 # check --list-subtests works correctly 78 echo " Checking subtest enumeration..." 79 LIST=`./$test --list-subtests` 80 RET=$? 81 if [ $RET -ne 0 -a $RET -ne 79 ]; then 82 fail $test 83 fi 84 85 if [ $RET -eq 79 -a -n "$LIST" ]; then 86 fail $test 87 fi 88 89 if [ $RET -eq 0 -a -z "$LIST" ]; then 90 # 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. 93 if [ "$testname" != "i915_selftest" -a "$testname" != "drm_mm" -a "$testname" != "kms_selftest" -a "$testname" != "dmabuf" ]; then 94 fail $test 95 fi 96 fi 97} 98 99TESTLISTFILE="$tests_dir/test-list.txt" 100if [ ! -r "$TESTLISTFILE" ]; then 101 tests_dir="tests" 102 TESTLISTFILE="$tests_dir/test-list.txt" 103fi 104 105TESTLIST=`cat $TESTLISTFILE` 106if [ $? -ne 0 ]; then 107 echo "Error: Could not read test lists" 108 exit 99 109fi 110 111if [ -n "$1" ] ; then 112 check_test $1 113 exit 0 114fi 115 116for test in $TESTLIST; do 117 check_test $test 118done 119