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 "hw/acpi/tpm.h"
19#include "io/channel-socket.h"
20#include "libqtest-single.h"
21#include "qemu/module.h"
22#include "tpm-emu.h"
23#include "tpm-tis-util.h"
24
25uint64_t tpm_tis_base_addr = TPM_TIS_ADDR_BASE;
26
27int main(int argc, char **argv)
28{
29 int ret;
30 char *args, *tmp_path = g_dir_make_tmp("qemu-tpm-tis-test.XXXXXX", NULL);
31 GThread *thread;
32 TPMTestState test;
33
34 module_call_init(MODULE_INIT_QOM);
35 g_test_init(&argc, &argv, NULL);
36
37 test.addr = g_new0(SocketAddress, 1);
38 test.addr->type = SOCKET_ADDRESS_TYPE_UNIX;
39 test.addr->u.q_unix.path = g_build_filename(tmp_path, "sock", NULL);
40 g_mutex_init(&test.data_mutex);
41 g_cond_init(&test.data_cond);
42 test.data_cond_signal = false;
43 test.tpm_version = TPM_VERSION_2_0;
44
45 thread = g_thread_new(NULL, tpm_emu_ctrl_thread, &test);
46 tpm_emu_test_wait_cond(&test);
47
48 args = g_strdup_printf(
49 "-chardev socket,id=chr,path=%s "
50 "-tpmdev emulator,id=dev,chardev=chr "
51 "-device tpm-tis,tpmdev=dev",
52 test.addr->u.q_unix.path);
53 qtest_start(args);
54
55 qtest_add_data_func("/tpm-tis/test_check_localities", &test,
56 tpm_tis_test_check_localities);
57
58 qtest_add_data_func("/tpm-tis/test_check_access_reg", &test,
59 tpm_tis_test_check_access_reg);
60
61 qtest_add_data_func("/tpm-tis/test_check_access_reg_seize", &test,
62 tpm_tis_test_check_access_reg_seize);
63
64 qtest_add_data_func("/tpm-tis/test_check_access_reg_release", &test,
65 tpm_tis_test_check_access_reg_release);
66
67 qtest_add_data_func("/tpm-tis/test_check_transmit", &test,
68 tpm_tis_test_check_transmit);
69
70 ret = g_test_run();
71
72 qtest_end();
73
74 g_thread_join(thread);
75 g_unlink(test.addr->u.q_unix.path);
76 qapi_free_SocketAddress(test.addr);
77 g_rmdir(tmp_path);
78 g_free(tmp_path);
79 g_free(args);
80 return ret;
81}
82