1fe985ed6SEric Auger /* 2fe985ed6SEric Auger * QTest testcase for Sysbus TPM TIS talking to external swtpm and swtpm 3fe985ed6SEric Auger * migration 4fe985ed6SEric Auger * 5fe985ed6SEric Auger * Copyright (c) 2018 IBM Corporation 6fe985ed6SEric Auger * with parts borrowed from migration-test.c that is: 7fe985ed6SEric Auger * Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates 8fe985ed6SEric Auger * 9fe985ed6SEric Auger * Authors: 10fe985ed6SEric Auger * Stefan Berger <stefanb@linux.vnet.ibm.com> 11fe985ed6SEric Auger * 12fe985ed6SEric Auger * This work is licensed under the terms of the GNU GPL, version 2 or later. 13fe985ed6SEric Auger * See the COPYING file in the top-level directory. 14fe985ed6SEric Auger */ 15fe985ed6SEric Auger 16fe985ed6SEric Auger #include "qemu/osdep.h" 17fe985ed6SEric Auger 18907b5105SMarc-André Lureau #include "libqtest.h" 19fe985ed6SEric Auger #include "qemu/module.h" 20fe985ed6SEric Auger #include "tpm-tests.h" 21fe985ed6SEric Auger #include "hw/acpi/tpm.h" 22fe985ed6SEric Auger 23fe985ed6SEric Auger uint64_t tpm_tis_base_addr = 0xc000000; 24fe985ed6SEric Auger #define MACHINE_OPTIONS "-machine virt,gic-version=max -accel tcg" 25fe985ed6SEric Auger 26fe985ed6SEric Auger typedef struct TestState { 27fe985ed6SEric Auger char *src_tpm_path; 28fe985ed6SEric Auger char *dst_tpm_path; 29fe985ed6SEric Auger char *uri; 30fe985ed6SEric Auger } TestState; 31fe985ed6SEric Auger 32fe985ed6SEric Auger static void tpm_tis_swtpm_test(const void *data) 33fe985ed6SEric Auger { 34fe985ed6SEric Auger const TestState *ts = data; 35fe985ed6SEric Auger 36fe985ed6SEric Auger tpm_test_swtpm_test(ts->src_tpm_path, tpm_util_tis_transfer, 37fe985ed6SEric Auger "tpm-tis-device", MACHINE_OPTIONS); 38fe985ed6SEric Auger } 39fe985ed6SEric Auger 40fe985ed6SEric Auger static void tpm_tis_swtpm_migration_test(const void *data) 41fe985ed6SEric Auger { 42fe985ed6SEric Auger const TestState *ts = data; 43fe985ed6SEric Auger 44fe985ed6SEric Auger tpm_test_swtpm_migration_test(ts->src_tpm_path, ts->dst_tpm_path, ts->uri, 45fe985ed6SEric Auger tpm_util_tis_transfer, "tpm-tis-device", 46fe985ed6SEric Auger MACHINE_OPTIONS); 47fe985ed6SEric Auger } 48fe985ed6SEric Auger 49fe985ed6SEric Auger int main(int argc, char **argv) 50fe985ed6SEric Auger { 51fe985ed6SEric Auger int ret; 52fe985ed6SEric Auger TestState ts = { 0 }; 53fe985ed6SEric Auger 54fe985ed6SEric Auger ts.src_tpm_path = g_dir_make_tmp("qemu-tpm-tis-device-swtpm-test.XXXXXX", 55fe985ed6SEric Auger NULL); 56fe985ed6SEric Auger ts.dst_tpm_path = g_dir_make_tmp("qemu-tpm-tis-device-swtpm-test.XXXXXX", 57fe985ed6SEric Auger NULL); 58fe985ed6SEric Auger ts.uri = g_strdup_printf("unix:%s/migsocket", ts.src_tpm_path); 59fe985ed6SEric Auger 60fe985ed6SEric Auger module_call_init(MODULE_INIT_QOM); 61fe985ed6SEric Auger g_test_init(&argc, &argv, NULL); 62fe985ed6SEric Auger 63fe985ed6SEric Auger qtest_add_data_func("/tpm/tis-swtpm/test", &ts, tpm_tis_swtpm_test); 64fe985ed6SEric Auger qtest_add_data_func("/tpm/tis-swtpm-migration/test", &ts, 65fe985ed6SEric Auger tpm_tis_swtpm_migration_test); 66fe985ed6SEric Auger ret = g_test_run(); 67fe985ed6SEric Auger 68*daa8bb57SThomas Huth tpm_util_rmdir(ts.dst_tpm_path); 69fe985ed6SEric Auger g_free(ts.dst_tpm_path); 70*daa8bb57SThomas Huth tpm_util_rmdir(ts.src_tpm_path); 71fe985ed6SEric Auger g_free(ts.src_tpm_path); 72fe985ed6SEric Auger g_free(ts.uri); 73fe985ed6SEric Auger 74fe985ed6SEric Auger return ret; 75fe985ed6SEric Auger } 76