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>
Stefan Berger committed
Apr 29, 2026 at 12:17 UTC
87ce42198d9f886226743183f5833536103c2996
2 files changed
+49
-26
tests/qtest/tpm-tests.c
+20
-10
@@ -59,11 +59,16 @@ void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx,
59
tpm_util_startup(s, tx);
60
tpm_util_pcrextend(s, tx);
61
62
- static const unsigned char tpm_pcrread_resp[] =
63
- "\x80\x01\x00\x00\x00\x3e\x00\x00\x00\x00\x00\x00\x00\x16\x00\x00"
64
- "\x00\x01\x00\x0b\x03\x00\x04\x00\x00\x00\x00\x01\x00\x20\xf6\x85"
65
- "\x98\xe5\x86\x8d\xe6\x8b\x97\x29\x99\x60\xf2\x71\x7d\x17\x67\x89"
66
- "\xa4\x2f\x9a\xae\xa8\xc7\xb7\xaa\x79\xa8\x62\x56\xc1\xde";
62
+ static const unsigned char tpm_pcrread_resp[] = {
63
+ 0x80, 0x01, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00,
64
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00,
65
+ 0x00, 0x01, 0x00, 0x0b, 0x03, 0x00, 0x04, 0x00,
66
+ 0x00, 0x00, 0x00, 0x01, 0x00, 0x20, 0xf6, 0x85,
67
+ 0x98, 0xe5, 0x86, 0x8d, 0xe6, 0x8b, 0x97, 0x29,
68
+ 0x99, 0x60, 0xf2, 0x71, 0x7d, 0x17, 0x67, 0x89,
69
+ 0xa4, 0x2f, 0x9a, 0xae, 0xa8, 0xc7, 0xb7, 0xaa,
70
+ 0x79, 0xa8, 0x62, 0x56, 0xc1, 0xde
71
+ };
72
tpm_util_pcrread(s, tx, tpm_pcrread_resp,
73
sizeof(tpm_pcrread_resp));
74
@@ -105,11 +110,16 @@ void tpm_test_swtpm_migration_test(const char *src_tpm_path,
110
tpm_util_startup(src_qemu, tx);
111
tpm_util_pcrextend(src_qemu, tx);
112
108
- static const unsigned char tpm_pcrread_resp[] =
109
- "\x80\x01\x00\x00\x00\x3e\x00\x00\x00\x00\x00\x00\x00\x16\x00\x00"
110
- "\x00\x01\x00\x0b\x03\x00\x04\x00\x00\x00\x00\x01\x00\x20\xf6\x85"
111
- "\x98\xe5\x86\x8d\xe6\x8b\x97\x29\x99\x60\xf2\x71\x7d\x17\x67\x89"
112
- "\xa4\x2f\x9a\xae\xa8\xc7\xb7\xaa\x79\xa8\x62\x56\xc1\xde";
113
+ static const unsigned char tpm_pcrread_resp[] = {
114
+ 0x80, 0x01, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00,
115
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00,
116
+ 0x00, 0x01, 0x00, 0x0b, 0x03, 0x00, 0x04, 0x00,
117
+ 0x00, 0x00, 0x00, 0x01, 0x00, 0x20, 0xf6, 0x85,
118
+ 0x98, 0xe5, 0x86, 0x8d, 0xe6, 0x8b, 0x97, 0x29,
119
+ 0x99, 0x60, 0xf2, 0x71, 0x7d, 0x17, 0x67, 0x89,
120
+ 0xa4, 0x2f, 0x9a, 0xae, 0xa8, 0xc7, 0xb7, 0xaa,
121
+ 0x79, 0xa8, 0x62, 0x56, 0xc1, 0xde,
122
+ };
123
tpm_util_pcrread(src_qemu, tx, tpm_pcrread_resp,
124
sizeof(tpm_pcrread_resp));
125
tests/qtest/tpm-util.c
+29
-16
@@ -54,10 +54,14 @@ void tpm_util_crb_transfer(QTestState *s,
54
void tpm_util_startup(QTestState *s, tx_func *tx)
55
{
56
unsigned char buffer[1024];
57
- static const unsigned char tpm_startup[] =
58
- "\x80\x01\x00\x00\x00\x0c\x00\x00\x01\x44\x00\x00";
59
- static const unsigned char tpm_startup_resp[] =
60
- "\x80\x01\x00\x00\x00\x0a\x00\x00\x00\x00";
57
+ static const unsigned char tpm_startup[] = {
58
+ 0x80, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00,
59
+ 0x01, 0x44, 0x00, 0x00
60
+ };
61
+ static const unsigned char tpm_startup_resp[] = {
62
+ 0x80, 0x01, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00,
63
+ 0x00, 0x00
64
+ };
65
66
tx(s, tpm_startup, sizeof(tpm_startup), buffer, sizeof(buffer));
67
@@ -68,16 +72,23 @@ void tpm_util_startup(QTestState *s, tx_func *tx)
72
void tpm_util_pcrextend(QTestState *s, tx_func *tx)
73
{
74
unsigned char buffer[1024];
71
- static const unsigned char tpm_pcrextend[] =
72
- "\x80\x02\x00\x00\x00\x41\x00\x00\x01\x82\x00\x00\x00\x0a\x00\x00"
73
- "\x00\x09\x40\x00\x00\x09\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00"
74
- "\x0b\x74\x65\x73\x74\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
75
- "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
76
- "\x00";
75
+ static const unsigned char tpm_pcrextend[] = {
76
+ 0x80, 0x02, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00,
77
+ 0x01, 0x82, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00,
78
+ 0x00, 0x09, 0x40, 0x00, 0x00, 0x09, 0x00, 0x00,
79
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
80
+ 0x0b, 0x74, 0x65, 0x73, 0x74, 0x00, 0x00, 0x00,
81
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
82
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
83
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
84
+ 0x00
85
+ };
86
78
- static const unsigned char tpm_pcrextend_resp[] =
79
- "\x80\x02\x00\x00\x00\x13\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
80
- "\x01\x00\x00";
87
+ static const unsigned char tpm_pcrextend_resp[] = {
88
+ 0x80, 0x02, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00,
89
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
90
+ 0x01, 0x00, 0x00
91
+ };
92
93
tx(s, tpm_pcrextend, sizeof(tpm_pcrextend), buffer, sizeof(buffer));
94
@@ -89,9 +100,11 @@ void tpm_util_pcrread(QTestState *s, tx_func *tx,
100
const unsigned char *exp_resp, size_t exp_resp_size)
101
{
102
unsigned char buffer[1024];
92
- static const unsigned char tpm_pcrread[] =
93
- "\x80\x01\x00\x00\x00\x14\x00\x00\x01\x7e\x00\x00\x00\x01\x00\x0b"
94
- "\x03\x00\x04\x00";
103
+ static const unsigned char tpm_pcrread[] = {
104
+ 0x80, 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00,
105
+ 0x01, 0x7e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0b,
106
+ 0x03, 0x00, 0x04, 0x00
107
+ };
108
109
tx(s, tpm_pcrread, sizeof(tpm_pcrread), buffer, sizeof(buffer));
110