]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - cddl/usr.sbin/dtrace/tests/tools/gentest.sh
MFC r277912,r278738,r279418,r280835,r288416:
[FreeBSD/stable/10.git] / cddl / usr.sbin / dtrace / tests / tools / gentest.sh
1 # $FreeBSD$
2
3 usage()
4 {
5     cat <<__EOF__ >&2
6 Generate ATF test cases from a set of DTrace tests.
7
8 usage: 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
19 gentestcase()
20 {
21     local mod tcase tfile
22
23     tfile=$1
24     tcase=$2
25     mod=$3
26
27     cat <<__EOF__
28 atf_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
42 gentestcases()
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
61 set -e
62
63 #
64 # Parse arguments.
65 #
66 case $1 in
67 -e)
68     shift; EXCLUDES=$1; shift
69     ;;
70 esac
71
72 CATEGORY=$1
73 shift
74 if ! expr "$CATEGORY" : '[^/]*/[^/]*' >/dev/null 2>&1; then
75     usage
76 fi
77 FEATURE=$(basename ${CATEGORY})
78 ARCH=$(dirname ${CATEGORY})
79
80 #
81 # Remove skipped tests and expected failures from the main test list.
82 #
83 . $EXCLUDES
84 EXFAILS=$(echo -e "$EXFAIL" | grep "^${CATEGORY}/" | xargs basename -a)
85 SKIPS=$(echo -e "$SKIP" | grep "^${CATEGORY}/" | xargs basename -a)
86
87 FILELIST=$(mktemp)
88 trap 'rm -f $FILELIST' EXIT
89
90 echo "$@" | tr ' ' '\n' | xargs basename -a | sort > ${FILELIST}
91 TFILES=$(printf '%s\n%s' "$EXFAILS" "$SKIPS" | sort | comm -13 /dev/stdin $FILELIST)
92
93 #
94 # Generate test cases.
95 #
96 gentestcases SKIPS "atf_skip \"test may hang or cause system instability\""
97 gentestcases EXFAILS "atf_expect_fail \"test is known to fail\""
98 gentestcases TFILES
99
100 #
101 # Generate the test init function.
102 #
103 cat <<__EOF__
104 atf_init_test_cases()
105 {
106 $(for tcase in ${TCASES}; do echo "    atf_add_test_case $tcase"; done)
107 }
108 __EOF__
109
110 rm -f $FILELIST