From patchwork Sat Aug 19 16:21:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 715099 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89616EE4993 for ; Sat, 19 Aug 2023 16:21:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233845AbjHSQVm (ORCPT ); Sat, 19 Aug 2023 12:21:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233786AbjHSQVl (ORCPT ); Sat, 19 Aug 2023 12:21:41 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A1D8255FF; Sat, 19 Aug 2023 09:21:40 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A370261AFD; Sat, 19 Aug 2023 16:21:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B18A5C433C8; Sat, 19 Aug 2023 16:21:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692462099; bh=76TyJsyA+FuZR/jjpu6GfoRCnAnDtDWFM6vwGAFIwqM=; h=From:To:Cc:Subject:Date:From; b=O79hoXclaFHdIx85hFnPdO2PF2msi8yR2JeIdpisRiTKZ6z3NLuf8ZxIDU7ep7k1k w89ecZsnOQ9uvg3Vm7yl7IkjLWZ4cX8/URZ7biSexaNPpRRe3ILRpxNNYZgU09MT/q 6rAU6fWWaI5ugjo4d8M6UF7c6y9SNt7wxK9BjSDfqN31Y1vPJpcCDCrEzRl0kfZBOK 2eT2fW4Rnwa2Sx3G2vqiibmD2lxcybDvGIw/NFTyfYd+s4MW55W/WLOjpPCscFQ5eY MKOcDbNIqnBPd94ERcwnEMX1ig2FrbneJDkYF0TukO1vEVAd3JixIN+mcR0p4MaN3n Ak54BZGd0tMeQ== From: Jarkko Sakkinen To: Shuah Khan Cc: Jarkko Sakkinen , =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4g?= =?utf-8?b?UHJhZG8=?= , linux-kernel@vger.kernel.org (open list), linux-kselftest@vger.kernel.org (open list:KERNEL SELFTEST FRAMEWORK) Subject: [PATCH] selftests/tpm2: tpm2-parse-error.py Date: Sat, 19 Aug 2023 16:21:30 +0000 Message-Id: <20230819162135.4181-1-jarkko@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org 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 --- 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()