Skip to contentSkip to conversation

qtest: add libqos

PATCH Applied Anthony Liguori 3 participants 13 messages Apr 16, 2013 – Apr 28, 2013

lore
Share & tools
lore
#0 lore raw

cover qtest: add libqos

This is libqos support for qtest. A few things are omitted from the RFC review in order to help get this merged quickly. Notably, there's still no way to tear down a device (pci_iounmap is hard to implement well). I haven't attempted to refactor i2c support and I have not introduced convenience macros.

But otherwise, I think the series is now in very good shape and mergable.

#1 lore raw

PATCH 1/7 qtest: don't use system command to avoid double fork

Currently we waitpid on the child process we spawn off that does nothing more than system() another process. While this does not appear to be incorrect, it's wasteful and confusing so get rid of it.

---
 tests/libqtest.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
tests/libqtest.c +4 -7
index 389596a..884f959 100644
@@ -107,7 +107,7 @@ static pid_t qtest_qemu_pid(QTestState *s)
 QTestState *qtest_init(const char *extra_args)
 {
     QTestState *s;
-    int sock, qmpsock, ret, i;
+    int sock, qmpsock, i;
     gchar *pid_file;
     gchar *command;
     const char *qemu_binary;
@@ -136,10 +136,8 @@ QTestState *qtest_init(const char *extra_args)
                                   "%s", qemu_binary, s->socket_path,
                                   s->qmp_socket_path, pid_file,
                                   extra_args ?: "");
-
-        ret = system(command);
-        exit(ret);
-        g_free(command);
+        execlp("/bin/sh", "sh", "-c", command, NULL);
+        exit(1);
     }
 
     s->fd = socket_accept(sock);
@@ -169,9 +167,8 @@ void qtest_quit(QTestState *s)
 
     pid_t pid = qtest_qemu_pid(s);
     if (pid != -1) {
-        /* kill QEMU, but wait for the child created by us to run system() */
         kill(pid, SIGTERM);
-        waitpid(s->child_pid, &status, 0);
+        waitpid(pid, &status, 0);
     }
 
     unlink(s->pid_file);
Signature · 1 line
1.8.0
#2 lore raw

PATCH 2/7 qtest: add libqos including PCI support

In reply to Anthony Liguori

This includes basic PCI support for the PC platform. Enough abstraction should be present to support non-PC platforms too.

---
v1 -> v2
- fixup size calculation (Kevin Wolf)

---
 configure             |   2 +-
 tests/Makefile        |   5 +-
 tests/libqos/pci-pc.c | 239 ++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/libqos/pci-pc.h |  20 +++++
 tests/libqos/pci.c    | 151 +++++++++++++++++++++++++++++++
 tests/libqos/pci.h    |  80 +++++++++++++++++
 6 files changed, 495 insertions(+), 2 deletions(-)
 create mode 100644 tests/libqos/pci-pc.c
 create mode 100644 tests/libqos/pci-pc.h
 create mode 100644 tests/libqos/pci.c
 create mode 100644 tests/libqos/pci.h
configure +1 -1
index 0788e27..d7484ad 100755
@@ -4475,7 +4475,7 @@ if [ "$pixman" = "internal" ]; then
 fi
 
 # build tree in object directory in case the source is not in the current directory
-DIRS="tests tests/tcg tests/tcg/cris tests/tcg/lm32"
+DIRS="tests tests/tcg tests/tcg/cris tests/tcg/lm32 tests/libqos"
 DIRS="$DIRS pc-bios/optionrom pc-bios/spapr-rtas"
 DIRS="$DIRS roms/seabios roms/vgabios"
 DIRS="$DIRS qapi-generated"
tests/Makefile +4 -1
index 7fa15c6..5303b29 100644
@@ -77,6 +77,7 @@ test-obj-y = tests/check-qint.o tests/check-qstring.o tests/check-qdict.o \
 test-qapi-obj-y = tests/test-qapi-visit.o tests/test-qapi-types.o
 
 $(test-obj-y): QEMU_INCLUDES += -Itests
+QEMU_CFLAGS += -I$(SRC_PATH)/tests
 
 tests/test-x86-cpuid.o: QEMU_INCLUDES += -I$(SRC_PATH)/target-i386
 
@@ -105,7 +106,6 @@ tests/test-qmp-commands.h tests/test-qmp-marshal.c :\
 $(SRC_PATH)/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-commands.py
 	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py $(gen-out-type) -o tests -p "test-" < $<, "  GEN   $@")
 
-
 tests/test-string-output-visitor$(EXESUF): tests/test-string-output-visitor.o $(test-qapi-obj-y) libqemuutil.a libqemustub.a
 tests/test-string-input-visitor$(EXESUF): tests/test-string-input-visitor.o $(test-qapi-obj-y) libqemuutil.a libqemustub.a
 tests/test-qmp-output-visitor$(EXESUF): tests/test-qmp-output-visitor.o $(test-qapi-obj-y) libqemuutil.a libqemustub.a
@@ -116,6 +116,9 @@ tests/test-visitor-serialization$(EXESUF): tests/test-visitor-serialization.o $(
 
 tests/test-mul64$(EXESUF): tests/test-mul64.o libqemuutil.a
 
+libqos-obj-y = tests/libqos/pci.o
+libqos-pc-obj-y = $(libqos-obj-y) tests/libqos/pci-pc.o
+
 tests/rtc-test$(EXESUF): tests/rtc-test.o
 tests/m48t59-test$(EXESUF): tests/m48t59-test.o
 tests/fdc-test$(EXESUF): tests/fdc-test.o
tests/libqos/pci-pc.c new file +239 -0

239 lines not on this page · raw message

tests/libqos/pci-pc.h new file +20 -0
new file mode 100644
index 0000000..4f7475f
@@ -0,0 +1,20 @@
+/*
+ * libqos PCI bindings 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_PCI_PC_H
+#define LIBQOS_PCI_PC_H
+
+#include "libqos/pci.h"
+
+QPCIBus *qpci_init_pc(void);
+
+#endif
tests/libqos/pci.c new file +151 -0

151 lines not on this page · raw message

tests/libqos/pci.h new file +80 -0

80 lines not on this page · raw message

Signature · 1 line
1.8.0
#3 lore raw

PATCH 3/7 libqos: add fw_cfg support

In reply to Anthony Liguori

fw_cfg is needed to get the top of memory which is necessary for doing PCI allocation and allocating RAM for DMA.

Add a PC version of fw_cfg and enough abstraction to support other platforms.

---
 tests/Makefile           |  4 ++--
 tests/libqos/fw_cfg-pc.c | 40 +++++++++++++++++++++++++++++++++++++
 tests/libqos/fw_cfg-pc.h | 20 +++++++++++++++++++
 tests/libqos/fw_cfg.c    | 51 ++++++++++++++++++++++++++++++++++++++++++++++++
 tests/libqos/fw_cfg.h    | 34 ++++++++++++++++++++++++++++++++
 5 files changed, 147 insertions(+), 2 deletions(-)
 create mode 100644 tests/libqos/fw_cfg-pc.c
 create mode 100644 tests/libqos/fw_cfg-pc.h
 create mode 100644 tests/libqos/fw_cfg.c
 create mode 100644 tests/libqos/fw_cfg.h
tests/Makefile +2 -2
index 5303b29..ce91980 100644
@@ -116,8 +116,8 @@ tests/test-visitor-serialization$(EXESUF): tests/test-visitor-serialization.o $(
 
 tests/test-mul64$(EXESUF): tests/test-mul64.o libqemuutil.a
 
-libqos-obj-y = tests/libqos/pci.o
-libqos-pc-obj-y = $(libqos-obj-y) tests/libqos/pci-pc.o
+libqos-obj-y = tests/libqos/pci.o tests/libqos/fw_cfg.o
+libqos-pc-obj-y = $(libqos-obj-y) tests/libqos/pci-pc.o tests/libqos/fw_cfg-pc.o
 
 tests/rtc-test$(EXESUF): tests/rtc-test.o
 tests/m48t59-test$(EXESUF): tests/m48t59-test.o
tests/libqos/fw_cfg-pc.c new file +40 -0
new file mode 100644
index 0000000..613604d
@@ -0,0 +1,40 @@
+/*
+ * 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 new file +20 -0
new file mode 100644
index 0000000..444bd79
@@ -0,0 +1,20 @@
+/*
+ * 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 new file +51 -0

51 lines not on this page · raw message

tests/libqos/fw_cfg.h new file +34 -0
new file mode 100644
index 0000000..44fc42b
@@ -0,0 +1,34 @@
+/*
+ * libqos fw_cfg support
+ *
+ * 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_H
+#define LIBQOS_FW_CFG_H
+
+#include <stdint.h>
+#include <sys/types.h>
+
+typedef struct QFWCFG QFWCFG;
+
+struct QFWCFG
+{
+    void (*select)(QFWCFG *fw_cfg, uint16_t key);
+    void (*read)(QFWCFG *fw_cfg, void *data, size_t len);
+};
+
+void qfw_cfg_select(QFWCFG *fw_cfg, uint16_t key);
+void qfw_cfg_read_data(QFWCFG *fw_cfg, void *data, size_t len);
+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);
+
+#endif
Signature · 1 line
1.8.0
#4 lore raw

PATCH 4/7 libqos: add malloc support

In reply to Anthony Liguori

This is a very simple allocator for the PC platform. It should be possible to add backends for other platforms.

---
 tests/Makefile           |  1 +
 tests/libqos/malloc-pc.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++
 tests/libqos/malloc-pc.h | 20 ++++++++++++++
 tests/libqos/malloc.h    | 38 ++++++++++++++++++++++++++
 4 files changed, 130 insertions(+)
 create mode 100644 tests/libqos/malloc-pc.c
 create mode 100644 tests/libqos/malloc-pc.h
 create mode 100644 tests/libqos/malloc.h
tests/Makefile +1 -0
index ce91980..cafbb27 100644
@@ -118,6 +118,7 @@ tests/test-mul64$(EXESUF): tests/test-mul64.o libqemuutil.a
 
 libqos-obj-y = tests/libqos/pci.o tests/libqos/fw_cfg.o
 libqos-pc-obj-y = $(libqos-obj-y) tests/libqos/pci-pc.o tests/libqos/fw_cfg-pc.o
+libqos-pc-obj-y += tests/libqos/malloc-pc.o
 
 tests/rtc-test$(EXESUF): tests/rtc-test.o
 tests/m48t59-test$(EXESUF): tests/m48t59-test.o
tests/libqos/malloc-pc.c new file +71 -0

71 lines not on this page · raw message

tests/libqos/malloc-pc.h new file +20 -0
new file mode 100644
index 0000000..ff964ab
@@ -0,0 +1,20 @@
+/*
+ * libqos malloc 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_MALLOC_PC_H
+#define LIBQOS_MALLOC_PC_H
+
+#include "libqos/malloc.h"
+
+QGuestAllocator *pc_alloc_init(void);
+
+#endif
tests/libqos/malloc.h new file +38 -0
new file mode 100644
index 0000000..46f6000
@@ -0,0 +1,38 @@
+/*
+ * libqos malloc support
+ *
+ * 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_MALLOC_H
+#define LIBQOS_MALLOC_H
+
+#include <stdint.h>
+#include <sys/types.h>
+
+typedef struct QGuestAllocator QGuestAllocator;
+
+struct QGuestAllocator
+{
+    uint64_t (*alloc)(QGuestAllocator *allocator, size_t size);
+    void (*free)(QGuestAllocator *allocator, uint64_t addr);
+};
+
+/* Always returns page aligned values */
+static inline uint64_t guest_alloc(QGuestAllocator *allocator, size_t size)
+{
+    return allocator->alloc(allocator, size);
+}
+
+static inline void guest_free(QGuestAllocator *allocator, uint64_t addr)
+{
+    allocator->alloc(allocator, addr);
+}
+
+#endif
Signature · 1 line
1.8.0
#5 lore raw

PATCH 5/7 i440fx-test: add test to compare default register values

In reply to Anthony Liguori

This test compares all of the default register values against the spec. It turns out we deviate in quite a few places. These places are really only visible to the BIOS though which is why this hasn't created any problems.

The deviation actually happens in the core PCI layer so I suspect it's not a simple fix if we really care to fix it. For now, just

---
 tests/Makefile      |   2 +
 tests/i440fx-test.c | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 150 insertions(+)
 create mode 100644 tests/i440fx-test.c
tests/Makefile +2 -0
index cafbb27..6c4b910 100644
@@ -54,6 +54,7 @@ gcov-files-i386-y = hw/fdc.c
 check-qtest-i386-y += tests/hd-geo-test$(EXESUF)
 gcov-files-i386-y += hw/hd-geometry.c
 check-qtest-i386-y += tests/rtc-test$(EXESUF)
+check-qtest-i386-y += tests/i440fx-test$(EXESUF)
 check-qtest-x86_64-y = $(check-qtest-i386-y)
 gcov-files-i386-y += i386-softmmu/hw/mc146818rtc.c
 gcov-files-x86_64-y = $(subst i386-softmmu/,x86_64-softmmu/,$(gcov-files-i386-y))
@@ -125,6 +126,7 @@ tests/m48t59-test$(EXESUF): tests/m48t59-test.o
 tests/fdc-test$(EXESUF): tests/fdc-test.o
 tests/hd-geo-test$(EXESUF): tests/hd-geo-test.o
 tests/tmp105-test$(EXESUF): tests/tmp105-test.o
+tests/i440fx-test$(EXESUF): tests/i440fx-test.o $(libqos-pc-obj-y)
 
 # QTest rules
 
tests/i440fx-test.c new file +148 -0

148 lines not on this page · raw message

Signature · 1 line
1.8.0
#6 lore raw

Re: [Qemu-devel] [PATCH 5/7] i440fx-test: add test to compare default register values

Quoted 8 lines · Anthony Liguori

This test compares all of the default register values against the spec. It turns out we deviate in quite a few places. These places are really only visible to the BIOS though which is why this hasn't created any problems.

The deviation actually happens in the core PCI layer so I suspect it's not a simple fix if we really care to fix it. For now, just

Conclusion of sentence?

Quoted 7 lines
---
 tests/Makefile      |   2 +
 tests/i440fx-test.c | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 150 insertions(+)
 create mode 100644 tests/i440fx-test.c
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#7 lore raw

Re: [Qemu-devel] [PATCH 5/7] i440fx-test: add test to compare default register values

Quoted 11 lines · Eric Blake
Quoted 8 lines · Anthony Liguori

This test compares all of the default register values against the spec. It turns out we deviate in quite a few places. These places are really only visible to the BIOS though which is why this hasn't created any problems.

The deviation actually happens in the core PCI layer so I suspect it's not a simple fix if we really care to fix it. For now, just

Conclusion of sentence?

Probably a case of your wording being similar to '#if 0 out the broken tests', and 'git commit' eating it because it looked like a comment.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#8 lore raw

Re: [Qemu-devel] [PATCH 5/7] i440fx-test: add test to compare default register values

Quoted 7 lines · Eric Blake
Quoted 6 lines · Eric Blake
Quoted 5 lines · Anthony Liguori

This test compares all of the default register values against the spec. It turns out we deviate in quite a few places. These places are really only visible to the BIOS though which is why this hasn't created any problems.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

The deviation actually happens in the core PCI layer so I suspect it's not a simple fix if we really care to fix it. For now, just

Conclusion of sentence?

Probably a case of your wording being similar to '#if 0 out the broken tests', and 'git commit' eating it because it looked like a comment.

Indeed :-/

Regards,

Anthony Liguori

Quoted 4 lines
Signature · 3 lines
-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#9 lore raw

PATCH 6/7 i440fx-test: add test for PAM functionality

In reply to Anthony Liguori

This tests PAM settings for the i440fx. This test does a lot of byte MMIO which is fairly slow with qtest today. But the test does complete in under 2 seconds.

We don't fully emulate PAM largely because of limitations with KVM so we #if 0 that part of the test case.

---
 tests/i440fx-test.c | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 138 insertions(+), 1 deletion(-)
tests/i440fx-test.c +138 -1
index 6fba741..08ce820 100644
@@ -17,10 +17,12 @@
 #include "hw/pci/pci_regs.h"
 
 #include <glib.h>
-#include <stdio.h>
+#include <string.h>
 
 #define BROKEN 1
 
+#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
+
 typedef struct TestData
 {
     int num_cpus;
@@ -119,6 +121,139 @@ static void test_i440fx_defaults(gconstpointer opaque)
     g_assert_cmpint(qpci_config_readb(dev, 0x93), ==, 0x00); /* TRC */
 }
 
+#define PAM_RE 1
+#define PAM_WE 2
+
+static void pam_set(QPCIDevice *dev, int index, int flags)
+{
+    int regno = 0x59 + (index / 2);
+    uint8_t reg;
+
+    reg = qpci_config_readb(dev, regno);
+    if (index & 1) {
+        reg = (reg & 0x0F) | (flags << 4);
+    } else {
+        reg = (reg & 0xF0) | flags;
+    }
+    qpci_config_writeb(dev, regno, reg);
+}
+
+static gboolean verify_area(uint32_t start, uint32_t end, uint8_t value)
+{
+    uint32_t size = end - start + 1;
+    gboolean ret = TRUE;
+    uint8_t *data;
+    int i;
+
+    data = g_malloc0(size);
+    memread(start, data, size);
+
+    g_test_message("verify_area: data[0] = 0x%x", data[0]);
+
+    for (i = 0; i < size; i++) {
+        if (data[i] != value) {
+            ret = FALSE;
+            break;
+        }
+    }
+
+    g_free(data);
+
+    return ret;
+}
+
+static void write_area(uint32_t start, uint32_t end, uint8_t value)
+{
+    uint32_t size = end - start + 1;
+    uint8_t *data;
+
+    data = g_malloc0(size);
+    memset(data, value, size);
+    memwrite(start, data, size);
+
+    g_free(data);
+}
+
+static void test_i440fx_pam(gconstpointer opaque)
+{
+    const TestData *s = opaque;
+    QPCIDevice *dev;
+    int i;
+    static struct {
+        uint32_t start;
+        uint32_t end;
+    } pam_area[] = {
+        { 0, 0 },             /* Reserved */
+        { 0xF0000, 0xFFFFF }, /* BIOS Area */
+        { 0xC0000, 0xC3FFF }, /* Option ROM */
+        { 0xC4000, 0xC7FFF }, /* Option ROM */
+        { 0xC8000, 0xCBFFF }, /* Option ROM */
+        { 0xCC000, 0xCFFFF }, /* Option ROM */
+        { 0xD0000, 0xD3FFF }, /* Option ROM */
+        { 0xD4000, 0xD7FFF }, /* Option ROM */
+        { 0xD8000, 0xDBFFF }, /* Option ROM */
+        { 0xDC000, 0xDFFFF }, /* Option ROM */
+        { 0xE0000, 0xE3FFF }, /* BIOS Extension */
+        { 0xE4000, 0xE7FFF }, /* BIOS Extension */
+        { 0xE8000, 0xEBFFF }, /* BIOS Extension */
+        { 0xEC000, 0xEFFFF }, /* BIOS Extension */
+    };
+
+    dev = qpci_device_find(s->bus, QPCI_DEVFN(0, 0));
+    g_assert(dev != NULL);
+
+    for (i = 0; i < ARRAY_SIZE(pam_area); i++) {
+        if (pam_area[i].start == pam_area[i].end) {
+            continue;
+        }
+
+        g_test_message("Checking area 0x%05x..0x%05x",
+                       pam_area[i].start, pam_area[i].end);
+        /* Switch to RE for the area */
+        pam_set(dev, i, PAM_RE);
+        /* Verify the RAM is all zeros */
+        g_assert(verify_area(pam_area[i].start, pam_area[i].end, 0));
+
+        /* Switch to WE for the area */
+        pam_set(dev, i, PAM_RE | PAM_WE);
+        /* Write out a non-zero mask to the full area */
+        write_area(pam_area[i].start, pam_area[i].end, 0x42);
+
+#ifndef BROKEN
+        /* QEMU only supports a limited form of PAM */
+
+        /* Switch to !RE for the area */
+        pam_set(dev, i, PAM_WE);
+        /* Verify the area is not our mask */
+        g_assert(!verify_area(pam_area[i].start, pam_area[i].end, 0x42));
+#endif
+
+        /* Verify the area is our new mask */
+        g_assert(verify_area(pam_area[i].start, pam_area[i].end, 0x42));
+
+        /* Write out a new mask */
+        write_area(pam_area[i].start, pam_area[i].end, 0x82);
+
+#ifndef BROKEN
+        /* QEMU only supports a limited form of PAM */
+
+        /* Verify the area is not our mask */
+        g_assert(!verify_area(pam_area[i].start, pam_area[i].end, 0x82));
+
+        /* Switch to RE for the area */
+        pam_set(dev, i, PAM_RE | PAM_WE);
+#endif
+        /* Verify the area is our new mask */
+        g_assert(verify_area(pam_area[i].start, pam_area[i].end, 0x82));
+
+        /* Reset area */
+        pam_set(dev, i, 0);
+
+        /* Verify the area is not our new mask */
+        g_assert(!verify_area(pam_area[i].start, pam_area[i].end, 0x82));
+    }
+}
+
 int main(int argc, char **argv)
 {
     QTestState *s;
@@ -137,6 +272,8 @@ int main(int argc, char **argv)
     data.bus = qpci_init_pc();
 
     g_test_add_data_func("/i440fx/defaults", &data, test_i440fx_defaults);
+    g_test_add_data_func("/i440fx/pam", &data, test_i440fx_pam);
+    
 
     ret = g_test_run();
 
Signature · 1 line
1.8.0
#10 lore raw

PATCH 7/7 fw_cfg: add qtest test case

In reply to Anthony Liguori

This validates some basic characteristics of fw_cfg.

---
 tests/Makefile      |   2 +
 tests/fw_cfg-test.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 143 insertions(+)
 create mode 100644 tests/fw_cfg-test.c
tests/Makefile +2 -0
index 6c4b910..72bf2cd 100644
@@ -55,6 +55,7 @@ check-qtest-i386-y += tests/hd-geo-test$(EXESUF)
 gcov-files-i386-y += hw/hd-geometry.c
 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)
 check-qtest-x86_64-y = $(check-qtest-i386-y)
 gcov-files-i386-y += i386-softmmu/hw/mc146818rtc.c
 gcov-files-x86_64-y = $(subst i386-softmmu/,x86_64-softmmu/,$(gcov-files-i386-y))
@@ -127,6 +128,7 @@ tests/fdc-test$(EXESUF): tests/fdc-test.o
 tests/hd-geo-test$(EXESUF): tests/hd-geo-test.o
 tests/tmp105-test$(EXESUF): tests/tmp105-test.o
 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)
 
 # QTest rules
 
tests/fw_cfg-test.c new file +141 -0

141 lines not on this page · raw message

Signature · 1 line
1.8.0
#11 lore raw

Re: [Qemu-devel] [PATCH 7/7] fw_cfg: add qtest test case

Am 16.04.2013 16:45, schrieb Anthony Liguori:

Quoted 8 lines

This validates some basic characteristics of fw_cfg.

---
 tests/Makefile      |   2 +
 tests/fw_cfg-test.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 143 insertions(+)
 create mode 100644 tests/fw_cfg-test.c

[...]

Quoted 37 lines
tests/fw_cfg-test.c new file +31 -0
new file mode 100644
index 0000000..c284c4d
@@ -0,0 +1,141 @@
+/*
+ * qtest fw_cfg test case
+ *
+ * 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.
+ */
+
+#define NO_QEMU_PROTOS
+
+#include "libqtest.h"
+#include "hw/nvram/fw_cfg.h"
+#include "libqos/fw_cfg-pc.h"
+
+#include <string.h>
+#include <glib.h>
+
+static uint64_t ram_size = 128 << 20;
+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)
+{
+    char buf[5];

tests/fw_cfg-test.c line 41

Quoted 10 lines
tests/fw_cfg-test.c new file +10 -0
+
+    qfw_cfg_get(fw_cfg, FW_CFG_SIGNATURE, buf, 4);
+    buf[4] = 0;
+
+    g_assert_cmpstr(buf, ==, "QEMU");
+}
+
+static void test_fw_cfg_id(void)
+{
+    g_assert_cmpint(qfw_cfg_get_u32(fw_cfg, FW_CFG_ID), ==, 1);

Breaks on ppc:

GTESTER check-qtest-i386
main-loop: WARNING: I/O thread spun for 1000 iterations
main-loop: WARNING: I/O thread spun for 1000 iterations
main-loop: WARNING: I/O thread spun for 1000 iterations
** ERROR:/home/andreas/QEMU/qemu/tests/fw_cfg-test.c:41:test_fw_cfg_id:
assertion failed (qfw_cfg_get_u32(fw_cfg, FW_CFG_ID) == 1): (16777216 == 1)
GTester: last random seed: R02Seb06159fdb5cae93a76e1fb2021712e6
** ERROR:/home/andreas/QEMU/qemu/tests/fw_cfg-test.c:58:test_fw_cfg_ram_size:
assertion failed (qfw_cfg_get_u64(fw_cfg, FW_CFG_RAM_SIZE) == ram_size):
(34359738368 == 134217728)
GTester: last random seed: R02Sb790037de99dc72c4011de8746bcf891
** ERROR:/home/andreas/QEMU/qemu/tests/fw_cfg-test.c:68:test_fw_cfg_nb_cpus: assertion failed (qfw_cfg_get_u16(fw_cfg, FW_CFG_NB_CPUS) == nb_cpus): (256 == 1)
GTester: last random seed: R02S8cbc5ce02a292007de9990e752915719
** ERROR:/home/andreas/QEMU/qemu/tests/fw_cfg-test.c:73:test_fw_cfg_max_cpus:
assertion failed (qfw_cfg_get_u16(fw_cfg, FW_CFG_MAX_CPUS) == max_cpus):
(256 == 1)
GTester: last random seed: R02S81c8abd06614ef0eef55cedea5f37429
make: *** [check-qtest-i386] Fehler 1

Andreas

Quoted 101 lines
tests/fw_cfg-test.c new file +100 -0
+}
+
+static void test_fw_cfg_uuid(void)
+{
+    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,
+    };
+
+    qfw_cfg_get(fw_cfg, FW_CFG_UUID, buf, 16);
+    g_assert(memcmp(buf, uuid, sizeof(buf)) == 0);
+}
+
+static void test_fw_cfg_ram_size(void)
+{
+    g_assert_cmpint(qfw_cfg_get_u64(fw_cfg, FW_CFG_RAM_SIZE), ==, ram_size);
+}
+
+static void test_fw_cfg_nographic(void)
+{
+    g_assert_cmpint(qfw_cfg_get_u16(fw_cfg, FW_CFG_NOGRAPHIC), ==, 0);
+}
+
+static void test_fw_cfg_nb_cpus(void)
+{
+    g_assert_cmpint(qfw_cfg_get_u16(fw_cfg, FW_CFG_NB_CPUS), ==, nb_cpus);
+}
+
+static void test_fw_cfg_max_cpus(void)
+{
+    g_assert_cmpint(qfw_cfg_get_u16(fw_cfg, FW_CFG_MAX_CPUS), ==, max_cpus);
+}
+
+static void test_fw_cfg_numa(void)
+{
+    uint64_t *cpu_mask;
+    uint64_t *node_mask;
+
+    g_assert_cmpint(qfw_cfg_get_u64(fw_cfg, FW_CFG_NUMA), ==, nb_nodes);
+
+    cpu_mask = g_malloc0(sizeof(uint64_t) * max_cpus);
+    node_mask = g_malloc0(sizeof(uint64_t) * nb_nodes);
+
+    qfw_cfg_read_data(fw_cfg, cpu_mask, sizeof(uint64_t) * max_cpus);
+    qfw_cfg_read_data(fw_cfg, node_mask, sizeof(uint64_t) * nb_nodes);
+
+    if (nb_nodes) {
+        g_assert(cpu_mask[0] & 0x01);
+        g_assert_cmpint(node_mask[0], ==, ram_size);
+    }
+
+    g_free(node_mask);
+    g_free(cpu_mask);
+}
+
+static void test_fw_cfg_boot_menu(void)
+{
+    g_assert_cmpint(qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_MENU), ==, boot_menu);
+}
+
+int main(int argc, char **argv)
+{
+    QTestState *s;
+    char *cmdline;
+    int ret;
+
+    g_test_init(&argc, &argv, NULL);
+
+    fw_cfg = pc_fw_cfg_init();
+
+    g_test_add_func("/fw_cfg/signature", test_fw_cfg_signature);
+    g_test_add_func("/fw_cfg/id", test_fw_cfg_id);
+    g_test_add_func("/fw_cfg/uuid", test_fw_cfg_uuid);
+    g_test_add_func("/fw_cfg/ram_size", test_fw_cfg_ram_size);
+    g_test_add_func("/fw_cfg/nographic", test_fw_cfg_nographic);
+    g_test_add_func("/fw_cfg/nb_cpus", test_fw_cfg_nb_cpus);
+#if 0
+    g_test_add_func("/fw_cfg/machine_id", test_fw_cfg_machine_id);
+    g_test_add_func("/fw_cfg/kernel", test_fw_cfg_kernel);
+    g_test_add_func("/fw_cfg/initrd", test_fw_cfg_initrd);
+    g_test_add_func("/fw_cfg/boot_device", test_fw_cfg_boot_device);
+#endif
+    g_test_add_func("/fw_cfg/max_cpus", test_fw_cfg_max_cpus);
+    g_test_add_func("/fw_cfg/numa", test_fw_cfg_numa);
+    g_test_add_func("/fw_cfg/boot_menu", test_fw_cfg_boot_menu);
+
+    cmdline = g_strdup_printf("-display none "
+                              "-uuid 4600cb32-38ec-4b2f-8acb-81c6ea54f2d8 ");
+    s = qtest_start(cmdline);
+    g_free(cmdline);
+
+    ret = g_test_run();
+
+    if (s) {
+        qtest_quit(s);
+    }
+
+    return ret;
+}
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg