* [Qemu-devel] [PATCH 1/4] test: Move reusable code from tpm-crb-swtpm-test.c to tpm-util.c
2018-05-30 19:35 [Qemu-devel] [PATCH 0/4] Refactor code and implement another TPM TIS test Stefan Berger
@ 2018-05-30 19:35 ` Stefan Berger
2018-05-31 10:53 ` Marc-André Lureau
2018-05-30 19:35 ` [Qemu-devel] [PATCH 2/4] test: Move common TPM test functions to tpm-tests.c Stefan Berger
` (2 subsequent siblings)
3 siblings, 1 reply; 9+ messages in thread
From: Stefan Berger @ 2018-05-30 19:35 UTC (permalink / raw)
To: qemu-devel; +Cc: marcandre.lureau, Stefan Berger
Move code we can reuse from tpm-crb-swtpm-test.c into tpm-util.c
and prefix functions with 'tpm_util_'.
Remove some unnecessary #include's.
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
---
tests/tpm-crb-swtpm-test.c | 100 +++------------------------------------------
tests/tpm-util.c | 89 ++++++++++++++++++++++++++++++++++++++++
tests/tpm-util.h | 10 +++++
3 files changed, 104 insertions(+), 95 deletions(-)
diff --git a/tests/tpm-crb-swtpm-test.c b/tests/tpm-crb-swtpm-test.c
index c2bde0cbaa..2a22b032ca 100644
--- a/tests/tpm-crb-swtpm-test.c
+++ b/tests/tpm-crb-swtpm-test.c
@@ -15,12 +15,8 @@
#include "qemu/osdep.h"
#include <glib/gstdio.h>
-#include "hw/acpi/tpm.h"
-#include "io/channel-socket.h"
#include "libqtest.h"
#include "tpm-util.h"
-#include "sysemu/tpm.h"
-#include "qapi/qmp/qdict.h"
typedef struct TestState {
char *src_tpm_path;
@@ -28,93 +24,6 @@ typedef struct TestState {
char *uri;
} TestState;
-bool got_stop;
-
-static void migrate(QTestState *who, const char *uri)
-{
- QDict *rsp;
- gchar *cmd;
-
- cmd = g_strdup_printf("{ 'execute': 'migrate',"
- "'arguments': { 'uri': '%s' } }",
- uri);
- rsp = qtest_qmp(who, cmd);
- g_free(cmd);
- g_assert(qdict_haskey(rsp, "return"));
- qobject_unref(rsp);
-}
-
-/*
- * Events can get in the way of responses we are actually waiting for.
- */
-static QDict *wait_command(QTestState *who, const char *command)
-{
- const char *event_string;
- QDict *response;
-
- response = qtest_qmp(who, command);
-
- while (qdict_haskey(response, "event")) {
- /* OK, it was an event */
- event_string = qdict_get_str(response, "event");
- if (!strcmp(event_string, "STOP")) {
- got_stop = true;
- }
- qobject_unref(response);
- response = qtest_qmp_receive(who);
- }
- return response;
-}
-
-static void wait_for_migration_complete(QTestState *who)
-{
- while (true) {
- QDict *rsp, *rsp_return;
- bool completed;
- const char *status;
-
- rsp = wait_command(who, "{ 'execute': 'query-migrate' }");
- rsp_return = qdict_get_qdict(rsp, "return");
- status = qdict_get_str(rsp_return, "status");
- completed = strcmp(status, "completed") == 0;
- g_assert_cmpstr(status, !=, "failed");
- qobject_unref(rsp);
- if (completed) {
- return;
- }
- usleep(1000);
- }
-}
-
-static void migration_start_qemu(QTestState **src_qemu, QTestState **dst_qemu,
- SocketAddress *src_tpm_addr,
- SocketAddress *dst_tpm_addr,
- const char *miguri)
-{
- char *src_qemu_args, *dst_qemu_args;
-
- src_qemu_args = g_strdup_printf(
- "-chardev socket,id=chr,path=%s "
- "-tpmdev emulator,id=dev,chardev=chr "
- "-device tpm-crb,tpmdev=dev ",
- src_tpm_addr->u.q_unix.path);
-
- *src_qemu = qtest_init(src_qemu_args);
-
- dst_qemu_args = g_strdup_printf(
- "-chardev socket,id=chr,path=%s "
- "-tpmdev emulator,id=dev,chardev=chr "
- "-device tpm-crb,tpmdev=dev "
- "-incoming %s",
- dst_tpm_addr->u.q_unix.path,
- miguri);
-
- *dst_qemu = qtest_init(dst_qemu_args);
-
- free(src_qemu_args);
- free(dst_qemu_args);
-}
-
static void tpm_crb_swtpm_test(const void *data)
{
char *args = NULL;
@@ -183,8 +92,9 @@ static void tpm_crb_swtpm_migration_test(const void *data)
goto err_src_tpm_kill;
}
- migration_start_qemu(&src_qemu, &dst_qemu, src_tpm_addr, dst_tpm_addr,
- ts->uri);
+ tpm_util_migration_start_qemu(&src_qemu, &dst_qemu,
+ src_tpm_addr, dst_tpm_addr,
+ ts->uri);
tpm_util_startup(src_qemu, tpm_util_crb_transfer);
tpm_util_pcrextend(src_qemu, tpm_util_crb_transfer);
@@ -197,8 +107,8 @@ static void tpm_crb_swtpm_migration_test(const void *data)
tpm_util_pcrread(src_qemu, tpm_util_crb_transfer, tpm_pcrread_resp,
sizeof(tpm_pcrread_resp));
- migrate(src_qemu, ts->uri);
- wait_for_migration_complete(src_qemu);
+ tpm_util_migrate(src_qemu, ts->uri);
+ tpm_util_wait_for_migration_complete(src_qemu);
tpm_util_pcrread(dst_qemu, tpm_util_crb_transfer, tpm_pcrread_resp,
sizeof(tpm_pcrread_resp));
diff --git a/tests/tpm-util.c b/tests/tpm-util.c
index c9b3947c1c..e6e3b922fa 100644
--- a/tests/tpm-util.c
+++ b/tests/tpm-util.c
@@ -17,6 +17,9 @@
#include "hw/acpi/tpm.h"
#include "libqtest.h"
#include "tpm-util.h"
+#include "qapi/qmp/qdict.h"
+
+static bool got_stop;
void tpm_util_crb_transfer(QTestState *s,
const unsigned char *req, size_t req_size,
@@ -184,3 +187,89 @@ void tpm_util_swtpm_kill(GPid pid)
kill(pid, SIGKILL);
}
+
+void tpm_util_migrate(QTestState *who, const char *uri)
+{
+ QDict *rsp;
+ gchar *cmd;
+
+ cmd = g_strdup_printf("{ 'execute': 'migrate',"
+ "'arguments': { 'uri': '%s' } }",
+ uri);
+ rsp = qtest_qmp(who, cmd);
+ g_free(cmd);
+ g_assert(qdict_haskey(rsp, "return"));
+ qobject_unref(rsp);
+}
+
+/*
+ * Events can get in the way of responses we are actually waiting for.
+ */
+static QDict *tpm_util_wait_command(QTestState *who, const char *command)
+{
+ const char *event_string;
+ QDict *response;
+
+ response = qtest_qmp(who, command);
+
+ while (qdict_haskey(response, "event")) {
+ /* OK, it was an event */
+ event_string = qdict_get_str(response, "event");
+ if (!strcmp(event_string, "STOP")) {
+ got_stop = true;
+ }
+ qobject_unref(response);
+ response = qtest_qmp_receive(who);
+ }
+ return response;
+}
+
+void tpm_util_wait_for_migration_complete(QTestState *who)
+{
+ while (true) {
+ QDict *rsp, *rsp_return;
+ bool completed;
+ const char *status;
+
+ rsp = tpm_util_wait_command(who, "{ 'execute': 'query-migrate' }");
+ rsp_return = qdict_get_qdict(rsp, "return");
+ status = qdict_get_str(rsp_return, "status");
+ completed = strcmp(status, "completed") == 0;
+ g_assert_cmpstr(status, !=, "failed");
+ qobject_unref(rsp);
+ if (completed) {
+ return;
+ }
+ usleep(1000);
+ }
+}
+
+void tpm_util_migration_start_qemu(QTestState **src_qemu,
+ QTestState **dst_qemu,
+ SocketAddress *src_tpm_addr,
+ SocketAddress *dst_tpm_addr,
+ const char *miguri)
+{
+ char *src_qemu_args, *dst_qemu_args;
+
+ src_qemu_args = g_strdup_printf(
+ "-chardev socket,id=chr,path=%s "
+ "-tpmdev emulator,id=dev,chardev=chr "
+ "-device tpm-crb,tpmdev=dev ",
+ src_tpm_addr->u.q_unix.path);
+
+ *src_qemu = qtest_init(src_qemu_args);
+
+ dst_qemu_args = g_strdup_printf(
+ "-chardev socket,id=chr,path=%s "
+ "-tpmdev emulator,id=dev,chardev=chr "
+ "-device tpm-crb,tpmdev=dev "
+ "-incoming %s",
+ dst_tpm_addr->u.q_unix.path,
+ miguri);
+
+ *dst_qemu = qtest_init(dst_qemu_args);
+
+ free(src_qemu_args);
+ free(dst_qemu_args);
+}
diff --git a/tests/tpm-util.h b/tests/tpm-util.h
index d155d99aea..b6253106d9 100644
--- a/tests/tpm-util.h
+++ b/tests/tpm-util.h
@@ -33,4 +33,14 @@ gboolean tpm_util_swtpm_start(const char *path, GPid *pid,
SocketAddress **addr, GError **error);
void tpm_util_swtpm_kill(GPid pid);
+void tpm_util_migrate(QTestState *who, const char *uri);
+
+void tpm_util_migration_start_qemu(QTestState **src_qemu,
+ QTestState **dst_qemu,
+ SocketAddress *src_tpm_addr,
+ SocketAddress *dst_tpm_addr,
+ const char *miguri);
+
+void tpm_util_wait_for_migration_complete(QTestState *who);
+
#endif /* TESTS_TPM_UTIL_H */
--
2.14.3
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH 1/4] test: Move reusable code from tpm-crb-swtpm-test.c to tpm-util.c
2018-05-30 19:35 ` [Qemu-devel] [PATCH 1/4] test: Move reusable code from tpm-crb-swtpm-test.c to tpm-util.c Stefan Berger
@ 2018-05-31 10:53 ` Marc-André Lureau
0 siblings, 0 replies; 9+ messages in thread
From: Marc-André Lureau @ 2018-05-31 10:53 UTC (permalink / raw)
To: Stefan Berger; +Cc: QEMU
On Wed, May 30, 2018 at 9:35 PM, Stefan Berger
<stefanb@linux.vnet.ibm.com> wrote:
> Move code we can reuse from tpm-crb-swtpm-test.c into tpm-util.c
> and prefix functions with 'tpm_util_'.
>
> Remove some unnecessary #include's.
>
> Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
> tests/tpm-crb-swtpm-test.c | 100 +++------------------------------------------
> tests/tpm-util.c | 89 ++++++++++++++++++++++++++++++++++++++++
> tests/tpm-util.h | 10 +++++
> 3 files changed, 104 insertions(+), 95 deletions(-)
>
> diff --git a/tests/tpm-crb-swtpm-test.c b/tests/tpm-crb-swtpm-test.c
> index c2bde0cbaa..2a22b032ca 100644
> --- a/tests/tpm-crb-swtpm-test.c
> +++ b/tests/tpm-crb-swtpm-test.c
> @@ -15,12 +15,8 @@
> #include "qemu/osdep.h"
> #include <glib/gstdio.h>
>
> -#include "hw/acpi/tpm.h"
> -#include "io/channel-socket.h"
> #include "libqtest.h"
> #include "tpm-util.h"
> -#include "sysemu/tpm.h"
> -#include "qapi/qmp/qdict.h"
>
> typedef struct TestState {
> char *src_tpm_path;
> @@ -28,93 +24,6 @@ typedef struct TestState {
> char *uri;
> } TestState;
>
> -bool got_stop;
> -
> -static void migrate(QTestState *who, const char *uri)
> -{
> - QDict *rsp;
> - gchar *cmd;
> -
> - cmd = g_strdup_printf("{ 'execute': 'migrate',"
> - "'arguments': { 'uri': '%s' } }",
> - uri);
> - rsp = qtest_qmp(who, cmd);
> - g_free(cmd);
> - g_assert(qdict_haskey(rsp, "return"));
> - qobject_unref(rsp);
> -}
> -
> -/*
> - * Events can get in the way of responses we are actually waiting for.
> - */
> -static QDict *wait_command(QTestState *who, const char *command)
> -{
> - const char *event_string;
> - QDict *response;
> -
> - response = qtest_qmp(who, command);
> -
> - while (qdict_haskey(response, "event")) {
> - /* OK, it was an event */
> - event_string = qdict_get_str(response, "event");
> - if (!strcmp(event_string, "STOP")) {
> - got_stop = true;
> - }
> - qobject_unref(response);
> - response = qtest_qmp_receive(who);
> - }
> - return response;
> -}
> -
> -static void wait_for_migration_complete(QTestState *who)
> -{
> - while (true) {
> - QDict *rsp, *rsp_return;
> - bool completed;
> - const char *status;
> -
> - rsp = wait_command(who, "{ 'execute': 'query-migrate' }");
> - rsp_return = qdict_get_qdict(rsp, "return");
> - status = qdict_get_str(rsp_return, "status");
> - completed = strcmp(status, "completed") == 0;
> - g_assert_cmpstr(status, !=, "failed");
> - qobject_unref(rsp);
> - if (completed) {
> - return;
> - }
> - usleep(1000);
> - }
> -}
> -
> -static void migration_start_qemu(QTestState **src_qemu, QTestState **dst_qemu,
> - SocketAddress *src_tpm_addr,
> - SocketAddress *dst_tpm_addr,
> - const char *miguri)
> -{
> - char *src_qemu_args, *dst_qemu_args;
> -
> - src_qemu_args = g_strdup_printf(
> - "-chardev socket,id=chr,path=%s "
> - "-tpmdev emulator,id=dev,chardev=chr "
> - "-device tpm-crb,tpmdev=dev ",
> - src_tpm_addr->u.q_unix.path);
> -
> - *src_qemu = qtest_init(src_qemu_args);
> -
> - dst_qemu_args = g_strdup_printf(
> - "-chardev socket,id=chr,path=%s "
> - "-tpmdev emulator,id=dev,chardev=chr "
> - "-device tpm-crb,tpmdev=dev "
> - "-incoming %s",
> - dst_tpm_addr->u.q_unix.path,
> - miguri);
> -
> - *dst_qemu = qtest_init(dst_qemu_args);
> -
> - free(src_qemu_args);
> - free(dst_qemu_args);
> -}
> -
> static void tpm_crb_swtpm_test(const void *data)
> {
> char *args = NULL;
> @@ -183,8 +92,9 @@ static void tpm_crb_swtpm_migration_test(const void *data)
> goto err_src_tpm_kill;
> }
>
> - migration_start_qemu(&src_qemu, &dst_qemu, src_tpm_addr, dst_tpm_addr,
> - ts->uri);
> + tpm_util_migration_start_qemu(&src_qemu, &dst_qemu,
> + src_tpm_addr, dst_tpm_addr,
> + ts->uri);
>
> tpm_util_startup(src_qemu, tpm_util_crb_transfer);
> tpm_util_pcrextend(src_qemu, tpm_util_crb_transfer);
> @@ -197,8 +107,8 @@ static void tpm_crb_swtpm_migration_test(const void *data)
> tpm_util_pcrread(src_qemu, tpm_util_crb_transfer, tpm_pcrread_resp,
> sizeof(tpm_pcrread_resp));
>
> - migrate(src_qemu, ts->uri);
> - wait_for_migration_complete(src_qemu);
> + tpm_util_migrate(src_qemu, ts->uri);
> + tpm_util_wait_for_migration_complete(src_qemu);
>
> tpm_util_pcrread(dst_qemu, tpm_util_crb_transfer, tpm_pcrread_resp,
> sizeof(tpm_pcrread_resp));
> diff --git a/tests/tpm-util.c b/tests/tpm-util.c
> index c9b3947c1c..e6e3b922fa 100644
> --- a/tests/tpm-util.c
> +++ b/tests/tpm-util.c
> @@ -17,6 +17,9 @@
> #include "hw/acpi/tpm.h"
> #include "libqtest.h"
> #include "tpm-util.h"
> +#include "qapi/qmp/qdict.h"
> +
> +static bool got_stop;
>
> void tpm_util_crb_transfer(QTestState *s,
> const unsigned char *req, size_t req_size,
> @@ -184,3 +187,89 @@ void tpm_util_swtpm_kill(GPid pid)
>
> kill(pid, SIGKILL);
> }
> +
> +void tpm_util_migrate(QTestState *who, const char *uri)
> +{
> + QDict *rsp;
> + gchar *cmd;
> +
> + cmd = g_strdup_printf("{ 'execute': 'migrate',"
> + "'arguments': { 'uri': '%s' } }",
> + uri);
> + rsp = qtest_qmp(who, cmd);
> + g_free(cmd);
> + g_assert(qdict_haskey(rsp, "return"));
> + qobject_unref(rsp);
> +}
> +
> +/*
> + * Events can get in the way of responses we are actually waiting for.
> + */
> +static QDict *tpm_util_wait_command(QTestState *who, const char *command)
> +{
> + const char *event_string;
> + QDict *response;
> +
> + response = qtest_qmp(who, command);
> +
> + while (qdict_haskey(response, "event")) {
> + /* OK, it was an event */
> + event_string = qdict_get_str(response, "event");
> + if (!strcmp(event_string, "STOP")) {
> + got_stop = true;
> + }
> + qobject_unref(response);
> + response = qtest_qmp_receive(who);
> + }
> + return response;
> +}
> +
> +void tpm_util_wait_for_migration_complete(QTestState *who)
> +{
> + while (true) {
> + QDict *rsp, *rsp_return;
> + bool completed;
> + const char *status;
> +
> + rsp = tpm_util_wait_command(who, "{ 'execute': 'query-migrate' }");
> + rsp_return = qdict_get_qdict(rsp, "return");
> + status = qdict_get_str(rsp_return, "status");
> + completed = strcmp(status, "completed") == 0;
> + g_assert_cmpstr(status, !=, "failed");
> + qobject_unref(rsp);
> + if (completed) {
> + return;
> + }
> + usleep(1000);
> + }
> +}
> +
> +void tpm_util_migration_start_qemu(QTestState **src_qemu,
> + QTestState **dst_qemu,
> + SocketAddress *src_tpm_addr,
> + SocketAddress *dst_tpm_addr,
> + const char *miguri)
> +{
> + char *src_qemu_args, *dst_qemu_args;
> +
> + src_qemu_args = g_strdup_printf(
> + "-chardev socket,id=chr,path=%s "
> + "-tpmdev emulator,id=dev,chardev=chr "
> + "-device tpm-crb,tpmdev=dev ",
> + src_tpm_addr->u.q_unix.path);
> +
> + *src_qemu = qtest_init(src_qemu_args);
> +
> + dst_qemu_args = g_strdup_printf(
> + "-chardev socket,id=chr,path=%s "
> + "-tpmdev emulator,id=dev,chardev=chr "
> + "-device tpm-crb,tpmdev=dev "
> + "-incoming %s",
> + dst_tpm_addr->u.q_unix.path,
> + miguri);
> +
> + *dst_qemu = qtest_init(dst_qemu_args);
> +
> + free(src_qemu_args);
> + free(dst_qemu_args);
> +}
> diff --git a/tests/tpm-util.h b/tests/tpm-util.h
> index d155d99aea..b6253106d9 100644
> --- a/tests/tpm-util.h
> +++ b/tests/tpm-util.h
> @@ -33,4 +33,14 @@ gboolean tpm_util_swtpm_start(const char *path, GPid *pid,
> SocketAddress **addr, GError **error);
> void tpm_util_swtpm_kill(GPid pid);
>
> +void tpm_util_migrate(QTestState *who, const char *uri);
> +
> +void tpm_util_migration_start_qemu(QTestState **src_qemu,
> + QTestState **dst_qemu,
> + SocketAddress *src_tpm_addr,
> + SocketAddress *dst_tpm_addr,
> + const char *miguri);
> +
> +void tpm_util_wait_for_migration_complete(QTestState *who);
> +
> #endif /* TESTS_TPM_UTIL_H */
> --
> 2.14.3
>
>
--
Marc-André Lureau
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Qemu-devel] [PATCH 2/4] test: Move common TPM test functions to tpm-tests.c
2018-05-30 19:35 [Qemu-devel] [PATCH 0/4] Refactor code and implement another TPM TIS test Stefan Berger
2018-05-30 19:35 ` [Qemu-devel] [PATCH 1/4] test: Move reusable code from tpm-crb-swtpm-test.c to tpm-util.c Stefan Berger
@ 2018-05-30 19:35 ` Stefan Berger
2018-05-31 10:53 ` Marc-André Lureau
2018-05-30 19:35 ` [Qemu-devel] [PATCH 3/4] test: Pass TPM interface model to functions creating command line Stefan Berger
2018-05-30 19:35 ` [Qemu-devel] [PATCH 4/4] test: Add swtpm migration test for the TPM TIS interface Stefan Berger
3 siblings, 1 reply; 9+ messages in thread
From: Stefan Berger @ 2018-05-30 19:35 UTC (permalink / raw)
To: qemu-devel; +Cc: marcandre.lureau, Stefan Berger
Move common TPM test functions from tpm-crb-swtpm-test.c to tpm-tests.c
so that for example test cases with the TPM TIS interface can use the
same code. Prefix all funcions with 'tpm_test_'.
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
---
tests/Makefile.include | 2 +-
tests/tpm-crb-swtpm-test.c | 99 ++----------------------------------
tests/tpm-tests.c | 124 +++++++++++++++++++++++++++++++++++++++++++++
tests/tpm-tests.h | 24 +++++++++
4 files changed, 153 insertions(+), 96 deletions(-)
create mode 100644 tests/tpm-tests.c
create mode 100644 tests/tpm-tests.h
diff --git a/tests/Makefile.include b/tests/Makefile.include
index b499ba1813..1597d09bd8 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -723,7 +723,7 @@ tests/test-io-task$(EXESUF): tests/test-io-task.o $(test-io-obj-y)
tests/test-io-channel-socket$(EXESUF): tests/test-io-channel-socket.o \
tests/io-channel-helpers.o tests/socket-helpers.o $(test-io-obj-y)
tests/tpm-crb-swtpm-test$(EXESUF): tests/tpm-crb-swtpm-test.o tests/tpm-emu.o \
- tests/tpm-util.o $(test-io-obj-y)
+ tests/tpm-util.o tests/tpm-tests.o $(test-io-obj-y)
tests/tpm-crb-test$(EXESUF): tests/tpm-crb-test.o tests/tpm-emu.o $(test-io-obj-y)
tests/tpm-tis-test$(EXESUF): tests/tpm-tis-test.o tests/tpm-emu.o $(test-io-obj-y)
tests/test-io-channel-file$(EXESUF): tests/test-io-channel-file.o \
diff --git a/tests/tpm-crb-swtpm-test.c b/tests/tpm-crb-swtpm-test.c
index 2a22b032ca..4acffff568 100644
--- a/tests/tpm-crb-swtpm-test.c
+++ b/tests/tpm-crb-swtpm-test.c
@@ -16,7 +16,7 @@
#include <glib/gstdio.h>
#include "libqtest.h"
-#include "tpm-util.h"
+#include "tpm-tests.h"
typedef struct TestState {
char *src_tpm_path;
@@ -26,108 +26,17 @@ typedef struct TestState {
static void tpm_crb_swtpm_test(const void *data)
{
- char *args = NULL;
- QTestState *s;
- SocketAddress *addr = NULL;
- gboolean succ;
- GPid swtpm_pid;
- GError *error = NULL;
const TestState *ts = data;
- succ = tpm_util_swtpm_start(ts->src_tpm_path, &swtpm_pid, &addr, &error);
- /* succ may be false if swtpm is not available */
- if (!succ) {
- return;
- }
-
- args = g_strdup_printf(
- "-chardev socket,id=chr,path=%s "
- "-tpmdev emulator,id=dev,chardev=chr "
- "-device tpm-crb,tpmdev=dev",
- addr->u.q_unix.path);
-
- s = qtest_start(args);
- g_free(args);
-
- tpm_util_startup(s, tpm_util_crb_transfer);
- tpm_util_pcrextend(s, tpm_util_crb_transfer);
-
- unsigned char tpm_pcrread_resp[] =
- "\x80\x01\x00\x00\x00\x3e\x00\x00\x00\x00\x00\x00\x00\x16\x00\x00"
- "\x00\x01\x00\x0b\x03\x00\x04\x00\x00\x00\x00\x01\x00\x20\xf6\x85"
- "\x98\xe5\x86\x8d\xe6\x8b\x97\x29\x99\x60\xf2\x71\x7d\x17\x67\x89"
- "\xa4\x2f\x9a\xae\xa8\xc7\xb7\xaa\x79\xa8\x62\x56\xc1\xde";
- tpm_util_pcrread(s, tpm_util_crb_transfer, tpm_pcrread_resp,
- sizeof(tpm_pcrread_resp));
-
- qtest_end();
- tpm_util_swtpm_kill(swtpm_pid);
-
- if (addr) {
- g_unlink(addr->u.q_unix.path);
- qapi_free_SocketAddress(addr);
- }
+ tpm_test_swtpm_test(ts->src_tpm_path, tpm_util_crb_transfer);
}
static void tpm_crb_swtpm_migration_test(const void *data)
{
const TestState *ts = data;
- gboolean succ;
- GPid src_tpm_pid, dst_tpm_pid;
- SocketAddress *src_tpm_addr = NULL, *dst_tpm_addr = NULL;
- GError *error = NULL;
- QTestState *src_qemu, *dst_qemu;
-
- succ = tpm_util_swtpm_start(ts->src_tpm_path, &src_tpm_pid,
- &src_tpm_addr, &error);
- /* succ may be false if swtpm is not available */
- if (!succ) {
- return;
- }
-
- succ = tpm_util_swtpm_start(ts->dst_tpm_path, &dst_tpm_pid,
- &dst_tpm_addr, &error);
- /* succ may be false if swtpm is not available */
- if (!succ) {
- goto err_src_tpm_kill;
- }
-
- tpm_util_migration_start_qemu(&src_qemu, &dst_qemu,
- src_tpm_addr, dst_tpm_addr,
- ts->uri);
-
- tpm_util_startup(src_qemu, tpm_util_crb_transfer);
- tpm_util_pcrextend(src_qemu, tpm_util_crb_transfer);
-
- unsigned char tpm_pcrread_resp[] =
- "\x80\x01\x00\x00\x00\x3e\x00\x00\x00\x00\x00\x00\x00\x16\x00\x00"
- "\x00\x01\x00\x0b\x03\x00\x04\x00\x00\x00\x00\x01\x00\x20\xf6\x85"
- "\x98\xe5\x86\x8d\xe6\x8b\x97\x29\x99\x60\xf2\x71\x7d\x17\x67\x89"
- "\xa4\x2f\x9a\xae\xa8\xc7\xb7\xaa\x79\xa8\x62\x56\xc1\xde";
- tpm_util_pcrread(src_qemu, tpm_util_crb_transfer, tpm_pcrread_resp,
- sizeof(tpm_pcrread_resp));
-
- tpm_util_migrate(src_qemu, ts->uri);
- tpm_util_wait_for_migration_complete(src_qemu);
-
- tpm_util_pcrread(dst_qemu, tpm_util_crb_transfer, tpm_pcrread_resp,
- sizeof(tpm_pcrread_resp));
-
- qtest_quit(dst_qemu);
- qtest_quit(src_qemu);
-
- tpm_util_swtpm_kill(dst_tpm_pid);
- if (dst_tpm_addr) {
- g_unlink(dst_tpm_addr->u.q_unix.path);
- qapi_free_SocketAddress(dst_tpm_addr);
- }
-err_src_tpm_kill:
- tpm_util_swtpm_kill(src_tpm_pid);
- if (src_tpm_addr) {
- g_unlink(src_tpm_addr->u.q_unix.path);
- qapi_free_SocketAddress(src_tpm_addr);
- }
+ tpm_test_swtpm_migration_test(ts->src_tpm_path, ts->dst_tpm_path, ts->uri,
+ tpm_util_crb_transfer);
}
int main(int argc, char **argv)
diff --git a/tests/tpm-tests.c b/tests/tpm-tests.c
new file mode 100644
index 0000000000..adf2c618c8
--- /dev/null
+++ b/tests/tpm-tests.c
@@ -0,0 +1,124 @@
+/*
+ * QTest TPM commont test code
+ *
+ * Copyright (c) 2018 IBM Corporation
+ * Copyright (c) 2018 Red Hat, Inc.
+ *
+ * Authors:
+ * Stefan Berger <stefanb@linux.vnet.ibm.com>
+ * Marc-André Lureau <marcandre.lureau@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include <glib/gstdio.h>
+
+#include "libqtest.h"
+#include "tpm-tests.h"
+
+void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx)
+{
+ char *args = NULL;
+ QTestState *s;
+ SocketAddress *addr = NULL;
+ gboolean succ;
+ GPid swtpm_pid;
+ GError *error = NULL;
+
+ succ = tpm_util_swtpm_start(src_tpm_path, &swtpm_pid, &addr, &error);
+ /* succ may be false if swtpm is not available */
+ if (!succ) {
+ return;
+ }
+
+ args = g_strdup_printf(
+ "-chardev socket,id=chr,path=%s "
+ "-tpmdev emulator,id=dev,chardev=chr "
+ "-device tpm-crb,tpmdev=dev",
+ addr->u.q_unix.path);
+
+ s = qtest_start(args);
+ g_free(args);
+
+ tpm_util_startup(s, tx);
+ tpm_util_pcrextend(s, tx);
+
+ unsigned char tpm_pcrread_resp[] =
+ "\x80\x01\x00\x00\x00\x3e\x00\x00\x00\x00\x00\x00\x00\x16\x00\x00"
+ "\x00\x01\x00\x0b\x03\x00\x04\x00\x00\x00\x00\x01\x00\x20\xf6\x85"
+ "\x98\xe5\x86\x8d\xe6\x8b\x97\x29\x99\x60\xf2\x71\x7d\x17\x67\x89"
+ "\xa4\x2f\x9a\xae\xa8\xc7\xb7\xaa\x79\xa8\x62\x56\xc1\xde";
+ tpm_util_pcrread(s, tx, tpm_pcrread_resp,
+ sizeof(tpm_pcrread_resp));
+
+ qtest_end();
+ tpm_util_swtpm_kill(swtpm_pid);
+
+ if (addr) {
+ g_unlink(addr->u.q_unix.path);
+ qapi_free_SocketAddress(addr);
+ }
+}
+
+void tpm_test_swtpm_migration_test(const char *src_tpm_path,
+ const char *dst_tpm_path,
+ const char *uri, tx_func *tx)
+{
+ gboolean succ;
+ GPid src_tpm_pid, dst_tpm_pid;
+ SocketAddress *src_tpm_addr = NULL, *dst_tpm_addr = NULL;
+ GError *error = NULL;
+ QTestState *src_qemu, *dst_qemu;
+
+ succ = tpm_util_swtpm_start(src_tpm_path, &src_tpm_pid,
+ &src_tpm_addr, &error);
+ /* succ may be false if swtpm is not available */
+ if (!succ) {
+ return;
+ }
+
+ succ = tpm_util_swtpm_start(dst_tpm_path, &dst_tpm_pid,
+ &dst_tpm_addr, &error);
+ /* succ may be false if swtpm is not available */
+ if (!succ) {
+ goto err_src_tpm_kill;
+ }
+
+ tpm_util_migration_start_qemu(&src_qemu, &dst_qemu,
+ src_tpm_addr, dst_tpm_addr, uri);
+
+ tpm_util_startup(src_qemu, tx);
+ tpm_util_pcrextend(src_qemu, tx);
+
+ unsigned char tpm_pcrread_resp[] =
+ "\x80\x01\x00\x00\x00\x3e\x00\x00\x00\x00\x00\x00\x00\x16\x00\x00"
+ "\x00\x01\x00\x0b\x03\x00\x04\x00\x00\x00\x00\x01\x00\x20\xf6\x85"
+ "\x98\xe5\x86\x8d\xe6\x8b\x97\x29\x99\x60\xf2\x71\x7d\x17\x67\x89"
+ "\xa4\x2f\x9a\xae\xa8\xc7\xb7\xaa\x79\xa8\x62\x56\xc1\xde";
+ tpm_util_pcrread(src_qemu, tx, tpm_pcrread_resp,
+ sizeof(tpm_pcrread_resp));
+
+ tpm_util_migrate(src_qemu, uri);
+ tpm_util_wait_for_migration_complete(src_qemu);
+
+ tpm_util_pcrread(dst_qemu, tx, tpm_pcrread_resp,
+ sizeof(tpm_pcrread_resp));
+
+ qtest_quit(dst_qemu);
+ qtest_quit(src_qemu);
+
+ tpm_util_swtpm_kill(dst_tpm_pid);
+ if (dst_tpm_addr) {
+ g_unlink(dst_tpm_addr->u.q_unix.path);
+ qapi_free_SocketAddress(dst_tpm_addr);
+ }
+
+err_src_tpm_kill:
+ tpm_util_swtpm_kill(src_tpm_pid);
+ if (src_tpm_addr) {
+ g_unlink(src_tpm_addr->u.q_unix.path);
+ qapi_free_SocketAddress(src_tpm_addr);
+ }
+}
diff --git a/tests/tpm-tests.h b/tests/tpm-tests.h
new file mode 100644
index 0000000000..377f184c77
--- /dev/null
+++ b/tests/tpm-tests.h
@@ -0,0 +1,24 @@
+/*
+ * QTest TPM commont test code
+ *
+ * Copyright (c) 2018 IBM Corporation
+ *
+ * Authors:
+ * Stefan Berger <stefanb@linux.vnet.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef TESTS_TPM_TESTS_H
+#define TESTS_TPM_TESTS_H
+
+#include "tpm-util.h"
+
+void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx);
+
+void tpm_test_swtpm_migration_test(const char *src_tpm_path,
+ const char *dst_tpm_path,
+ const char *uri, tx_func *tx);
+
+#endif /* TESTS_TPM_TESTS_H */
--
2.14.3
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH 2/4] test: Move common TPM test functions to tpm-tests.c
2018-05-30 19:35 ` [Qemu-devel] [PATCH 2/4] test: Move common TPM test functions to tpm-tests.c Stefan Berger
@ 2018-05-31 10:53 ` Marc-André Lureau
0 siblings, 0 replies; 9+ messages in thread
From: Marc-André Lureau @ 2018-05-31 10:53 UTC (permalink / raw)
To: Stefan Berger; +Cc: QEMU
On Wed, May 30, 2018 at 9:35 PM, Stefan Berger
<stefanb@linux.vnet.ibm.com> wrote:
> Move common TPM test functions from tpm-crb-swtpm-test.c to tpm-tests.c
> so that for example test cases with the TPM TIS interface can use the
> same code. Prefix all funcions with 'tpm_test_'.
>
> Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
> tests/Makefile.include | 2 +-
> tests/tpm-crb-swtpm-test.c | 99 ++----------------------------------
> tests/tpm-tests.c | 124 +++++++++++++++++++++++++++++++++++++++++++++
> tests/tpm-tests.h | 24 +++++++++
> 4 files changed, 153 insertions(+), 96 deletions(-)
> create mode 100644 tests/tpm-tests.c
> create mode 100644 tests/tpm-tests.h
>
> diff --git a/tests/Makefile.include b/tests/Makefile.include
> index b499ba1813..1597d09bd8 100644
> --- a/tests/Makefile.include
> +++ b/tests/Makefile.include
> @@ -723,7 +723,7 @@ tests/test-io-task$(EXESUF): tests/test-io-task.o $(test-io-obj-y)
> tests/test-io-channel-socket$(EXESUF): tests/test-io-channel-socket.o \
> tests/io-channel-helpers.o tests/socket-helpers.o $(test-io-obj-y)
> tests/tpm-crb-swtpm-test$(EXESUF): tests/tpm-crb-swtpm-test.o tests/tpm-emu.o \
> - tests/tpm-util.o $(test-io-obj-y)
> + tests/tpm-util.o tests/tpm-tests.o $(test-io-obj-y)
> tests/tpm-crb-test$(EXESUF): tests/tpm-crb-test.o tests/tpm-emu.o $(test-io-obj-y)
> tests/tpm-tis-test$(EXESUF): tests/tpm-tis-test.o tests/tpm-emu.o $(test-io-obj-y)
> tests/test-io-channel-file$(EXESUF): tests/test-io-channel-file.o \
> diff --git a/tests/tpm-crb-swtpm-test.c b/tests/tpm-crb-swtpm-test.c
> index 2a22b032ca..4acffff568 100644
> --- a/tests/tpm-crb-swtpm-test.c
> +++ b/tests/tpm-crb-swtpm-test.c
> @@ -16,7 +16,7 @@
> #include <glib/gstdio.h>
>
> #include "libqtest.h"
> -#include "tpm-util.h"
> +#include "tpm-tests.h"
>
> typedef struct TestState {
> char *src_tpm_path;
> @@ -26,108 +26,17 @@ typedef struct TestState {
>
> static void tpm_crb_swtpm_test(const void *data)
> {
> - char *args = NULL;
> - QTestState *s;
> - SocketAddress *addr = NULL;
> - gboolean succ;
> - GPid swtpm_pid;
> - GError *error = NULL;
> const TestState *ts = data;
>
> - succ = tpm_util_swtpm_start(ts->src_tpm_path, &swtpm_pid, &addr, &error);
> - /* succ may be false if swtpm is not available */
> - if (!succ) {
> - return;
> - }
> -
> - args = g_strdup_printf(
> - "-chardev socket,id=chr,path=%s "
> - "-tpmdev emulator,id=dev,chardev=chr "
> - "-device tpm-crb,tpmdev=dev",
> - addr->u.q_unix.path);
> -
> - s = qtest_start(args);
> - g_free(args);
> -
> - tpm_util_startup(s, tpm_util_crb_transfer);
> - tpm_util_pcrextend(s, tpm_util_crb_transfer);
> -
> - unsigned char tpm_pcrread_resp[] =
> - "\x80\x01\x00\x00\x00\x3e\x00\x00\x00\x00\x00\x00\x00\x16\x00\x00"
> - "\x00\x01\x00\x0b\x03\x00\x04\x00\x00\x00\x00\x01\x00\x20\xf6\x85"
> - "\x98\xe5\x86\x8d\xe6\x8b\x97\x29\x99\x60\xf2\x71\x7d\x17\x67\x89"
> - "\xa4\x2f\x9a\xae\xa8\xc7\xb7\xaa\x79\xa8\x62\x56\xc1\xde";
> - tpm_util_pcrread(s, tpm_util_crb_transfer, tpm_pcrread_resp,
> - sizeof(tpm_pcrread_resp));
> -
> - qtest_end();
> - tpm_util_swtpm_kill(swtpm_pid);
> -
> - if (addr) {
> - g_unlink(addr->u.q_unix.path);
> - qapi_free_SocketAddress(addr);
> - }
> + tpm_test_swtpm_test(ts->src_tpm_path, tpm_util_crb_transfer);
> }
>
> static void tpm_crb_swtpm_migration_test(const void *data)
> {
> const TestState *ts = data;
> - gboolean succ;
> - GPid src_tpm_pid, dst_tpm_pid;
> - SocketAddress *src_tpm_addr = NULL, *dst_tpm_addr = NULL;
> - GError *error = NULL;
> - QTestState *src_qemu, *dst_qemu;
> -
> - succ = tpm_util_swtpm_start(ts->src_tpm_path, &src_tpm_pid,
> - &src_tpm_addr, &error);
> - /* succ may be false if swtpm is not available */
> - if (!succ) {
> - return;
> - }
> -
> - succ = tpm_util_swtpm_start(ts->dst_tpm_path, &dst_tpm_pid,
> - &dst_tpm_addr, &error);
> - /* succ may be false if swtpm is not available */
> - if (!succ) {
> - goto err_src_tpm_kill;
> - }
> -
> - tpm_util_migration_start_qemu(&src_qemu, &dst_qemu,
> - src_tpm_addr, dst_tpm_addr,
> - ts->uri);
> -
> - tpm_util_startup(src_qemu, tpm_util_crb_transfer);
> - tpm_util_pcrextend(src_qemu, tpm_util_crb_transfer);
> -
> - unsigned char tpm_pcrread_resp[] =
> - "\x80\x01\x00\x00\x00\x3e\x00\x00\x00\x00\x00\x00\x00\x16\x00\x00"
> - "\x00\x01\x00\x0b\x03\x00\x04\x00\x00\x00\x00\x01\x00\x20\xf6\x85"
> - "\x98\xe5\x86\x8d\xe6\x8b\x97\x29\x99\x60\xf2\x71\x7d\x17\x67\x89"
> - "\xa4\x2f\x9a\xae\xa8\xc7\xb7\xaa\x79\xa8\x62\x56\xc1\xde";
> - tpm_util_pcrread(src_qemu, tpm_util_crb_transfer, tpm_pcrread_resp,
> - sizeof(tpm_pcrread_resp));
> -
> - tpm_util_migrate(src_qemu, ts->uri);
> - tpm_util_wait_for_migration_complete(src_qemu);
> -
> - tpm_util_pcrread(dst_qemu, tpm_util_crb_transfer, tpm_pcrread_resp,
> - sizeof(tpm_pcrread_resp));
> -
> - qtest_quit(dst_qemu);
> - qtest_quit(src_qemu);
> -
> - tpm_util_swtpm_kill(dst_tpm_pid);
> - if (dst_tpm_addr) {
> - g_unlink(dst_tpm_addr->u.q_unix.path);
> - qapi_free_SocketAddress(dst_tpm_addr);
> - }
>
> -err_src_tpm_kill:
> - tpm_util_swtpm_kill(src_tpm_pid);
> - if (src_tpm_addr) {
> - g_unlink(src_tpm_addr->u.q_unix.path);
> - qapi_free_SocketAddress(src_tpm_addr);
> - }
> + tpm_test_swtpm_migration_test(ts->src_tpm_path, ts->dst_tpm_path, ts->uri,
> + tpm_util_crb_transfer);
> }
>
> int main(int argc, char **argv)
> diff --git a/tests/tpm-tests.c b/tests/tpm-tests.c
> new file mode 100644
> index 0000000000..adf2c618c8
> --- /dev/null
> +++ b/tests/tpm-tests.c
> @@ -0,0 +1,124 @@
> +/*
> + * QTest TPM commont test code
> + *
> + * Copyright (c) 2018 IBM Corporation
> + * Copyright (c) 2018 Red Hat, Inc.
> + *
> + * Authors:
> + * Stefan Berger <stefanb@linux.vnet.ibm.com>
> + * Marc-André Lureau <marcandre.lureau@redhat.com>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> + * See the COPYING file in the top-level directory.
> + */
> +
> +#include "qemu/osdep.h"
> +#include <glib/gstdio.h>
> +
> +#include "libqtest.h"
> +#include "tpm-tests.h"
> +
> +void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx)
> +{
> + char *args = NULL;
> + QTestState *s;
> + SocketAddress *addr = NULL;
> + gboolean succ;
> + GPid swtpm_pid;
> + GError *error = NULL;
> +
> + succ = tpm_util_swtpm_start(src_tpm_path, &swtpm_pid, &addr, &error);
> + /* succ may be false if swtpm is not available */
> + if (!succ) {
> + return;
> + }
> +
> + args = g_strdup_printf(
> + "-chardev socket,id=chr,path=%s "
> + "-tpmdev emulator,id=dev,chardev=chr "
> + "-device tpm-crb,tpmdev=dev",
> + addr->u.q_unix.path);
> +
> + s = qtest_start(args);
> + g_free(args);
> +
> + tpm_util_startup(s, tx);
> + tpm_util_pcrextend(s, tx);
> +
> + unsigned char tpm_pcrread_resp[] =
> + "\x80\x01\x00\x00\x00\x3e\x00\x00\x00\x00\x00\x00\x00\x16\x00\x00"
> + "\x00\x01\x00\x0b\x03\x00\x04\x00\x00\x00\x00\x01\x00\x20\xf6\x85"
> + "\x98\xe5\x86\x8d\xe6\x8b\x97\x29\x99\x60\xf2\x71\x7d\x17\x67\x89"
> + "\xa4\x2f\x9a\xae\xa8\xc7\xb7\xaa\x79\xa8\x62\x56\xc1\xde";
> + tpm_util_pcrread(s, tx, tpm_pcrread_resp,
> + sizeof(tpm_pcrread_resp));
> +
> + qtest_end();
> + tpm_util_swtpm_kill(swtpm_pid);
> +
> + if (addr) {
> + g_unlink(addr->u.q_unix.path);
> + qapi_free_SocketAddress(addr);
> + }
> +}
> +
> +void tpm_test_swtpm_migration_test(const char *src_tpm_path,
> + const char *dst_tpm_path,
> + const char *uri, tx_func *tx)
> +{
> + gboolean succ;
> + GPid src_tpm_pid, dst_tpm_pid;
> + SocketAddress *src_tpm_addr = NULL, *dst_tpm_addr = NULL;
> + GError *error = NULL;
> + QTestState *src_qemu, *dst_qemu;
> +
> + succ = tpm_util_swtpm_start(src_tpm_path, &src_tpm_pid,
> + &src_tpm_addr, &error);
> + /* succ may be false if swtpm is not available */
> + if (!succ) {
> + return;
> + }
> +
> + succ = tpm_util_swtpm_start(dst_tpm_path, &dst_tpm_pid,
> + &dst_tpm_addr, &error);
> + /* succ may be false if swtpm is not available */
> + if (!succ) {
> + goto err_src_tpm_kill;
> + }
> +
> + tpm_util_migration_start_qemu(&src_qemu, &dst_qemu,
> + src_tpm_addr, dst_tpm_addr, uri);
> +
> + tpm_util_startup(src_qemu, tx);
> + tpm_util_pcrextend(src_qemu, tx);
> +
> + unsigned char tpm_pcrread_resp[] =
> + "\x80\x01\x00\x00\x00\x3e\x00\x00\x00\x00\x00\x00\x00\x16\x00\x00"
> + "\x00\x01\x00\x0b\x03\x00\x04\x00\x00\x00\x00\x01\x00\x20\xf6\x85"
> + "\x98\xe5\x86\x8d\xe6\x8b\x97\x29\x99\x60\xf2\x71\x7d\x17\x67\x89"
> + "\xa4\x2f\x9a\xae\xa8\xc7\xb7\xaa\x79\xa8\x62\x56\xc1\xde";
> + tpm_util_pcrread(src_qemu, tx, tpm_pcrread_resp,
> + sizeof(tpm_pcrread_resp));
> +
> + tpm_util_migrate(src_qemu, uri);
> + tpm_util_wait_for_migration_complete(src_qemu);
> +
> + tpm_util_pcrread(dst_qemu, tx, tpm_pcrread_resp,
> + sizeof(tpm_pcrread_resp));
> +
> + qtest_quit(dst_qemu);
> + qtest_quit(src_qemu);
> +
> + tpm_util_swtpm_kill(dst_tpm_pid);
> + if (dst_tpm_addr) {
> + g_unlink(dst_tpm_addr->u.q_unix.path);
> + qapi_free_SocketAddress(dst_tpm_addr);
> + }
> +
> +err_src_tpm_kill:
> + tpm_util_swtpm_kill(src_tpm_pid);
> + if (src_tpm_addr) {
> + g_unlink(src_tpm_addr->u.q_unix.path);
> + qapi_free_SocketAddress(src_tpm_addr);
> + }
> +}
> diff --git a/tests/tpm-tests.h b/tests/tpm-tests.h
> new file mode 100644
> index 0000000000..377f184c77
> --- /dev/null
> +++ b/tests/tpm-tests.h
> @@ -0,0 +1,24 @@
> +/*
> + * QTest TPM commont test code
> + *
> + * Copyright (c) 2018 IBM Corporation
> + *
> + * Authors:
> + * Stefan Berger <stefanb@linux.vnet.ibm.com>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> + * See the COPYING file in the top-level directory.
> + */
> +
> +#ifndef TESTS_TPM_TESTS_H
> +#define TESTS_TPM_TESTS_H
> +
> +#include "tpm-util.h"
> +
> +void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx);
> +
> +void tpm_test_swtpm_migration_test(const char *src_tpm_path,
> + const char *dst_tpm_path,
> + const char *uri, tx_func *tx);
> +
> +#endif /* TESTS_TPM_TESTS_H */
> --
> 2.14.3
>
>
--
Marc-André Lureau
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Qemu-devel] [PATCH 3/4] test: Pass TPM interface model to functions creating command line
2018-05-30 19:35 [Qemu-devel] [PATCH 0/4] Refactor code and implement another TPM TIS test Stefan Berger
2018-05-30 19:35 ` [Qemu-devel] [PATCH 1/4] test: Move reusable code from tpm-crb-swtpm-test.c to tpm-util.c Stefan Berger
2018-05-30 19:35 ` [Qemu-devel] [PATCH 2/4] test: Move common TPM test functions to tpm-tests.c Stefan Berger
@ 2018-05-30 19:35 ` Stefan Berger
2018-05-31 10:54 ` Marc-André Lureau
2018-05-30 19:35 ` [Qemu-devel] [PATCH 4/4] test: Add swtpm migration test for the TPM TIS interface Stefan Berger
3 siblings, 1 reply; 9+ messages in thread
From: Stefan Berger @ 2018-05-30 19:35 UTC (permalink / raw)
To: qemu-devel; +Cc: marcandre.lureau, Stefan Berger
Pass the TPM interface model, such as 'tpm-crb', through to the functions
that create the command line for QEMU.
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
---
tests/tpm-crb-swtpm-test.c | 4 ++--
tests/tpm-tests.c | 13 ++++++++-----
tests/tpm-tests.h | 6 ++++--
tests/tpm-util.c | 11 ++++++-----
tests/tpm-util.h | 3 ++-
5 files changed, 22 insertions(+), 15 deletions(-)
diff --git a/tests/tpm-crb-swtpm-test.c b/tests/tpm-crb-swtpm-test.c
index 4acffff568..8c0a55f3ca 100644
--- a/tests/tpm-crb-swtpm-test.c
+++ b/tests/tpm-crb-swtpm-test.c
@@ -28,7 +28,7 @@ static void tpm_crb_swtpm_test(const void *data)
{
const TestState *ts = data;
- tpm_test_swtpm_test(ts->src_tpm_path, tpm_util_crb_transfer);
+ tpm_test_swtpm_test(ts->src_tpm_path, tpm_util_crb_transfer, "tpm-crb");
}
static void tpm_crb_swtpm_migration_test(const void *data)
@@ -36,7 +36,7 @@ static void tpm_crb_swtpm_migration_test(const void *data)
const TestState *ts = data;
tpm_test_swtpm_migration_test(ts->src_tpm_path, ts->dst_tpm_path, ts->uri,
- tpm_util_crb_transfer);
+ tpm_util_crb_transfer, "tpm-crb");
}
int main(int argc, char **argv)
diff --git a/tests/tpm-tests.c b/tests/tpm-tests.c
index adf2c618c8..10c6592aac 100644
--- a/tests/tpm-tests.c
+++ b/tests/tpm-tests.c
@@ -18,7 +18,8 @@
#include "libqtest.h"
#include "tpm-tests.h"
-void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx)
+void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx,
+ const char *ifmodel)
{
char *args = NULL;
QTestState *s;
@@ -36,8 +37,8 @@ void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx)
args = g_strdup_printf(
"-chardev socket,id=chr,path=%s "
"-tpmdev emulator,id=dev,chardev=chr "
- "-device tpm-crb,tpmdev=dev",
- addr->u.q_unix.path);
+ "-device %s,tpmdev=dev",
+ addr->u.q_unix.path, ifmodel);
s = qtest_start(args);
g_free(args);
@@ -64,7 +65,8 @@ void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx)
void tpm_test_swtpm_migration_test(const char *src_tpm_path,
const char *dst_tpm_path,
- const char *uri, tx_func *tx)
+ const char *uri, tx_func *tx,
+ const char *ifmodel)
{
gboolean succ;
GPid src_tpm_pid, dst_tpm_pid;
@@ -87,7 +89,8 @@ void tpm_test_swtpm_migration_test(const char *src_tpm_path,
}
tpm_util_migration_start_qemu(&src_qemu, &dst_qemu,
- src_tpm_addr, dst_tpm_addr, uri);
+ src_tpm_addr, dst_tpm_addr, uri,
+ ifmodel);
tpm_util_startup(src_qemu, tx);
tpm_util_pcrextend(src_qemu, tx);
diff --git a/tests/tpm-tests.h b/tests/tpm-tests.h
index 377f184c77..b97688fe75 100644
--- a/tests/tpm-tests.h
+++ b/tests/tpm-tests.h
@@ -15,10 +15,12 @@
#include "tpm-util.h"
-void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx);
+void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx,
+ const char *ifmodel);
void tpm_test_swtpm_migration_test(const char *src_tpm_path,
const char *dst_tpm_path,
- const char *uri, tx_func *tx);
+ const char *uri, tx_func *tx,
+ const char *ifmodel);
#endif /* TESTS_TPM_TESTS_H */
diff --git a/tests/tpm-util.c b/tests/tpm-util.c
index e6e3b922fa..e1ac4d1bd5 100644
--- a/tests/tpm-util.c
+++ b/tests/tpm-util.c
@@ -248,25 +248,26 @@ void tpm_util_migration_start_qemu(QTestState **src_qemu,
QTestState **dst_qemu,
SocketAddress *src_tpm_addr,
SocketAddress *dst_tpm_addr,
- const char *miguri)
+ const char *miguri,
+ const char *ifmodel)
{
char *src_qemu_args, *dst_qemu_args;
src_qemu_args = g_strdup_printf(
"-chardev socket,id=chr,path=%s "
"-tpmdev emulator,id=dev,chardev=chr "
- "-device tpm-crb,tpmdev=dev ",
- src_tpm_addr->u.q_unix.path);
+ "-device %s,tpmdev=dev ",
+ src_tpm_addr->u.q_unix.path, ifmodel);
*src_qemu = qtest_init(src_qemu_args);
dst_qemu_args = g_strdup_printf(
"-chardev socket,id=chr,path=%s "
"-tpmdev emulator,id=dev,chardev=chr "
- "-device tpm-crb,tpmdev=dev "
+ "-device %s,tpmdev=dev "
"-incoming %s",
dst_tpm_addr->u.q_unix.path,
- miguri);
+ ifmodel, miguri);
*dst_qemu = qtest_init(dst_qemu_args);
diff --git a/tests/tpm-util.h b/tests/tpm-util.h
index b6253106d9..bb128360dd 100644
--- a/tests/tpm-util.h
+++ b/tests/tpm-util.h
@@ -39,7 +39,8 @@ void tpm_util_migration_start_qemu(QTestState **src_qemu,
QTestState **dst_qemu,
SocketAddress *src_tpm_addr,
SocketAddress *dst_tpm_addr,
- const char *miguri);
+ const char *miguri,
+ const char *ifmodel);
void tpm_util_wait_for_migration_complete(QTestState *who);
--
2.14.3
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH 3/4] test: Pass TPM interface model to functions creating command line
2018-05-30 19:35 ` [Qemu-devel] [PATCH 3/4] test: Pass TPM interface model to functions creating command line Stefan Berger
@ 2018-05-31 10:54 ` Marc-André Lureau
0 siblings, 0 replies; 9+ messages in thread
From: Marc-André Lureau @ 2018-05-31 10:54 UTC (permalink / raw)
To: Stefan Berger; +Cc: QEMU
On Wed, May 30, 2018 at 9:35 PM, Stefan Berger
<stefanb@linux.vnet.ibm.com> wrote:
> Pass the TPM interface model, such as 'tpm-crb', through to the functions
> that create the command line for QEMU.
>
> Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
> tests/tpm-crb-swtpm-test.c | 4 ++--
> tests/tpm-tests.c | 13 ++++++++-----
> tests/tpm-tests.h | 6 ++++--
> tests/tpm-util.c | 11 ++++++-----
> tests/tpm-util.h | 3 ++-
> 5 files changed, 22 insertions(+), 15 deletions(-)
>
> diff --git a/tests/tpm-crb-swtpm-test.c b/tests/tpm-crb-swtpm-test.c
> index 4acffff568..8c0a55f3ca 100644
> --- a/tests/tpm-crb-swtpm-test.c
> +++ b/tests/tpm-crb-swtpm-test.c
> @@ -28,7 +28,7 @@ static void tpm_crb_swtpm_test(const void *data)
> {
> const TestState *ts = data;
>
> - tpm_test_swtpm_test(ts->src_tpm_path, tpm_util_crb_transfer);
> + tpm_test_swtpm_test(ts->src_tpm_path, tpm_util_crb_transfer, "tpm-crb");
> }
>
> static void tpm_crb_swtpm_migration_test(const void *data)
> @@ -36,7 +36,7 @@ static void tpm_crb_swtpm_migration_test(const void *data)
> const TestState *ts = data;
>
> tpm_test_swtpm_migration_test(ts->src_tpm_path, ts->dst_tpm_path, ts->uri,
> - tpm_util_crb_transfer);
> + tpm_util_crb_transfer, "tpm-crb");
> }
>
> int main(int argc, char **argv)
> diff --git a/tests/tpm-tests.c b/tests/tpm-tests.c
> index adf2c618c8..10c6592aac 100644
> --- a/tests/tpm-tests.c
> +++ b/tests/tpm-tests.c
> @@ -18,7 +18,8 @@
> #include "libqtest.h"
> #include "tpm-tests.h"
>
> -void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx)
> +void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx,
> + const char *ifmodel)
> {
> char *args = NULL;
> QTestState *s;
> @@ -36,8 +37,8 @@ void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx)
> args = g_strdup_printf(
> "-chardev socket,id=chr,path=%s "
> "-tpmdev emulator,id=dev,chardev=chr "
> - "-device tpm-crb,tpmdev=dev",
> - addr->u.q_unix.path);
> + "-device %s,tpmdev=dev",
> + addr->u.q_unix.path, ifmodel);
>
> s = qtest_start(args);
> g_free(args);
> @@ -64,7 +65,8 @@ void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx)
>
> void tpm_test_swtpm_migration_test(const char *src_tpm_path,
> const char *dst_tpm_path,
> - const char *uri, tx_func *tx)
> + const char *uri, tx_func *tx,
> + const char *ifmodel)
> {
> gboolean succ;
> GPid src_tpm_pid, dst_tpm_pid;
> @@ -87,7 +89,8 @@ void tpm_test_swtpm_migration_test(const char *src_tpm_path,
> }
>
> tpm_util_migration_start_qemu(&src_qemu, &dst_qemu,
> - src_tpm_addr, dst_tpm_addr, uri);
> + src_tpm_addr, dst_tpm_addr, uri,
> + ifmodel);
>
> tpm_util_startup(src_qemu, tx);
> tpm_util_pcrextend(src_qemu, tx);
> diff --git a/tests/tpm-tests.h b/tests/tpm-tests.h
> index 377f184c77..b97688fe75 100644
> --- a/tests/tpm-tests.h
> +++ b/tests/tpm-tests.h
> @@ -15,10 +15,12 @@
>
> #include "tpm-util.h"
>
> -void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx);
> +void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx,
> + const char *ifmodel);
>
> void tpm_test_swtpm_migration_test(const char *src_tpm_path,
> const char *dst_tpm_path,
> - const char *uri, tx_func *tx);
> + const char *uri, tx_func *tx,
> + const char *ifmodel);
>
> #endif /* TESTS_TPM_TESTS_H */
> diff --git a/tests/tpm-util.c b/tests/tpm-util.c
> index e6e3b922fa..e1ac4d1bd5 100644
> --- a/tests/tpm-util.c
> +++ b/tests/tpm-util.c
> @@ -248,25 +248,26 @@ void tpm_util_migration_start_qemu(QTestState **src_qemu,
> QTestState **dst_qemu,
> SocketAddress *src_tpm_addr,
> SocketAddress *dst_tpm_addr,
> - const char *miguri)
> + const char *miguri,
> + const char *ifmodel)
> {
> char *src_qemu_args, *dst_qemu_args;
>
> src_qemu_args = g_strdup_printf(
> "-chardev socket,id=chr,path=%s "
> "-tpmdev emulator,id=dev,chardev=chr "
> - "-device tpm-crb,tpmdev=dev ",
> - src_tpm_addr->u.q_unix.path);
> + "-device %s,tpmdev=dev ",
> + src_tpm_addr->u.q_unix.path, ifmodel);
>
> *src_qemu = qtest_init(src_qemu_args);
>
> dst_qemu_args = g_strdup_printf(
> "-chardev socket,id=chr,path=%s "
> "-tpmdev emulator,id=dev,chardev=chr "
> - "-device tpm-crb,tpmdev=dev "
> + "-device %s,tpmdev=dev "
> "-incoming %s",
> dst_tpm_addr->u.q_unix.path,
> - miguri);
> + ifmodel, miguri);
>
> *dst_qemu = qtest_init(dst_qemu_args);
>
> diff --git a/tests/tpm-util.h b/tests/tpm-util.h
> index b6253106d9..bb128360dd 100644
> --- a/tests/tpm-util.h
> +++ b/tests/tpm-util.h
> @@ -39,7 +39,8 @@ void tpm_util_migration_start_qemu(QTestState **src_qemu,
> QTestState **dst_qemu,
> SocketAddress *src_tpm_addr,
> SocketAddress *dst_tpm_addr,
> - const char *miguri);
> + const char *miguri,
> + const char *ifmodel);
>
> void tpm_util_wait_for_migration_complete(QTestState *who);
>
> --
> 2.14.3
>
>
--
Marc-André Lureau
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Qemu-devel] [PATCH 4/4] test: Add swtpm migration test for the TPM TIS interface
2018-05-30 19:35 [Qemu-devel] [PATCH 0/4] Refactor code and implement another TPM TIS test Stefan Berger
` (2 preceding siblings ...)
2018-05-30 19:35 ` [Qemu-devel] [PATCH 3/4] test: Pass TPM interface model to functions creating command line Stefan Berger
@ 2018-05-30 19:35 ` Stefan Berger
2018-05-31 10:56 ` Marc-André Lureau
3 siblings, 1 reply; 9+ messages in thread
From: Stefan Berger @ 2018-05-30 19:35 UTC (permalink / raw)
To: qemu-devel; +Cc: marcandre.lureau, Stefan Berger
Add a test case for testing swtpm migration with the TPM TIS
interface.
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
---
tests/Makefile.include | 3 +++
tests/tpm-tis-swtpm-test.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++
tests/tpm-util.c | 48 +++++++++++++++++++++++++++++++++
tests/tpm-util.h | 3 +++
4 files changed, 120 insertions(+)
create mode 100644 tests/tpm-tis-swtpm-test.c
diff --git a/tests/Makefile.include b/tests/Makefile.include
index 1597d09bd8..8a28c49d86 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -299,6 +299,7 @@ check-qtest-x86_64-$(CONFIG_VHOST_USER_NET_TEST_x86_64) += tests/vhost-user-test
endif
check-qtest-i386-$(CONFIG_TPM) += tests/tpm-crb-swtpm-test$(EXESUF)
check-qtest-i386-$(CONFIG_TPM) += tests/tpm-crb-test$(EXESUF)
+check-qtest-i386-$(CONFIG_TPM) += tests/tpm-tis-swtpm-test$(EXESUF)
check-qtest-i386-$(CONFIG_TPM) += tests/tpm-tis-test$(EXESUF)
check-qtest-i386-$(CONFIG_SLIRP) += tests/test-netfilter$(EXESUF)
check-qtest-i386-$(CONFIG_POSIX) += tests/test-filter-mirror$(EXESUF)
@@ -725,6 +726,8 @@ tests/test-io-channel-socket$(EXESUF): tests/test-io-channel-socket.o \
tests/tpm-crb-swtpm-test$(EXESUF): tests/tpm-crb-swtpm-test.o tests/tpm-emu.o \
tests/tpm-util.o tests/tpm-tests.o $(test-io-obj-y)
tests/tpm-crb-test$(EXESUF): tests/tpm-crb-test.o tests/tpm-emu.o $(test-io-obj-y)
+tests/tpm-tis-swtpm-test$(EXESUF): tests/tpm-tis-swtpm-test.o tests/tpm-emu.o \
+ tests/tpm-util.o tests/tpm-tests.o $(test-io-obj-y)
tests/tpm-tis-test$(EXESUF): tests/tpm-tis-test.o tests/tpm-emu.o $(test-io-obj-y)
tests/test-io-channel-file$(EXESUF): tests/test-io-channel-file.o \
tests/io-channel-helpers.o $(test-io-obj-y)
diff --git a/tests/tpm-tis-swtpm-test.c b/tests/tpm-tis-swtpm-test.c
new file mode 100644
index 0000000000..7dcd1d3912
--- /dev/null
+++ b/tests/tpm-tis-swtpm-test.c
@@ -0,0 +1,66 @@
+/*
+ * QTest testcase for TPM TIS talking to external swtpm and swtpm migration
+ *
+ * Copyright (c) 2018 IBM Corporation
+ * with parts borrowed from migration-test.c that is:
+ * Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates
+ *
+ * Authors:
+ * Stefan Berger <stefanb@linux.vnet.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include <glib/gstdio.h>
+
+#include "libqtest.h"
+#include "tpm-tests.h"
+
+typedef struct TestState {
+ char *src_tpm_path;
+ char *dst_tpm_path;
+ char *uri;
+} TestState;
+
+static void tpm_tis_swtpm_test(const void *data)
+{
+ const TestState *ts = data;
+
+ tpm_test_swtpm_test(ts->src_tpm_path, tpm_util_tis_transfer, "tpm-tis");
+}
+
+static void tpm_tis_swtpm_migration_test(const void *data)
+{
+ const TestState *ts = data;
+
+ tpm_test_swtpm_migration_test(ts->src_tpm_path, ts->dst_tpm_path, ts->uri,
+ tpm_util_tis_transfer, "tpm-tis");
+}
+
+int main(int argc, char **argv)
+{
+ int ret;
+ TestState ts = { 0 };
+
+ ts.src_tpm_path = g_dir_make_tmp("qemu-tpm-tis-swtpm-test.XXXXXX", NULL);
+ ts.dst_tpm_path = g_dir_make_tmp("qemu-tpm-tis-swtpm-test.XXXXXX", NULL);
+ ts.uri = g_strdup_printf("unix:%s/migsocket", ts.src_tpm_path);
+
+ module_call_init(MODULE_INIT_QOM);
+ g_test_init(&argc, &argv, NULL);
+
+ qtest_add_data_func("/tpm/tis-swtpm/test", &ts, tpm_tis_swtpm_test);
+ qtest_add_data_func("/tpm/tis-swtpm-migration/test", &ts,
+ tpm_tis_swtpm_migration_test);
+ ret = g_test_run();
+
+ g_rmdir(ts.dst_tpm_path);
+ g_free(ts.dst_tpm_path);
+ g_rmdir(ts.src_tpm_path);
+ g_free(ts.src_tpm_path);
+ g_free(ts.uri);
+
+ return ret;
+}
diff --git a/tests/tpm-util.c b/tests/tpm-util.c
index e1ac4d1bd5..672cedf905 100644
--- a/tests/tpm-util.c
+++ b/tests/tpm-util.c
@@ -19,6 +19,9 @@
#include "tpm-util.h"
#include "qapi/qmp/qdict.h"
+#define TIS_REG(LOCTY, REG) \
+ (TPM_TIS_ADDR_BASE + ((LOCTY) << 12) + REG)
+
static bool got_stop;
void tpm_util_crb_transfer(QTestState *s,
@@ -52,6 +55,51 @@ void tpm_util_crb_transfer(QTestState *s,
qtest_memread(s, raddr, rsp, rsp_size);
}
+void tpm_util_tis_transfer(QTestState *s,
+ const unsigned char *req, size_t req_size,
+ unsigned char *rsp, size_t rsp_size)
+{
+ uint32_t sts;
+ uint16_t bcount;
+ size_t i;
+
+ /* request use of locality 0 */
+ qtest_writeb(s, TIS_REG(0, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_REQUEST_USE);
+ qtest_writel(s, TIS_REG(0, TPM_TIS_REG_STS), TPM_TIS_STS_COMMAND_READY);
+
+ sts = qtest_readl(s, TIS_REG(0, TPM_TIS_REG_STS));
+ bcount = (sts >> 8) & 0xffff;
+ g_assert_cmpint(bcount, >=, req_size);
+
+ /* transmit command */
+ for (i = 0; i < req_size; i++) {
+ qtest_writeb(s, TIS_REG(0, TPM_TIS_REG_DATA_FIFO), req[i]);
+ }
+
+ /* start processing */
+ qtest_writeb(s, TIS_REG(0, TPM_TIS_REG_STS), TPM_TIS_STS_TPM_GO);
+
+ uint64_t end_time = g_get_monotonic_time() + 50 * G_TIME_SPAN_SECOND;
+ do {
+ sts = qtest_readl(s, TIS_REG(0, TPM_TIS_REG_STS));
+ if ((sts & TPM_TIS_STS_DATA_AVAILABLE) != 0) {
+ break;
+ }
+ } while (g_get_monotonic_time() < end_time);
+
+ sts = qtest_readl(s, TIS_REG(0, TPM_TIS_REG_STS));
+ bcount = (sts >> 8) & 0xffff;
+
+ memset(rsp, 0, rsp_size);
+ for (i = 0; i < bcount; i++) {
+ rsp[i] = qtest_readb(s, TIS_REG(0, TPM_TIS_REG_DATA_FIFO));
+ }
+
+ /* relinquish use of locality 0 */
+ qtest_writeb(s, TIS_REG(0, TPM_TIS_REG_ACCESS),
+ TPM_TIS_ACCESS_ACTIVE_LOCALITY);
+}
+
void tpm_util_startup(QTestState *s, tx_func *tx)
{
unsigned char buffer[1024];
diff --git a/tests/tpm-util.h b/tests/tpm-util.h
index bb128360dd..330b9657fe 100644
--- a/tests/tpm-util.h
+++ b/tests/tpm-util.h
@@ -23,6 +23,9 @@ typedef void (tx_func)(QTestState *s,
void tpm_util_crb_transfer(QTestState *s,
const unsigned char *req, size_t req_size,
unsigned char *rsp, size_t rsp_size);
+void tpm_util_tis_transfer(QTestState *s,
+ const unsigned char *req, size_t req_size,
+ unsigned char *rsp, size_t rsp_size);
void tpm_util_startup(QTestState *s, tx_func *tx);
void tpm_util_pcrextend(QTestState *s, tx_func *tx);
--
2.14.3
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH 4/4] test: Add swtpm migration test for the TPM TIS interface
2018-05-30 19:35 ` [Qemu-devel] [PATCH 4/4] test: Add swtpm migration test for the TPM TIS interface Stefan Berger
@ 2018-05-31 10:56 ` Marc-André Lureau
0 siblings, 0 replies; 9+ messages in thread
From: Marc-André Lureau @ 2018-05-31 10:56 UTC (permalink / raw)
To: Stefan Berger; +Cc: QEMU
Hi
On Wed, May 30, 2018 at 9:35 PM, Stefan Berger
<stefanb@linux.vnet.ibm.com> wrote:
> Add a test case for testing swtpm migration with the TPM TIS
> interface.
>
> Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
> tests/Makefile.include | 3 +++
> tests/tpm-tis-swtpm-test.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++
> tests/tpm-util.c | 48 +++++++++++++++++++++++++++++++++
> tests/tpm-util.h | 3 +++
> 4 files changed, 120 insertions(+)
> create mode 100644 tests/tpm-tis-swtpm-test.c
>
> diff --git a/tests/Makefile.include b/tests/Makefile.include
> index 1597d09bd8..8a28c49d86 100644
> --- a/tests/Makefile.include
> +++ b/tests/Makefile.include
> @@ -299,6 +299,7 @@ check-qtest-x86_64-$(CONFIG_VHOST_USER_NET_TEST_x86_64) += tests/vhost-user-test
> endif
> check-qtest-i386-$(CONFIG_TPM) += tests/tpm-crb-swtpm-test$(EXESUF)
> check-qtest-i386-$(CONFIG_TPM) += tests/tpm-crb-test$(EXESUF)
> +check-qtest-i386-$(CONFIG_TPM) += tests/tpm-tis-swtpm-test$(EXESUF)
> check-qtest-i386-$(CONFIG_TPM) += tests/tpm-tis-test$(EXESUF)
> check-qtest-i386-$(CONFIG_SLIRP) += tests/test-netfilter$(EXESUF)
> check-qtest-i386-$(CONFIG_POSIX) += tests/test-filter-mirror$(EXESUF)
> @@ -725,6 +726,8 @@ tests/test-io-channel-socket$(EXESUF): tests/test-io-channel-socket.o \
> tests/tpm-crb-swtpm-test$(EXESUF): tests/tpm-crb-swtpm-test.o tests/tpm-emu.o \
> tests/tpm-util.o tests/tpm-tests.o $(test-io-obj-y)
> tests/tpm-crb-test$(EXESUF): tests/tpm-crb-test.o tests/tpm-emu.o $(test-io-obj-y)
> +tests/tpm-tis-swtpm-test$(EXESUF): tests/tpm-tis-swtpm-test.o tests/tpm-emu.o \
> + tests/tpm-util.o tests/tpm-tests.o $(test-io-obj-y)
> tests/tpm-tis-test$(EXESUF): tests/tpm-tis-test.o tests/tpm-emu.o $(test-io-obj-y)
> tests/test-io-channel-file$(EXESUF): tests/test-io-channel-file.o \
> tests/io-channel-helpers.o $(test-io-obj-y)
> diff --git a/tests/tpm-tis-swtpm-test.c b/tests/tpm-tis-swtpm-test.c
> new file mode 100644
> index 0000000000..7dcd1d3912
> --- /dev/null
> +++ b/tests/tpm-tis-swtpm-test.c
> @@ -0,0 +1,66 @@
> +/*
> + * QTest testcase for TPM TIS talking to external swtpm and swtpm migration
> + *
> + * Copyright (c) 2018 IBM Corporation
> + * with parts borrowed from migration-test.c that is:
> + * Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates
Probably not relevant anymore.
> + *
> + * Authors:
> + * Stefan Berger <stefanb@linux.vnet.ibm.com>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> + * See the COPYING file in the top-level directory.
> + */
> +
> +#include "qemu/osdep.h"
> +#include <glib/gstdio.h>
> +
> +#include "libqtest.h"
> +#include "tpm-tests.h"
> +
> +typedef struct TestState {
> + char *src_tpm_path;
> + char *dst_tpm_path;
> + char *uri;
> +} TestState;
> +
> +static void tpm_tis_swtpm_test(const void *data)
> +{
> + const TestState *ts = data;
> +
> + tpm_test_swtpm_test(ts->src_tpm_path, tpm_util_tis_transfer, "tpm-tis");
> +}
> +
> +static void tpm_tis_swtpm_migration_test(const void *data)
> +{
> + const TestState *ts = data;
> +
> + tpm_test_swtpm_migration_test(ts->src_tpm_path, ts->dst_tpm_path, ts->uri,
> + tpm_util_tis_transfer, "tpm-tis");
> +}
> +
> +int main(int argc, char **argv)
> +{
> + int ret;
> + TestState ts = { 0 };
> +
> + ts.src_tpm_path = g_dir_make_tmp("qemu-tpm-tis-swtpm-test.XXXXXX", NULL);
> + ts.dst_tpm_path = g_dir_make_tmp("qemu-tpm-tis-swtpm-test.XXXXXX", NULL);
> + ts.uri = g_strdup_printf("unix:%s/migsocket", ts.src_tpm_path);
> +
> + module_call_init(MODULE_INIT_QOM);
> + g_test_init(&argc, &argv, NULL);
> +
> + qtest_add_data_func("/tpm/tis-swtpm/test", &ts, tpm_tis_swtpm_test);
> + qtest_add_data_func("/tpm/tis-swtpm-migration/test", &ts,
> + tpm_tis_swtpm_migration_test);
> + ret = g_test_run();
> +
> + g_rmdir(ts.dst_tpm_path);
> + g_free(ts.dst_tpm_path);
> + g_rmdir(ts.src_tpm_path);
> + g_free(ts.src_tpm_path);
> + g_free(ts.uri);
> +
> + return ret;
> +}
> diff --git a/tests/tpm-util.c b/tests/tpm-util.c
> index e1ac4d1bd5..672cedf905 100644
> --- a/tests/tpm-util.c
> +++ b/tests/tpm-util.c
> @@ -19,6 +19,9 @@
> #include "tpm-util.h"
> #include "qapi/qmp/qdict.h"
>
> +#define TIS_REG(LOCTY, REG) \
> + (TPM_TIS_ADDR_BASE + ((LOCTY) << 12) + REG)
> +
> static bool got_stop;
>
> void tpm_util_crb_transfer(QTestState *s,
> @@ -52,6 +55,51 @@ void tpm_util_crb_transfer(QTestState *s,
> qtest_memread(s, raddr, rsp, rsp_size);
> }
>
> +void tpm_util_tis_transfer(QTestState *s,
> + const unsigned char *req, size_t req_size,
> + unsigned char *rsp, size_t rsp_size)
> +{
> + uint32_t sts;
> + uint16_t bcount;
> + size_t i;
> +
> + /* request use of locality 0 */
> + qtest_writeb(s, TIS_REG(0, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_REQUEST_USE);
> + qtest_writel(s, TIS_REG(0, TPM_TIS_REG_STS), TPM_TIS_STS_COMMAND_READY);
> +
> + sts = qtest_readl(s, TIS_REG(0, TPM_TIS_REG_STS));
> + bcount = (sts >> 8) & 0xffff;
> + g_assert_cmpint(bcount, >=, req_size);
> +
> + /* transmit command */
> + for (i = 0; i < req_size; i++) {
> + qtest_writeb(s, TIS_REG(0, TPM_TIS_REG_DATA_FIFO), req[i]);
> + }
> +
> + /* start processing */
> + qtest_writeb(s, TIS_REG(0, TPM_TIS_REG_STS), TPM_TIS_STS_TPM_GO);
> +
> + uint64_t end_time = g_get_monotonic_time() + 50 * G_TIME_SPAN_SECOND;
> + do {
> + sts = qtest_readl(s, TIS_REG(0, TPM_TIS_REG_STS));
> + if ((sts & TPM_TIS_STS_DATA_AVAILABLE) != 0) {
> + break;
> + }
> + } while (g_get_monotonic_time() < end_time);
> +
> + sts = qtest_readl(s, TIS_REG(0, TPM_TIS_REG_STS));
> + bcount = (sts >> 8) & 0xffff;
> +
> + memset(rsp, 0, rsp_size);
> + for (i = 0; i < bcount; i++) {
> + rsp[i] = qtest_readb(s, TIS_REG(0, TPM_TIS_REG_DATA_FIFO));
> + }
> +
> + /* relinquish use of locality 0 */
> + qtest_writeb(s, TIS_REG(0, TPM_TIS_REG_ACCESS),
> + TPM_TIS_ACCESS_ACTIVE_LOCALITY);
> +}
> +
> void tpm_util_startup(QTestState *s, tx_func *tx)
> {
> unsigned char buffer[1024];
> diff --git a/tests/tpm-util.h b/tests/tpm-util.h
> index bb128360dd..330b9657fe 100644
> --- a/tests/tpm-util.h
> +++ b/tests/tpm-util.h
> @@ -23,6 +23,9 @@ typedef void (tx_func)(QTestState *s,
> void tpm_util_crb_transfer(QTestState *s,
> const unsigned char *req, size_t req_size,
> unsigned char *rsp, size_t rsp_size);
> +void tpm_util_tis_transfer(QTestState *s,
> + const unsigned char *req, size_t req_size,
> + unsigned char *rsp, size_t rsp_size);
>
> void tpm_util_startup(QTestState *s, tx_func *tx);
> void tpm_util_pcrextend(QTestState *s, tx_func *tx);
> --
> 2.14.3
>
>
--
Marc-André Lureau
^ permalink raw reply [flat|nested] 9+ messages in thread