master
c 82 lines 2.29 KB
Raw
1 /*
2 * SPDX-License-Identifier: GPL-2.0-or-later
3 *
4 * QTest testcase for TPM TIS over I2C talking to external swtpm
5 *
6 * Copyright (c) 2018, 2026 IBM Corporation
7 * with parts borrowed from migration-test.c that is:
8 * Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates
9 *
10 * Authors:
11 * Stefan Berger <stefanb@linux.ibm.com>
12 *
13 */
14
15 #include "qemu/osdep.h"
16
17 #include "libqtest.h"
18 #include "qemu/module.h"
19 #include "tpm-tests.h"
20 #include "tpm-tis-i2c-util.h"
21 #include "qtest_aspeed.h"
22
23 typedef struct TestState {
24 char *src_tpm_path;
25 char *dst_tpm_path;
26 char *uri;
27 const char *machine_options;
28 char *ifmodel;
29 } TestState;
30
31 static void tpm_tis_i2c_swtpm_test(const void *data)
32 {
33 const TestState *ts = data;
34
35 tpm_test_swtpm_test(ts->src_tpm_path, tpm_tis_i2c_transfer,
36 ts->ifmodel, ts->machine_options);
37 }
38
39 static void tpm_tis_swtpm_migration_test(const void *data)
40 {
41 const TestState *ts = data;
42
43 tpm_test_swtpm_migration_test(ts->src_tpm_path, ts->dst_tpm_path,
44 ts->uri, tpm_tis_i2c_transfer,
45 ts->ifmodel, ts->machine_options);
46 }
47
48
49 int main(int argc, char **argv)
50 {
51 int ret;
52 TestState ts;
53
54 ts.src_tpm_path = g_dir_make_tmp("qemu-tpm-tis-i2c-swtpm-test.XXXXXX",
55 NULL);
56 ts.dst_tpm_path = g_dir_make_tmp("qemu-tpm-tis-i2c-swtpm-test.XXXXXX",
57 NULL);
58 ts.uri = g_strdup_printf("unix:%s/migsocket", ts.src_tpm_path);
59 ts.machine_options = "-machine rainier-bmc -accel tcg";
60 ts.ifmodel = g_strdup_printf(
61 "tpm-tis-i2c,bus=aspeed.i2c.bus.%d,address=0x%x",
62 I2C_DEV_BUS_NUM, I2C_SLAVE_ADDR);
63
64 module_call_init(MODULE_INIT_QOM);
65 g_test_init(&argc, &argv, NULL);
66
67 aspeed_bus_addr = ast2600_i2c_calc_bus_addr(I2C_DEV_BUS_NUM);
68
69 qtest_add_data_func("/tpm/tis-i2c-swtpm/test", &ts, tpm_tis_i2c_swtpm_test);
70 qtest_add_data_func("/tpm/tis-i2c-swtpm-migration/test", &ts,
71 tpm_tis_swtpm_migration_test);
72 ret = g_test_run();
73
74 tpm_util_rmdir(ts.dst_tpm_path);
75 g_free(ts.dst_tpm_path);
76 tpm_util_rmdir(ts.src_tpm_path);
77 g_free(ts.src_tpm_path);
78 g_free(ts.uri);
79 g_free(ts.ifmodel);
80
81 return ret;
82 }