1fe985ed6SEric Auger /*
2fe985ed6SEric Auger * QTest testcase for Sysbus TPM TIS talking to external swtpm and swtpm
3fe985ed6SEric Auger * migration
4fe985ed6SEric Auger *
5fe985ed6SEric Auger * Copyright (c) 2018 IBM Corporation
6fe985ed6SEric Auger * with parts borrowed from migration-test.c that is:
7fe985ed6SEric Auger * Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates
8fe985ed6SEric Auger *
9fe985ed6SEric Auger * Authors:
10fe985ed6SEric Auger * Stefan Berger <stefanb@linux.vnet.ibm.com>
11fe985ed6SEric Auger *
12fe985ed6SEric Auger * This work is licensed under the terms of the GNU GPL, version 2 or later.
13fe985ed6SEric Auger * See the COPYING file in the top-level directory.
14fe985ed6SEric Auger */
15fe985ed6SEric Auger
16fe985ed6SEric Auger #include "qemu/osdep.h"
17fe985ed6SEric Auger
18907b5105SMarc-André Lureau #include "libqtest.h"
19fe985ed6SEric Auger #include "qemu/module.h"
20fe985ed6SEric Auger #include "tpm-tests.h"
21*f8d64616SStefan Berger #include "tpm-tis-util.h"
22fe985ed6SEric Auger #include "hw/acpi/tpm.h"
23fe985ed6SEric Auger
24fe985ed6SEric Auger uint64_t tpm_tis_base_addr = 0xc000000;
25fe985ed6SEric Auger #define MACHINE_OPTIONS "-machine virt,gic-version=max -accel tcg"
26fe985ed6SEric Auger
27fe985ed6SEric Auger typedef struct TestState {
28fe985ed6SEric Auger char *src_tpm_path;
29fe985ed6SEric Auger char *dst_tpm_path;
30fe985ed6SEric Auger char *uri;
31fe985ed6SEric Auger } TestState;
32fe985ed6SEric Auger
tpm_tis_swtpm_test(const void * data)33fe985ed6SEric Auger static void tpm_tis_swtpm_test(const void *data)
34fe985ed6SEric Auger {
35fe985ed6SEric Auger const TestState *ts = data;
36fe985ed6SEric Auger
37*f8d64616SStefan Berger tpm_test_swtpm_test(ts->src_tpm_path, tpm_tis_transfer,
38fe985ed6SEric Auger "tpm-tis-device", MACHINE_OPTIONS);
39fe985ed6SEric Auger }
40fe985ed6SEric Auger
tpm_tis_swtpm_migration_test(const void * data)41fe985ed6SEric Auger static void tpm_tis_swtpm_migration_test(const void *data)
42fe985ed6SEric Auger {
43fe985ed6SEric Auger const TestState *ts = data;
44fe985ed6SEric Auger
45fe985ed6SEric Auger tpm_test_swtpm_migration_test(ts->src_tpm_path, ts->dst_tpm_path, ts->uri,
46*f8d64616SStefan Berger tpm_tis_transfer, "tpm-tis-device",
47fe985ed6SEric Auger MACHINE_OPTIONS);
48fe985ed6SEric Auger }
49fe985ed6SEric Auger
main(int argc,char ** argv)50fe985ed6SEric Auger int main(int argc, char **argv)
51fe985ed6SEric Auger {
52fe985ed6SEric Auger int ret;
53fe985ed6SEric Auger TestState ts = { 0 };
54fe985ed6SEric Auger
55fe985ed6SEric Auger ts.src_tpm_path = g_dir_make_tmp("qemu-tpm-tis-device-swtpm-test.XXXXXX",
56fe985ed6SEric Auger NULL);
57fe985ed6SEric Auger ts.dst_tpm_path = g_dir_make_tmp("qemu-tpm-tis-device-swtpm-test.XXXXXX",
58fe985ed6SEric Auger NULL);
59fe985ed6SEric Auger ts.uri = g_strdup_printf("unix:%s/migsocket", ts.src_tpm_path);
60fe985ed6SEric Auger
61fe985ed6SEric Auger module_call_init(MODULE_INIT_QOM);
62fe985ed6SEric Auger g_test_init(&argc, &argv, NULL);
63fe985ed6SEric Auger
64fe985ed6SEric Auger qtest_add_data_func("/tpm/tis-swtpm/test", &ts, tpm_tis_swtpm_test);
65fe985ed6SEric Auger qtest_add_data_func("/tpm/tis-swtpm-migration/test", &ts,
66fe985ed6SEric Auger tpm_tis_swtpm_migration_test);
67fe985ed6SEric Auger ret = g_test_run();
68fe985ed6SEric Auger
69daa8bb57SThomas Huth tpm_util_rmdir(ts.dst_tpm_path);
70fe985ed6SEric Auger g_free(ts.dst_tpm_path);
71daa8bb57SThomas Huth tpm_util_rmdir(ts.src_tpm_path);
72fe985ed6SEric Auger g_free(ts.src_tpm_path);
73fe985ed6SEric Auger g_free(ts.uri);
74fe985ed6SEric Auger
75fe985ed6SEric Auger return ret;
76fe985ed6SEric Auger }
77