2 * QTest testcase for SYSBUS TPM TIS
4 * Copyright (c) 2018 Red Hat, Inc.
5 * Copyright (c) 2018 IBM Corporation
8 * Marc-André Lureau <marcandre.lureau@redhat.com>
9 * Stefan Berger <stefanb@linux.vnet.ibm.com>
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.
15 #include "qemu/osdep.h"
16 #include <glib/gstdio.h>
18 #include "io/channel-socket.h"
19 #include "libqtest-single.h"
20 #include "qemu/module.h"
23 #include "tpm-tis-util.h"
26 * As the Sysbus tpm-tis-device is instantiated on the ARM virt
27 * platform bus and it is the only sysbus device dynamically
28 * instantiated, it gets plugged at its base address
30 uint64_t tpm_tis_base_addr
= 0xc000000;
32 int main(int argc
, char **argv
)
34 char *tmp_path
= g_dir_make_tmp("qemu-tpm-tis-device-test.XXXXXX", NULL
);
40 module_call_init(MODULE_INIT_QOM
);
41 g_test_init(&argc
, &argv
, NULL
);
43 test
.addr
= g_new0(SocketAddress
, 1);
44 test
.addr
->type
= SOCKET_ADDRESS_TYPE_UNIX
;
45 test
.addr
->u
.q_unix
.path
= g_build_filename(tmp_path
, "sock", NULL
);
46 g_mutex_init(&test
.data_mutex
);
47 g_cond_init(&test
.data_cond
);
48 test
.data_cond_signal
= false;
50 thread
= g_thread_new(NULL
, tpm_emu_ctrl_thread
, &test
);
51 tpm_emu_test_wait_cond(&test
);
53 args
= g_strdup_printf(
54 "-machine virt,gic-version=max -accel tcg "
55 "-chardev socket,id=chr,path=%s "
56 "-tpmdev emulator,id=dev,chardev=chr "
57 "-device tpm-tis-device,tpmdev=dev",
58 test
.addr
->u
.q_unix
.path
);
61 qtest_add_data_func("/tpm-tis/test_check_localities", &test
,
62 tpm_tis_test_check_localities
);
64 qtest_add_data_func("/tpm-tis/test_check_access_reg", &test
,
65 tpm_tis_test_check_access_reg
);
67 qtest_add_data_func("/tpm-tis/test_check_access_reg_seize", &test
,
68 tpm_tis_test_check_access_reg_seize
);
70 qtest_add_data_func("/tpm-tis/test_check_access_reg_release", &test
,
71 tpm_tis_test_check_access_reg_release
);
73 qtest_add_data_func("/tpm-tis/test_check_transmit", &test
,
74 tpm_tis_test_check_transmit
);
80 g_thread_join(thread
);
81 g_unlink(test
.addr
->u
.q_unix
.path
);
82 qapi_free_SocketAddress(test
.addr
);