11e8a1faeSThomas Huth /*
25166c326SEric Auger * QTest testcase for ISA TPM TIS
31e8a1faeSThomas Huth *
41e8a1faeSThomas Huth * Copyright (c) 2018 Red Hat, Inc.
51e8a1faeSThomas Huth * Copyright (c) 2018 IBM Corporation
61e8a1faeSThomas Huth *
71e8a1faeSThomas Huth * Authors:
81e8a1faeSThomas Huth * Marc-André Lureau <marcandre.lureau@redhat.com>
91e8a1faeSThomas Huth * Stefan Berger <stefanb@linux.vnet.ibm.com>
101e8a1faeSThomas Huth *
111e8a1faeSThomas Huth * This work is licensed under the terms of the GNU GPL, version 2 or later.
121e8a1faeSThomas Huth * See the COPYING file in the top-level directory.
131e8a1faeSThomas Huth */
141e8a1faeSThomas Huth
151e8a1faeSThomas Huth #include "qemu/osdep.h"
161e8a1faeSThomas Huth #include <glib/gstdio.h>
171e8a1faeSThomas Huth
181e8a1faeSThomas Huth #include "hw/acpi/tpm.h"
191e8a1faeSThomas Huth #include "io/channel-socket.h"
201e8a1faeSThomas Huth #include "libqtest-single.h"
211e8a1faeSThomas Huth #include "qemu/module.h"
221e8a1faeSThomas Huth #include "tpm-emu.h"
235166c326SEric Auger #include "tpm-tis-util.h"
241e8a1faeSThomas Huth
255166c326SEric Auger uint64_t tpm_tis_base_addr = TPM_TIS_ADDR_BASE;
261e8a1faeSThomas Huth
main(int argc,char ** argv)271e8a1faeSThomas Huth int main(int argc, char **argv)
281e8a1faeSThomas Huth {
291e8a1faeSThomas Huth int ret;
301e8a1faeSThomas Huth char *args, *tmp_path = g_dir_make_tmp("qemu-tpm-tis-test.XXXXXX", NULL);
311e8a1faeSThomas Huth GThread *thread;
329bd0e32aSStefan Berger TPMTestState test;
331e8a1faeSThomas Huth
341e8a1faeSThomas Huth module_call_init(MODULE_INIT_QOM);
351e8a1faeSThomas Huth g_test_init(&argc, &argv, NULL);
361e8a1faeSThomas Huth
371e8a1faeSThomas Huth test.addr = g_new0(SocketAddress, 1);
381e8a1faeSThomas Huth test.addr->type = SOCKET_ADDRESS_TYPE_UNIX;
391e8a1faeSThomas Huth test.addr->u.q_unix.path = g_build_filename(tmp_path, "sock", NULL);
401e8a1faeSThomas Huth g_mutex_init(&test.data_mutex);
411e8a1faeSThomas Huth g_cond_init(&test.data_cond);
421e8a1faeSThomas Huth test.data_cond_signal = false;
43*09b20a14SStefan Berger test.tpm_version = TPM_VERSION_2_0;
441e8a1faeSThomas Huth
451e8a1faeSThomas Huth thread = g_thread_new(NULL, tpm_emu_ctrl_thread, &test);
461e8a1faeSThomas Huth tpm_emu_test_wait_cond(&test);
471e8a1faeSThomas Huth
481e8a1faeSThomas Huth args = g_strdup_printf(
491e8a1faeSThomas Huth "-chardev socket,id=chr,path=%s "
501e8a1faeSThomas Huth "-tpmdev emulator,id=dev,chardev=chr "
511e8a1faeSThomas Huth "-device tpm-tis,tpmdev=dev",
521e8a1faeSThomas Huth test.addr->u.q_unix.path);
531e8a1faeSThomas Huth qtest_start(args);
541e8a1faeSThomas Huth
551e8a1faeSThomas Huth qtest_add_data_func("/tpm-tis/test_check_localities", &test,
561e8a1faeSThomas Huth tpm_tis_test_check_localities);
571e8a1faeSThomas Huth
581e8a1faeSThomas Huth qtest_add_data_func("/tpm-tis/test_check_access_reg", &test,
591e8a1faeSThomas Huth tpm_tis_test_check_access_reg);
601e8a1faeSThomas Huth
611e8a1faeSThomas Huth qtest_add_data_func("/tpm-tis/test_check_access_reg_seize", &test,
621e8a1faeSThomas Huth tpm_tis_test_check_access_reg_seize);
631e8a1faeSThomas Huth
641e8a1faeSThomas Huth qtest_add_data_func("/tpm-tis/test_check_access_reg_release", &test,
651e8a1faeSThomas Huth tpm_tis_test_check_access_reg_release);
661e8a1faeSThomas Huth
671e8a1faeSThomas Huth qtest_add_data_func("/tpm-tis/test_check_transmit", &test,
681e8a1faeSThomas Huth tpm_tis_test_check_transmit);
691e8a1faeSThomas Huth
701e8a1faeSThomas Huth ret = g_test_run();
711e8a1faeSThomas Huth
721e8a1faeSThomas Huth qtest_end();
731e8a1faeSThomas Huth
741e8a1faeSThomas Huth g_thread_join(thread);
751e8a1faeSThomas Huth g_unlink(test.addr->u.q_unix.path);
761e8a1faeSThomas Huth qapi_free_SocketAddress(test.addr);
771e8a1faeSThomas Huth g_rmdir(tmp_path);
781e8a1faeSThomas Huth g_free(tmp_path);
791e8a1faeSThomas Huth g_free(args);
801e8a1faeSThomas Huth return ret;
811e8a1faeSThomas Huth }
82