From patchwork Tue Mar 19 02:30:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 10858759 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A63861575 for ; Tue, 19 Mar 2019 02:34:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D9AD29502 for ; Tue, 19 Mar 2019 02:34:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 813A429504; Tue, 19 Mar 2019 02:34:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6ED3229502 for ; Tue, 19 Mar 2019 02:34:03 +0000 (UTC) Received: from localhost ([127.0.0.1]:50431 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h64Zm-0004fo-QD for patchwork-qemu-devel@patchwork.kernel.org; Mon, 18 Mar 2019 22:34:02 -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 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= 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) 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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" void qfw_cfg_select(QFWCFG *fw_cfg, uint16_t key) { fw_cfg->select(fw_cfg, key); } +/* + * 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 = NULL; + size_t dsize; + FWCfgFile *pdir_entry; + size_t filesize = 0; + + qfw_cfg_get(fw_cfg, FW_CFG_FILE_DIR, &count, sizeof(count)); + count = be32_to_cpu(count); + dsize = sizeof(uint32_t) + count * sizeof(struct fw_cfg_file); + filesbuf = g_malloc0(dsize); + qfw_cfg_get(fw_cfg, FW_CFG_FILE_DIR, filesbuf, dsize); + pdir_entry = (FWCfgFile *)(filesbuf + sizeof(uint32_t)); + for (i = 0; i < count; ++i, ++pdir_entry) { + if (!strcmp(pdir_entry->name, filename)) { + uint32_t len = be32_to_cpu(pdir_entry->size); + uint16_t sel = be16_to_cpu(pdir_entry->select); + filesize = len; + if (len > buflen) { + len = 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); QFWCFG *mm_fw_cfg_init(QTestState *qts, uint64_t base); QFWCFG *io_fw_cfg_init(QTestState *qts, uint16_t base); From patchwork Tue Mar 19 02:30:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 10858755 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BFA6B15AC for ; Tue, 19 Mar 2019 02:32:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A847629502 for ; Tue, 19 Mar 2019 02:32:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9C4F429504; Tue, 19 Mar 2019 02:32:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 52F5529502 for ; Tue, 19 Mar 2019 02:32:19 +0000 (UTC) Received: from localhost ([127.0.0.1]:50423 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h64Y6-0003la-Hm for patchwork-qemu-devel@patchwork.kernel.org; Mon, 18 Mar 2019 22:32:18 -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 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= 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) 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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), ==, boot_menu); } +static void test_fw_cfg_reboot_timeout(void) +{ + uint32_t reboot_timeout = 0; + size_t filesize; + + filesize = qfw_cfg_get_file(fw_cfg, "etc/boot-fail-wait", + &reboot_timeout, sizeof(reboot_timeout)); + g_assert_cmpint(filesize, ==, sizeof(reboot_timeout)); + g_assert_cmpint(reboot_timeout, ==, 15); +} + int main(int argc, char **argv) { QTestState *s; @@ -106,7 +117,8 @@ int main(int argc, char **argv) g_test_init(&argc, &argv, NULL); - s = qtest_init("-uuid 4600cb32-38ec-4b2f-8acb-81c6ea54f2d8"); + s = qtest_init("-uuid 4600cb32-38ec-4b2f-8acb-81c6ea54f2d8 " + "-boot reboot-timeout=15"); fw_cfg = pc_fw_cfg_init(s); @@ -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); ret = g_test_run();