Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko@kernel.org>
To: Shuah Khan <shuah@kernel.org>
Cc: "Jarkko Sakkinen" <jarkko@kernel.org>,
	"Nícolas F. R. A. Prado" <nfraprado@collabora.com>,
	linux-kernel@vger.kernel.org (open list),
	linux-kselftest@vger.kernel.org (open list:KERNEL SELFTEST
	FRAMEWORK)
Subject: [PATCH v2] selftests/tpm2: tpm2-parse-error.py
Date: Sat, 19 Aug 2023 16:25:37 +0000	[thread overview]
Message-ID: <20230819162540.5717-1-jarkko@kernel.org> (raw)

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>
---
v2:
Makefile: s/tpm2-parse-error/tpm2-parse-error.py/
---
 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..dbff77612785 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.py
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


                 reply	other threads:[~2023-08-19 16:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230819162540.5717-1-jarkko@kernel.org \
    --to=jarkko@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=nfraprado@collabora.com \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox