11e8a1faeSThomas Huth /*
21e8a1faeSThomas Huth * QTest testcase for TPM CRB 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"
205166c326SEric Auger #include "hw/acpi/tpm.h"
215166c326SEric Auger
221e8a1faeSThomas Huth typedef struct TestState {
231e8a1faeSThomas Huth char *src_tpm_path;
241e8a1faeSThomas Huth char *dst_tpm_path;
251e8a1faeSThomas Huth char *uri;
261e8a1faeSThomas Huth } TestState;
271e8a1faeSThomas Huth
tpm_crb_swtpm_test(const void * data)281e8a1faeSThomas Huth static void tpm_crb_swtpm_test(const void *data)
291e8a1faeSThomas Huth {
301e8a1faeSThomas Huth const TestState *ts = data;
311e8a1faeSThomas Huth
32551cabdfSEric Auger tpm_test_swtpm_test(ts->src_tpm_path, tpm_util_crb_transfer,
33551cabdfSEric Auger "tpm-crb", NULL);
341e8a1faeSThomas Huth }
351e8a1faeSThomas Huth
tpm_crb_swtpm_migration_test(const void * data)361e8a1faeSThomas Huth static void tpm_crb_swtpm_migration_test(const void *data)
371e8a1faeSThomas Huth {
381e8a1faeSThomas Huth const TestState *ts = data;
391e8a1faeSThomas Huth
401e8a1faeSThomas Huth tpm_test_swtpm_migration_test(ts->src_tpm_path, ts->dst_tpm_path, ts->uri,
41551cabdfSEric Auger tpm_util_crb_transfer, "tpm-crb", NULL);
421e8a1faeSThomas Huth }
431e8a1faeSThomas Huth
main(int argc,char ** argv)441e8a1faeSThomas Huth int main(int argc, char **argv)
451e8a1faeSThomas Huth {
461e8a1faeSThomas Huth int ret;
471e8a1faeSThomas Huth TestState ts = { 0 };
481e8a1faeSThomas Huth
491e8a1faeSThomas Huth ts.src_tpm_path = g_dir_make_tmp("qemu-tpm-crb-swtpm-test.XXXXXX", NULL);
501e8a1faeSThomas Huth ts.dst_tpm_path = g_dir_make_tmp("qemu-tpm-crb-swtpm-test.XXXXXX", NULL);
511e8a1faeSThomas Huth ts.uri = g_strdup_printf("unix:%s/migsocket", ts.src_tpm_path);
521e8a1faeSThomas Huth
531e8a1faeSThomas Huth module_call_init(MODULE_INIT_QOM);
541e8a1faeSThomas Huth g_test_init(&argc, &argv, NULL);
551e8a1faeSThomas Huth
561e8a1faeSThomas Huth qtest_add_data_func("/tpm/crb-swtpm/test", &ts, tpm_crb_swtpm_test);
571e8a1faeSThomas Huth qtest_add_data_func("/tpm/crb-swtpm-migration/test", &ts,
581e8a1faeSThomas Huth tpm_crb_swtpm_migration_test);
591e8a1faeSThomas Huth ret = g_test_run();
601e8a1faeSThomas Huth
61*daa8bb57SThomas Huth tpm_util_rmdir(ts.dst_tpm_path);
621e8a1faeSThomas Huth g_free(ts.dst_tpm_path);
63*daa8bb57SThomas Huth tpm_util_rmdir(ts.src_tpm_path);
641e8a1faeSThomas Huth g_free(ts.src_tpm_path);
651e8a1faeSThomas Huth g_free(ts.uri);
661e8a1faeSThomas Huth
671e8a1faeSThomas Huth return ret;
681e8a1faeSThomas Huth }
69