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