tests/qtest/bios-tables-test: Check for dup2() failure
[qemu/ar7.git] / tests / qtest / tpm-tis-device-test.c
blob63ed36440fd290499a8bcf8d1b87abb3bda0e590
1 /*
2 * QTest testcase for SYSBUS TPM TIS
4 * Copyright (c) 2018 Red Hat, Inc.
5 * Copyright (c) 2018 IBM Corporation
7 * Authors:
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"
21 #include "tpm-emu.h"
22 #include "tpm-util.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);
35 GThread *thread;
36 TestState test;
37 char *args;
38 int ret;
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);
59 qtest_start(args);
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);
76 ret = g_test_run();
78 qtest_end();
80 g_thread_join(thread);
81 g_unlink(test.addr->u.q_unix.path);
82 qapi_free_SocketAddress(test.addr);
83 g_rmdir(tmp_path);
84 g_free(tmp_path);
85 g_free(args);
86 return ret;