From nobody Sun May 19 00:47:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=163.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 155296286429211.335530517946495; Mon, 18 Mar 2019 19:34:24 -0700 (PDT) Received: from localhost ([127.0.0.1]:50431 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h64a3-0004fo-7s for importer@patchew.org; Mon, 18 Mar 2019 22:34:19 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34016) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h64Wx-0003As-Hc for qemu-devel@nongnu.org; Mon, 18 Mar 2019 22:31:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h64Wt-0001QD-QD for qemu-devel@nongnu.org; Mon, 18 Mar 2019 22:31:05 -0400 Received: from m12-15.163.com ([220.181.12.15]:56355) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h64Wr-000100-Cq for qemu-devel@nongnu.org; Mon, 18 Mar 2019 22:31:03 -0400 Received: from test-VirtualBox.hz.ali.com (unknown [42.120.75.35]) by smtp11 (Coremail) with SMTP id D8CowADnLW1GVJBc54WfAw--.32058S3; Tue, 19 Mar 2019 10:30:33 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=sJG0O/WEVzfGhWdfvC 5LPYeeVQDEFTGSPwj53vie+BE=; b=BRKDvY+WLcglk3e/1gs2nBWjkAENv45HCt 1tu/Tc5vElLT6yq1jcQXXhivvDrGrrx6QLmAiiuqQQfQLJN30mpuIOh1Web1hA0I OpCzxwpnIFMIsoFdbyWWnmfn/R5CrDQXFj8jKorP7VNsxyR1nMJbkMldi3iY2B+W eKwqWl4xA= From: Li Qiang To: thuth@redhat.com, lvivier@redhat.com, pbonzini@redhat.com, philmd@redhat.com, lersek@redhat.com, kraxel@redhat.com Date: Tue, 19 Mar 2019 10:30:29 +0800 Message-Id: <20190319023030.947-2-liq3ea@163.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190319023030.947-1-liq3ea@163.com> References: <20190319023030.947-1-liq3ea@163.com> X-CM-TRANSID: D8CowADnLW1GVJBc54WfAw--.32058S3 X-Coremail-Antispam: 1Uf129KBjvJXoWxWr4kZF4xKF4xAw1UGr4fuFg_yoW5Ww1rpF ZIkFy3trZ3G3WfKrnxJw13JF1agrykXr1UW3y3ZFWFyw17Cr15tFsFk34FkryUXr1UZF45 tw4qgFyYkFn7XaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jbo7tUUUUU= X-Originating-IP: [42.120.75.35] X-CM-SenderInfo: 5oltjvrd6rljoofrz/xtbBLwl8bVUMIUWzqQAAsQ X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 220.181.12.15 Subject: [Qemu-devel] [PATCH 1/2] tests: fw_cfg: add a function to get the fw_cfg file 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: Li Qiang , liq3ea@gmail.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This is useful to write qtest about fw_cfg file entry. Signed-off-by: Li Qiang --- tests/libqos/fw_cfg.c | 45 +++++++++++++++++++++++++++++++++++++++++++ tests/libqos/fw_cfg.h | 2 ++ 2 files changed, 47 insertions(+) diff --git a/tests/libqos/fw_cfg.c b/tests/libqos/fw_cfg.c index d0889d1e22..2df33df859 100644 --- a/tests/libqos/fw_cfg.c +++ b/tests/libqos/fw_cfg.c @@ -16,12 +16,57 @@ #include "libqos/fw_cfg.h" #include "libqtest.h" #include "qemu/bswap.h" +#include "hw/nvram/fw_cfg.h" =20 void qfw_cfg_select(QFWCFG *fw_cfg, uint16_t key) { fw_cfg->select(fw_cfg, key); } =20 +/* + * The caller need check the return value. When the return value is + * nonzero, it means that some bytes have been transferred. + * + * If the fw_cfg file in question is smaller than the allocated & passed-in + * buffer, then the buffer has been populated only in part. + * + * If the fw_cfg file in question is larger than the passed-in + * buffer, then the return value explains how much room would have been + * necessary in total. And, while the caller's buffer has been fully + * populated, it has received only a starting slice of the fw_cfg file. + */ +size_t qfw_cfg_get_file(QFWCFG *fw_cfg, const char *filename, + void *data, size_t buflen) +{ + uint32_t count; + uint32_t i; + unsigned char *filesbuf =3D NULL; + size_t dsize; + FWCfgFile *pdir_entry; + size_t filesize =3D 0; + + qfw_cfg_get(fw_cfg, FW_CFG_FILE_DIR, &count, sizeof(count)); + count =3D be32_to_cpu(count); + dsize =3D sizeof(uint32_t) + count * sizeof(struct fw_cfg_file); + filesbuf =3D g_malloc0(dsize); + qfw_cfg_get(fw_cfg, FW_CFG_FILE_DIR, filesbuf, dsize); + pdir_entry =3D (FWCfgFile *)(filesbuf + sizeof(uint32_t)); + for (i =3D 0; i < count; ++i, ++pdir_entry) { + if (!strcmp(pdir_entry->name, filename)) { + uint32_t len =3D be32_to_cpu(pdir_entry->size); + uint16_t sel =3D be16_to_cpu(pdir_entry->select); + filesize =3D len; + if (len > buflen) { + len =3D buflen; + } + qfw_cfg_get(fw_cfg, sel, data, len); + break; + } + } + g_free(filesbuf); + return filesize; +} + void qfw_cfg_read_data(QFWCFG *fw_cfg, void *data, size_t len) { fw_cfg->read(fw_cfg, data, len); diff --git a/tests/libqos/fw_cfg.h b/tests/libqos/fw_cfg.h index 0353416af0..4996774f7d 100644 --- a/tests/libqos/fw_cfg.h +++ b/tests/libqos/fw_cfg.h @@ -31,6 +31,8 @@ void qfw_cfg_get(QFWCFG *fw_cfg, uint16_t key, void *data= , size_t len); uint16_t qfw_cfg_get_u16(QFWCFG *fw_cfg, uint16_t key); uint32_t qfw_cfg_get_u32(QFWCFG *fw_cfg, uint16_t key); uint64_t qfw_cfg_get_u64(QFWCFG *fw_cfg, uint16_t key); +size_t qfw_cfg_get_file(QFWCFG *fw_cfg, const char *filename, + void *data, size_t buflen); =20 QFWCFG *mm_fw_cfg_init(QTestState *qts, uint64_t base); QFWCFG *io_fw_cfg_init(QTestState *qts, uint16_t base); --=20 2.17.1 From nobody Sun May 19 00:47:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=163.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552962776219213.12969850639854; Mon, 18 Mar 2019 19:32:56 -0700 (PDT) Received: from localhost ([127.0.0.1]:50423 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h64Yb-0003la-6S for importer@patchew.org; Mon, 18 Mar 2019 22:32:49 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33971) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h64Wt-00039J-PX for qemu-devel@nongnu.org; Mon, 18 Mar 2019 22:31:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h64Ws-0001Og-JK for qemu-devel@nongnu.org; Mon, 18 Mar 2019 22:31:03 -0400 Received: from m12-15.163.com ([220.181.12.15]:56406) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h64Wo-00010B-2A for qemu-devel@nongnu.org; Mon, 18 Mar 2019 22:31:01 -0400 Received: from test-VirtualBox.hz.ali.com (unknown [42.120.75.35]) by smtp11 (Coremail) with SMTP id D8CowADnLW1GVJBc54WfAw--.32058S4; Tue, 19 Mar 2019 10:30:35 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=0eB1+QBlWbXGCAw+qu CruIPOxFUUvrx83fsJBBdsAeE=; b=CnVPcckZCgurxIw42hRPY8YT0WsEM+S06Z j16O0/xOC20VyKQaweiv8za7j0qEy6YHBQYTUC58xz8Ejxi6V11d/W65ZwE7xnbN ZA2CI9hqIAZ49lL6BVKVrMva0iNrBb1lpQbGdCuViGFaCXRLGcGrDtyaoDpO+T49 2cGMU4hag= From: Li Qiang To: thuth@redhat.com, lvivier@redhat.com, pbonzini@redhat.com, philmd@redhat.com, lersek@redhat.com, kraxel@redhat.com Date: Tue, 19 Mar 2019 10:30:30 +0800 Message-Id: <20190319023030.947-3-liq3ea@163.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190319023030.947-1-liq3ea@163.com> References: <20190319023030.947-1-liq3ea@163.com> X-CM-TRANSID: D8CowADnLW1GVJBc54WfAw--.32058S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7KF1UCFykXw4fCF45CF1xXwb_yoW8XrWUpr yj93WqkrZ5JF4aqr13GrnrXr1ftr97Cr48CFWqqFWIyw18Gr1qqa18CasYgF1DWFWIvFs8 Z3WktF15Krs8JaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UgeOXUUUUU= X-Originating-IP: [42.120.75.35] X-CM-SenderInfo: 5oltjvrd6rljoofrz/xtbBoQt8bVQHD-cdDgAAsD X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 220.181.12.15 Subject: [Qemu-devel] [PATCH 2/2] tests: fw_cfg: add reboot_timeout test case 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: Li Qiang , liq3ea@gmail.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Li Qiang --- tests/fw_cfg-test.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/fw_cfg-test.c b/tests/fw_cfg-test.c index 1c5103fe1c..551b51e38f 100644 --- a/tests/fw_cfg-test.c +++ b/tests/fw_cfg-test.c @@ -99,6 +99,17 @@ static void test_fw_cfg_boot_menu(void) g_assert_cmpint(qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_MENU), =3D=3D, boo= t_menu); } =20 +static void test_fw_cfg_reboot_timeout(void) +{ + uint32_t reboot_timeout =3D 0; + size_t filesize; + + filesize =3D qfw_cfg_get_file(fw_cfg, "etc/boot-fail-wait", + &reboot_timeout, sizeof(reboot_timeout)); + g_assert_cmpint(filesize, =3D=3D, sizeof(reboot_timeout)); + g_assert_cmpint(reboot_timeout, =3D=3D, 15); +} + int main(int argc, char **argv) { QTestState *s; @@ -106,7 +117,8 @@ int main(int argc, char **argv) =20 g_test_init(&argc, &argv, NULL); =20 - s =3D qtest_init("-uuid 4600cb32-38ec-4b2f-8acb-81c6ea54f2d8"); + s =3D qtest_init("-uuid 4600cb32-38ec-4b2f-8acb-81c6ea54f2d8 " + "-boot reboot-timeout=3D15"); =20 fw_cfg =3D pc_fw_cfg_init(s); =20 @@ -125,6 +137,7 @@ int main(int argc, char **argv) qtest_add_func("fw_cfg/max_cpus", test_fw_cfg_max_cpus); qtest_add_func("fw_cfg/numa", test_fw_cfg_numa); qtest_add_func("fw_cfg/boot_menu", test_fw_cfg_boot_menu); + qtest_add_func("fw_cfg/reboot_timeout", test_fw_cfg_reboot_timeout); =20 ret =3D g_test_run(); =20 --=20 2.17.1