2 * QTest TPM commont test code
4 * Copyright (c) 2018 IBM Corporation
5 * Copyright (c) 2018 Red Hat, Inc.
8 * Stefan Berger <stefanb@linux.vnet.ibm.com>
9 * Marc-André Lureau <marcandre.lureau@redhat.com>
11 * This work is licensed under the terms of the GNU GPL, version 2 or later.
12 * See the COPYING file in the top-level directory.
15 #include "qemu/osdep.h"
16 #include <glib/gstdio.h>
19 #include "tpm-tests.h"
21 void tpm_test_swtpm_test(const char *src_tpm_path
, tx_func
*tx
,
26 SocketAddress
*addr
= NULL
;
31 succ
= tpm_util_swtpm_start(src_tpm_path
, &swtpm_pid
, &addr
, &error
);
32 /* succ may be false if swtpm is not available */
37 args
= g_strdup_printf(
38 "-chardev socket,id=chr,path=%s "
39 "-tpmdev emulator,id=dev,chardev=chr "
40 "-device %s,tpmdev=dev",
41 addr
->u
.q_unix
.path
, ifmodel
);
43 s
= qtest_start(args
);
46 tpm_util_startup(s
, tx
);
47 tpm_util_pcrextend(s
, tx
);
49 unsigned char tpm_pcrread_resp
[] =
50 "\x80\x01\x00\x00\x00\x3e\x00\x00\x00\x00\x00\x00\x00\x16\x00\x00"
51 "\x00\x01\x00\x0b\x03\x00\x04\x00\x00\x00\x00\x01\x00\x20\xf6\x85"
52 "\x98\xe5\x86\x8d\xe6\x8b\x97\x29\x99\x60\xf2\x71\x7d\x17\x67\x89"
53 "\xa4\x2f\x9a\xae\xa8\xc7\xb7\xaa\x79\xa8\x62\x56\xc1\xde";
54 tpm_util_pcrread(s
, tx
, tpm_pcrread_resp
,
55 sizeof(tpm_pcrread_resp
));
58 tpm_util_swtpm_kill(swtpm_pid
);
61 g_unlink(addr
->u
.q_unix
.path
);
62 qapi_free_SocketAddress(addr
);
66 void tpm_test_swtpm_migration_test(const char *src_tpm_path
,
67 const char *dst_tpm_path
,
68 const char *uri
, tx_func
*tx
,
72 GPid src_tpm_pid
, dst_tpm_pid
;
73 SocketAddress
*src_tpm_addr
= NULL
, *dst_tpm_addr
= NULL
;
75 QTestState
*src_qemu
, *dst_qemu
;
77 succ
= tpm_util_swtpm_start(src_tpm_path
, &src_tpm_pid
,
78 &src_tpm_addr
, &error
);
79 /* succ may be false if swtpm is not available */
84 succ
= tpm_util_swtpm_start(dst_tpm_path
, &dst_tpm_pid
,
85 &dst_tpm_addr
, &error
);
86 /* succ may be false if swtpm is not available */
88 goto err_src_tpm_kill
;
91 tpm_util_migration_start_qemu(&src_qemu
, &dst_qemu
,
92 src_tpm_addr
, dst_tpm_addr
, uri
,
95 tpm_util_startup(src_qemu
, tx
);
96 tpm_util_pcrextend(src_qemu
, tx
);
98 unsigned char tpm_pcrread_resp
[] =
99 "\x80\x01\x00\x00\x00\x3e\x00\x00\x00\x00\x00\x00\x00\x16\x00\x00"
100 "\x00\x01\x00\x0b\x03\x00\x04\x00\x00\x00\x00\x01\x00\x20\xf6\x85"
101 "\x98\xe5\x86\x8d\xe6\x8b\x97\x29\x99\x60\xf2\x71\x7d\x17\x67\x89"
102 "\xa4\x2f\x9a\xae\xa8\xc7\xb7\xaa\x79\xa8\x62\x56\xc1\xde";
103 tpm_util_pcrread(src_qemu
, tx
, tpm_pcrread_resp
,
104 sizeof(tpm_pcrread_resp
));
106 tpm_util_migrate(src_qemu
, uri
);
107 tpm_util_wait_for_migration_complete(src_qemu
);
109 tpm_util_pcrread(dst_qemu
, tx
, tpm_pcrread_resp
,
110 sizeof(tpm_pcrread_resp
));
112 qtest_quit(dst_qemu
);
113 qtest_quit(src_qemu
);
115 tpm_util_swtpm_kill(dst_tpm_pid
);
117 g_unlink(dst_tpm_addr
->u
.q_unix
.path
);
118 qapi_free_SocketAddress(dst_tpm_addr
);
122 tpm_util_swtpm_kill(src_tpm_pid
);
124 g_unlink(src_tpm_addr
->u
.q_unix
.path
);
125 qapi_free_SocketAddress(src_tpm_addr
);