1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#include "qemu/osdep.h"
16#include <glib/gstdio.h>
17
18#include "libqos/libqtest.h"
19#include "qemu/module.h"
20#include "tpm-tests.h"
21#include "hw/acpi/tpm.h"
22
23
24uint64_t tpm_tis_base_addr = TPM_TIS_ADDR_BASE;
25
26typedef struct TestState {
27 char *src_tpm_path;
28 char *dst_tpm_path;
29 char *uri;
30} TestState;
31
32static void tpm_crb_swtpm_test(const void *data)
33{
34 const TestState *ts = data;
35
36 tpm_test_swtpm_test(ts->src_tpm_path, tpm_util_crb_transfer,
37 "tpm-crb", NULL);
38}
39
40static void tpm_crb_swtpm_migration_test(const void *data)
41{
42 const TestState *ts = data;
43
44 tpm_test_swtpm_migration_test(ts->src_tpm_path, ts->dst_tpm_path, ts->uri,
45 tpm_util_crb_transfer, "tpm-crb", NULL);
46}
47
48int main(int argc, char **argv)
49{
50 int ret;
51 TestState ts = { 0 };
52
53 ts.src_tpm_path = g_dir_make_tmp("qemu-tpm-crb-swtpm-test.XXXXXX", NULL);
54 ts.dst_tpm_path = g_dir_make_tmp("qemu-tpm-crb-swtpm-test.XXXXXX", NULL);
55 ts.uri = g_strdup_printf("unix:%s/migsocket", ts.src_tpm_path);
56
57 module_call_init(MODULE_INIT_QOM);
58 g_test_init(&argc, &argv, NULL);
59
60 qtest_add_data_func("/tpm/crb-swtpm/test", &ts, tpm_crb_swtpm_test);
61 qtest_add_data_func("/tpm/crb-swtpm-migration/test", &ts,
62 tpm_crb_swtpm_migration_test);
63 ret = g_test_run();
64
65 g_rmdir(ts.dst_tpm_path);
66 g_free(ts.dst_tpm_path);
67 g_rmdir(ts.src_tpm_path);
68 g_free(ts.src_tpm_path);
69 g_free(ts.uri);
70
71 return ret;
72}
73