xref: /qemu/tests/qtest/tpm-tis-swtpm-test.c (revision 29b62a10)
1 /*
2  * QTest testcase for TPM TIS talking to external swtpm and swtpm migration
3  *
4  * Copyright (c) 2018 IBM Corporation
5  *  with parts borrowed from migration-test.c that is:
6  *     Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates
7  *
8  * Authors:
9  *   Stefan Berger <stefanb@linux.vnet.ibm.com>
10  *
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.
13  */
14 
15 #include "qemu/osdep.h"
16 
17 #include "libqtest.h"
18 #include "qemu/module.h"
19 #include "tpm-tests.h"
20 #include "hw/acpi/tpm.h"
21 
22 uint64_t tpm_tis_base_addr = TPM_TIS_ADDR_BASE;
23 
24 typedef struct TestState {
25     char *src_tpm_path;
26     char *dst_tpm_path;
27     char *uri;
28 } TestState;
29 
30 static void tpm_tis_swtpm_test(const void *data)
31 {
32     const TestState *ts = data;
33 
34     tpm_test_swtpm_test(ts->src_tpm_path, tpm_util_tis_transfer,
35                         "tpm-tis", NULL);
36 }
37 
38 static void tpm_tis_swtpm_migration_test(const void *data)
39 {
40     const TestState *ts = data;
41 
42     tpm_test_swtpm_migration_test(ts->src_tpm_path, ts->dst_tpm_path, ts->uri,
43                                   tpm_util_tis_transfer, "tpm-tis", NULL);
44 }
45 
46 int main(int argc, char **argv)
47 {
48     int ret;
49     TestState ts = { 0 };
50 
51     ts.src_tpm_path = g_dir_make_tmp("qemu-tpm-tis-swtpm-test.XXXXXX", NULL);
52     ts.dst_tpm_path = g_dir_make_tmp("qemu-tpm-tis-swtpm-test.XXXXXX", NULL);
53     ts.uri = g_strdup_printf("unix:%s/migsocket", ts.src_tpm_path);
54 
55     module_call_init(MODULE_INIT_QOM);
56     g_test_init(&argc, &argv, NULL);
57 
58     qtest_add_data_func("/tpm/tis-swtpm/test", &ts, tpm_tis_swtpm_test);
59     qtest_add_data_func("/tpm/tis-swtpm-migration/test", &ts,
60                         tpm_tis_swtpm_migration_test);
61     ret = g_test_run();
62 
63     tpm_util_rmdir(ts.dst_tpm_path);
64     g_free(ts.dst_tpm_path);
65     tpm_util_rmdir(ts.src_tpm_path);
66     g_free(ts.src_tpm_path);
67     g_free(ts.uri);
68 
69     return ret;
70 }
71