aboutsummaryrefslogtreecommitdiff
path: root/cddl/usr.sbin/dtrace/tests/tools/gentest.sh
blob: 9c34b79f547d7a689383c170d22399fd6d4df290 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# $FreeBSD$

usage()
{
    cat <<__EOF__ >&2
Generate ATF test cases from a set of DTrace tests.

usage: sh $(basename $0) [-e <excludes>] <category> [<testfiles>]

  excludes:     A shell script which defines test cases that are to be skipped,
                or aren't expected to pass.
  category:     The test category, in the form of <arch>/<feature>. For example,
                "common/aggs" is the test category for D aggregations.
  testfiles:    The test files for the tests in the specified category.
__EOF__
    exit 1
}

gentestcase()
{
    local mod tcase tfile

    tfile=$1
    tcase=$2
    mod=$3

    cat <<__EOF__
atf_test_case $tcase
${tcase}_head()
{
    atf_set 'descr' 'DTrace test ${CATEGORY}/${tfile}'
}
${tcase}_body()
{
    $mod
    atf_check -s exit:0 -o empty -e empty \\
        "\$(atf_get_srcdir)/../../dtest" "\$(atf_get_srcdir)/${tfile}"
}
__EOF__
}

gentestcases()
{
    local mod tcase tfile tfiles

    eval tfiles=\$$1
    mod=$2

    for tfile in ${tfiles}; do
        case $tfile in
        drp.*.d|err.*.d|tst.*.d|*.ksh)
            # Test names need to be mangled for ATF.
            tcase=$(echo "$tfile" | tr '.-' '_')
            gentestcase "$tfile" "$tcase" "$mod"
            TCASES="$TCASES $tcase"
            ;;
        esac
    done
}

set -e

#
# Parse arguments.
#
case $1 in
-e)
    shift; EXCLUDES=$1; shift
    ;;
esac

CATEGORY=$1
shift
if ! expr "$CATEGORY" : '[^/]*/[^/]*' >/dev/null 2>&1; then
    usage
fi
FEATURE=$(basename ${CATEGORY})
ARCH=$(dirname ${CATEGORY})

#
# Remove skipped tests and expected failures from the main test list.
#
. $EXCLUDES
EXFAILS=$(echo -e "$EXFAIL" | grep "^${CATEGORY}/" | xargs basename -a)
SKIPS=$(echo -e "$SKIP" | grep "^${CATEGORY}/" | xargs basename -a)

FILELIST=$(mktemp)
trap 'rm -f $FILELIST' EXIT

echo "$@" | tr ' ' '\n' | xargs basename -a | sort > ${FILELIST}
TFILES=$(printf '%s\n%s' "$EXFAILS" "$SKIPS" | sort | comm -13 /dev/stdin $FILELIST)

#
# Generate test cases.
#
gentestcases SKIPS "atf_skip \"test may hang or cause system instability\""
gentestcases EXFAILS "atf_expect_fail \"test is known to fail\""
gentestcases TFILES

#
# Generate the test init function.
#
cat <<__EOF__
atf_init_test_cases()
{
$(for tcase in ${TCASES}; do echo "    atf_add_test_case $tcase"; done)
}
__EOF__

rm -f $FILELIST