11e8a1faeSThomas Huth /*
21e8a1faeSThomas Huth * QTest testcase for TPM TIS talking to external swtpm and swtpm migration
31e8a1faeSThomas Huth *
41e8a1faeSThomas Huth * Copyright (c) 2018 IBM Corporation
51e8a1faeSThomas Huth * with parts borrowed from migration-test.c that is:
61e8a1faeSThomas Huth * Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates
71e8a1faeSThomas Huth *
81e8a1faeSThomas Huth * Authors:
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
17907b5105SMarc-André Lureau #include "libqtest.h"
181e8a1faeSThomas Huth #include "qemu/module.h"
191e8a1faeSThomas Huth #include "tpm-tests.h"
20*a4c12c1dSStefan Berger #include "tpm-tis-util.h"
215166c326SEric Auger #include "hw/acpi/tpm.h"
225166c326SEric Auger
235166c326SEric Auger uint64_t tpm_tis_base_addr = TPM_TIS_ADDR_BASE;
241e8a1faeSThomas Huth
251e8a1faeSThomas Huth typedef struct TestState {
261e8a1faeSThomas Huth char *src_tpm_path;
271e8a1faeSThomas Huth char *dst_tpm_path;
281e8a1faeSThomas Huth char *uri;
291e8a1faeSThomas Huth } TestState;
301e8a1faeSThomas Huth
tpm_tis_swtpm_test(const void * data)311e8a1faeSThomas Huth static void tpm_tis_swtpm_test(const void *data)
321e8a1faeSThomas Huth {
331e8a1faeSThomas Huth const TestState *ts = data;
341e8a1faeSThomas Huth
35*a4c12c1dSStefan Berger tpm_test_swtpm_test(ts->src_tpm_path, tpm_tis_transfer,
36551cabdfSEric Auger "tpm-tis", NULL);
371e8a1faeSThomas Huth }
381e8a1faeSThomas Huth
tpm_tis_swtpm_migration_test(const void * data)391e8a1faeSThomas Huth static void tpm_tis_swtpm_migration_test(const void *data)
401e8a1faeSThomas Huth {
411e8a1faeSThomas Huth const TestState *ts = data;
421e8a1faeSThomas Huth
431e8a1faeSThomas Huth tpm_test_swtpm_migration_test(ts->src_tpm_path, ts->dst_tpm_path, ts->uri,
44*a4c12c1dSStefan Berger tpm_tis_transfer, "tpm-tis", NULL);
451e8a1faeSThomas Huth }
461e8a1faeSThomas Huth
main(int argc,char ** argv)471e8a1faeSThomas Huth int main(int argc, char **argv)
481e8a1faeSThomas Huth {
491e8a1faeSThomas Huth int ret;
501e8a1faeSThomas Huth TestState ts = { 0 };
511e8a1faeSThomas Huth
521e8a1faeSThomas Huth ts.src_tpm_path = g_dir_make_tmp("qemu-tpm-tis-swtpm-test.XXXXXX", NULL);
531e8a1faeSThomas Huth ts.dst_tpm_path = g_dir_make_tmp("qemu-tpm-tis-swtpm-test.XXXXXX", NULL);
541e8a1faeSThomas Huth ts.uri = g_strdup_printf("unix:%s/migsocket", ts.src_tpm_path);
551e8a1faeSThomas Huth
561e8a1faeSThomas Huth module_call_init(MODULE_INIT_QOM);
571e8a1faeSThomas Huth g_test_init(&argc, &argv, NULL);
581e8a1faeSThomas Huth
591e8a1faeSThomas Huth qtest_add_data_func("/tpm/tis-swtpm/test", &ts, tpm_tis_swtpm_test);
601e8a1faeSThomas Huth qtest_add_data_func("/tpm/tis-swtpm-migration/test", &ts,
611e8a1faeSThomas Huth tpm_tis_swtpm_migration_test);
621e8a1faeSThomas Huth ret = g_test_run();
631e8a1faeSThomas Huth
64daa8bb57SThomas Huth tpm_util_rmdir(ts.dst_tpm_path);
651e8a1faeSThomas Huth g_free(ts.dst_tpm_path);
66daa8bb57SThomas Huth tpm_util_rmdir(ts.src_tpm_path);
671e8a1faeSThomas Huth g_free(ts.src_tpm_path);
681e8a1faeSThomas Huth g_free(ts.uri);
691e8a1faeSThomas Huth
701e8a1faeSThomas Huth return ret;
711e8a1faeSThomas Huth }
72