Skip to contentSkip to conversation

selftests: tpm2: remove redundant ord()

PATCH In review Tzung-Bi Shih 3 participants 3 messages Feb 3, 2023 – Feb 8, 2023

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

PATCH 1/1 selftests: tpm2: remove redundant ord()

When testing with FLAG_DEBUG enabled client, it emits the following error messages:

File "/root/tpm2/tpm2.py", line 347, in hex_dump

    d = [format(ord(x), '02x') for x in d]
File "/root/tpm2/tpm2.py", line 347, in <listcomp>
    d = [format(ord(x), '02x') for x in d]

TypeError: ord() expected string of length 1, but int found

The input of hex_dump() should be packed binary data. Remove the ord().

---
 tools/testing/selftests/tpm2/tpm2.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/tpm2/tpm2.py +1 -1
index c7363c6764fc..bba8cb54548e 100644
@@ -344,7 +344,7 @@ def get_algorithm(name):
 
 
 def hex_dump(d):
-    d = [format(ord(x), '02x') for x in d]
+    d = [format(x, '02x') for x in d]
     d = [d[i: i + 16] for i in range(0, len(d), 16)]
     d = [' '.join(x) for x in d]
     d = os.linesep.join(d)
Signature · 1 line
2.39.1.519.gcb327c4b5f-goog
maintainer
#1 lore raw
Quoted 22 lines · Tzung-Bi Shih

When testing with FLAG_DEBUG enabled client, it emits the following error messages:

File "/root/tpm2/tpm2.py", line 347, in hex_dump

     d = [format(ord(x), '02x') for x in d]
File "/root/tpm2/tpm2.py", line 347, in <listcomp>
     d = [format(ord(x), '02x') for x in d]

TypeError: ord() expected string of length 1, but int found

The input of hex_dump() should be packed binary data. Remove the ord().

---
  tools/testing/selftests/tpm2/tpm2.py | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/tpm2/tpm2.py +0 -0
index c7363c6764fc..bba8cb54548e 100644

tools/testing/selftests/tpm2/tpm2.py def get_algorithm(name): · line 350

Quoted 8 lines
tools/testing/selftests/tpm2/tpm2.py +1 -1
@@ -344,7 +344,7 @@ def get_algorithm(name):
 
 
  def hex_dump(d):
-    d = [format(ord(x), '02x') for x in d]
+    d = [format(x, '02x') for x in d]
      d = [d[i: i + 16] for i in range(0, len(d), 16)]
      d = [' '.join(x) for x in d]
      d = os.linesep.join(d)

Thank you for the patch. It will appear shortly in linux-kselftest next for Linux 6.3-rc1

thanks,
-- Shuah

maintainer Acked-by on v1 1/1
#2 lore raw
In reply to Tzung-Bi Shih
Quoted 33 lines · Tzung-Bi Shih

When testing with FLAG_DEBUG enabled client, it emits the following error messages:

File "/root/tpm2/tpm2.py", line 347, in hex_dump

    d = [format(ord(x), '02x') for x in d]
File "/root/tpm2/tpm2.py", line 347, in <listcomp>
    d = [format(ord(x), '02x') for x in d]

TypeError: ord() expected string of length 1, but int found

The input of hex_dump() should be packed binary data. Remove the ord().

---
 tools/testing/selftests/tpm2/tpm2.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/tpm2/tpm2.py +1 -1
index c7363c6764fc..bba8cb54548e 100644
@@ -344,7 +344,7 @@ def get_algorithm(name):
 
 
 def hex_dump(d):
-    d = [format(ord(x), '02x') for x in d]
+    d = [format(x, '02x') for x in d]
     d = [d[i: i + 16] for i in range(0, len(d), 16)]
     d = [' '.join(x) for x in d]
     d = os.linesep.join(d)
Signature · 1 line
2.39.1.519.gcb327c4b5f-goog

BR, Jarkko