Skip to contentSkip to conversation

selftests/tpm2: Split async tests call to separate shell script runner

PATCH In review Nícolas F. R. A. Prado 3 participants 3 messages Nov 28, 2022 – Dec 8, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/tpm2: Split async tests call to separate shell script runner

When the async test case was introduced, despite being a completely independent test case, the command to run it was added to the same shell script as the smoke test case. Since a shell script implicitly returns the error code from the last run command, this effectively caused the script to only return as error code the result from the async test case, hiding the smoke test result (which could then only be seen from the python unittest logs).

Move the async test case call to its own shell script runner to avoid the aforementioned issue. This also makes the output clearer to read, since each kselftest KTAP result now matches with one python unittest report.

While at it, also make it so the async test case is skipped if /dev/tpmrm0 doesn't exist, since commit 8335adb8f9d3 ("selftests: tpm:
add async space test with noneexisting handle") added a test that relies on it.

---

 tools/testing/selftests/tpm2/Makefile      |  2 +-
 tools/testing/selftests/tpm2/test_async.sh | 10 ++++++++++
 tools/testing/selftests/tpm2/test_smoke.sh |  1 -
 3 files changed, 11 insertions(+), 2 deletions(-)
 create mode 100755 tools/testing/selftests/tpm2/test_async.sh
tools/testing/selftests/tpm2/Makefile +1 -1
index 1a5db1eb8ed5..a9bf9459fb25 100644
@@ -1,5 +1,5 @@
 # SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
 include ../lib.mk
 
-TEST_PROGS := test_smoke.sh test_space.sh
+TEST_PROGS := test_smoke.sh test_space.sh test_async.sh
 TEST_PROGS_EXTENDED := tpm2.py tpm2_tests.py
tools/testing/selftests/tpm2/test_async.sh new file +10 -0
new file mode 100755
index 000000000000..43bf5bd772fd
@@ -0,0 +1,10 @@
+#!/bin/sh
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
+
+# Kselftest framework requirement - SKIP code is 4.
+ksft_skip=4
+
+[ -e /dev/tpm0 ] || exit $ksft_skip
+[ -e /dev/tpmrm0 ] || exit $ksft_skip
+
+python3 -m unittest -v tpm2_tests.AsyncTest
tools/testing/selftests/tpm2/test_smoke.sh +0 -1
index 3e5ff29ee1dd..58af963e5b55 100755
@@ -7,4 +7,3 @@ ksft_skip=4
 [ -e /dev/tpm0 ] || exit $ksft_skip
 
 python3 -m unittest -v tpm2_tests.SmokeTest
-python3 -m unittest -v tpm2_tests.AsyncTest
Signature · 1 line
2.38.1
maintainer
#1 lore raw
Quoted 60 lines · Nícolas F. R. A. Prado

When the async test case was introduced, despite being a completely independent test case, the command to run it was added to the same shell script as the smoke test case. Since a shell script implicitly returns the error code from the last run command, this effectively caused the script to only return as error code the result from the async test case, hiding the smoke test result (which could then only be seen from the python unittest logs).

Move the async test case call to its own shell script runner to avoid the aforementioned issue. This also makes the output clearer to read, since each kselftest KTAP result now matches with one python unittest report.

While at it, also make it so the async test case is skipped if /dev/tpmrm0 doesn't exist, since commit 8335adb8f9d3 ("selftests: tpm:
add async space test with noneexisting handle") added a test that relies on it.

---

  tools/testing/selftests/tpm2/Makefile      |  2 +-
  tools/testing/selftests/tpm2/test_async.sh | 10 ++++++++++
  tools/testing/selftests/tpm2/test_smoke.sh |  1 -
  3 files changed, 11 insertions(+), 2 deletions(-)

create mode 100755 tools/testing/selftests/tpm2/test_async.sh

tools/testing/selftests/tpm2/Makefile +1 -1
index 1a5db1eb8ed5..a9bf9459fb25 100644
@@ -1,5 +1,5 @@
  # SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
  include ../lib.mk
 
-TEST_PROGS := test_smoke.sh test_space.sh
+TEST_PROGS := test_smoke.sh test_space.sh test_async.sh
  TEST_PROGS_EXTENDED := tpm2.py tpm2_tests.py
tools/testing/selftests/tpm2/test_async.sh new file +10 -0
new file mode 100755
index 000000000000..43bf5bd772fd
@@ -0,0 +1,10 @@
+#!/bin/sh
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
+
+# Kselftest framework requirement - SKIP code is 4.
+ksft_skip=4
+
+[ -e /dev/tpm0 ] || exit $ksft_skip
+[ -e /dev/tpmrm0 ] || exit $ksft_skip
+
+python3 -m unittest -v tpm2_tests.AsyncTest
tools/testing/selftests/tpm2/test_smoke.sh +0 -0
index 3e5ff29ee1dd..58af963e5b55 100755

tools/testing/selftests/tpm2/test_smoke.sh ksft_skip=4 · line 10

Quoted 4 lines
tools/testing/selftests/tpm2/test_smoke.sh +0 -1
@@ -7,4 +7,3 @@ ksft_skip=4
  [ -e /dev/tpm0 ] || exit $ksft_skip
 
  python3 -m unittest -v tpm2_tests.SmokeTest
-python3 -m unittest -v tpm2_tests.AsyncTest

Thank you for fixing the problem. Applied to linux-kselftest next for Linux 6.2-rc1

thanks,
-- Shuah

maintainer Tested-by Reviewed-by on v1 1/1
#2 lore raw
In reply to Nícolas F. R. A. Prado
Quoted 13 lines · Nícolas F. R. A. Prado

When the async test case was introduced, despite being a completely independent test case, the command to run it was added to the same shell script as the smoke test case. Since a shell script implicitly returns the error code from the last run command, this effectively caused the script to only return as error code the result from the async test case, hiding the smoke test result (which could then only be seen from the python unittest logs).

Move the async test case call to its own shell script runner to avoid the aforementioned issue. This also makes the output clearer to read, since each kselftest KTAP result now matches with one python unittest report.

Quoted 6 lines

While at it, also make it so the async test case is skipped if /dev/tpmrm0 doesn't exist, since commit 8335adb8f9d3 ("selftests: tpm:
add async space test with noneexisting handle") added a test that relies on it.

[nix-shell:~/linux-tpmdd]$ sudo make -C tools/testing/selftests TARGETS=tpm2 run_tests
make: Entering directory '/home/nixos/linux-tpmdd/tools/testing/selftests'
make[1]: Entering directory '/home/nixos/linux-tpmdd/tools/testing/selftests/tpm2'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/nixos/linux-tpmdd/tools/testing/selftests/tpm2'
make[1]: Entering directory '/home/nixos/linux-tpmdd/tools/testing/selftests/tpm2'
TAP version 13
1..3
# selftests: tpm2: test_smoke.sh
# test_read_partial_overwrite (tpm2_tests.SmokeTest) ... ok
# test_read_partial_resp (tpm2_tests.SmokeTest) ... ok
# test_seal_with_auth (tpm2_tests.SmokeTest) ... ok
# test_seal_with_policy (tpm2_tests.SmokeTest) ... ok
# test_seal_with_too_long_auth (tpm2_tests.SmokeTest) ... ok
# test_send_two_cmds (tpm2_tests.SmokeTest) ... ok
# test_too_short_cmd (tpm2_tests.SmokeTest) ... ok
# test_unseal_with_wrong_auth (tpm2_tests.SmokeTest) ... ok
# test_unseal_with_wrong_policy (tpm2_tests.SmokeTest) ... ok
#
# ----------------------------------------------------------------------
# Ran 9 tests in 82.385s
#
# OK
ok 1 selftests: tpm2: test_smoke.sh
# selftests: tpm2: test_space.sh
# test_flush_context (tpm2_tests.SpaceTest) ... ok
# test_get_handles (tpm2_tests.SpaceTest) ... ok
# test_invalid_cc (tpm2_tests.SpaceTest) ... ok
# test_make_two_spaces (tpm2_tests.SpaceTest) ... ok
#
# ----------------------------------------------------------------------
# Ran 4 tests in 73.287s
#
# OK
ok 2 selftests: tpm2: test_space.sh
# selftests: tpm2: test_async.sh
# test_async (tpm2_tests.AsyncTest) ... ok
# test_flush_invalid_context (tpm2_tests.AsyncTest) ... ok
#
# ----------------------------------------------------------------------
# Ran 2 tests in 0.018s
#
# OK
ok 3 selftests: tpm2: test_async.sh
make[1]: Leaving directory '/home/nixos/linux-tpmdd/tools/testing/selftests/tpm2'
make: Leaving directory '/home/nixos/linux-tpmdd/tools/testing/selftests'
[nix-shell:~/linux-tpmdd]$ lsmod|grep tpm
tpm_crb                20480  0
tpm_tis                16384  0
tpm_tis_core           32768  1 tpm_tis
tpm                    94208  3 tpm_tis,tpm_crb,tpm_tis_core
rng_core               20480  1 tpm

LGTM, thanks!

BR, Jarkko