Linux Kernel Selftest development
 help / color / mirror / Atom feed
* [PATCH] selftests/tpm2: tpm2-parse-error.py
@ 2023-08-19 16:21 Jarkko Sakkinen
  0 siblings, 0 replies; 2+ messages in thread
From: Jarkko Sakkinen @ 2023-08-19 16:21 UTC (permalink / raw)
  To: Shuah Khan
  Cc: Jarkko Sakkinen, Nícolas F. R. A. Prado, open list,
	open list:KERNEL SELFTEST FRAMEWORK

Add a script to quickly parse any TPM error code. This can be useful, e.g.
when parsing klog output when TPM fails in an internal kernel operation.

Example transcript:

$ python3 tpm2-parse-error.py 0x1C4
TPM_RC_VALUE: rc=0x000001c4

Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 tools/testing/selftests/tpm2/Makefile           |  2 +-
 .../testing/selftests/tpm2/tpm2-parse-error.py  | 17 +++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/tpm2/tpm2-parse-error.py

diff --git a/tools/testing/selftests/tpm2/Makefile b/tools/testing/selftests/tpm2/Makefile
index a9bf9459fb25..b2c0504bcca6 100644
--- a/tools/testing/selftests/tpm2/Makefile
+++ b/tools/testing/selftests/tpm2/Makefile
@@ -2,4 +2,4 @@
 include ../lib.mk
 
 TEST_PROGS := test_smoke.sh test_space.sh test_async.sh
-TEST_PROGS_EXTENDED := tpm2.py tpm2_tests.py
+TEST_PROGS_EXTENDED := tpm2.py tpm2_tests.py tpm2-parse-error
diff --git a/tools/testing/selftests/tpm2/tpm2-parse-error.py b/tools/testing/selftests/tpm2/tpm2-parse-error.py
new file mode 100644
index 000000000000..8eed72681af1
--- /dev/null
+++ b/tools/testing/selftests/tpm2/tpm2-parse-error.py
@@ -0,0 +1,17 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
+
+from argparse import ArgumentParser
+from argparse import FileType
+import os
+import sys
+import tpm2
+
+def main():
+    parser = ArgumentParser(description='Parse a TPM error code')
+    parser.add_argument('rc', type=(lambda x: int(x, 0)))
+    args = parser.parse_args()
+    print(str(tpm2.ProtocolError(None, args.rc)))
+
+if __name__ == '__main__':
+    main()
-- 
2.39.2


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

* [PATCH] selftests/tpm2: tpm2-parse-error.py
@ 2023-08-19 16:24 Jarkko Sakkinen
  0 siblings, 0 replies; 2+ messages in thread
From: Jarkko Sakkinen @ 2023-08-19 16:24 UTC (permalink / raw)
  To: Shuah Khan
  Cc: Jarkko Sakkinen, Nícolas F. R. A. Prado, open list,
	open list:KERNEL SELFTEST FRAMEWORK

Add a script to quickly parse any TPM error code. This can be useful, e.g.
when parsing klog output when TPM fails in an internal kernel operation.

Example transcript:

$ python3 tpm2-parse-error.py 0x1C4
TPM_RC_VALUE: rc=0x000001c4

Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 tools/testing/selftests/tpm2/Makefile           |  2 +-
 .../testing/selftests/tpm2/tpm2-parse-error.py  | 17 +++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/tpm2/tpm2-parse-error.py

diff --git a/tools/testing/selftests/tpm2/Makefile b/tools/testing/selftests/tpm2/Makefile
index a9bf9459fb25..b2c0504bcca6 100644
--- a/tools/testing/selftests/tpm2/Makefile
+++ b/tools/testing/selftests/tpm2/Makefile
@@ -2,4 +2,4 @@
 include ../lib.mk
 
 TEST_PROGS := test_smoke.sh test_space.sh test_async.sh
-TEST_PROGS_EXTENDED := tpm2.py tpm2_tests.py
+TEST_PROGS_EXTENDED := tpm2.py tpm2_tests.py tpm2-parse-error
diff --git a/tools/testing/selftests/tpm2/tpm2-parse-error.py b/tools/testing/selftests/tpm2/tpm2-parse-error.py
new file mode 100644
index 000000000000..8eed72681af1
--- /dev/null
+++ b/tools/testing/selftests/tpm2/tpm2-parse-error.py
@@ -0,0 +1,17 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
+
+from argparse import ArgumentParser
+from argparse import FileType
+import os
+import sys
+import tpm2
+
+def main():
+    parser = ArgumentParser(description='Parse a TPM error code')
+    parser.add_argument('rc', type=(lambda x: int(x, 0)))
+    args = parser.parse_args()
+    print(str(tpm2.ProtocolError(None, args.rc)))
+
+if __name__ == '__main__':
+    main()
-- 
2.39.2


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

end of thread, other threads:[~2023-08-19 16:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-19 16:24 [PATCH] selftests/tpm2: tpm2-parse-error.py Jarkko Sakkinen
  -- strict thread matches above, loose matches on Subject: below --
2023-08-19 16:21 Jarkko Sakkinen

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