1 /* 2 * QTest testcase for ISA TPM TIS 3 * 4 * Copyright (c) 2018 Red Hat, Inc. 5 * Copyright (c) 2018 IBM Corporation 6 * 7 * Authors: 8 * Marc-André Lureau <marcandre.lureau@redhat.com> 9 * Stefan Berger <stefanb@linux.vnet.ibm.com> 10 * 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. 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 25 uint64_t tpm_tis_base_addr = TPM_TIS_ADDR_BASE; 26 27 int 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