Linux Kernel Selftest development
 help / color / mirror / Atom feed
* [PATCH] selftests: tpm2: conform test to TAP output
@ 2024-04-26  9:14 Muhammad Usama Anjum
  2024-05-28  5:05 ` Muhammad Usama Anjum
  0 siblings, 1 reply; 9+ messages in thread
From: Muhammad Usama Anjum @ 2024-04-26  9:14 UTC (permalink / raw)
  To: Shuah Khan, Muhammad Usama Anjum; +Cc: kernel, linux-kselftest, linux-kernel

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@collabora.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


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] selftests: tpm2: conform test to TAP output
  2024-04-26  9:14 Muhammad Usama Anjum
@ 2024-05-28  5:05 ` Muhammad Usama Anjum
  2024-07-01  8:40   ` Muhammad Usama Anjum
  0 siblings, 1 reply; 9+ messages in thread
From: Muhammad Usama Anjum @ 2024-05-28  5:05 UTC (permalink / raw)
  To: Shuah Khan; +Cc: Muhammad Usama Anjum, kernel, linux-kselftest, linux-kernel

Kind reminder

On 4/26/24 2:14 PM, Muhammad Usama Anjum wrote:
> 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@collabora.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

-- 
BR,
Muhammad Usama Anjum

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] selftests: tpm2: conform test to TAP output
  2024-05-28  5:05 ` Muhammad Usama Anjum
@ 2024-07-01  8:40   ` Muhammad Usama Anjum
  2024-07-01 15:24     ` Jarkko Sakkinen
  0 siblings, 1 reply; 9+ messages in thread
From: Muhammad Usama Anjum @ 2024-07-01  8:40 UTC (permalink / raw)
  To: Jarkko Sakkinen
  Cc: Muhammad Usama Anjum, kernel, linux-kselftest, linux-kernel,
	Shuah Khan

Adding Jarkko

On 5/28/24 10:05 AM, Muhammad Usama Anjum wrote:
> Kind reminder
> 
> On 4/26/24 2:14 PM, Muhammad Usama Anjum wrote:
>> 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@collabora.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
> 

-- 
BR,
Muhammad Usama Anjum

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] selftests: tpm2: conform test to TAP output
  2024-07-01  8:40   ` Muhammad Usama Anjum
@ 2024-07-01 15:24     ` Jarkko Sakkinen
  0 siblings, 0 replies; 9+ messages in thread
From: Jarkko Sakkinen @ 2024-07-01 15:24 UTC (permalink / raw)
  To: Muhammad Usama Anjum; +Cc: kernel, linux-kselftest, linux-kernel, Shuah Khan

On Mon, 2024-07-01 at 13:40 +0500, Muhammad Usama Anjum wrote:
> Adding Jarkko
> 
> On 5/28/24 10:05 AM, Muhammad Usama Anjum wrote:
> > Kind reminder
> > 
> > On 4/26/24 2:14 PM, Muhammad Usama Anjum wrote:
> > > 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@collabora.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
> > 
> 

Cc me to the next patch version.

BR, Jarkko

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH] selftests: tpm2: conform test to TAP output
@ 2024-07-02  6:55 Muhammad Usama Anjum
  2024-07-02 10:13 ` Muhammad Usama Anjum
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Muhammad Usama Anjum @ 2024-07-02  6:55 UTC (permalink / raw)
  To: Jarkko Sakkinen, Shuah Khan, Muhammad Usama Anjum
  Cc: kernel, linux-kselftest, linux-kernel

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 <jarkko@kernel.org>
Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
---
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(-)

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


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] selftests: tpm2: conform test to TAP output
  2024-07-02  6:55 [PATCH] selftests: tpm2: conform test to TAP output Muhammad Usama Anjum
@ 2024-07-02 10:13 ` Muhammad Usama Anjum
  2024-07-02 23:50 ` Jarkko Sakkinen
  2024-07-09 23:36 ` Shuah Khan
  2 siblings, 0 replies; 9+ messages in thread
From: Muhammad Usama Anjum @ 2024-07-02 10:13 UTC (permalink / raw)
  To: Jarkko Sakkinen, Shuah Khan
  Cc: Muhammad Usama Anjum, kernel, linux-kselftest, linux-kernel

This is PATCH v2. I missed updating the version number in the subject.

On 7/2/24 11:55 AM, Muhammad Usama Anjum wrote:
> 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 <jarkko@kernel.org>
> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
> ---
> 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(-)
> 
> 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

-- 
BR,
Muhammad Usama Anjum

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] selftests: tpm2: conform test to TAP output
  2024-07-02  6:55 [PATCH] selftests: tpm2: conform test to TAP output Muhammad Usama Anjum
  2024-07-02 10:13 ` Muhammad Usama Anjum
@ 2024-07-02 23:50 ` Jarkko Sakkinen
  2024-07-09 23:36 ` Shuah Khan
  2 siblings, 0 replies; 9+ messages in thread
From: Jarkko Sakkinen @ 2024-07-02 23:50 UTC (permalink / raw)
  To: Muhammad Usama Anjum, Shuah Khan; +Cc: kernel, linux-kselftest, linux-kernel

On Tue, 2024-07-02 at 11:55 +0500, Muhammad Usama Anjum wrote:
> 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 <jarkko@kernel.org>
> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
> ---
> 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(-)
> 
> 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

Acknowledging that I noticed this but won't test
before week 31, when I'm back from holiday.

BR, Jarkko


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] selftests: tpm2: conform test to TAP output
  2024-07-02  6:55 [PATCH] selftests: tpm2: conform test to TAP output Muhammad Usama Anjum
  2024-07-02 10:13 ` Muhammad Usama Anjum
  2024-07-02 23:50 ` Jarkko Sakkinen
@ 2024-07-09 23:36 ` Shuah Khan
  2024-07-10  7:58   ` Muhammad Usama Anjum
  2 siblings, 1 reply; 9+ messages in thread
From: Shuah Khan @ 2024-07-09 23:36 UTC (permalink / raw)
  To: Muhammad Usama Anjum, Jarkko Sakkinen, Shuah Khan
  Cc: kernel, linux-kselftest, linux-kernel, Shuah Khan

On 7/2/24 00:55, Muhammad Usama Anjum wrote:
> 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 <jarkko@kernel.org>
> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
> ---
> 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(-)
> 
> 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

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




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] selftests: tpm2: conform test to TAP output
  2024-07-09 23:36 ` Shuah Khan
@ 2024-07-10  7:58   ` Muhammad Usama Anjum
  0 siblings, 0 replies; 9+ messages in thread
From: Muhammad Usama Anjum @ 2024-07-10  7:58 UTC (permalink / raw)
  To: Shuah Khan, Jarkko Sakkinen, Shuah Khan
  Cc: Muhammad Usama Anjum, kernel, linux-kselftest, linux-kernel

Hi Shuah,

On 7/10/24 4:36 AM, Shuah Khan wrote:
> On 7/2/24 00:55, Muhammad Usama Anjum wrote:
>> 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 <jarkko@kernel.org>
>> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
>> ---
>> 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(-)
>>
>> 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
> 
> 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
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.

> 
> thanks,
> -- Shuah
> 
> 
> 
> 

-- 
BR,
Muhammad Usama Anjum

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-07-10  8:06 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-02  6:55 [PATCH] selftests: tpm2: conform test to TAP output Muhammad Usama Anjum
2024-07-02 10:13 ` Muhammad Usama Anjum
2024-07-02 23:50 ` Jarkko Sakkinen
2024-07-09 23:36 ` Shuah Khan
2024-07-10  7:58   ` Muhammad Usama Anjum
  -- strict thread matches above, loose matches on Subject: below --
2024-04-26  9:14 Muhammad Usama Anjum
2024-05-28  5:05 ` Muhammad Usama Anjum
2024-07-01  8:40   ` Muhammad Usama Anjum
2024-07-01 15:24     ` Jarkko Sakkinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox