aboutsummaryrefslogtreecommitdiff
path: root/tests/fw_cfg-test.c
diff options
context:
space:
mode:
authorLi Qiang <liq3ea@163.com>2019-05-18 21:35:10 +0200
committerPhilippe Mathieu-Daudé <philmd@redhat.com>2019-05-23 14:10:31 +0200
commit7a44091d48c1054a859f44a70ef280c7cef4698f (patch)
tree3dab78f42b056b7cc65ec6185fa2935a43df8f12 /tests/fw_cfg-test.c
parent10b789b70cb78e7215f4efd2c568bec7b0b826a0 (diff)
downloadqemu-7a44091d48c1054a859f44a70ef280c7cef4698f.zip
qemu-7a44091d48c1054a859f44a70ef280c7cef4698f.tar.gz
qemu-7a44091d48c1054a859f44a70ef280c7cef4698f.tar.bz2
tests: refactor fw_cfg_test
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 <liq3ea@163.com> Acked-by: Thomas Huth <thuth@redhat.com> Tested-by: Thomas Huth <thuth@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com> Message-Id: <20190424140643.62457-2-liq3ea@163.com> [PMD: Removed 'ret' local variable in main()] Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Diffstat (limited to 'tests/fw_cfg-test.c')
-rw-r--r--tests/fw_cfg-test.c93
1 files changed, 78 insertions, 15 deletions
diff --git a/tests/fw_cfg-test.c b/tests/fw_cfg-test.c
index a370ad5..4597626 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,27 @@ 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);
@@ -126,10 +194,5 @@ 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);
- ret = g_test_run();
-
- pc_fw_cfg_uninit(fw_cfg);
- qtest_quit(s);
-
- return ret;
+ return g_test_run();
}