selftests: ktap_helpers: Add helper to pass/fail test based on exit code
authorNícolas F. R. A. Prado <nfraprado@collabora.com>
Wed, 31 Jan 2024 22:02:41 +0000 (17:02 -0500)
committerShuah Khan <skhan@linuxfoundation.org>
Tue, 20 Feb 2024 22:53:08 +0000 (15:53 -0700)
Similar to the C counterpart, add a helper function that runs a command
and passes or fails the test based on the result.

Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
tools/testing/selftests/kselftest/ktap_helpers.sh

index ecc1413c22cdfd258ed8ae8cadf0c617ee7c5834..29107924f5c2013b599bec70b6340e723f6b44e2 100644 (file)
@@ -76,6 +76,17 @@ ktap_test_fail() {
        KTAP_CNT_FAIL=$((KTAP_CNT_FAIL+1))
 }
 
+ktap_test_result() {
+       description="$1"
+       shift
+
+       if $@; then
+               ktap_test_pass "$description"
+       else
+               ktap_test_fail "$description"
+       fi
+}
+
 ktap_print_totals() {
        echo "# Totals: pass:$KTAP_CNT_PASS fail:$KTAP_CNT_FAIL xfail:0 xpass:0 skip:$KTAP_CNT_SKIP error:0"
 }