Skip to contentSkip to conversation

Boot order tests

PATCH Applied Markus Armbruster 2 participants 15 messages Jun 26, 2013 – Jul 23, 2013

lore
Share & tools
lore
#3 lore raw

PATCH v4 3/12 libqos: include dependencies

In reply to Markus Armbruster

From: Anthony Liguori <[email protected]>

Otherwise rebuilds can fail when libqos is modified.

---
 tests/Makefile | 1 +
 1 file changed, 1 insertion(+)
tests/Makefile +1 -0
index 394e029..34a2325 100644
@@ -224,3 +224,4 @@ check-block: $(patsubst %,check-%, $(check-block-y))
 check: check-unit check-qtest
 
 -include $(wildcard tests/*.d)
+-include $(wildcard tests/libqos/*.d)
Signature · 1 line
1.7.11.7
#9 lore raw

PATCH v4 9/12 boot-order-test: Add tests for PowerPC PREP

In reply to Markus Armbruster
---
 tests/boot-order-test.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
tests/boot-order-test.c +25 -0
index c711c71..75b1642 100644
@@ -112,6 +112,30 @@ static void test_pc_boot_order(void)
     test_boot_orders(NULL, read_boot_order_pc, test_cases_pc);
 }
 
+static uint8_t read_m48t59(uint64_t addr, uint16_t reg)
+{
+    writeb(addr, reg & 0xff);
+    writeb(addr + 1, reg >> 8);
+    return readb(addr + 3);
+}
+
+static uint64_t read_boot_order_prep(void)
+{
+    return read_m48t59(0x80000000 + 0x74, 0x34);
+}
+
+static const boot_order_test test_cases_prep[] = {
+    { "", 'c', 'c' },
+    { "-boot c", 'c', 'c' },
+    { "-boot d", 'd', 'd' },
+    {}
+};
+
+static void test_prep_boot_order(void)
+{
+    test_boot_orders("prep", read_boot_order_prep, test_cases_prep);
+}
+
 static uint64_t read_boot_order_pmac(void)
 {
     QFWCFG *fw_cfg = mm_fw_cfg_init(0xf0000510);
@@ -146,6 +170,7 @@ int main(int argc, char *argv[])
     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
         qtest_add_func("boot-order/pc", test_pc_boot_order);
     } else if (strcmp(arch, "ppc") == 0 || strcmp(arch, "ppc64") == 0) {
+        qtest_add_func("boot-order/prep", test_prep_boot_order);
         qtest_add_func("boot-order/pmac_oldworld",
                        test_pmac_oldworld_boot_order);
         qtest_add_func("boot-order/pmac_newworld",
Signature · 1 line
1.7.11.7
#0 lore raw

v4 cover Boot order tests

v4:
* Old PATCH 1-6 got merged, only tests left; cover letter changed accordingly
* PATCH 1,6 unchanged
* PATCH 2 fix system-reset race (Anthony)
* New PATCH 4,11 to make libqos/fw_cfg usable for the ppc, Sun4 tests
* New PATCH 3 shanghaied from Anthony, to make PATCH 4 compile without make clean.
* PATCH 5,10,12 use libqos/fw_cfg (Anthony)
* PATCH 7-9 rebased, minor tweaks
v3:
* Rebased, with only trivial conflicts
* PATCH 08 cosmetic improvements
* More test cases: new PATCH 09-16
v2:
* New PATCH 7 to make testing -boot once possible
* Old PATCH 5 reworked and extended became PATCH 8
* Writing more tests uncovered -no-fd-bootchk weirdness, cleaned up in new PATCH 5+6

Andreas Färber (1):
boot-order-test: Add tests for PowerMacs

Anthony Liguori (1):
libqos: include dependencies

Markus Armbruster (10):
qtest: Don't reset on qtest chardev connect
boot-order-test: New; covering just PC for now
libqos: Add support for memory-mapped fw_cfg
boot-order-test: Cover -boot once in ppc tests
boot-order-test: Better separate target-specific and generic parts
boot-order-test: Code motion for better readability
boot-order-test: Add tests for PowerPC PREP
boot-order-test: Add tests for Sun4m
libqos: Generalize I/O-mapped fw_cfg
boot-order-test: Add tests for Sun4u

 qtest.c                  |   7 +-
 tests/Makefile           |   7 +-
 tests/boot-order-test.c  | 209 +++++++++++++++++++++++++++++++++++++++++++++++
 tests/fw_cfg-test.c      |   2 +-
 tests/libqos/fw_cfg-pc.c |  40 ---------
 tests/libqos/fw_cfg-pc.h |  20 -----
 tests/libqos/fw_cfg.c    |  55 +++++++++++++
 tests/libqos/fw_cfg.h    |   9 ++
 tests/libqos/malloc-pc.c |   2 +-
 9 files changed, 287 insertions(+), 64 deletions(-)
 create mode 100644 tests/boot-order-test.c
 delete mode 100644 tests/libqos/fw_cfg-pc.c
 delete mode 100644 tests/libqos/fw_cfg-pc.h
Signature · 1 line
1.7.11.7
#2 lore raw

PATCH v4 2/12 boot-order-test: New; covering just PC for now

---
 tests/Makefile          |  2 ++
 tests/boot-order-test.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 75 insertions(+)
 create mode 100644 tests/boot-order-test.c
tests/Makefile +2 -0
index c107489..394e029 100644
@@ -54,6 +54,7 @@ gcov-files-i386-y = hw/fdc.c
 check-qtest-i386-y += tests/ide-test$(EXESUF)
 check-qtest-i386-y += tests/hd-geo-test$(EXESUF)
 gcov-files-i386-y += hw/hd-geometry.c
+check-qtest-i386-y += tests/boot-order-test$(EXESUF)
 check-qtest-i386-y += tests/rtc-test$(EXESUF)
 check-qtest-i386-y += tests/i440fx-test$(EXESUF)
 check-qtest-i386-y += tests/fw_cfg-test$(EXESUF)
@@ -130,6 +131,7 @@ tests/m48t59-test$(EXESUF): tests/m48t59-test.o
 tests/fdc-test$(EXESUF): tests/fdc-test.o
 tests/ide-test$(EXESUF): tests/ide-test.o $(libqos-pc-obj-y)
 tests/hd-geo-test$(EXESUF): tests/hd-geo-test.o
+tests/boot-order-test$(EXESUF): tests/boot-order-test.o
 tests/tmp105-test$(EXESUF): tests/tmp105-test.o $(libqos-omap-obj-y)
 tests/i440fx-test$(EXESUF): tests/i440fx-test.o $(libqos-pc-obj-y)
 tests/fw_cfg-test$(EXESUF): tests/fw_cfg-test.o $(libqos-pc-obj-y)
tests/boot-order-test.c new file +73 -0

73 lines not on this page · raw message

Signature · 1 line
1.7.11.7
#5 lore raw

PATCH v4 5/12 boot-order-test: Add tests for PowerMacs

In reply to Markus Armbruster

From: Andreas Färber <[email protected]>

They set the boot device via fw_cfg, which is then translated to a boot path of "hd" or "cd" in OpenBIOS.

Converted to libqos/fw_cfg on Anthony's request.

---
 tests/Makefile          |  4 +++-
 tests/boot-order-test.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 52 insertions(+), 2 deletions(-)
tests/Makefile +3 -1
index 34a2325..8c7352d 100644
@@ -67,6 +67,8 @@ gcov-files-sparc-y += hw/m48t59.c
 gcov-files-sparc64-y += hw/m48t59.c
 check-qtest-arm-y = tests/tmp105-test$(EXESUF)
 gcov-files-arm-y += hw/tmp105.c
+check-qtest-ppc-y += tests/boot-order-test$(EXESUF)
+check-qtest-ppc64-y += tests/boot-order-test$(EXESUF)
 
 GENERATED_HEADERS += tests/test-qapi-types.h tests/test-qapi-visit.h tests/test-qmp-commands.h
 
@@ -131,7 +133,7 @@ tests/m48t59-test$(EXESUF): tests/m48t59-test.o
 tests/fdc-test$(EXESUF): tests/fdc-test.o
 tests/ide-test$(EXESUF): tests/ide-test.o $(libqos-pc-obj-y)
 tests/hd-geo-test$(EXESUF): tests/hd-geo-test.o
-tests/boot-order-test$(EXESUF): tests/boot-order-test.o
+tests/boot-order-test$(EXESUF): tests/boot-order-test.o $(libqos-obj-y)
 tests/tmp105-test$(EXESUF): tests/tmp105-test.o $(libqos-omap-obj-y)
 tests/i440fx-test$(EXESUF): tests/i440fx-test.o $(libqos-pc-obj-y)
 tests/fw_cfg-test$(EXESUF): tests/fw_cfg-test.o $(libqos-pc-obj-y)
tests/boot-order-test.c +49 -1

67 lines not on this page · raw message

Signature · 1 line
1.7.11.7
#10 lore raw

PATCH v4 10/12 boot-order-test: Add tests for Sun4m

In reply to Markus Armbruster
---
 tests/boot-order-test.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
tests/boot-order-test.c +14 -0
index 75b1642..a3928ed 100644
@@ -161,6 +161,18 @@ static void test_pmac_newworld_boot_order(void)
     test_boot_orders("mac99", read_boot_order_pmac, test_cases_fw_cfg);
 }
 
+static uint64_t read_boot_order_sun4m(void)
+{
+    QFWCFG *fw_cfg = mm_fw_cfg_init(0xd00000510ULL);
+
+    return qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_DEVICE);
+}
+
+static void test_sun4m_boot_order(void)
+{
+    test_boot_orders("SS-5", read_boot_order_sun4m, test_cases_fw_cfg);
+}
+
 int main(int argc, char *argv[])
 {
     const char *arch = qtest_get_arch();
@@ -175,6 +187,8 @@ int main(int argc, char *argv[])
                        test_pmac_oldworld_boot_order);
         qtest_add_func("boot-order/pmac_newworld",
                        test_pmac_newworld_boot_order);
+    } else if (strcmp(arch, "sparc") == 0) {
+        qtest_add_func("boot-order/sun4m", test_sun4m_boot_order);
     }
 
     return g_test_run();
Signature · 1 line
1.7.11.7
#1 lore raw

PATCH v4 1/12 qtest: Don't reset on qtest chardev connect

In reply to Markus Armbruster

libqtest's qtest_init() connecting to the qtest socket triggers reset. This was coded in the hope we could use the same QEMU process for multiple tests that way. Never used. Injects an extra reset even when it's not used, and that can mess up tests such as the one of -boot once I'm about to add. Drop it.

---
 qtest.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
qtest.c +6 -1
index 07a9612..74f1842 100644
@@ -472,7 +472,12 @@ static void qtest_event(void *opaque, int event)
 
     switch (event) {
     case CHR_EVENT_OPENED:
-        qemu_system_reset(false);
+        /*
+         * We used to call qemu_system_reset() here, hoping we could
+         * use the same process for multiple tests that way.  Never
+         * used.  Injects an extra reset even when it's not used, and
+         * that can mess up tests, e.g. -boot once.
+         */
         for (i = 0; i < ARRAY_SIZE(irq_levels); i++) {
             irq_levels[i] = 0;
         }
Signature · 1 line
1.7.11.7
#4 lore raw

PATCH v4 4/12 libqos: Add support for memory-mapped fw_cfg

In reply to Markus Armbruster
---
 tests/libqos/fw_cfg.c | 29 +++++++++++++++++++++++++++++
 tests/libqos/fw_cfg.h |  3 +++
 2 files changed, 32 insertions(+)
tests/libqos/fw_cfg.c +29 -0
index e386ff7..49d1683 100644
@@ -2,15 +2,19 @@
  * libqos fw_cfg support
  *
  * Copyright IBM, Corp. 2012-2013
+ * Copyright (C) 2013 Red Hat Inc.
  *
  * Authors:
  *  Anthony Liguori   <[email protected]>
+ *  Markus Armbruster <[email protected]>
  *
  * This work is licensed under the terms of the GNU GPL, version 2 or later.
  * See the COPYING file in the top-level directory.
  */
 
+#include <glib.h>
 #include "libqos/fw_cfg.h"
+#include "libqtest.h"
 #include "qemu/bswap.h"
 
 void qfw_cfg_select(QFWCFG *fw_cfg, uint16_t key)
@@ -50,3 +54,28 @@ uint64_t qfw_cfg_get_u64(QFWCFG *fw_cfg, uint16_t key)
     return le64_to_cpu(value);
 }
 
+static void mm_fw_cfg_select(QFWCFG *fw_cfg, uint16_t key)
+{
+    writew(fw_cfg->base, key);
+}
+
+static void mm_fw_cfg_read(QFWCFG *fw_cfg, void *data, size_t len)
+{
+    uint8_t *ptr = data;
+    int i;
+
+    for (i = 0; i < len; i++) {
+        ptr[i] = readb(fw_cfg->base + 2);
+    }
+}
+
+QFWCFG *mm_fw_cfg_init(uint64_t base)
+{
+    QFWCFG *fw_cfg = g_malloc0(sizeof(*fw_cfg));
+
+    fw_cfg->base = base;
+    fw_cfg->select = mm_fw_cfg_select;
+    fw_cfg->read = mm_fw_cfg_read;
+
+    return fw_cfg;
+}
tests/libqos/fw_cfg.h +3 -0
index 44fc42b..19bb053 100644
@@ -20,6 +20,7 @@ typedef struct QFWCFG QFWCFG;
 
 struct QFWCFG
 {
+    uint64_t base;
     void (*select)(QFWCFG *fw_cfg, uint16_t key);
     void (*read)(QFWCFG *fw_cfg, void *data, size_t len);
 };
@@ -31,4 +32,6 @@ 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);
 
+QFWCFG *mm_fw_cfg_init(uint64_t base);
+
 #endif
Signature · 1 line
1.7.11.7
#8 lore raw

PATCH v4 8/12 boot-order-test: Code motion for better readability

In reply to Markus Armbruster
---
 tests/boot-order-test.c | 44 ++++++++++++++++++++++----------------------
 1 file changed, 22 insertions(+), 22 deletions(-)
tests/boot-order-test.c +22 -22
index 78249fc..c711c71 100644
@@ -15,19 +15,15 @@
 #include "libqos/fw_cfg.h"
 #include "libqtest.h"
 
-static uint8_t read_mc146818(uint16_t port, uint8_t reg)
-{
-    outb(port, reg);
-    return inb(port + 1);
-}
-
-static uint64_t read_boot_order_pc(void)
-{
-    uint8_t b1 = read_mc146818(0x70, 0x38);
-    uint8_t b2 = read_mc146818(0x70, 0x3d);
+#define NO_QEMU_PROTOS
+#include "hw/nvram/fw_cfg.h"
+#undef NO_QEMU_PROTOS
 
-    return b1 | (b2 << 8);
-}
+typedef struct {
+    const char *args;
+    uint64_t expected_boot;
+    uint64_t expected_reboot;
+} boot_order_test;
 
 static void test_a_boot_order(const char *machine,
                               const char *test_args,
@@ -57,12 +53,6 @@ static void test_a_boot_order(const char *machine,
     g_free(args);
 }
 
-typedef struct {
-    const char *args;
-    uint64_t expected_boot;
-    uint64_t expected_reboot;
-} boot_order_test;
-
 static void test_boot_orders(const char *machine,
                              uint64_t (*read_boot_order)(void),
                              const boot_order_test *tests)
@@ -77,6 +67,20 @@ static void test_boot_orders(const char *machine,
     }
 }
 
+static uint8_t read_mc146818(uint16_t port, uint8_t reg)
+{
+    outb(port, reg);
+    return inb(port + 1);
+}
+
+static uint64_t read_boot_order_pc(void)
+{
+    uint8_t b1 = read_mc146818(0x70, 0x38);
+    uint8_t b2 = read_mc146818(0x70, 0x3d);
+
+    return b1 | (b2 << 8);
+}
+
 static const boot_order_test test_cases_pc[] = {
     { "",
       0x1230, 0x1230 },
@@ -108,10 +112,6 @@ static void test_pc_boot_order(void)
     test_boot_orders(NULL, read_boot_order_pc, test_cases_pc);
 }
 
-#define NO_QEMU_PROTOS
-#include "hw/nvram/fw_cfg.h"
-#undef NO_QEMU_PROTOS
-
 static uint64_t read_boot_order_pmac(void)
 {
     QFWCFG *fw_cfg = mm_fw_cfg_init(0xf0000510);
Signature · 1 line
1.7.11.7
#11 lore raw

PATCH v4 11/12 libqos: Generalize I/O-mapped fw_cfg

In reply to Markus Armbruster

Provide a constructor that takes the base address in addition to the PC-specific one.

---
 tests/Makefile           |  2 +-
 tests/fw_cfg-test.c      |  2 +-
 tests/libqos/fw_cfg-pc.c | 40 ----------------------------------------
 tests/libqos/fw_cfg-pc.h | 20 --------------------
 tests/libqos/fw_cfg.c    | 26 ++++++++++++++++++++++++++
 tests/libqos/fw_cfg.h    |  6 ++++++
 tests/libqos/malloc-pc.c |  2 +-
 7 files changed, 35 insertions(+), 63 deletions(-)
 delete mode 100644 tests/libqos/fw_cfg-pc.c
 delete mode 100644 tests/libqos/fw_cfg-pc.h
tests/Makefile +1 -1
index 8c7352d..708eb79 100644
@@ -124,7 +124,7 @@ tests/test-mul64$(EXESUF): tests/test-mul64.o libqemuutil.a
 
 libqos-obj-y = tests/libqos/pci.o tests/libqos/fw_cfg.o
 libqos-obj-y += tests/libqos/i2c.o
-libqos-pc-obj-y = $(libqos-obj-y) tests/libqos/pci-pc.o tests/libqos/fw_cfg-pc.o
+libqos-pc-obj-y = $(libqos-obj-y) tests/libqos/pci-pc.o
 libqos-pc-obj-y += tests/libqos/malloc-pc.o
 libqos-omap-obj-y = $(libqos-obj-y) tests/libqos/i2c-omap.o
 
tests/fw_cfg-test.c +1 -1
index c284c4d..b86e49a 100644
@@ -14,7 +14,7 @@
 
 #include "libqtest.h"
 #include "hw/nvram/fw_cfg.h"
-#include "libqos/fw_cfg-pc.h"
+#include "libqos/fw_cfg.h"
 
 #include <string.h>
 #include <glib.h>
tests/libqos/fw_cfg-pc.c deleted +0 -40
deleted file mode 100644
index 613604d..0000000
@@ -1,40 +0,0 @@
-/*
- * libqos fw_cfg support for PC
- *
- * Copyright IBM, Corp. 2012-2013
- *
- * Authors:
- *  Anthony Liguori   <[email protected]>
- *
- * This work is licensed under the terms of the GNU GPL, version 2 or later.
- * See the COPYING file in the top-level directory.
- */
-
-#include "libqos/fw_cfg-pc.h"
-#include "libqtest.h"
-#include <glib.h>
-
-static void pc_fw_cfg_select(QFWCFG *fw_cfg, uint16_t key)
-{
-    outw(0x510, key);
-}
-
-static void pc_fw_cfg_read(QFWCFG *fw_cfg, void *data, size_t len)
-{
-    uint8_t *ptr = data;
-    int i;
-
-    for (i = 0; i < len; i++) {
-        ptr[i] = inb(0x511);
-    }
-}
-
-QFWCFG *pc_fw_cfg_init(void)
-{
-    QFWCFG *fw_cfg = g_malloc0(sizeof(*fw_cfg));
-
-    fw_cfg->select = pc_fw_cfg_select;
-    fw_cfg->read = pc_fw_cfg_read;
-
-    return fw_cfg;
-}
tests/libqos/fw_cfg-pc.h deleted +0 -20
deleted file mode 100644
index 444bd79..0000000
@@ -1,20 +0,0 @@
-/*
- * libqos fw_cfg support for PC
- *
- * Copyright IBM, Corp. 2012-2013
- *
- * Authors:
- *  Anthony Liguori   <[email protected]>
- *
- * This work is licensed under the terms of the GNU GPL, version 2 or later.
- * See the COPYING file in the top-level directory.
- */
-
-#ifndef LIBQOS_FW_CFG_PC_H
-#define LIBQOS_FW_CFG_PC_H
-
-#include "libqos/fw_cfg.h"
-
-QFWCFG *pc_fw_cfg_init(void);
-
-#endif
tests/libqos/fw_cfg.c +26 -0
index 49d1683..ef00fed 100644
@@ -79,3 +79,29 @@ QFWCFG *mm_fw_cfg_init(uint64_t base)
 
     return fw_cfg;
 }
+
+static void io_fw_cfg_select(QFWCFG *fw_cfg, uint16_t key)
+{
+    outw(fw_cfg->base, key);
+}
+
+static void io_fw_cfg_read(QFWCFG *fw_cfg, void *data, size_t len)
+{
+    uint8_t *ptr = data;
+    int i;
+
+    for (i = 0; i < len; i++) {
+        ptr[i] = inb(fw_cfg->base + 1);
+    }
+}
+
+QFWCFG *io_fw_cfg_init(uint16_t base)
+{
+    QFWCFG *fw_cfg = g_malloc0(sizeof(*fw_cfg));
+
+    fw_cfg->base = base;
+    fw_cfg->select = io_fw_cfg_select;
+    fw_cfg->read = io_fw_cfg_read;
+
+    return fw_cfg;
+}
tests/libqos/fw_cfg.h +6 -0
index 19bb053..61b1548 100644
@@ -33,5 +33,11 @@ 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(uint64_t base);
+QFWCFG *io_fw_cfg_init(uint16_t base);
+
+static inline QFWCFG *pc_fw_cfg_init(void)
+{
+    return io_fw_cfg_init(0x510);
+}
 
 #endif
tests/libqos/malloc-pc.c +1 -1
index adc36c4..db1496c 100644
@@ -11,7 +11,7 @@
  */
 
 #include "libqos/malloc-pc.h"
-#include "libqos/fw_cfg-pc.h"
+#include "libqos/fw_cfg.h"
 
 #define NO_QEMU_PROTOS
 #include "hw/nvram/fw_cfg.h"
Signature · 1 line
1.7.11.7
#6 lore raw

PATCH v4 6/12 boot-order-test: Cover -boot once in ppc tests

In reply to Markus Armbruster
---
 tests/boot-order-test.c | 1 +
 1 file changed, 1 insertion(+)
tests/boot-order-test.c +1 -0
index 766981d..1a8e22a 100644
@@ -102,6 +102,7 @@ static void test_powermac_boot_order(void)
         test_powermac_with_args(newworld, "", 'c', 'c');
         test_powermac_with_args(newworld, "-boot c", 'c', 'c');
         test_powermac_with_args(newworld, "-boot d", 'd', 'd');
+        test_powermac_with_args(newworld, "-boot once=d,order=c", 'd', 'c');
     }
 }
 
Signature · 1 line
1.7.11.7
#12 lore raw

PATCH v4 12/12 boot-order-test: Add tests for Sun4u

In reply to Markus Armbruster
---
 tests/boot-order-test.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
tests/boot-order-test.c +14 -0
index a3928ed..4b233d0 100644
@@ -173,6 +173,18 @@ static void test_sun4m_boot_order(void)
     test_boot_orders("SS-5", read_boot_order_sun4m, test_cases_fw_cfg);
 }
 
+static uint64_t read_boot_order_sun4u(void)
+{
+    QFWCFG *fw_cfg = io_fw_cfg_init(0x510);
+
+    return qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_DEVICE);
+}
+
+static void test_sun4u_boot_order(void)
+{
+    test_boot_orders("sun4u", read_boot_order_sun4u, test_cases_fw_cfg);
+}
+
 int main(int argc, char *argv[])
 {
     const char *arch = qtest_get_arch();
@@ -189,6 +201,8 @@ int main(int argc, char *argv[])
                        test_pmac_newworld_boot_order);
     } else if (strcmp(arch, "sparc") == 0) {
         qtest_add_func("boot-order/sun4m", test_sun4m_boot_order);
+    } else if (strcmp(arch, "sparc64") == 0) {
+        qtest_add_func("boot-order/sun4u", test_sun4u_boot_order);
     }
 
     return g_test_run();
Signature · 1 line
1.7.11.7
#7 lore raw

PATCH v4 7/12 boot-order-test: Better separate target-specific and generic parts

In reply to Markus Armbruster

The initial version did just PC. I didn't bother to separate out generic parts, because I don't like to abstract from a single case.

Now we have two cases, PC and PowerMac, and I'm about to add more. Time to do it right.

To ease review, this commit changes the code in-place, and the next commit reorders it for better readability.

---
 tests/boot-order-test.c | 148 +++++++++++++++++++++++++++++-------------------
 1 file changed, 91 insertions(+), 57 deletions(-)
tests/boot-order-test.c +91 -57
index 1a8e22a..78249fc 100644
@@ -15,95 +15,126 @@
 #include "libqos/fw_cfg.h"
 #include "libqtest.h"
 
-static void test_pc_cmos_byte(int reg, int expected)
+static uint8_t read_mc146818(uint16_t port, uint8_t reg)
 {
-    int actual;
-
-    outb(0x70, reg);
-    actual = inb(0x71);
-    g_assert_cmphex(actual, ==, expected);
+    outb(port, reg);
+    return inb(port + 1);
 }
 
-static void test_pc_cmos(uint8_t boot1, uint8_t boot2)
+static uint64_t read_boot_order_pc(void)
 {
-    test_pc_cmos_byte(0x38, boot1);
-    test_pc_cmos_byte(0x3d, boot2);
+    uint8_t b1 = read_mc146818(0x70, 0x38);
+    uint8_t b2 = read_mc146818(0x70, 0x3d);
+
+    return b1 | (b2 << 8);
 }
 
-static void test_pc_with_args(const char *test_args,
-                              uint8_t boot1, uint8_t boot2,
-                              uint8_t reboot1, uint8_t reboot2)
+static void test_a_boot_order(const char *machine,
+                              const char *test_args,
+                              uint64_t (*read_boot_order)(void),
+                              uint64_t expected_boot,
+                              uint64_t expected_reboot)
 {
-    char *args = g_strdup_printf("-nodefaults -display none %s", test_args);
+    char *args;
+    uint64_t actual;
 
+    args = g_strdup_printf("-nodefaults -display none%s%s %s",
+                           machine ? " -M " : "",
+                           machine ?: "",
+                           test_args);
     qtest_start(args);
-    test_pc_cmos(boot1, boot2);
+    actual = read_boot_order();
+    g_assert_cmphex(actual, ==, expected_boot);
     qmp("{ 'execute': 'system_reset' }");
     /*
      * system_reset only requests reset.  We get a RESET event after
      * the actual reset completes.  Need to wait for that.
      */
     qmp("");                    /* HACK: wait for event */
-    test_pc_cmos(reboot1, reboot2);
+    actual = read_boot_order();
+    g_assert_cmphex(actual, ==, expected_reboot);
     qtest_quit(global_qtest);
     g_free(args);
 }
 
-static void test_pc_boot_order(void)
+typedef struct {
+    const char *args;
+    uint64_t expected_boot;
+    uint64_t expected_reboot;
+} boot_order_test;
+
+static void test_boot_orders(const char *machine,
+                             uint64_t (*read_boot_order)(void),
+                             const boot_order_test *tests)
 {
-    test_pc_with_args("", 0x30, 0x12, 0x30, 0x12);
-    test_pc_with_args("-no-fd-bootchk", 0x31, 0x12, 0x31, 0x12);
-    test_pc_with_args("-boot c", 0, 0x02, 0, 0x02);
-    test_pc_with_args("-boot nda", 0x10, 0x34, 0x10, 0x34);
-    test_pc_with_args("-boot order=", 0, 0, 0, 0);
-    test_pc_with_args("-boot order= -boot order=c", 0, 0x02, 0, 0x02);
-    test_pc_with_args("-boot once=a", 0, 0x01, 0x30, 0x12);
-    test_pc_with_args("-boot once=a -no-fd-bootchk", 0x01, 0x01, 0x31, 0x12);
-    test_pc_with_args("-boot once=a,order=c", 0, 0x01, 0, 0x02);
-    test_pc_with_args("-boot once=d -boot order=nda", 0, 0x03, 0x10, 0x34);
-    test_pc_with_args("-boot once=a -boot once=b -boot once=c",
-                      0, 0x02, 0x30, 0x12);
+    int i;
+
+    for (i = 0; tests[i].args; i++) {
+        test_a_boot_order(machine, tests[i].args,
+                          read_boot_order,
+                          tests[i].expected_boot,
+                          tests[i].expected_reboot);
+    }
 }
 
-#define G3BEIGE_CFG_ADDR 0xf0000510
-#define MAC99_CFG_ADDR   0xf0000510
+static const boot_order_test test_cases_pc[] = {
+    { "",
+      0x1230, 0x1230 },
+    { "-no-fd-bootchk",
+      0x1231, 0x1231 },
+    { "-boot c",
+      0x0200, 0x0200 },
+    { "-boot nda",
+      0x3410, 0x3410 },
+    { "-boot order=",
+      0, 0 },
+    { "-boot order= -boot order=c",
+      0x0200, 0x0200 },
+    { "-boot once=a",
+      0x0100, 0x1230 },
+    { "-boot once=a -no-fd-bootchk",
+      0x0101, 0x1231 },
+    { "-boot once=a,order=c",
+      0x0100, 0x0200 },
+    { "-boot once=d -boot order=nda",
+      0x0300, 0x3410 },
+    { "-boot once=a -boot once=b -boot once=c",
+      0x0200, 0x1230 },
+    {}
+};
+
+static void test_pc_boot_order(void)
+{
+    test_boot_orders(NULL, read_boot_order_pc, test_cases_pc);
+}
 
 #define NO_QEMU_PROTOS
 #include "hw/nvram/fw_cfg.h"
 #undef NO_QEMU_PROTOS
 
-static void test_powermac_with_args(bool newworld, const char *extra_args,
-                                    uint16_t expected_boot,
-                                    uint16_t expected_reboot)
+static uint64_t read_boot_order_pmac(void)
 {
-    char *args = g_strdup_printf("-nodefaults -display none -machine %s %s",
-                                 newworld ? "mac99" : "g3beige", extra_args);
-    QFWCFG *fw_cfg = mm_fw_cfg_init(newworld ? MAC99_CFG_ADDR
-                                    : G3BEIGE_CFG_ADDR);
-    uint16_t actual;
+    QFWCFG *fw_cfg = mm_fw_cfg_init(0xf0000510);
 
-    qtest_start(args);
-    actual = qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_DEVICE);
-    g_assert_cmphex(actual, ==, expected_boot);
-    qmp("{ 'execute': 'system_reset' }");
-    actual = qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_DEVICE);
-    g_assert_cmphex(actual, ==, expected_reboot);
-    qtest_quit(global_qtest);
-    g_free(args);
+    return qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_DEVICE);
 }
 
-static void test_powermac_boot_order(void)
-{
-    int i;
+static const boot_order_test test_cases_fw_cfg[] = {
+    { "", 'c', 'c' },
+    { "-boot c", 'c', 'c' },
+    { "-boot d", 'd', 'd' },
+    { "-boot once=d,order=c", 'd', 'c' },
+    {}
+};
 
-    for (i = 0; i < 2; i++) {
-        bool newworld = (i == 1);
+static void test_pmac_oldworld_boot_order(void)
+{
+    test_boot_orders("g3beige", read_boot_order_pmac, test_cases_fw_cfg);
+}
 
-        test_powermac_with_args(newworld, "", 'c', 'c');
-        test_powermac_with_args(newworld, "-boot c", 'c', 'c');
-        test_powermac_with_args(newworld, "-boot d", 'd', 'd');
-        test_powermac_with_args(newworld, "-boot once=d,order=c", 'd', 'c');
-    }
+static void test_pmac_newworld_boot_order(void)
+{
+    test_boot_orders("mac99", read_boot_order_pmac, test_cases_fw_cfg);
 }
 
 int main(int argc, char *argv[])
@@ -115,7 +146,10 @@ int main(int argc, char *argv[])
     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
         qtest_add_func("boot-order/pc", test_pc_boot_order);
     } else if (strcmp(arch, "ppc") == 0 || strcmp(arch, "ppc64") == 0) {
-        qtest_add_func("boot-order/powermac", test_powermac_boot_order);
+        qtest_add_func("boot-order/pmac_oldworld",
+                       test_pmac_oldworld_boot_order);
+        qtest_add_func("boot-order/pmac_newworld",
+                       test_pmac_newworld_boot_order);
     }
 
     return g_test_run();
Signature · 1 line
1.7.11.7
#13 lore raw
In reply to Markus Armbruster

Ping?

Quoted 51 lines · Markus Armbruster

v4:
* Old PATCH 1-6 got merged, only tests left; cover letter changed accordingly
* PATCH 1,6 unchanged
* PATCH 2 fix system-reset race (Anthony)
* New PATCH 4,11 to make libqos/fw_cfg usable for the ppc, Sun4 tests
* New PATCH 3 shanghaied from Anthony, to make PATCH 4 compile without make clean.
* PATCH 5,10,12 use libqos/fw_cfg (Anthony)
* PATCH 7-9 rebased, minor tweaks
v3:
* Rebased, with only trivial conflicts
* PATCH 08 cosmetic improvements
* More test cases: new PATCH 09-16
v2:
* New PATCH 7 to make testing -boot once possible
* Old PATCH 5 reworked and extended became PATCH 8
* Writing more tests uncovered -no-fd-bootchk weirdness, cleaned up in new PATCH 5+6

Andreas Färber (1):
boot-order-test: Add tests for PowerMacs

Anthony Liguori (1):
libqos: include dependencies

Markus Armbruster (10):
qtest: Don't reset on qtest chardev connect
boot-order-test: New; covering just PC for now
libqos: Add support for memory-mapped fw_cfg
boot-order-test: Cover -boot once in ppc tests
boot-order-test: Better separate target-specific and generic parts
boot-order-test: Code motion for better readability
boot-order-test: Add tests for PowerPC PREP
boot-order-test: Add tests for Sun4m
libqos: Generalize I/O-mapped fw_cfg
boot-order-test: Add tests for Sun4u

 qtest.c                  |   7 +-
 tests/Makefile           |   7 +-
 tests/boot-order-test.c  | 209 +++++++++++++++++++++++++++++++++++++++++++++++
 tests/fw_cfg-test.c      |   2 +-
 tests/libqos/fw_cfg-pc.c |  40 ---------
 tests/libqos/fw_cfg-pc.h |  20 -----
 tests/libqos/fw_cfg.c    |  55 +++++++++++++
 tests/libqos/fw_cfg.h    |   9 ++
 tests/libqos/malloc-pc.c |   2 +-
 9 files changed, 287 insertions(+), 64 deletions(-)
 create mode 100644 tests/boot-order-test.c
 delete mode 100644 tests/libqos/fw_cfg-pc.c
 delete mode 100644 tests/libqos/fw_cfg-pc.h