Commit 87ce42198d for qemu.org
commit 87ce42198d9f886226743183f5833536103c2996
Author: Stefan Berger <stefanb@linux.vnet.ibm.com>
Date: Wed Apr 29 12:17:40 2026 +0000
tests: Convert string arrays to byte arrays
Convert the TPM command and response string arrays to byte arrays.
Reviewed-by: Arun Menon <armenon@redhat.com>
Link: https://lore.kernel.org/qemu-devel/20260429121743.1346635-4-stefanb@linux.ibm.com
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
diff --git a/tests/qtest/tpm-tests.c b/tests/qtest/tpm-tests.c
index 197714f8d9..8bd3288f80 100644
--- a/tests/qtest/tpm-tests.c
+++ b/tests/qtest/tpm-tests.c
@@ -59,11 +59,16 @@ void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx,
tpm_util_startup(s, tx);
tpm_util_pcrextend(s, tx);
- static const unsigned char tpm_pcrread_resp[] =
- "\x80\x01\x00\x00\x00\x3e\x00\x00\x00\x00\x00\x00\x00\x16\x00\x00"
- "\x00\x01\x00\x0b\x03\x00\x04\x00\x00\x00\x00\x01\x00\x20\xf6\x85"
- "\x98\xe5\x86\x8d\xe6\x8b\x97\x29\x99\x60\xf2\x71\x7d\x17\x67\x89"
- "\xa4\x2f\x9a\xae\xa8\xc7\xb7\xaa\x79\xa8\x62\x56\xc1\xde";
+ static const unsigned char tpm_pcrread_resp[] = {
+ 0x80, 0x01, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00,
+ 0x00, 0x01, 0x00, 0x0b, 0x03, 0x00, 0x04, 0x00,
+ 0x00, 0x00, 0x00, 0x01, 0x00, 0x20, 0xf6, 0x85,
+ 0x98, 0xe5, 0x86, 0x8d, 0xe6, 0x8b, 0x97, 0x29,
+ 0x99, 0x60, 0xf2, 0x71, 0x7d, 0x17, 0x67, 0x89,
+ 0xa4, 0x2f, 0x9a, 0xae, 0xa8, 0xc7, 0xb7, 0xaa,
+ 0x79, 0xa8, 0x62, 0x56, 0xc1, 0xde
+ };
tpm_util_pcrread(s, tx, tpm_pcrread_resp,
sizeof(tpm_pcrread_resp));
@@ -105,11 +110,16 @@ void tpm_test_swtpm_migration_test(const char *src_tpm_path,
tpm_util_startup(src_qemu, tx);
tpm_util_pcrextend(src_qemu, tx);
- static const unsigned char tpm_pcrread_resp[] =
- "\x80\x01\x00\x00\x00\x3e\x00\x00\x00\x00\x00\x00\x00\x16\x00\x00"
- "\x00\x01\x00\x0b\x03\x00\x04\x00\x00\x00\x00\x01\x00\x20\xf6\x85"
- "\x98\xe5\x86\x8d\xe6\x8b\x97\x29\x99\x60\xf2\x71\x7d\x17\x67\x89"
- "\xa4\x2f\x9a\xae\xa8\xc7\xb7\xaa\x79\xa8\x62\x56\xc1\xde";
+ static const unsigned char tpm_pcrread_resp[] = {
+ 0x80, 0x01, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00,
+ 0x00, 0x01, 0x00, 0x0b, 0x03, 0x00, 0x04, 0x00,
+ 0x00, 0x00, 0x00, 0x01, 0x00, 0x20, 0xf6, 0x85,
+ 0x98, 0xe5, 0x86, 0x8d, 0xe6, 0x8b, 0x97, 0x29,
+ 0x99, 0x60, 0xf2, 0x71, 0x7d, 0x17, 0x67, 0x89,
+ 0xa4, 0x2f, 0x9a, 0xae, 0xa8, 0xc7, 0xb7, 0xaa,
+ 0x79, 0xa8, 0x62, 0x56, 0xc1, 0xde,
+ };
tpm_util_pcrread(src_qemu, tx, tpm_pcrread_resp,
sizeof(tpm_pcrread_resp));
diff --git a/tests/qtest/tpm-util.c b/tests/qtest/tpm-util.c
index 2cb2dd4796..63cd5b69db 100644
--- a/tests/qtest/tpm-util.c
+++ b/tests/qtest/tpm-util.c
@@ -54,10 +54,14 @@ void tpm_util_crb_transfer(QTestState *s,
void tpm_util_startup(QTestState *s, tx_func *tx)
{
unsigned char buffer[1024];
- static const unsigned char tpm_startup[] =
- "\x80\x01\x00\x00\x00\x0c\x00\x00\x01\x44\x00\x00";
- static const unsigned char tpm_startup_resp[] =
- "\x80\x01\x00\x00\x00\x0a\x00\x00\x00\x00";
+ static const unsigned char tpm_startup[] = {
+ 0x80, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00,
+ 0x01, 0x44, 0x00, 0x00
+ };
+ static const unsigned char tpm_startup_resp[] = {
+ 0x80, 0x01, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00,
+ 0x00, 0x00
+ };
tx(s, tpm_startup, sizeof(tpm_startup), buffer, sizeof(buffer));
@@ -68,16 +72,23 @@ void tpm_util_startup(QTestState *s, tx_func *tx)
void tpm_util_pcrextend(QTestState *s, tx_func *tx)
{
unsigned char buffer[1024];
- static const unsigned char tpm_pcrextend[] =
- "\x80\x02\x00\x00\x00\x41\x00\x00\x01\x82\x00\x00\x00\x0a\x00\x00"
- "\x00\x09\x40\x00\x00\x09\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00"
- "\x0b\x74\x65\x73\x74\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
- "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
- "\x00";
+ static const unsigned char tpm_pcrextend[] = {
+ 0x80, 0x02, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00,
+ 0x01, 0x82, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00,
+ 0x00, 0x09, 0x40, 0x00, 0x00, 0x09, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
+ 0x0b, 0x74, 0x65, 0x73, 0x74, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00
+ };
- static const unsigned char tpm_pcrextend_resp[] =
- "\x80\x02\x00\x00\x00\x13\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
- "\x01\x00\x00";
+ static const unsigned char tpm_pcrextend_resp[] = {
+ 0x80, 0x02, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x01, 0x00, 0x00
+ };
tx(s, tpm_pcrextend, sizeof(tpm_pcrextend), buffer, sizeof(buffer));
@@ -89,9 +100,11 @@ void tpm_util_pcrread(QTestState *s, tx_func *tx,
const unsigned char *exp_resp, size_t exp_resp_size)
{
unsigned char buffer[1024];
- static const unsigned char tpm_pcrread[] =
- "\x80\x01\x00\x00\x00\x14\x00\x00\x01\x7e\x00\x00\x00\x01\x00\x0b"
- "\x03\x00\x04\x00";
+ static const unsigned char tpm_pcrread[] = {
+ 0x80, 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00,
+ 0x01, 0x7e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0b,
+ 0x03, 0x00, 0x04, 0x00
+ };
tx(s, tpm_pcrread, sizeof(tpm_pcrread), buffer, sizeof(buffer));