| 1 | /* |
| 2 | * QTest testcase for TPM CRB talking to external swtpm and swtpm migration |
| 3 | * |
| 4 | * Copyright (c) 2018 IBM Corporation |
| 5 | * with parts borrowed from migration-test.c that is: |
| 6 | * Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates |
| 7 | * |
| 8 | * Authors: |
| 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 | |
| 17 | #include "libqtest.h" |
| 18 | #include "qemu/module.h" |
| 19 | #include "tpm-tests.h" |
| 20 | #include "hw/acpi/tpm.h" |
| 21 | |
| 22 | typedef struct TestState { |
| 23 | char *src_tpm_path; |
| 24 | char *dst_tpm_path; |
| 25 | char *uri; |
| 26 | } TestState; |
| 27 | |
| 28 | static void tpm_crb_swtpm_test(const void *data) |
| 29 | { |
| 30 | const TestState *ts = data; |
| 31 | |
| 32 | tpm_test_swtpm_test(ts->src_tpm_path, tpm_util_crb_transfer, |
| 33 | "tpm-crb", NULL); |
| 34 | } |
| 35 | |
| 36 | static void tpm_crb_chunk_swtpm_test(const void *data) |
| 37 | { |
| 38 | const TestState *ts = data; |
| 39 | |
| 40 | tpm_test_swtpm_test(ts->src_tpm_path, tpm_util_crb_chunk_transfer, |
| 41 | "tpm-crb", NULL); |
| 42 | } |
| 43 | |
| 44 | static void tpm_crb_swtpm_migration_test(const void *data) |
| 45 | { |
| 46 | const TestState *ts = data; |
| 47 | |
| 48 | tpm_test_swtpm_migration_test(ts->src_tpm_path, ts->dst_tpm_path, ts->uri, |
| 49 | tpm_util_crb_transfer, "tpm-crb", NULL); |
| 50 | } |
| 51 | |
| 52 | int main(int argc, char **argv) |
| 53 | { |
| 54 | int ret; |
| 55 | TestState ts = { 0 }; |
| 56 | |
| 57 | ts.src_tpm_path = g_dir_make_tmp("qemu-tpm-crb-swtpm-test.XXXXXX", NULL); |
| 58 | ts.dst_tpm_path = g_dir_make_tmp("qemu-tpm-crb-swtpm-test.XXXXXX", NULL); |
| 59 | ts.uri = g_strdup_printf("unix:%s/migsocket", ts.src_tpm_path); |
| 60 | |
| 61 | module_call_init(MODULE_INIT_QOM); |
| 62 | g_test_init(&argc, &argv, NULL); |
| 63 | |
| 64 | qtest_add_data_func("/tpm/crb-swtpm/test", &ts, tpm_crb_swtpm_test); |
| 65 | qtest_add_data_func("/tpm/crb-chunk-swtpm/test", &ts, |
| 66 | tpm_crb_chunk_swtpm_test); |
| 67 | qtest_add_data_func("/tpm/crb-swtpm-migration/test", &ts, |
| 68 | tpm_crb_swtpm_migration_test); |
| 69 | ret = g_test_run(); |
| 70 | |
| 71 | tpm_util_rmdir(ts.dst_tpm_path); |
| 72 | g_free(ts.dst_tpm_path); |
| 73 | tpm_util_rmdir(ts.src_tpm_path); |
| 74 | g_free(ts.src_tpm_path); |
| 75 | g_free(ts.uri); |
| 76 | |
| 77 | return ret; |
| 78 | } |