Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/cddl/usr.sbin/dtrace/tests/tools/gentest.sh
107108 views
1
2
usage()
3
{
4
cat <<__EOF__ >&2
5
Generate ATF test cases from a set of DTrace tests.
6
7
usage: 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
18
gentestcase()
19
{
20
local mod tcase tfile
21
22
tfile=$1
23
tcase=$2
24
mod=$3
25
26
cat <<__EOF__
27
atf_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
41
gentestcases()
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
60
set -e
61
62
#
63
# Parse arguments.
64
#
65
case $1 in
66
-e)
67
shift; EXCLUDES=$1; shift
68
;;
69
esac
70
71
CATEGORY=$1
72
shift
73
if ! expr "$CATEGORY" : '[^/]*/[^/]*' >/dev/null 2>&1; then
74
usage
75
fi
76
FEATURE=$(basename ${CATEGORY})
77
ARCH=$(dirname ${CATEGORY})
78
79
#
80
# Remove skipped tests and expected failures from the main test list.
81
#
82
. $EXCLUDES
83
EXFAILS=$(echo -e "$EXFAIL" | grep "^${CATEGORY}/" | xargs basename -a)
84
SKIPS=$(echo -e "$SKIP" | grep "^${CATEGORY}/" | xargs basename -a)
85
SKIPCIS=$(echo -e "$SKIPCI" | 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" "$SKIPCIS" | 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 SKIPCIS "if [ \"\$(atf_config_get ci false)\" = \"true\" ]; then atf_skip \"see cddl/usr.sbin/dtrace/tests/tools/exclude.sh\"; fi"
99
gentestcases TFILES
100
101
#
102
# Generate the test init function.
103
#
104
cat <<__EOF__
105
atf_init_test_cases()
106
{
107
$(for tcase in ${TCASES}; do echo " atf_add_test_case $tcase"; done)
108
}
109
__EOF__
110
111
rm -f $FILELIST
112
113