From: Laura Nao Date: Tue, 2 Jan 2024 14:15:28 +0000 (+0100) Subject: selftests: Move KTAP bash helpers to selftests common folder X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=7c079e909b21f8f6e5d8e501c037752ff302a15e;p=linux.git selftests: Move KTAP bash helpers to selftests common folder Move bash helpers for outputting in KTAP format to the common selftests folder. This allows kselftests other than the dt one to source the file and make use of the helper functions. Define pass, fail and skip codes in the same file too. Signed-off-by: Laura Nao Reviewed-by: NĂ­colas F. R. A. Prado Tested-by: NĂ­colas F. R. A. Prado Acked-by: Rob Herring Signed-off-by: Shuah Khan --- diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index 15b6a111c3bea..c5b4574045b30 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -236,6 +236,7 @@ ifdef INSTALL_PATH install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/ install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/ install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/ + install -m 744 kselftest/ktap_helpers.sh $(INSTALL_PATH)/kselftest/ install -m 744 run_kselftest.sh $(INSTALL_PATH)/ rm -f $(TEST_LIST) @ret=1; \ diff --git a/tools/testing/selftests/dt/Makefile b/tools/testing/selftests/dt/Makefile index 62dc00ee4978a..2d33ee9e9b71a 100644 --- a/tools/testing/selftests/dt/Makefile +++ b/tools/testing/selftests/dt/Makefile @@ -4,7 +4,7 @@ ifneq ($(PY3),) TEST_PROGS := test_unprobed_devices.sh TEST_GEN_FILES := compatible_list -TEST_FILES := compatible_ignore_list ktap_helpers.sh +TEST_FILES := compatible_ignore_list include ../lib.mk diff --git a/tools/testing/selftests/dt/ktap_helpers.sh b/tools/testing/selftests/dt/ktap_helpers.sh deleted file mode 100644 index 8dfae51bb4e2e..0000000000000 --- a/tools/testing/selftests/dt/ktap_helpers.sh +++ /dev/null @@ -1,70 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -# -# Copyright (c) 2023 Collabora Ltd -# -# Helpers for outputting in KTAP format -# -KTAP_TESTNO=1 -KTAP_CNT_PASS=0 -KTAP_CNT_FAIL=0 -KTAP_CNT_SKIP=0 - -ktap_print_header() { - echo "TAP version 13" -} - -ktap_set_plan() { - num_tests="$1" - - echo "1..$num_tests" -} - -ktap_skip_all() { - echo -n "1..0 # SKIP " - echo $@ -} - -__ktap_test() { - result="$1" - description="$2" - directive="$3" # optional - - local directive_str= - [[ ! -z "$directive" ]] && directive_str="# $directive" - - echo $result $KTAP_TESTNO $description $directive_str - - KTAP_TESTNO=$((KTAP_TESTNO+1)) -} - -ktap_test_pass() { - description="$1" - - result="ok" - __ktap_test "$result" "$description" - - KTAP_CNT_PASS=$((KTAP_CNT_PASS+1)) -} - -ktap_test_skip() { - description="$1" - - result="ok" - directive="SKIP" - __ktap_test "$result" "$description" "$directive" - - KTAP_CNT_SKIP=$((KTAP_CNT_SKIP+1)) -} - -ktap_test_fail() { - description="$1" - - result="not ok" - __ktap_test "$result" "$description" - - KTAP_CNT_FAIL=$((KTAP_CNT_FAIL+1)) -} - -ktap_print_totals() { - echo "# Totals: pass:$KTAP_CNT_PASS fail:$KTAP_CNT_FAIL xfail:0 xpass:0 skip:$KTAP_CNT_SKIP error:0" -} diff --git a/tools/testing/selftests/dt/test_unprobed_devices.sh b/tools/testing/selftests/dt/test_unprobed_devices.sh index b07af2a4c4de0..f2307ee443a6d 100755 --- a/tools/testing/selftests/dt/test_unprobed_devices.sh +++ b/tools/testing/selftests/dt/test_unprobed_devices.sh @@ -15,16 +15,12 @@ DIR="$(dirname $(readlink -f "$0"))" -source "${DIR}"/ktap_helpers.sh +source "${DIR}"/../kselftest/ktap_helpers.sh PDT=/proc/device-tree/ COMPAT_LIST="${DIR}"/compatible_list IGNORE_LIST="${DIR}"/compatible_ignore_list -KSFT_PASS=0 -KSFT_FAIL=1 -KSFT_SKIP=4 - ktap_print_header if [[ ! -d "${PDT}" ]]; then diff --git a/tools/testing/selftests/kselftest/ktap_helpers.sh b/tools/testing/selftests/kselftest/ktap_helpers.sh new file mode 100644 index 0000000000000..dd79d96f3b5ac --- /dev/null +++ b/tools/testing/selftests/kselftest/ktap_helpers.sh @@ -0,0 +1,76 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (c) 2023 Collabora Ltd +# +# Helpers for outputting in KTAP format +# +KTAP_TESTNO=1 +KTAP_CNT_PASS=0 +KTAP_CNT_FAIL=0 +KTAP_CNT_SKIP=0 + +KSFT_PASS=0 +KSFT_FAIL=1 +KSFT_XFAIL=2 +KSFT_XPASS=3 +KSFT_SKIP=4 + +ktap_print_header() { + echo "TAP version 13" +} + +ktap_set_plan() { + num_tests="$1" + + echo "1..$num_tests" +} + +ktap_skip_all() { + echo -n "1..0 # SKIP " + echo $@ +} + +__ktap_test() { + result="$1" + description="$2" + directive="$3" # optional + + local directive_str= + [[ ! -z "$directive" ]] && directive_str="# $directive" + + echo $result $KTAP_TESTNO $description $directive_str + + KTAP_TESTNO=$((KTAP_TESTNO+1)) +} + +ktap_test_pass() { + description="$1" + + result="ok" + __ktap_test "$result" "$description" + + KTAP_CNT_PASS=$((KTAP_CNT_PASS+1)) +} + +ktap_test_skip() { + description="$1" + + result="ok" + directive="SKIP" + __ktap_test "$result" "$description" "$directive" + + KTAP_CNT_SKIP=$((KTAP_CNT_SKIP+1)) +} + +ktap_test_fail() { + description="$1" + + result="not ok" + __ktap_test "$result" "$description" + + KTAP_CNT_FAIL=$((KTAP_CNT_FAIL+1)) +} + +ktap_print_totals() { + echo "# Totals: pass:$KTAP_CNT_PASS fail:$KTAP_CNT_FAIL xfail:0 xpass:0 skip:$KTAP_CNT_SKIP error:0" +}