From nobody Fri May 3 18:52:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528315226812932.1105343114631; Wed, 6 Jun 2018 13:00:26 -0700 (PDT) Received: from localhost ([::1]:54404 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQebW-0001CV-QG for importer@patchew.org; Wed, 06 Jun 2018 16:00:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49078) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQeZb-00089N-CS for qemu-devel@nongnu.org; Wed, 06 Jun 2018 15:58:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fQeZY-00028d-7O for qemu-devel@nongnu.org; Wed, 06 Jun 2018 15:58:23 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:46098) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fQeZX-000285-SX for qemu-devel@nongnu.org; Wed, 06 Jun 2018 15:58:20 -0400 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w56JmpVM056096 for ; Wed, 6 Jun 2018 15:58:18 -0400 Received: from e31.co.us.ibm.com (e31.co.us.ibm.com [32.97.110.149]) by mx0a-001b2d01.pphosted.com with ESMTP id 2jektx6hqb-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 06 Jun 2018 15:58:17 -0400 Received: from localhost by e31.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 6 Jun 2018 13:58:17 -0600 Received: from b03cxnp08028.gho.boulder.ibm.com (9.17.130.20) by e31.co.us.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 6 Jun 2018 13:58:15 -0600 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w56JwEDT18808846 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 6 Jun 2018 12:58:14 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B6AEB78063; Wed, 6 Jun 2018 13:58:14 -0600 (MDT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 738687805E; Wed, 6 Jun 2018 13:58:14 -0600 (MDT) Received: from sbct-3.pok.ibm.com (unknown [9.47.158.153]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 6 Jun 2018 13:58:14 -0600 (MDT) From: Stefan Berger To: qemu-devel@nongnu.org Date: Wed, 6 Jun 2018 15:58:02 -0400 X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180606195805.185833-1-stefanb@linux.vnet.ibm.com> References: <20180606195805.185833-1-stefanb@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 18060619-8235-0000-0000-00000DAF07CB X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009139; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000265; SDB=6.01043027; UDB=6.00534142; IPR=6.00822157; MB=3.00021491; MTD=3.00000008; XFM=3.00000015; UTC=2018-06-06 19:58:17 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18060619-8236-0000-0000-000041620F2A Message-Id: <20180606195805.185833-2-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-06-06_09:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1805220000 definitions=main-1806060220 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by mx0a-001b2d01.pphosted.com id w56JmpVM056096 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PULL v1 1/4] test: Move reusable code from tpm-crb-swtpm-test.c to tpm-util.c X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Stefan Berger Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Marc-Andr=C3=A9 Lureau --- 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 =20 -#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" =20 typedef struct TestState { char *src_tpm_path; @@ -28,93 +24,6 @@ typedef struct TestState { char *uri; } TestState; =20 -bool got_stop; - -static void migrate(QTestState *who, const char *uri) -{ - QDict *rsp; - gchar *cmd; - - cmd =3D g_strdup_printf("{ 'execute': 'migrate'," - "'arguments': { 'uri': '%s' } }", - uri); - rsp =3D 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 =3D qtest_qmp(who, command); - - while (qdict_haskey(response, "event")) { - /* OK, it was an event */ - event_string =3D qdict_get_str(response, "event"); - if (!strcmp(event_string, "STOP")) { - got_stop =3D true; - } - qobject_unref(response); - response =3D 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 =3D wait_command(who, "{ 'execute': 'query-migrate' }"); - rsp_return =3D qdict_get_qdict(rsp, "return"); - status =3D qdict_get_str(rsp_return, "status"); - completed =3D strcmp(status, "completed") =3D=3D 0; - g_assert_cmpstr(status, !=3D, "failed"); - qobject_unref(rsp); - if (completed) { - return; - } - usleep(1000); - } -} - -static void migration_start_qemu(QTestState **src_qemu, QTestState **dst_q= emu, - SocketAddress *src_tpm_addr, - SocketAddress *dst_tpm_addr, - const char *miguri) -{ - char *src_qemu_args, *dst_qemu_args; - - src_qemu_args =3D g_strdup_printf( - "-chardev socket,id=3Dchr,path=3D%s " - "-tpmdev emulator,id=3Ddev,chardev=3Dchr " - "-device tpm-crb,tpmdev=3Ddev ", - src_tpm_addr->u.q_unix.path); - - *src_qemu =3D qtest_init(src_qemu_args); - - dst_qemu_args =3D g_strdup_printf( - "-chardev socket,id=3Dchr,path=3D%s " - "-tpmdev emulator,id=3Ddev,chardev=3Dchr " - "-device tpm-crb,tpmdev=3Ddev " - "-incoming %s", - dst_tpm_addr->u.q_unix.path, - miguri); - - *dst_qemu =3D qtest_init(dst_qemu_args); - - free(src_qemu_args); - free(dst_qemu_args); -} - static void tpm_crb_swtpm_test(const void *data) { char *args =3D NULL; @@ -183,8 +92,9 @@ static void tpm_crb_swtpm_migration_test(const void *dat= a) goto err_src_tpm_kill; } =20 - 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); =20 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 *da= ta) tpm_util_pcrread(src_qemu, tpm_util_crb_transfer, tpm_pcrread_resp, sizeof(tpm_pcrread_resp)); =20 - 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); =20 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; =20 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) =20 kill(pid, SIGKILL); } + +void tpm_util_migrate(QTestState *who, const char *uri) +{ + QDict *rsp; + gchar *cmd; + + cmd =3D g_strdup_printf("{ 'execute': 'migrate'," + "'arguments': { 'uri': '%s' } }", + uri); + rsp =3D 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 =3D qtest_qmp(who, command); + + while (qdict_haskey(response, "event")) { + /* OK, it was an event */ + event_string =3D qdict_get_str(response, "event"); + if (!strcmp(event_string, "STOP")) { + got_stop =3D true; + } + qobject_unref(response); + response =3D 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 =3D tpm_util_wait_command(who, "{ 'execute': 'query-migrate' }= "); + rsp_return =3D qdict_get_qdict(rsp, "return"); + status =3D qdict_get_str(rsp_return, "status"); + completed =3D strcmp(status, "completed") =3D=3D 0; + g_assert_cmpstr(status, !=3D, "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 =3D g_strdup_printf( + "-chardev socket,id=3Dchr,path=3D%s " + "-tpmdev emulator,id=3Ddev,chardev=3Dchr " + "-device tpm-crb,tpmdev=3Ddev ", + src_tpm_addr->u.q_unix.path); + + *src_qemu =3D qtest_init(src_qemu_args); + + dst_qemu_args =3D g_strdup_printf( + "-chardev socket,id=3Dchr,path=3D%s " + "-tpmdev emulator,id=3Ddev,chardev=3Dchr " + "-device tpm-crb,tpmdev=3Ddev " + "-incoming %s", + dst_tpm_addr->u.q_unix.path, + miguri); + + *dst_qemu =3D 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 *pi= d, SocketAddress **addr, GError **error); void tpm_util_swtpm_kill(GPid pid); =20 +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 */ --=20 2.14.4 From nobody Fri May 3 18:52:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15283152271781014.3018859665306; Wed, 6 Jun 2018 13:00:27 -0700 (PDT) Received: from localhost ([::1]:54405 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQeba-0001KT-H7 for importer@patchew.org; Wed, 06 Jun 2018 16:00:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49085) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQeZb-00089Z-NH for qemu-devel@nongnu.org; Wed, 06 Jun 2018 15:58:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fQeZY-000293-H6 for qemu-devel@nongnu.org; Wed, 06 Jun 2018 15:58:23 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:45946 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fQeZY-00028I-8n for qemu-devel@nongnu.org; Wed, 06 Jun 2018 15:58:20 -0400 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w56Jmrbo000731 for ; Wed, 6 Jun 2018 15:58:19 -0400 Received: from e36.co.us.ibm.com (e36.co.us.ibm.com [32.97.110.154]) by mx0b-001b2d01.pphosted.com with ESMTP id 2jek4vgquq-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 06 Jun 2018 15:58:19 -0400 Received: from localhost by e36.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 6 Jun 2018 13:58:18 -0600 Received: from b03cxnp08028.gho.boulder.ibm.com (9.17.130.20) by e36.co.us.ibm.com (192.168.1.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 6 Jun 2018 13:58:17 -0600 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w56JwGW03932646 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 6 Jun 2018 12:58:16 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2EFBD78069; Wed, 6 Jun 2018 13:58:16 -0600 (MDT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DA5FC78070; Wed, 6 Jun 2018 13:58:15 -0600 (MDT) Received: from sbct-3.pok.ibm.com (unknown [9.47.158.153]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 6 Jun 2018 13:58:15 -0600 (MDT) From: Stefan Berger To: qemu-devel@nongnu.org Date: Wed, 6 Jun 2018 15:58:03 -0400 X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180606195805.185833-1-stefanb@linux.vnet.ibm.com> References: <20180606195805.185833-1-stefanb@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 18060619-0020-0000-0000-00000E1DA3FF X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009139; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000265; SDB=6.01043027; UDB=6.00534142; IPR=6.00822157; MB=3.00021491; MTD=3.00000008; XFM=3.00000015; UTC=2018-06-06 19:58:17 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18060619-0021-0000-0000-000061CB04E3 Message-Id: <20180606195805.185833-3-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-06-06_09:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1805220000 definitions=main-1806060220 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by mx0b-001b2d01.pphosted.com id w56Jmrbo000731 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PULL v1 2/4] test: Move common TPM test functions to tpm-tests.c X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Stefan Berger Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Marc-Andr=C3=A9 Lureau --- 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 9854e7794b..392273317f 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -724,7 +724,7 @@ tests/test-io-task$(EXESUF): tests/test-io-task.o $(tes= t-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-em= u.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-i= o-obj-y) tests/tpm-tis-test$(EXESUF): tests/tpm-tis-test.o tests/tpm-emu.o $(test-i= o-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 =20 #include "libqtest.h" -#include "tpm-util.h" +#include "tpm-tests.h" =20 typedef struct TestState { char *src_tpm_path; @@ -26,108 +26,17 @@ typedef struct TestState { =20 static void tpm_crb_swtpm_test(const void *data) { - char *args =3D NULL; - QTestState *s; - SocketAddress *addr =3D NULL; - gboolean succ; - GPid swtpm_pid; - GError *error =3D NULL; const TestState *ts =3D data; =20 - succ =3D tpm_util_swtpm_start(ts->src_tpm_path, &swtpm_pid, &addr, &er= ror); - /* succ may be false if swtpm is not available */ - if (!succ) { - return; - } - - args =3D g_strdup_printf( - "-chardev socket,id=3Dchr,path=3D%s " - "-tpmdev emulator,id=3Ddev,chardev=3Dchr " - "-device tpm-crb,tpmdev=3Ddev", - addr->u.q_unix.path); - - s =3D 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[] =3D - "\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); } =20 static void tpm_crb_swtpm_migration_test(const void *data) { const TestState *ts =3D data; - gboolean succ; - GPid src_tpm_pid, dst_tpm_pid; - SocketAddress *src_tpm_addr =3D NULL, *dst_tpm_addr =3D NULL; - GError *error =3D NULL; - QTestState *src_qemu, *dst_qemu; - - succ =3D 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 =3D 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[] =3D - "\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); - } =20 -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); } =20 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 + * Marc-Andr=C3=A9 Lureau + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include + +#include "libqtest.h" +#include "tpm-tests.h" + +void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx) +{ + char *args =3D NULL; + QTestState *s; + SocketAddress *addr =3D NULL; + gboolean succ; + GPid swtpm_pid; + GError *error =3D NULL; + + succ =3D tpm_util_swtpm_start(src_tpm_path, &swtpm_pid, &addr, &error); + /* succ may be false if swtpm is not available */ + if (!succ) { + return; + } + + args =3D g_strdup_printf( + "-chardev socket,id=3Dchr,path=3D%s " + "-tpmdev emulator,id=3Ddev,chardev=3Dchr " + "-device tpm-crb,tpmdev=3Ddev", + addr->u.q_unix.path); + + s =3D qtest_start(args); + g_free(args); + + tpm_util_startup(s, tx); + tpm_util_pcrextend(s, tx); + + unsigned char tpm_pcrread_resp[] =3D + "\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 =3D NULL, *dst_tpm_addr =3D NULL; + GError *error =3D NULL; + QTestState *src_qemu, *dst_qemu; + + succ =3D 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 =3D 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[] =3D + "\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 + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * 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 */ --=20 2.14.4 From nobody Fri May 3 18:52:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528315445419901.7939230050306; Wed, 6 Jun 2018 13:04:05 -0700 (PDT) Received: from localhost ([::1]:54427 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQef6-0004Cj-9q for importer@patchew.org; Wed, 06 Jun 2018 16:04:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49141) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQeZe-0008BZ-Cp for qemu-devel@nongnu.org; Wed, 06 Jun 2018 15:58:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fQeZa-0002BB-WC for qemu-devel@nongnu.org; Wed, 06 Jun 2018 15:58:26 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:46896 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fQeZa-0002As-Pw for qemu-devel@nongnu.org; Wed, 06 Jun 2018 15:58:22 -0400 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w56Jnt6q126568 for ; Wed, 6 Jun 2018 15:58:22 -0400 Received: from e33.co.us.ibm.com (e33.co.us.ibm.com [32.97.110.151]) by mx0b-001b2d01.pphosted.com with ESMTP id 2jenhj9m1e-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 06 Jun 2018 15:58:21 -0400 Received: from localhost by e33.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 6 Jun 2018 13:58:21 -0600 Received: from b03cxnp08027.gho.boulder.ibm.com (9.17.130.19) by e33.co.us.ibm.com (192.168.1.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 6 Jun 2018 13:58:18 -0600 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w56JwH1i49741878 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 6 Jun 2018 12:58:17 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 99A9678077; Wed, 6 Jun 2018 13:58:17 -0600 (MDT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5F0EB78066; Wed, 6 Jun 2018 13:58:17 -0600 (MDT) Received: from sbct-3.pok.ibm.com (unknown [9.47.158.153]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 6 Jun 2018 13:58:17 -0600 (MDT) From: Stefan Berger To: qemu-devel@nongnu.org Date: Wed, 6 Jun 2018 15:58:04 -0400 X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180606195805.185833-1-stefanb@linux.vnet.ibm.com> References: <20180606195805.185833-1-stefanb@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 18060619-0036-0000-0000-000009EC02CE X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009139; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000265; SDB=6.01043027; UDB=6.00534142; IPR=6.00822157; MB=3.00021491; MTD=3.00000008; XFM=3.00000015; UTC=2018-06-06 19:58:20 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18060619-0037-0000-0000-0000479604CD Message-Id: <20180606195805.185833-4-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-06-06_09:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1805220000 definitions=main-1806060220 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by mx0b-001b2d01.pphosted.com id w56Jnt6q126568 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PULL v1 3/4] test: Pass TPM interface model to functions creating command line X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Stefan Berger Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Marc-Andr=C3=A9 Lureau --- 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 =3D data; =20 - 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"= ); } =20 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 =3D data; =20 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"); } =20 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" =20 -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 =3D NULL; QTestState *s; @@ -36,8 +37,8 @@ void tpm_test_swtpm_test(const char *src_tpm_path, tx_fun= c *tx) args =3D g_strdup_printf( "-chardev socket,id=3Dchr,path=3D%s " "-tpmdev emulator,id=3Ddev,chardev=3Dchr " - "-device tpm-crb,tpmdev=3Ddev", - addr->u.q_unix.path); + "-device %s,tpmdev=3Ddev", + addr->u.q_unix.path, ifmodel); =20 s =3D qtest_start(args); g_free(args); @@ -64,7 +65,8 @@ void tpm_test_swtpm_test(const char *src_tpm_path, tx_fun= c *tx) =20 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_pa= th, } =20 tpm_util_migration_start_qemu(&src_qemu, &dst_qemu, - src_tpm_addr, dst_tpm_addr, uri); + src_tpm_addr, dst_tpm_addr, uri, + ifmodel); =20 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 @@ =20 #include "tpm-util.h" =20 -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); =20 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); =20 #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_q= emu, 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; =20 src_qemu_args =3D g_strdup_printf( "-chardev socket,id=3Dchr,path=3D%s " "-tpmdev emulator,id=3Ddev,chardev=3Dchr " - "-device tpm-crb,tpmdev=3Ddev ", - src_tpm_addr->u.q_unix.path); + "-device %s,tpmdev=3Ddev ", + src_tpm_addr->u.q_unix.path, ifmodel); =20 *src_qemu =3D qtest_init(src_qemu_args); =20 dst_qemu_args =3D g_strdup_printf( "-chardev socket,id=3Dchr,path=3D%s " "-tpmdev emulator,id=3Ddev,chardev=3Dchr " - "-device tpm-crb,tpmdev=3Ddev " + "-device %s,tpmdev=3Ddev " "-incoming %s", dst_tpm_addr->u.q_unix.path, - miguri); + ifmodel, miguri); =20 *dst_qemu =3D qtest_init(dst_qemu_args); =20 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); =20 void tpm_util_wait_for_migration_complete(QTestState *who); =20 --=20 2.14.4 From nobody Fri May 3 18:52:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528315390327562.2910123075928; Wed, 6 Jun 2018 13:03:10 -0700 (PDT) Received: from localhost ([::1]:54425 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQeeD-0003Z7-78 for importer@patchew.org; Wed, 06 Jun 2018 16:03:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49154) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQeZf-0008By-0H for qemu-devel@nongnu.org; Wed, 06 Jun 2018 15:58:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fQeZb-0002C5-S1 for qemu-devel@nongnu.org; Wed, 06 Jun 2018 15:58:27 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:40906 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fQeZb-0002BX-L7 for qemu-devel@nongnu.org; Wed, 06 Jun 2018 15:58:23 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w56JobC0059984 for ; Wed, 6 Jun 2018 15:58:23 -0400 Received: from e35.co.us.ibm.com (e35.co.us.ibm.com [32.97.110.153]) by mx0a-001b2d01.pphosted.com with ESMTP id 2jej41u9ew-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 06 Jun 2018 15:58:22 -0400 Received: from localhost by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 6 Jun 2018 13:58:22 -0600 Received: from b03cxnp08028.gho.boulder.ibm.com (9.17.130.20) by e35.co.us.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 6 Jun 2018 13:58:20 -0600 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w56JwJqq9896360 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 6 Jun 2018 12:58:19 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0B17A78064; Wed, 6 Jun 2018 13:58:19 -0600 (MDT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BD3DD78060; Wed, 6 Jun 2018 13:58:18 -0600 (MDT) Received: from sbct-3.pok.ibm.com (unknown [9.47.158.153]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 6 Jun 2018 13:58:18 -0600 (MDT) From: Stefan Berger To: qemu-devel@nongnu.org Date: Wed, 6 Jun 2018 15:58:05 -0400 X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180606195805.185833-1-stefanb@linux.vnet.ibm.com> References: <20180606195805.185833-1-stefanb@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 18060619-0012-0000-0000-0000166AA5A7 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009139; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000265; SDB=6.01043027; UDB=6.00534142; IPR=6.00822157; MB=3.00021491; MTD=3.00000008; XFM=3.00000015; UTC=2018-06-06 19:58:20 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18060619-0013-0000-0000-0000532D21AA Message-Id: <20180606195805.185833-5-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-06-06_09:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1805220000 definitions=main-1806060220 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by mx0a-001b2d01.pphosted.com id w56JobC0059984 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PULL v1 4/4] test: Add swtpm migration test for the TPM TIS interface X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Stefan Berger Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add a test case for testing swtpm migration with the TPM TIS interface. Signed-off-by: Stefan Berger Reviewed-by: Marc-Andr=C3=A9 Lureau --- 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 392273317f..0eaa835b8a 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -299,6 +299,7 @@ check-qtest-x86_64-$(CONFIG_VHOST_USER_NET_TEST_x86_64)= +=3D tests/vhost-user-test endif check-qtest-i386-$(CONFIG_TPM) +=3D tests/tpm-crb-swtpm-test$(EXESUF) check-qtest-i386-$(CONFIG_TPM) +=3D tests/tpm-crb-test$(EXESUF) +check-qtest-i386-$(CONFIG_TPM) +=3D tests/tpm-tis-swtpm-test$(EXESUF) check-qtest-i386-$(CONFIG_TPM) +=3D tests/tpm-tis-test$(EXESUF) check-qtest-i386-$(CONFIG_SLIRP) +=3D tests/test-netfilter$(EXESUF) check-qtest-i386-$(CONFIG_POSIX) +=3D tests/test-filter-mirror$(EXESUF) @@ -726,6 +727,8 @@ tests/test-io-channel-socket$(EXESUF): tests/test-io-ch= annel-socket.o \ tests/tpm-crb-swtpm-test$(EXESUF): tests/tpm-crb-swtpm-test.o tests/tpm-em= u.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-i= o-obj-y) +tests/tpm-tis-swtpm-test$(EXESUF): tests/tpm-tis-swtpm-test.o tests/tpm-em= u.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-i= o-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 + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include + +#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 =3D 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 =3D 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 =3D { 0 }; + + ts.src_tpm_path =3D g_dir_make_tmp("qemu-tpm-tis-swtpm-test.XXXXXX", N= ULL); + ts.dst_tpm_path =3D g_dir_make_tmp("qemu-tpm-tis-swtpm-test.XXXXXX", N= ULL); + ts.uri =3D 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 =3D 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" =20 +#define TIS_REG(LOCTY, REG) \ + (TPM_TIS_ADDR_BASE + ((LOCTY) << 12) + REG) + static bool got_stop; =20 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); } =20 +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 =3D qtest_readl(s, TIS_REG(0, TPM_TIS_REG_STS)); + bcount =3D (sts >> 8) & 0xffff; + g_assert_cmpint(bcount, >=3D, req_size); + + /* transmit command */ + for (i =3D 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 =3D g_get_monotonic_time() + 50 * G_TIME_SPAN_SECOND; + do { + sts =3D qtest_readl(s, TIS_REG(0, TPM_TIS_REG_STS)); + if ((sts & TPM_TIS_STS_DATA_AVAILABLE) !=3D 0) { + break; + } + } while (g_get_monotonic_time() < end_time); + + sts =3D qtest_readl(s, TIS_REG(0, TPM_TIS_REG_STS)); + bcount =3D (sts >> 8) & 0xffff; + + memset(rsp, 0, rsp_size); + for (i =3D 0; i < bcount; i++) { + rsp[i] =3D 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); =20 void tpm_util_startup(QTestState *s, tx_func *tx); void tpm_util_pcrextend(QTestState *s, tx_func *tx); --=20 2.14.4