selftests: tpm2: conform test to TAP output
Subsystems (2)
PATCH 1/1 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.
---
Changes since v1:
- CC more people which were missing earlier
--- 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(-)
tools/testing/selftests/tpm2/test_async.sh +18 -6
@@ -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
tools/testing/selftests/tpm2/test_smoke.sh +16 -3
@@ -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
tools/testing/selftests/tpm2/test_space.sh +16 -3
@@ -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
Signature · 1 line
2.39.2
This is PATCH v2. I missed updating the version number in the subject.
Quoted 117 lines · Muhammad Usama Anjum
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.
Cc Jarkko Sakkinen <[email protected]>Signed-off-by Muhammad Usama Anjum <[email protected]>---
Changes since v1:
- CC more people which were missing earlier--- 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(-)tools/testing/selftests/tpm2/test_async.sh +18
-6@@ -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_finishedtools/testing/selftests/tpm2/test_smoke.sh +16
-3@@ -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_finishedtools/testing/selftests/tpm2/test_space.sh +16
-3@@ -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
Signature · 2 lines
BR, Muhammad Usama Anjum
Jarkko Sakkinen
maintainerQuoted 110 lines · Muhammad Usama Anjum
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.
Cc Jarkko Sakkinen <[email protected]>Signed-off-by Muhammad Usama Anjum <[email protected]>---
Changes since v1:
- CC more people which were missing earlier
---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(-)tools/testing/selftests/tpm2/test_async.sh +1
-1@@ -1,10 +1,22 @@ -#!/bin/sh +#!/bin/bash # SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)tools/testing/selftests/tpm2/test_async.sh +2
-2-# 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_headertools/testing/selftests/tpm2/test_async.sh +14
-1-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_finishedtools/testing/selftests/tpm2/test_smoke.sh +1
-1@@ -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.tools/testing/selftests/tpm2/test_smoke.sh +4
-1-ksft_skip=4 +DIR="$(dirname $(readlink -f "$0"))" +source "${DIR}"/../kselftest/ktap_helpers.sh + +ktap_print_header
[ -e/dev/tpm0] || exit $ksft_skiptools/testing/selftests/tpm2/test_smoke.sh +11
-1-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_finishedtools/testing/selftests/tpm2/test_space.sh +1
-1@@ -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.tools/testing/selftests/tpm2/test_space.sh +4
-1-ksft_skip=4 +DIR="$(dirname $(readlink -f "$0"))" +source "${DIR}"/../kselftest/ktap_helpers.sh + +ktap_print_header
[ -e/dev/tpmrm0] || exit $ksft_skiptools/testing/selftests/tpm2/test_space.sh +1
-1-python3 -m unittest -v tpm2_tests.SpaceTest +ktap_set_plan 1
tools/testing/selftests/tpm2/test_space.sh line 22
Quoted 10 lines
tools/testing/selftests/tpm2/test_space.sh +10
-0+ +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
Acknowledging that I noticed this but won't test
before week 31, when I'm back from holiday.
BR, Jarkko
Shuah Khan
maintainerQuoted 107 lines · Muhammad Usama Anjum
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.
Cc Jarkko Sakkinen <[email protected]>Signed-off-by Muhammad Usama Anjum <[email protected]>---
Changes since v1:
- CC more people which were missing earlier--- 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(-)tools/testing/selftests/tpm2/test_async.sh +18
-6@@ -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_finishedtools/testing/selftests/tpm2/test_smoke.sh +16
-3@@ -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_finishedtools/testing/selftests/tpm2/test_space.sh +6
-3@@ -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
tools/testing/selftests/tpm2/test_space.sh line 22
Quoted 10 lines
tools/testing/selftests/tpm2/test_space.sh +10
-0+ +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
Usama,
As I mentioned another TAP conversion patch from you patch if the following command gives you TAP, there is no need to convert.
make -C tools/testing/tmp2 run_tests
make kselftest TARGETS=tmp2
kselftest framework lib.mk and runtests wrappers take care for TAP. The reason to take care of this at framework level is to avoid changes to individual tests. The wrapper keys off of KSFT_* codes returned from tests.
Please don't send TAP conversion patches like this one. The output from the commands will have duplicate messages. The reason tests return
make -C tools/testing/tmp2 run_tests
make kselftest TARGETS=tmp2
thanks,
-- Shuah
Hi Shuah,
Quoted 126 lines · Shuah Khan
Quoted 101 lines · Muhammad Usama Anjum
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.
Cc Jarkko Sakkinen <[email protected]>Signed-off-by Muhammad Usama Anjum <[email protected]>---
Changes since v1:
- CC more people which were missing earlier
---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(-)tools/testing/selftests/tpm2/test_async.sh +1
-1@@ -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.
tools/testing/selftests/tpm2/test_async.sh +2
-1-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_finishedtools/testing/selftests/tpm2/test_async.sh +12
-0+ +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_finishedtools/testing/selftests/tpm2/test_smoke.sh +5
-2@@ -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.SmokeTesttools/testing/selftests/tpm2/test_smoke.sh +11
-0+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_finishedtools/testing/selftests/tpm2/test_space.sh +5
-2@@ -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.SpaceTesttools/testing/selftests/tpm2/test_space.sh +1
-0+ktap_set_plan 1tools/testing/selftests/tpm2/test_space.sh line 22
Quoted 10 lines
tools/testing/selftests/tpm2/test_space.sh +10
-0+ +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_finishedUsama,
As I mentioned another TAP conversion patch from you patch if the following command gives you TAP, there is no need to convert.
make -C
tools/testing/tmp2run_tests
make kselftest TARGETS=tmp2kselftest framework lib.mk and runtests wrappers take care for TAP. The reason to take care of this at framework level is to avoid changes to individual tests. The wrapper keys off of KSFT_* codes returned from tests.
Quoted 6 lines
Please don't send TAP conversion patches like this one. The output from the commands will have duplicate messages. The reason tests return
make -C
tools/testing/tmp2run_tests
make kselftest TARGETS=tmp2
It is understandable. Thank you for clearing this about TAP conformance. I've been looking at individual test conformance.
This patch has some fixes. I'll send them as new patch series after removing TAP conformance changes.
Quoted 7 lines
thanks,
-- Shuah
Signature · 2 lines
BR, Muhammad Usama Anjum