Path: blob/main/cddl/usr.sbin/dtrace/tests/tools/gentest.sh
107108 views
1usage()2{3cat <<__EOF__ >&24Generate ATF test cases from a set of DTrace tests.56usage: sh $(basename $0) [-e <excludes>] <category> [<testfiles>]78excludes: A shell script which defines test cases that are to be skipped,9or aren't expected to pass.10category: The test category, in the form of <arch>/<feature>. For example,11"common/aggs" is the test category for D aggregations.12testfiles: The test files for the tests in the specified category.13__EOF__14exit 115}1617gentestcase()18{19local mod tcase tfile2021tfile=$122tcase=$223mod=$32425cat <<__EOF__26atf_test_case $tcase27${tcase}_head()28{29atf_set 'descr' 'DTrace test ${CATEGORY}/${tfile}'30}31${tcase}_body()32{33$mod34atf_check -s exit:0 -o empty -e empty \\35"\$(atf_get_srcdir)/../../dtest" "\$(atf_get_srcdir)/${tfile}"36}37__EOF__38}3940gentestcases()41{42local mod tcase tfile tfiles4344eval tfiles=\$$145mod=$24647for tfile in ${tfiles}; do48case $tfile in49drp.*.d|err.*.d|tst.*.d|*.ksh)50# Test names need to be mangled for ATF.51tcase=$(echo "$tfile" | tr '.-' '_')52gentestcase "$tfile" "$tcase" "$mod"53TCASES="$TCASES $tcase"54;;55esac56done57}5859set -e6061#62# Parse arguments.63#64case $1 in65-e)66shift; EXCLUDES=$1; shift67;;68esac6970CATEGORY=$171shift72if ! expr "$CATEGORY" : '[^/]*/[^/]*' >/dev/null 2>&1; then73usage74fi75FEATURE=$(basename ${CATEGORY})76ARCH=$(dirname ${CATEGORY})7778#79# Remove skipped tests and expected failures from the main test list.80#81. $EXCLUDES82EXFAILS=$(echo -e "$EXFAIL" | grep "^${CATEGORY}/" | xargs basename -a)83SKIPS=$(echo -e "$SKIP" | grep "^${CATEGORY}/" | xargs basename -a)84SKIPCIS=$(echo -e "$SKIPCI" | grep "^${CATEGORY}/" | xargs basename -a)8586FILELIST=$(mktemp)87trap 'rm -f $FILELIST' EXIT8889echo "$@" | tr ' ' '\n' | xargs basename -a | sort > ${FILELIST}90TFILES=$(printf '%s\n%s' "$EXFAILS" "$SKIPS" "$SKIPCIS" | sort | comm -13 /dev/stdin $FILELIST)9192#93# Generate test cases.94#95gentestcases SKIPS "atf_skip \"test may hang or cause system instability\""96gentestcases EXFAILS "atf_expect_fail \"test is known to fail\""97gentestcases SKIPCIS "if [ \"\$(atf_config_get ci false)\" = \"true\" ]; then atf_skip \"see cddl/usr.sbin/dtrace/tests/tools/exclude.sh\"; fi"98gentestcases TFILES99100#101# Generate the test init function.102#103cat <<__EOF__104atf_init_test_cases()105{106$(for tcase in ${TCASES}; do echo " atf_add_test_case $tcase"; done)107}108__EOF__109110rm -f $FILELIST111112113