1# $FreeBSD$ 2 3usage() 4{ 5 cat <<__EOF__ >&2 6Generate ATF test cases from a set of DTrace tests. 7 8usage: sh $(basename $0) [-e <excludes>] <category> [<testfiles>] 9 10 excludes: A shell script which defines test cases that are to be skipped, 11 or aren't expected to pass. 12 category: The test category, in the form of <arch>/<feature>. For example, 13 "common/aggs" is the test category for D aggregations. 14 testfiles: The test files for the tests in the specified category. 15__EOF__ 16 exit 1 17} 18 19gentestcase() 20{ 21 local mod tcase tfile 22 23 tfile=$1 24 tcase=$2 25 mod=$3 26 27 cat <<__EOF__ 28atf_test_case $tcase 29${tcase}_head() 30{ 31 atf_set 'descr' 'DTrace test ${CATEGORY}/${tfile}' 32} 33${tcase}_body() 34{ 35 $mod 36 atf_check -s exit:0 -o empty -e empty \\ 37 "\$(atf_get_srcdir)/../../dtest" "\$(atf_get_srcdir)/${tfile}" 38} 39__EOF__ 40} 41 42gentestcases() 43{ 44 local mod tcase tfile tfiles 45 46 eval tfiles=\$$1 47 mod=$2 48 49 for tfile in ${tfiles}; do 50 case $tfile in 51 drp.*.d|err.*.d|tst.*.d|*.ksh) 52 # Test names need to be mangled for ATF. 53 tcase=$(echo "$tfile" | tr '.-' '_') 54 gentestcase "$tfile" "$tcase" "$mod" 55 TCASES="$TCASES $tcase" 56 ;; 57 esac 58 done 59} 60 61set -e 62 63# 64# Parse arguments. 65# 66case $1 in 67-e) 68 shift; EXCLUDES=$1; shift 69 ;; 70esac 71 72CATEGORY=$1 73shift 74if ! expr "$CATEGORY" : '[^/]*/[^/]*' >/dev/null 2>&1; then 75 usage 76fi 77FEATURE=$(basename ${CATEGORY}) 78ARCH=$(dirname ${CATEGORY}) 79 80# 81# Remove skipped tests and expected failures from the main test list. 82# 83. $EXCLUDES 84EXFAILS=$(echo -e "$EXFAIL" | grep "^${CATEGORY}/" | xargs basename -a) 85SKIPS=$(echo -e "$SKIP" | grep "^${CATEGORY}/" | xargs basename -a) 86SKIPCIS=$(echo -e "$SKIPCI" | grep "^${CATEGORY}/" | xargs basename -a) 87 88FILELIST=$(mktemp) 89trap 'rm -f $FILELIST' EXIT 90 91echo "$@" | tr ' ' '\n' | xargs basename -a | sort > ${FILELIST} 92TFILES=$(printf '%s\n%s' "$EXFAILS" "$SKIPS" "$SKIPCIS" | sort | comm -13 /dev/stdin $FILELIST) 93 94# 95# Generate test cases. 96# 97gentestcases SKIPS "atf_skip \"test may hang or cause system instability\"" 98gentestcases EXFAILS "atf_expect_fail \"test is known to fail\"" 99gentestcases SKIPCIS "if [ \"\$(atf_config_get ci false)\" = \"true\" ]; then atf_skip \"see cddl/usr.sbin/dtrace/tests/tools/exclude.sh\"; fi" 100gentestcases TFILES 101 102# 103# Generate the test init function. 104# 105cat <<__EOF__ 106atf_init_test_cases() 107{ 108$(for tcase in ${TCASES}; do echo " atf_add_test_case $tcase"; done) 109} 110__EOF__ 111 112rm -f $FILELIST 113