All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Walle <michael@walle.cc>
To: qemu-devel@nongnu.org
Cc: Michael Walle <michael@walle.cc>
Subject: [Qemu-devel] [PATCH 3/3] milkymist-pfpu: add qtests
Date: Wed, 18 Jul 2018 12:48:36 +0200	[thread overview]
Message-ID: <20180718104836.18488-3-michael@walle.cc> (raw)
In-Reply-To: <20180718104836.18488-1-michael@walle.cc>

Add initial tests which check basic computations and error cases on the
PFPU.

Signed-off-by: Michael Walle <michael@walle.cc>
---
 MAINTAINERS                 |   1 +
 hw/lm32/lm32.h              |   2 +
 tests/Makefile.include      |   4 +
 tests/milkymist-pfpu-test.c | 193 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 200 insertions(+)
 create mode 100644 tests/milkymist-pfpu-test.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 666e936812..bde0d132b9 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -171,6 +171,7 @@ F: hw/*/milkymist-*
 F: include/hw/char/lm32_juart.h
 F: include/hw/lm32/
 F: tests/tcg/lm32/
+F: tests/milkymist-*
 
 M68K
 M: Laurent Vivier <laurent@vivier.eu>
diff --git a/hw/lm32/lm32.h b/hw/lm32/lm32.h
index d1514a61b3..b14f7ce158 100644
--- a/hw/lm32/lm32.h
+++ b/hw/lm32/lm32.h
@@ -9,6 +9,8 @@ static inline DeviceState *lm32_pic_init(qemu_irq cpu_irq)
     SysBusDevice *d;
 
     dev = qdev_create(NULL, "lm32-pic");
+    object_property_add_child(qdev_get_machine(), "lm32-pic", OBJECT(dev),
+            NULL);
     qdev_init_nofail(dev);
     d = SYS_BUS_DEVICE(dev);
     sysbus_connect_irq(d, 0, cpu_irq);
diff --git a/tests/Makefile.include b/tests/Makefile.include
index a49282704e..d02d673f7d 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -406,6 +406,8 @@ check-qtest-s390x-y += tests/virtio-console-test$(EXESUF)
 check-qtest-s390x-y += tests/virtio-serial-test$(EXESUF)
 check-qtest-s390x-y += tests/cpu-plug-test$(EXESUF)
 
+check-qtest-lm32-y = tests/milkymist-pfpu-test$(EXESUF)
+
 check-qtest-generic-y += tests/machine-none-test$(EXESUF)
 check-qtest-generic-y += tests/qom-test$(EXESUF)
 check-qtest-generic-y += tests/test-hmp$(EXESUF)
@@ -868,6 +870,8 @@ tests/migration/initrd-stress.img: tests/migration/stress$(EXESUF)
 	rm $(INITRD_WORK_DIR)/init
 	rmdir $(INITRD_WORK_DIR)
 
+tests/milkymist-pfpu-test$(EXESUF): tests/milkymist-pfpu-test.o
+
 ifeq ($(CONFIG_POSIX),y)
 LIBS += -lutil
 endif
diff --git a/tests/milkymist-pfpu-test.c b/tests/milkymist-pfpu-test.c
new file mode 100644
index 0000000000..da506bbdf8
--- /dev/null
+++ b/tests/milkymist-pfpu-test.c
@@ -0,0 +1,193 @@
+/*
+ * QTest testcase for the Milkymist PFPU
+ *
+ * Copyright (c) 2018 Michael Walle <michael@walle.cc>
+ *
+ * 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 "qemu/osdep.h"
+
+#include "libqtest.h"
+
+#define PFPU_BASE 0x60006000
+#define PFPU_IRQ 8
+
+static void pfpu_load_microcode(uint32_t *insn, int len)
+{
+    uint32_t addr = PFPU_BASE + 0x800;
+    while (len) {
+        writel(addr, *insn);
+        insn++;
+        len--;
+        addr += 4;
+    }
+}
+
+static void pfpu_clear_microcode(void)
+{
+    uint32_t addr = PFPU_BASE + 0x800;
+    uint32_t len = 512;
+    while (len) {
+        writel(addr, 0);
+        len--;
+        addr += 4;
+    }
+}
+
+static uint32_t float_to_u32(float val)
+{
+    return (*((uint32_t *)&(val)));
+}
+
+static void pfpu_add(void)
+{
+    static uint32_t ucode[] = {
+        0x000c2080, /* FADD R3, R4 */
+        0x00000000, /* NOP */
+        0x00000000, /* NOP */
+        0x00000000, /* NOP */
+        0x00000000, /* NOP */
+        0x00000003, /* NOP | EXIT R3 */
+        0x000c2380  /* VECTOUT R3, R4 */
+    };
+
+    /* 2x1 mesh size */
+    writel(PFPU_BASE + 0x8, 1);
+    writel(PFPU_BASE + 0xc, 0);
+
+    /* write test operands to r3 and r4 */
+    writel(PFPU_BASE + 0x40c, float_to_u32(3.0f));
+    writel(PFPU_BASE + 0x410, float_to_u32(9.0f));
+
+    pfpu_load_microcode(ucode, ARRAY_SIZE(ucode));
+
+    /* dma base */
+    writel(PFPU_BASE + 0x4, 0x40000000);
+
+    /* start */
+    writel(PFPU_BASE, 1);
+
+    /* on a successful run, the busy flag should be cleared */
+    g_assert(readl(PFPU_BASE) == 0);
+
+    /* interrupt line should have been pulsed */
+    g_assert(get_irq_latched(PFPU_IRQ) == 1);
+    clear_irq_latch(PFPU_IRQ);
+    g_assert(get_irq_latched(PFPU_IRQ) == 0);
+
+    /* resulting vertices should be written to RAM */
+    g_assert(readl(0x40000000) == float_to_u32(12.0f));
+    g_assert(readl(0x40000004) == float_to_u32(9.0f));
+    g_assert(readl(0x40000008) == float_to_u32(21.0f));
+    g_assert(readl(0x4000000c) == float_to_u32(9.0f));
+
+    /* count of computed vertices */
+    g_assert(readl(PFPU_BASE + 0x14) == 2);
+
+    /* no collisions */
+    g_assert(readl(PFPU_BASE + 0x18) == 0);
+
+    /* no stray writes */
+    g_assert(readl(PFPU_BASE + 0x1c) == 0);
+}
+
+static void pfpu_microcode_overflow(void)
+{
+    /* 1x1 mesh size */
+    writel(PFPU_BASE + 0x8, 1);
+    writel(PFPU_BASE + 0xc, 0);
+
+    pfpu_clear_microcode();
+
+    /* start */
+    writel(PFPU_BASE, 1);
+
+    /* because there is no VECTOUT, the busy flag should not be cleared */
+    g_assert(readl(PFPU_BASE) == 1);
+
+    /* and there should be no pending interrupt */
+    g_assert(get_irq_latched(PFPU_IRQ) == 0);
+}
+
+static void pfpu_stray_writes(void)
+{
+    static uint32_t ucode[] = {
+        0x000c0600, /* COPY R3 */
+        0x00000000, /* NOP */
+        0x00000000, /* NOP */
+        0x000c2380  /* VECTOUT R3, R4 */
+    };
+
+    /* 1x1 mesh size */
+    writel(PFPU_BASE + 0x8, 0);
+    writel(PFPU_BASE + 0xc, 0);
+
+    /* write test operands to r3 and r4 */
+    writel(PFPU_BASE + 0x40c, float_to_u32(1.0f));
+    writel(PFPU_BASE + 0x410, float_to_u32(2.0f));
+
+    pfpu_load_microcode(ucode, ARRAY_SIZE(ucode));
+
+    /* dma base */
+    writel(PFPU_BASE + 0x4, 0x40000000);
+
+    /* start */
+    writel(PFPU_BASE, 1);
+    clear_irq_latch(PFPU_IRQ);
+
+    /* stray writes */
+    g_assert(readl(PFPU_BASE + 0x1c) == 1);
+}
+
+static void pfpu_collision(void)
+{
+    static uint32_t ucode[] = {
+        0x000c0300, /* I2F R3 */
+        0x000c0600, /* COPY R3 */
+        0x00000000, /* NOP */
+        0x00000000, /* NOP */
+        0x000c2380  /* VECTOUT R3, R4 */
+    };
+
+    /* 1x1 mesh size */
+    writel(PFPU_BASE + 0x8, 0);
+    writel(PFPU_BASE + 0xc, 0);
+
+    /* write test operands to r3 and r4 */
+    writel(PFPU_BASE + 0x40c, float_to_u32(1.0f));
+    writel(PFPU_BASE + 0x410, float_to_u32(2.0f));
+
+    pfpu_load_microcode(ucode, ARRAY_SIZE(ucode));
+
+    /* dma base */
+    writel(PFPU_BASE + 0x4, 0x40000000);
+
+    /* start */
+    writel(PFPU_BASE, 1);
+    clear_irq_latch(PFPU_IRQ);
+
+    /* collisions */
+    g_assert(readl(PFPU_BASE + 0x18) == 1);
+}
+
+int main(int argc, char **argv)
+{
+    int ret;
+
+    g_test_init(&argc, &argv, NULL);
+
+    qtest_start("-machine milkymist");
+    irq_intercept_in("lm32-pic");
+    qtest_add_func("/milkymist-pfpu/add", pfpu_add);
+    qtest_add_func("/milkymist-pfpu/microcode-overflow", pfpu_microcode_overflow);
+    qtest_add_func("/milkymist-pfpu/collision", pfpu_collision);
+    qtest_add_func("/milkymist-pfpu/stray-writes", pfpu_stray_writes);
+
+    ret = g_test_run();
+
+    qtest_end();
+
+    return ret;
+}
-- 
2.11.0

      parent reply	other threads:[~2018-07-18 10:48 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-18 10:48 [Qemu-devel] [PATCH 1/3] milkymist-pfpu: more accurate emulation Michael Walle
2018-07-18 10:48 ` [Qemu-devel] [PATCH 2/3] qtest: new functions for pulsed IRQs Michael Walle
2018-10-31  8:31   ` Michael Walle
2018-10-31  9:43     ` Andreas Färber
2018-10-31 10:19   ` Paolo Bonzini
2018-10-31 14:30     ` Michael Walle
2018-10-31 14:44       ` Paolo Bonzini
2018-07-18 10:48 ` Michael Walle [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180718104836.18488-3-michael@walle.cc \
    --to=michael@walle.cc \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.