lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240426091435.2742024-1-usama.anjum@collabora.com>
Date: Fri, 26 Apr 2024 14:14:31 +0500
From: Muhammad Usama Anjum <usama.anjum@...labora.com>
To: Shuah Khan <shuah@...nel.org>,
	Muhammad Usama Anjum <usama.anjum@...labora.com>
Cc: kernel@...labora.com,
	linux-kselftest@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: [PATCH] selftests: tpm2: conform test to TAP output

The python unittest is being used for executing tests. TAP output
cannot be added in the unittest framework. The python unittest is being
run from a script. Add the output TAP logs to the script. Add "#"
prefix to the python unittest output which will mark all output as
informational TAP messages. Check exit status of the python unittest to
decide if test passed or failed. Not sure why but python unittest
outputs logs in stderr. So redirect the logs to stdout and then add
prefix.

Specify the bash explicitly instead of sh to run these tests as all of
the kselftests are shifting towards using bash explicitly. Some
interpreters have different syntax and cause issues.

Signed-off-by: Muhammad Usama Anjum <usama.anjum@...labora.com>
---
 tools/testing/selftests/tpm2/test_async.sh | 24 ++++++++++++++++------
 tools/testing/selftests/tpm2/test_smoke.sh | 19 ++++++++++++++---
 tools/testing/selftests/tpm2/test_space.sh | 19 ++++++++++++++---
 3 files changed, 50 insertions(+), 12 deletions(-)

diff --git a/tools/testing/selftests/tpm2/test_async.sh b/tools/testing/selftests/tpm2/test_async.sh
index 43bf5bd772fd4..0e6e5d9d649fb 100755
--- a/tools/testing/selftests/tpm2/test_async.sh
+++ b/tools/testing/selftests/tpm2/test_async.sh
@@ -1,10 +1,22 @@
-#!/bin/sh
+#!/bin/bash
 # SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
 
-# Kselftest framework requirement - SKIP code is 4.
-ksft_skip=4
+DIR="$(dirname $(readlink -f "$0"))"
+source "${DIR}"/../kselftest/ktap_helpers.sh
 
-[ -e /dev/tpm0 ] || exit $ksft_skip
-[ -e /dev/tpmrm0 ] || exit $ksft_skip
+ktap_print_header
 
-python3 -m unittest -v tpm2_tests.AsyncTest
+[ -e /dev/tpm0 ] || ktap_finished
+[ -e /dev/tpmrm0 ] || ktap_finished
+
+ktap_set_plan 1
+
+python3 -m unittest -v tpm2_tests.AsyncTest 2>&1 | sed "s/^/# /"
+
+if [ ${PIPESTATUS[0]} -eq $ksft_pass ]; then
+	ktap_test_pass "tpm2_tests.AsyncTest"
+else
+	ktap_test_fail "tpm2_tests.AsyncTest"
+fi
+
+ktap_finished
diff --git a/tools/testing/selftests/tpm2/test_smoke.sh b/tools/testing/selftests/tpm2/test_smoke.sh
index 58af963e5b55a..2219a180de91d 100755
--- a/tools/testing/selftests/tpm2/test_smoke.sh
+++ b/tools/testing/selftests/tpm2/test_smoke.sh
@@ -1,9 +1,22 @@
-#!/bin/sh
+#!/bin/bash
 # SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
 
 # Kselftest framework requirement - SKIP code is 4.
-ksft_skip=4
+DIR="$(dirname $(readlink -f "$0"))"
+source "${DIR}"/../kselftest/ktap_helpers.sh
+
+ktap_print_header
 
 [ -e /dev/tpm0 ] || exit $ksft_skip
 
-python3 -m unittest -v tpm2_tests.SmokeTest
+ktap_set_plan 1
+
+python3 -m unittest -v tpm2_tests.SmokeTest 2>&1 | sed "s/^/# /"
+
+if [ ${PIPESTATUS[0]} -eq $ksft_pass ]; then
+	ktap_test_pass "tpm2_tests.AsyncTest"
+else
+	ktap_test_fail "tpm2_tests.AsyncTest"
+fi
+
+ktap_finished
diff --git a/tools/testing/selftests/tpm2/test_space.sh b/tools/testing/selftests/tpm2/test_space.sh
index 04c47b13fe8ac..6a55d13d74983 100755
--- a/tools/testing/selftests/tpm2/test_space.sh
+++ b/tools/testing/selftests/tpm2/test_space.sh
@@ -1,9 +1,22 @@
-#!/bin/sh
+#!/bin/bash
 # SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
 
 # Kselftest framework requirement - SKIP code is 4.
-ksft_skip=4
+DIR="$(dirname $(readlink -f "$0"))"
+source "${DIR}"/../kselftest/ktap_helpers.sh
+
+ktap_print_header
 
 [ -e /dev/tpmrm0 ] || exit $ksft_skip
 
-python3 -m unittest -v tpm2_tests.SpaceTest
+ktap_set_plan 1
+
+python3 -m unittest -v tpm2_tests.SpaceTest 2>&1 | sed "s/^/# /"
+
+if [ ${PIPESTATUS[0]} -eq $ksft_pass ]; then
+	ktap_test_pass "tpm2_tests.AsyncTest"
+else
+	ktap_test_fail "tpm2_tests.AsyncTest"
+fi
+
+ktap_finished
-- 
2.39.2


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ