Skip to contentSkip to conversation

selftests: tpm2: Fix ill defined assertions

PATCH In review Maurice Hieronymus 2 participants 2 messages Nov 23, 2025 – Nov 25, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests: tpm2: Fix ill defined assertions

Remove parentheses around assert statements in Python. With parentheses, assert always evaluates to True, making the checks ineffective.

---
 tools/testing/selftests/tpm2/tpm2.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/tpm2/tpm2.py +2 -2
index bba8cb54548e..3d130c30bc7c 100644
@@ -437,7 +437,7 @@ class Client:
 
     def extend_pcr(self, i, dig, bank_alg = TPM2_ALG_SHA1):
         ds = get_digest_size(bank_alg)
-        assert(ds == len(dig))
+        assert ds == len(dig)
 
         auth_cmd = AuthCommand()
 
@@ -589,7 +589,7 @@ class Client:
     def seal(self, parent_key, data, auth_value, policy_dig,
              name_alg = TPM2_ALG_SHA1):
         ds = get_digest_size(name_alg)
-        assert(not policy_dig or ds == len(policy_dig))
+        assert not policy_dig or ds == len(policy_dig)
 
         attributes = 0
         if not policy_dig:

base-commit: 821e6e2a328bb907d40f8d1141d8b6c079aa7340

Signature · 1 line
2.50.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 31 lines · Maurice Hieronymus

Remove parentheses around assert statements in Python. With parentheses, assert always evaluates to True, making the checks ineffective.

---
 tools/testing/selftests/tpm2/tpm2.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/tpm2/tpm2.py +2 -2
index bba8cb54548e..3d130c30bc7c 100644
@@ -437,7 +437,7 @@ class Client:
 
     def extend_pcr(self, i, dig, bank_alg = TPM2_ALG_SHA1):
         ds = get_digest_size(bank_alg)
-        assert(ds == len(dig))
+        assert ds == len(dig)
 
         auth_cmd = AuthCommand()
 
@@ -589,7 +589,7 @@ class Client:
     def seal(self, parent_key, data, auth_value, policy_dig,
              name_alg = TPM2_ALG_SHA1):
         ds = get_digest_size(name_alg)
-        assert(not policy_dig or ds == len(policy_dig))
+        assert not policy_dig or ds == len(policy_dig)
 
         attributes = 0
         if not policy_dig:
Quoted 4 lines

base-commit: 821e6e2a328bb907d40f8d1141d8b6c079aa7340

Signature · 1 line
2.50.1

BR, Jarkko