From patchwork Wed Apr 24 14:06:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 10914925 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 B17A214DB for ; Wed, 24 Apr 2019 14:25:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9CEFC28A85 for ; Wed, 24 Apr 2019 14:25:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F2AF28A9D; Wed, 24 Apr 2019 14:25:02 +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=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 0017F28A85 for ; Wed, 24 Apr 2019 14:25:01 +0000 (UTC) Received: from localhost ([127.0.0.1]:42525 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hJIpZ-0001sE-8Z for patchwork-qemu-devel@patchwork.kernel.org; Wed, 24 Apr 2019 10:25:01 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39092) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hJIfe-0002aR-7L for qemu-devel@nongnu.org; Wed, 24 Apr 2019 10:14:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hJIY5-0006in-E4 for qemu-devel@nongnu.org; Wed, 24 Apr 2019 10:06:59 -0400 Received: from m12-14.163.com ([220.181.12.14]:54119) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hJIY4-0006eU-3r for qemu-devel@nongnu.org; Wed, 24 Apr 2019 10:06:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=KTK796b+CN5s4f878d ALjFdRsk5kTGsNKIS5A/bVlYE=; b=kBH6L7Kzuypthh7yOsnx+HiMSSbKxSg39V tFmAsbKBawmbwlGA0t8xiZ+Q3eIPszfhaebI9gX5LdVqK/ZuGu+kEdnw3J6yiILM RVIWqfDM4n8g1J8zXS2S80x7cIotH1N8ZKKbchaQCupd+cmNTTZbf8N2hjBT9rut lkm55b+Es= Received: from localhost.localdomain (unknown [115.200.201.0]) by smtp10 (Coremail) with SMTP id DsCowAC3Ayl0bcBcrks9CA--.5531S3; Wed, 24 Apr 2019 22:06:48 +0800 (CST) From: Li Qiang To: philmd@redhat.com, lersek@redhat.com, kraxel@redhat.com, thuth@redhat.com, lvivier@redhat.com, pbonzini@redhat.com Date: Wed, 24 Apr 2019 07:06:39 -0700 Message-Id: <20190424140643.62457-2-liq3ea@163.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190424140643.62457-1-liq3ea@163.com> References: <20190424140643.62457-1-liq3ea@163.com> X-CM-TRANSID: DsCowAC3Ayl0bcBcrks9CA--.5531S3 X-Coremail-Antispam: 1Uf129KBjvJXoW3JryfKFWDGr13XFyrCrW3ZFb_yoW7tryfpr y7uF1YkrZ3JFsaqry3Jr1Ut3W3t34xW34kGw4Utay5tw4Uur4UJF4kAw1akw1DXrW8Zay5 Aa1vyr1YkFnxWaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UgAwsUUUUU= X-Originating-IP: [115.200.201.0] X-CM-SenderInfo: 5oltjvrd6rljoofrz/1tbitAKgbVSIbtkMXwABsC X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 220.181.12.14 Subject: [Qemu-devel] [PATCH v2 1/5] tests: refactor fw_cfg_test 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 Currently, fw_cfg_test uses one QTestState for every test case. This will add all command lines for every test case and this is unnecessary. This patch split the test cases and for every test case it uses his own QTestState. This patch does following things: 1. Get rid of the global 'fw_cfg', this need add a uninit function 2. Convert every test case in a separate QTestState After this patch, we can add fw_cfg test case freely and will not have effect on other test cases. Signed-off-by: Li Qiang Acked-by: Thomas Huth --- tests/fw_cfg-test.c | 86 ++++++++++++++++++++++++++++++++++++++----- tests/libqos/fw_cfg.c | 10 +++++ tests/libqos/fw_cfg.h | 7 ++++ 3 files changed, 94 insertions(+), 9 deletions(-) diff --git a/tests/fw_cfg-test.c b/tests/fw_cfg-test.c index 1c5103fe1c..c22503619f 100644 --- a/tests/fw_cfg-test.c +++ b/tests/fw_cfg-test.c @@ -21,62 +21,127 @@ static uint16_t nb_cpus = 1; static uint16_t max_cpus = 1; static uint64_t nb_nodes = 0; static uint16_t boot_menu = 0; -static QFWCFG *fw_cfg = NULL; static void test_fw_cfg_signature(void) { + QFWCFG *fw_cfg; + QTestState *s; char buf[5]; + s = qtest_init(""); + fw_cfg = pc_fw_cfg_init(s); + qfw_cfg_get(fw_cfg, FW_CFG_SIGNATURE, buf, 4); buf[4] = 0; g_assert_cmpstr(buf, ==, "QEMU"); + pc_fw_cfg_uninit(fw_cfg); + qtest_quit(s); } static void test_fw_cfg_id(void) { - uint32_t id = qfw_cfg_get_u32(fw_cfg, FW_CFG_ID); + QFWCFG *fw_cfg; + QTestState *s; + uint32_t id; + + s = qtest_init(""); + fw_cfg = pc_fw_cfg_init(s); + + id = qfw_cfg_get_u32(fw_cfg, FW_CFG_ID); g_assert((id == 1) || (id == 3)); + pc_fw_cfg_uninit(fw_cfg); + qtest_quit(s); } static void test_fw_cfg_uuid(void) { + QFWCFG *fw_cfg; + QTestState *s; + uint8_t buf[16]; static const uint8_t uuid[16] = { 0x46, 0x00, 0xcb, 0x32, 0x38, 0xec, 0x4b, 0x2f, 0x8a, 0xcb, 0x81, 0xc6, 0xea, 0x54, 0xf2, 0xd8, }; + s = qtest_init("-uuid 4600cb32-38ec-4b2f-8acb-81c6ea54f2d8"); + fw_cfg = pc_fw_cfg_init(s); + qfw_cfg_get(fw_cfg, FW_CFG_UUID, buf, 16); g_assert(memcmp(buf, uuid, sizeof(buf)) == 0); + + pc_fw_cfg_uninit(fw_cfg); + qtest_quit(s); + } static void test_fw_cfg_ram_size(void) { + QFWCFG *fw_cfg; + QTestState *s; + + s = qtest_init(""); + fw_cfg = pc_fw_cfg_init(s); + g_assert_cmpint(qfw_cfg_get_u64(fw_cfg, FW_CFG_RAM_SIZE), ==, ram_size); + + pc_fw_cfg_uninit(fw_cfg); + qtest_quit(s); } static void test_fw_cfg_nographic(void) { + QFWCFG *fw_cfg; + QTestState *s; + + s = qtest_init(""); + fw_cfg = pc_fw_cfg_init(s); + g_assert_cmpint(qfw_cfg_get_u16(fw_cfg, FW_CFG_NOGRAPHIC), ==, 0); + + pc_fw_cfg_uninit(fw_cfg); + qtest_quit(s); } static void test_fw_cfg_nb_cpus(void) { + QFWCFG *fw_cfg; + QTestState *s; + + s = qtest_init(""); + fw_cfg = pc_fw_cfg_init(s); + g_assert_cmpint(qfw_cfg_get_u16(fw_cfg, FW_CFG_NB_CPUS), ==, nb_cpus); + + pc_fw_cfg_uninit(fw_cfg); + qtest_quit(s); } static void test_fw_cfg_max_cpus(void) { + QFWCFG *fw_cfg; + QTestState *s; + + s = qtest_init(""); + fw_cfg = pc_fw_cfg_init(s); + g_assert_cmpint(qfw_cfg_get_u16(fw_cfg, FW_CFG_MAX_CPUS), ==, max_cpus); + pc_fw_cfg_uninit(fw_cfg); + qtest_quit(s); } static void test_fw_cfg_numa(void) { + QFWCFG *fw_cfg; + QTestState *s; uint64_t *cpu_mask; uint64_t *node_mask; + s = qtest_init(""); + fw_cfg = pc_fw_cfg_init(s); + g_assert_cmpint(qfw_cfg_get_u64(fw_cfg, FW_CFG_NUMA), ==, nb_nodes); cpu_mask = g_new0(uint64_t, max_cpus); @@ -92,24 +157,29 @@ static void test_fw_cfg_numa(void) g_free(node_mask); g_free(cpu_mask); + pc_fw_cfg_uninit(fw_cfg); + qtest_quit(s); } static void test_fw_cfg_boot_menu(void) { + QFWCFG *fw_cfg; + QTestState *s; + + s = qtest_init(""); + fw_cfg = pc_fw_cfg_init(s); + g_assert_cmpint(qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_MENU), ==, boot_menu); + pc_fw_cfg_uninit(fw_cfg); + qtest_quit(s); } int main(int argc, char **argv) { - QTestState *s; int ret; g_test_init(&argc, &argv, NULL); - s = qtest_init("-uuid 4600cb32-38ec-4b2f-8acb-81c6ea54f2d8"); - - fw_cfg = pc_fw_cfg_init(s); - qtest_add_func("fw_cfg/signature", test_fw_cfg_signature); qtest_add_func("fw_cfg/id", test_fw_cfg_id); qtest_add_func("fw_cfg/uuid", test_fw_cfg_uuid); @@ -128,7 +198,5 @@ int main(int argc, char **argv) ret = g_test_run(); - qtest_quit(s); - return ret; } diff --git a/tests/libqos/fw_cfg.c b/tests/libqos/fw_cfg.c index d0889d1e22..c6839c53c8 100644 --- a/tests/libqos/fw_cfg.c +++ b/tests/libqos/fw_cfg.c @@ -81,6 +81,11 @@ QFWCFG *mm_fw_cfg_init(QTestState *qts, uint64_t base) return fw_cfg; } +void mm_fw_cfg_uninit(QFWCFG *fw_cfg) +{ + g_free(fw_cfg); +} + static void io_fw_cfg_select(QFWCFG *fw_cfg, uint16_t key) { qtest_outw(fw_cfg->qts, fw_cfg->base, key); @@ -107,3 +112,8 @@ QFWCFG *io_fw_cfg_init(QTestState *qts, uint16_t base) return fw_cfg; } + +void io_fw_cfg_uninit(QFWCFG *fw_cfg) +{ + g_free(fw_cfg); +} diff --git a/tests/libqos/fw_cfg.h b/tests/libqos/fw_cfg.h index 0353416af0..60de81e863 100644 --- a/tests/libqos/fw_cfg.h +++ b/tests/libqos/fw_cfg.h @@ -33,11 +33,18 @@ uint32_t qfw_cfg_get_u32(QFWCFG *fw_cfg, uint16_t key); uint64_t qfw_cfg_get_u64(QFWCFG *fw_cfg, uint16_t key); QFWCFG *mm_fw_cfg_init(QTestState *qts, uint64_t base); +void mm_fw_cfg_uninit(QFWCFG *fw_cfg); QFWCFG *io_fw_cfg_init(QTestState *qts, uint16_t base); +void io_fw_cfg_uninit(QFWCFG *fw_cfg); static inline QFWCFG *pc_fw_cfg_init(QTestState *qts) { return io_fw_cfg_init(qts, 0x510); } +static inline void pc_fw_cfg_uninit(QFWCFG *fw_cfg) +{ + io_fw_cfg_uninit(fw_cfg); +} + #endif From patchwork Wed Apr 24 14:06:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 10914903 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 E0F3B1708 for ; Wed, 24 Apr 2019 14:23:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE924289D8 for ; Wed, 24 Apr 2019 14:23:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C2DE4289F6; Wed, 24 Apr 2019 14:23: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=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 653B328A75 for ; Wed, 24 Apr 2019 14:23:19 +0000 (UTC) Received: from localhost ([127.0.0.1]:42493 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hJInu-0000j8-Mz for patchwork-qemu-devel@patchwork.kernel.org; Wed, 24 Apr 2019 10:23:18 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39117) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hJIfe-0002as-7g for qemu-devel@nongnu.org; Wed, 24 Apr 2019 10:14:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hJIY6-0006jE-2f for qemu-devel@nongnu.org; Wed, 24 Apr 2019 10:06:59 -0400 Received: from m12-14.163.com ([220.181.12.14]:54282) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hJIY4-0006fB-19 for qemu-devel@nongnu.org; Wed, 24 Apr 2019 10:06:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=PwPb4mLM2B0UzCTSk2 KeE78xv8ZHNYgaXG8Hlt3/UP8=; b=Bj4KFbY+oJQhATtW8WDlyUSG7ACyBW490c nlwxDY79kJ53viKMgb2h9Kdg+oejgb00a+xpV3rzu/ZfCSvt1LDHqZjn/TiQ6bhV JfCYX5qIdFpQmNjJ4ImVaajbkuCTcYPIf+r9i59oGef3uKPwhQAzKHnskoemcpZm HMsa7sIu8= Received: from localhost.localdomain (unknown [115.200.201.0]) by smtp10 (Coremail) with SMTP id DsCowAC3Ayl0bcBcrks9CA--.5531S4; Wed, 24 Apr 2019 22:06:49 +0800 (CST) From: Li Qiang To: philmd@redhat.com, lersek@redhat.com, kraxel@redhat.com, thuth@redhat.com, lvivier@redhat.com, pbonzini@redhat.com Date: Wed, 24 Apr 2019 07:06:40 -0700 Message-Id: <20190424140643.62457-3-liq3ea@163.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190424140643.62457-1-liq3ea@163.com> References: <20190424140643.62457-1-liq3ea@163.com> X-CM-TRANSID: DsCowAC3Ayl0bcBcrks9CA--.5531S4 X-Coremail-Antispam: 1Uf129KBjvJXoWxWr4DAr4rtrW8Jw18Ar1xAFb_yoW5AFW3pF ZxCF13trZ3G3WfKrnxJw17JF1a9rykXr1UW3y3uFWFyw17Arn8tF42k34Y9ryUXrW8ZF45 A3yq9Fyak3Z7XFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j8TmhUUUUU= X-Originating-IP: [115.200.201.0] X-CM-SenderInfo: 5oltjvrd6rljoofrz/xtbBZhmgbVaD1JFpjQAAsG X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 220.181.12.14 Subject: [Qemu-devel] [PATCH v2 2/5] 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 Acked-by: Thomas Huth --- 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 c6839c53c8..1f46258f96 100644 --- a/tests/libqos/fw_cfg.c +++ b/tests/libqos/fw_cfg.c @@ -16,6 +16,7 @@ #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) { @@ -59,6 +60,50 @@ static void mm_fw_cfg_select(QFWCFG *fw_cfg, uint16_t key) qtest_writew(fw_cfg->qts, fw_cfg->base, 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_malloc(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; +} + static void mm_fw_cfg_read(QFWCFG *fw_cfg, void *data, size_t len) { uint8_t *ptr = data; diff --git a/tests/libqos/fw_cfg.h b/tests/libqos/fw_cfg.h index 60de81e863..13325cc4ff 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); void mm_fw_cfg_uninit(QFWCFG *fw_cfg); From patchwork Wed Apr 24 14:06:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 10914901 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 7342D1515 for ; Wed, 24 Apr 2019 14:23:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 62D6D289D8 for ; Wed, 24 Apr 2019 14:23:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5713928A6D; Wed, 24 Apr 2019 14:23: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=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 E3FBF289D8 for ; Wed, 24 Apr 2019 14:23:18 +0000 (UTC) Received: from localhost ([127.0.0.1]:42491 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hJInu-0000j4-5G for patchwork-qemu-devel@patchwork.kernel.org; Wed, 24 Apr 2019 10:23:18 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39085) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hJIfe-0002aF-9o for qemu-devel@nongnu.org; Wed, 24 Apr 2019 10:14:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hJIY2-0006hS-OE for qemu-devel@nongnu.org; Wed, 24 Apr 2019 10:06:56 -0400 Received: from m12-14.163.com ([220.181.12.14]:54537) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hJIY1-0006fH-8q for qemu-devel@nongnu.org; Wed, 24 Apr 2019 10:06:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=BBctNjDbfh7h2nNE/V nZPLT9nVBtuY81kv5/qyNenhU=; b=E9B7PVevEE46QOVsoSuKAu2BWPUWTKmFIL KCs1c+wGZyuVOcecxS8LW/UjeuUIzzreCsRxcMIpGgVTa30lPO2z/unRoMK0XEHl rDzJCFqdZcj2LqLwBOJ7hUfuDYwb/8t0xPeb54vByUS/1rzR59DElpDGSy4ya0x+ Ioa3xRn0w= Received: from localhost.localdomain (unknown [115.200.201.0]) by smtp10 (Coremail) with SMTP id DsCowAC3Ayl0bcBcrks9CA--.5531S5; Wed, 24 Apr 2019 22:06:51 +0800 (CST) From: Li Qiang To: philmd@redhat.com, lersek@redhat.com, kraxel@redhat.com, thuth@redhat.com, lvivier@redhat.com, pbonzini@redhat.com Date: Wed, 24 Apr 2019 07:06:41 -0700 Message-Id: <20190424140643.62457-4-liq3ea@163.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190424140643.62457-1-liq3ea@163.com> References: <20190424140643.62457-1-liq3ea@163.com> X-CM-TRANSID: DsCowAC3Ayl0bcBcrks9CA--.5531S5 X-Coremail-Antispam: 1Uf129KBjvdXoWrKr45Wr1DZF17CFyxJr45Awb_yoWfCFc_uF W3Aw1rW3y7AwnFkF9YyF15Aw15Ka4UXF9Ikrn7KFyqy34UX39Fkw4Iqa9F9w1rWFWUCr9x Ca95Xr1DCa1v9jkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IU8IzuJUUUUU== X-Originating-IP: [115.200.201.0] X-CM-SenderInfo: 5oltjvrd6rljoofrz/xtbBLxWgbVUMI+dgjQAAsH X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 220.181.12.14 Subject: [Qemu-devel] [PATCH v2 3/5] fw_cfg: reboot: store reboot-timeout as little endian 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 So that if the guest and host endianess does not match it can still work as expection. Signed-off-by: Li Qiang --- hw/nvram/fw_cfg.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c index 5c3a46ce6f..df4242fc9c 100644 --- a/hw/nvram/fw_cfg.c +++ b/hw/nvram/fw_cfg.c @@ -178,6 +178,7 @@ static void fw_cfg_reboot(FWCfgState *s) { const char *reboot_timeout = NULL; int64_t rt_val = -1; + uint32_t rt_le32; /* get user configuration */ QemuOptsList *plist = qemu_find_opts("boot-opts"); @@ -194,7 +195,8 @@ static void fw_cfg_reboot(FWCfgState *s) } } - fw_cfg_add_file(s, "etc/boot-fail-wait", g_memdup(&rt_val, 4), 4); + rt_le32 = cpu_to_le32(rt_val); + fw_cfg_add_file(s, "etc/boot-fail-wait", g_memdup(&rt_le32, 4), 4); } static void fw_cfg_write(FWCfgState *s, uint8_t value) From patchwork Wed Apr 24 14:06:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 10914889 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 E183D1515 for ; Wed, 24 Apr 2019 14:16:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D16F4289C7 for ; Wed, 24 Apr 2019 14:16:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C4A7D289E0; Wed, 24 Apr 2019 14:16:42 +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=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 29B67289C7 for ; Wed, 24 Apr 2019 14:16:42 +0000 (UTC) Received: from localhost ([127.0.0.1]:42371 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hJIhV-0004AA-9H for patchwork-qemu-devel@patchwork.kernel.org; Wed, 24 Apr 2019 10:16:41 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39025) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hJIfe-0002XO-9D for qemu-devel@nongnu.org; Wed, 24 Apr 2019 10:14:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hJIY4-0006iH-5O for qemu-devel@nongnu.org; Wed, 24 Apr 2019 10:06:57 -0400 Received: from m12-14.163.com ([220.181.12.14]:54701) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hJIY2-0006gJ-HF for qemu-devel@nongnu.org; Wed, 24 Apr 2019 10:06:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=vgOeaRvpko5K839zOg 5xl9f11bNiWV/S9xLagM3xojs=; b=Iky/ArWzE7zTNSsAoAPwbDm222RehfXnnB qyxdaVjMRiWZtcydpJ2hOQDLdnD13AHU3VxZTW3Cqryv4AFDHPkxncy/FjPF4HfW tDGYUxQAP/zNZrWG7e/diM5+bDLnqyBgcjrNfTUKqmAFgsAw1pKtxvrSePPUwglm PEWhpoz4I= Received: from localhost.localdomain (unknown [115.200.201.0]) by smtp10 (Coremail) with SMTP id DsCowAC3Ayl0bcBcrks9CA--.5531S6; Wed, 24 Apr 2019 22:06:52 +0800 (CST) From: Li Qiang To: philmd@redhat.com, lersek@redhat.com, kraxel@redhat.com, thuth@redhat.com, lvivier@redhat.com, pbonzini@redhat.com Date: Wed, 24 Apr 2019 07:06:42 -0700 Message-Id: <20190424140643.62457-5-liq3ea@163.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190424140643.62457-1-liq3ea@163.com> References: <20190424140643.62457-1-liq3ea@163.com> X-CM-TRANSID: DsCowAC3Ayl0bcBcrks9CA--.5531S6 X-Coremail-Antispam: 1Uf129KBjvJXoW7CFyrWw48tw45CrWDAw1rXrb_yoW8WF13pF 1jk3ZFkrZ5JFW2qr13KrnFqr1aq3s7Jr4UArZrXFW0yw18Wr1qqa18Ca4Fg3WDWFZ2vFs8 ZF4vqF13KF1DWaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07U2_M-UUUUU= X-Originating-IP: [115.200.201.0] X-CM-SenderInfo: 5oltjvrd6rljoofrz/1tbitBygbVSIbtkMzQAAsP X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 220.181.12.14 Subject: [Qemu-devel] [PATCH v2 4/5] 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 --- Change since v1: Converting little endian reboot_timeout to cpu endian tests/fw_cfg-test.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/fw_cfg-test.c b/tests/fw_cfg-test.c index c22503619f..6c6add54db 100644 --- a/tests/fw_cfg-test.c +++ b/tests/fw_cfg-test.c @@ -15,6 +15,7 @@ #include "libqtest.h" #include "standard-headers/linux/qemu_fw_cfg.h" #include "libqos/fw_cfg.h" +#include "qemu/bswap.h" static uint64_t ram_size = 128 << 20; static uint16_t nb_cpus = 1; @@ -174,6 +175,25 @@ static void test_fw_cfg_boot_menu(void) qtest_quit(s); } +static void test_fw_cfg_reboot_timeout(void) +{ + QFWCFG *fw_cfg; + QTestState *s; + uint32_t reboot_timeout = 0; + size_t filesize; + + s = qtest_init("-boot reboot-timeout=15"); + fw_cfg = pc_fw_cfg_init(s); + + filesize = qfw_cfg_get_file(fw_cfg, "etc/boot-fail-wait", + &reboot_timeout, sizeof(reboot_timeout)); + g_assert_cmpint(filesize, ==, sizeof(reboot_timeout)); + reboot_timeout = le32_to_cpu(reboot_timeout); + g_assert_cmpint(reboot_timeout, ==, 15); + pc_fw_cfg_uninit(fw_cfg); + qtest_quit(s); +} + int main(int argc, char **argv) { int ret; @@ -195,6 +215,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(); From patchwork Wed Apr 24 14:06:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 10914891 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 40F591515 for ; Wed, 24 Apr 2019 14:16:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 318D2289E0 for ; Wed, 24 Apr 2019 14:16:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 252E3289EF; Wed, 24 Apr 2019 14:16:44 +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=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 C1DB4289E0 for ; Wed, 24 Apr 2019 14:16:43 +0000 (UTC) Received: from localhost ([127.0.0.1]:42373 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hJIhX-0004Bg-10 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 24 Apr 2019 10:16:43 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39161) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hJIfe-0002cB-5w for qemu-devel@nongnu.org; Wed, 24 Apr 2019 10:14:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hJIYT-0006wA-2k for qemu-devel@nongnu.org; Wed, 24 Apr 2019 10:07:21 -0400 Received: from m12-14.163.com ([220.181.12.14]:54855) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hJIY5-0006i8-Kb for qemu-devel@nongnu.org; Wed, 24 Apr 2019 10:07:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=yPoN3JtMf8K84xexdR k3En+SE9Vh0h9Hg/YpOfcyn0s=; b=HgOp5AyRS31HS5TSSJZBzqnUpuvg2bxYlq FGb4XsyMgRnTTbFQPmJhWcVrIRSMTjCmmJxbnY958FWg/oGzUh5ld98EfhhzrLU+ pVO7r2C3SW3FCxaW5LZqah9npzRtQqiV5UNr9vkYd4S2yXNYCJqtA3Pkcpd1S/oL 9Q2IHvvL8= Received: from localhost.localdomain (unknown [115.200.201.0]) by smtp10 (Coremail) with SMTP id DsCowAC3Ayl0bcBcrks9CA--.5531S7; Wed, 24 Apr 2019 22:06:54 +0800 (CST) From: Li Qiang To: philmd@redhat.com, lersek@redhat.com, kraxel@redhat.com, thuth@redhat.com, lvivier@redhat.com, pbonzini@redhat.com Date: Wed, 24 Apr 2019 07:06:43 -0700 Message-Id: <20190424140643.62457-6-liq3ea@163.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190424140643.62457-1-liq3ea@163.com> References: <20190424140643.62457-1-liq3ea@163.com> X-CM-TRANSID: DsCowAC3Ayl0bcBcrks9CA--.5531S7 X-Coremail-Antispam: 1Uf129KBjvJXoW7CFy7trW7Gr43KF4fXr17Awb_yoW8GF15pF WUu3WakrZ5JFZFqrnxGr1DWF1ftr97Jr4UJrZ0qrWjyw48Xr1DKa1Ika4Fgws8JFWkXa13 Z3ZYqF43KF1DXaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UCiihUUUUU= X-Originating-IP: [115.200.201.0] X-CM-SenderInfo: 5oltjvrd6rljoofrz/1tbiTxKgbVsGO+h6qAAAsM X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 220.181.12.14 Subject: [Qemu-devel] [PATCH v2 5/5] tests: fw_cfg: add splash time 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 --- Change since v1: Converting little endian splash time to cpu endian tests/fw_cfg-test.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/fw_cfg-test.c b/tests/fw_cfg-test.c index 6c6add54db..c6a3d6bb23 100644 --- a/tests/fw_cfg-test.c +++ b/tests/fw_cfg-test.c @@ -194,6 +194,25 @@ static void test_fw_cfg_reboot_timeout(void) qtest_quit(s); } +static void test_fw_cfg_splash_time(void) +{ + QFWCFG *fw_cfg; + QTestState *s; + uint16_t splash_time = 0; + size_t filesize; + + s = qtest_init("-boot splash-time=12"); + fw_cfg = pc_fw_cfg_init(s); + + filesize = qfw_cfg_get_file(fw_cfg, "etc/boot-menu-wait", + &splash_time, sizeof(splash_time)); + g_assert_cmpint(filesize, ==, sizeof(splash_time)); + splash_time = le16_to_cpu(splash_time); + g_assert_cmpint(splash_time, ==, 12); + pc_fw_cfg_uninit(fw_cfg); + qtest_quit(s); +} + int main(int argc, char **argv) { int ret; @@ -216,6 +235,7 @@ int main(int argc, char **argv) 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); + qtest_add_func("fw_cfg/splash_time", test_fw_cfg_splash_time); ret = g_test_run();