Stefan Berger | b21373d | 2018-03-07 14:45:06 -0500 | [diff] [blame] | 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 | #include <glib/gstdio.h> |
| 17 | |
Stefan Berger | b21373d | 2018-03-07 14:45:06 -0500 | [diff] [blame] | 18 | #include "libqtest.h" |
Stefan Berger | 2b4ccb8 | 2018-05-30 12:30:26 -0400 | [diff] [blame] | 19 | #include "tpm-tests.h" |
Stefan Berger | b21373d | 2018-03-07 14:45:06 -0500 | [diff] [blame] | 20 | |
| 21 | typedef struct TestState { |
| 22 | char *src_tpm_path; |
| 23 | char *dst_tpm_path; |
| 24 | char *uri; |
| 25 | } TestState; |
| 26 | |
Stefan Berger | b21373d | 2018-03-07 14:45:06 -0500 | [diff] [blame] | 27 | static void tpm_crb_swtpm_test(const void *data) |
| 28 | { |
Stefan Berger | b21373d | 2018-03-07 14:45:06 -0500 | [diff] [blame] | 29 | const TestState *ts = data; |
| 30 | |
Stefan Berger | ea71a33 | 2018-05-30 14:31:12 -0400 | [diff] [blame] | 31 | tpm_test_swtpm_test(ts->src_tpm_path, tpm_util_crb_transfer, "tpm-crb"); |
Stefan Berger | b21373d | 2018-03-07 14:45:06 -0500 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | static void tpm_crb_swtpm_migration_test(const void *data) |
| 35 | { |
| 36 | const TestState *ts = data; |
Stefan Berger | b21373d | 2018-03-07 14:45:06 -0500 | [diff] [blame] | 37 | |
Stefan Berger | 2b4ccb8 | 2018-05-30 12:30:26 -0400 | [diff] [blame] | 38 | tpm_test_swtpm_migration_test(ts->src_tpm_path, ts->dst_tpm_path, ts->uri, |
Stefan Berger | ea71a33 | 2018-05-30 14:31:12 -0400 | [diff] [blame] | 39 | tpm_util_crb_transfer, "tpm-crb"); |
Stefan Berger | b21373d | 2018-03-07 14:45:06 -0500 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | int main(int argc, char **argv) |
| 43 | { |
| 44 | int ret; |
| 45 | TestState ts = { 0 }; |
| 46 | |
| 47 | ts.src_tpm_path = g_dir_make_tmp("qemu-tpm-crb-swtpm-test.XXXXXX", NULL); |
| 48 | ts.dst_tpm_path = g_dir_make_tmp("qemu-tpm-crb-swtpm-test.XXXXXX", NULL); |
| 49 | ts.uri = g_strdup_printf("unix:%s/migsocket", ts.src_tpm_path); |
| 50 | |
| 51 | module_call_init(MODULE_INIT_QOM); |
| 52 | g_test_init(&argc, &argv, NULL); |
| 53 | |
| 54 | qtest_add_data_func("/tpm/crb-swtpm/test", &ts, tpm_crb_swtpm_test); |
| 55 | qtest_add_data_func("/tpm/crb-swtpm-migration/test", &ts, |
| 56 | tpm_crb_swtpm_migration_test); |
| 57 | ret = g_test_run(); |
| 58 | |
| 59 | g_rmdir(ts.dst_tpm_path); |
| 60 | g_free(ts.dst_tpm_path); |
| 61 | g_rmdir(ts.src_tpm_path); |
| 62 | g_free(ts.src_tpm_path); |
| 63 | g_free(ts.uri); |
| 64 | |
| 65 | return ret; |
| 66 | } |