Skip to contentSkip to conversation

Add the m68k next-cube machine

GIT PULL Applied Thomas Huth 4 participants 15 messages Sep 7, 2019 – Sep 18, 2019

lore
Share & tools
lore
#0 lore raw

Hi Peter,

the following changes since commit 90b1e3afd33226b6078fec6d77a18373712a975c:

Merge remote-tracking branch 'remotes/huth-gitlab/tags/pull-request-2019-09-05-v2' into staging (2019-09-05 17:09:13 +0100)

are available in the Git repository at:

https://gitlab.com/huth/qemu.git tags/m68k-pull-2019-09-07

for you to fetch changes up to 25311649592f5584b1e1012d69c7327ef87473f4:

.travis.yml: Let the avocado job run the NeXTcube tests (2019-09-07 08:35:41 +0200)

----------------------------------------------------------------
Add the m68k next-cube machine
----------------------------------------------------------------

Laurent Vivier (1):
escc: introduce a selector for the register bit

Philippe Mathieu-Daudé (2):
tests/acceptance: Add test of NeXTcube framebuffer using OCR .travis.yml: Let the avocado job run the NeXTcube tests

Thomas Huth (5):
m68k: Add NeXTcube framebuffer device emulation
m68k: Add NeXTcube keyboard device
m68k: Add NeXTcube machine
m68k: Add serial controller to the NeXTcube machine
m68k: Add an entry for the NeXTcube machine to the MAINTAINERS file

 .travis.yml                               |   7 +-
 MAINTAINERS                               |   7 +
 default-configs/m68k-softmmu.mak          |   1 +
 hw/char/escc.c                            |  30 +-
 hw/display/Makefile.objs                  |   1 +
 hw/display/next-fb.c                      | 146 +++++
 hw/m68k/Kconfig                           |   5 +
 hw/m68k/Makefile.objs                     |   1 +
 hw/m68k/next-cube.c                       | 978 ++++++++++++++++++++++++++++++
 hw/m68k/next-kbd.c                        | 291 +++++++++
 include/hw/char/escc.h                    |   1 +
 include/hw/m68k/next-cube.h               |  47 ++
 tests/acceptance/machine_m68k_nextcube.py | 121 ++++
 tests/boot-serial-test.c                  |  12 +
 14 files changed, 1641 insertions(+), 7 deletions(-)
 create mode 100644 hw/display/next-fb.c
 create mode 100644 hw/m68k/next-cube.c
 create mode 100644 hw/m68k/next-kbd.c
 create mode 100644 include/hw/m68k/next-cube.h
 create mode 100644 tests/acceptance/machine_m68k_nextcube.py
#1 lore raw

[Qemu-devel] [PULL 1/8] m68k: Add NeXTcube framebuffer device emulation

The NeXTcube uses a linear framebuffer with 4 greyscale colors and a fixed resolution of 1120 * 832.
This code has been taken from Bryce Lanham's GSoC 2011 NeXT branch at

https://github.com/blanham/qemu-NeXT/blob/next-cube/hw/next-fb.c

and altered to fit the latest interface of the current QEMU (e.g. the device has been "qdev"-ified etc.).

Message-Id: <[email protected]>

---
 default-configs/m68k-softmmu.mak |   1 +
 hw/display/Makefile.objs         |   1 +
 hw/display/next-fb.c             | 146 +++++++++++++++++++++++++++++++
 hw/m68k/Kconfig                  |   4 +
 include/hw/m68k/next-cube.h      |   7 ++
 5 files changed, 159 insertions(+)
 create mode 100644 hw/display/next-fb.c
 create mode 100644 include/hw/m68k/next-cube.h
default-configs/m68k-softmmu.mak +1 -0
index 4049a8f2ba..d67ab8b96d 100644
@@ -6,3 +6,4 @@ CONFIG_SEMIHOSTING=y
 #
 CONFIG_AN5206=y
 CONFIG_MCF5208=y
+CONFIG_NEXTCUBE=y
hw/display/Makefile.objs +1 -0
index 0f11d55b14..5a4066383b 100644
@@ -38,6 +38,7 @@ common-obj-$(CONFIG_RASPI) += bcm2835_fb.o
 common-obj-$(CONFIG_SM501) += sm501.o
 common-obj-$(CONFIG_TCX) += tcx.o
 common-obj-$(CONFIG_CG3) += cg3.o
+common-obj-$(CONFIG_NEXTCUBE) += next-fb.o
 
 obj-$(CONFIG_VGA) += vga.o
 
hw/display/next-fb.c new file +146 -0

146 lines not on this page · raw message

hw/m68k/Kconfig +4 -0
index 49ef0b3f6d..ec58a2eb06 100644
@@ -7,3 +7,7 @@ config MCF5208
     bool
     select COLDFIRE
     select PTIMER
+
+config NEXTCUBE
+    bool
+    select FRAMEBUFFER
include/hw/m68k/next-cube.h new file +7 -0
new file mode 100644
index 0000000000..090c7c51aa
@@ -0,0 +1,7 @@
+
+#ifndef NEXT_CUBE_H
+#define NEXT_CUBE_H
+
+#define TYPE_NEXTFB "next-fb"
+
+#endif /* NEXT_CUBE_H */
Signature · 1 line
2.21.0
#2 lore raw

[Qemu-devel] [PULL 4/8] escc: introduce a selector for the register bit

In reply to Thomas Huth

From: Laurent Vivier <[email protected]>

On Sparc and PowerMac, the bit 0 of the address selects the register type (control or data) and bit 1 selects the channel (B or A).

On m68k Macintosh and NeXTcube, the bit 0 selects the channel and bit 1 the register type.

This patch introduces a new parameter (bit_swap) to the device interface to indicate bits usage must be swapped between registers and channels.

For the moment all the machines use the bit 0, but this change will be needed to emulate the Quadra 800 or NeXTcube machine.

Message-Id: <[email protected]>

---
 hw/char/escc.c         | 30 ++++++++++++++++++++++++------
 include/hw/char/escc.h |  1 +
 2 files changed, 25 insertions(+), 6 deletions(-)
hw/char/escc.c +24 -6
index e185522e27..8f7bf322cb 100644
@@ -45,14 +45,21 @@
  * mouse and keyboard ports don't implement all functions and they are
  * only asynchronous. There is no DMA.
  *
- * Z85C30 is also used on PowerMacs. There are some small differences
- * between Sparc version (sunzilog) and PowerMac (pmac):
+ * Z85C30 is also used on PowerMacs and m68k Macs.
+ *
+ * There are some small differences between Sparc version (sunzilog)
+ * and PowerMac (pmac):
  *  Offset between control and data registers
  *  There is some kind of lockup bug, but we can ignore it
  *  CTS is inverted
  *  DMA on pmac using DBDMA chip
  *  pmac can do IRDA and faster rates, sunzilog can only do 38400
  *  pmac baud rate generator clock is 3.6864 MHz, sunzilog 4.9152 MHz
+ *
+ * Linux driver for m68k Macs is the same as for PowerMac (pmac_zilog),
+ * but registers are grouped by type and not by channel:
+ * channel is selected by bit 0 of the address (instead of bit 1)
+ * and register is selected by bit 1 of the address (instead of bit 0).
  */
 
 /*
@@ -172,6 +179,16 @@ static void handle_kbd_command(ESCCChannelState *s, int val);
 static int serial_can_receive(void *opaque);
 static void serial_receive_byte(ESCCChannelState *s, int ch);
 
+static int reg_shift(ESCCState *s)
+{
+    return s->bit_swap ? s->it_shift + 1 : s->it_shift;
+}
+
+static int chn_shift(ESCCState *s)
+{
+    return s->bit_swap ? s->it_shift : s->it_shift + 1;
+}
+
 static void clear_queue(void *opaque)
 {
     ESCCChannelState *s = opaque;
@@ -436,8 +453,8 @@ static void escc_mem_write(void *opaque, hwaddr addr,
     int newreg, channel;
 
     val &= 0xff;
-    saddr = (addr >> serial->it_shift) & 1;
-    channel = (addr >> (serial->it_shift + 1)) & 1;
+    saddr = (addr >> reg_shift(serial)) & 1;
+    channel = (addr >> chn_shift(serial)) & 1;
     s = &serial->chn[channel];
     switch (saddr) {
     case SERIAL_CTRL:
@@ -547,8 +564,8 @@ static uint64_t escc_mem_read(void *opaque, hwaddr addr,
     uint32_t ret;
     int channel;
 
-    saddr = (addr >> serial->it_shift) & 1;
-    channel = (addr >> (serial->it_shift + 1)) & 1;
+    saddr = (addr >> reg_shift(serial)) & 1;
+    channel = (addr >> chn_shift(serial)) & 1;
     s = &serial->chn[channel];
     switch (saddr) {
     case SERIAL_CTRL:
@@ -832,6 +849,7 @@ static void escc_realize(DeviceState *dev, Error **errp)
 static Property escc_properties[] = {
     DEFINE_PROP_UINT32("frequency", ESCCState, frequency,   0),
     DEFINE_PROP_UINT32("it_shift",  ESCCState, it_shift,    0),
+    DEFINE_PROP_BOOL("bit_swap",    ESCCState, bit_swap,    false),
     DEFINE_PROP_UINT32("disabled",  ESCCState, disabled,    0),
     DEFINE_PROP_UINT32("chnBtype",  ESCCState, chn[0].type, 0),
     DEFINE_PROP_UINT32("chnAtype",  ESCCState, chn[1].type, 0),
include/hw/char/escc.h +1 -0
index d5196c53e6..794b653484 100644
@@ -51,6 +51,7 @@ typedef struct ESCCState {
 
     struct ESCCChannelState chn[2];
     uint32_t it_shift;
+    bool bit_swap;
     MemoryRegion mmio;
     uint32_t disabled;
     uint32_t frequency;
Signature · 1 line
2.21.0
#3 lore raw

[Qemu-devel] [PULL 3/8] m68k: Add NeXTcube machine

In reply to Thomas Huth

It is still quite incomplete (no SCSI, no floppy emulation, no network, etc.), but the firmware already shows up the debug monitor prompt in the framebuffer display, so at least the very basics are already working.

This code has been taken from Bryce Lanham's GSoC 2011 NeXT branch at

https://github.com/blanham/qemu-NeXT/blob/next-cube/hw/next-cube.c

and altered quite a bit to fit the latest interface and coding conventions of the current QEMU.

Message-Id: <[email protected]>

---
 hw/m68k/Makefile.objs       |   2 +-
 hw/m68k/next-cube.c         | 941 ++++++++++++++++++++++++++++++++++++
 include/hw/m68k/next-cube.h |  38 ++
 3 files changed, 980 insertions(+), 1 deletion(-)
 create mode 100644 hw/m68k/next-cube.c
hw/m68k/Makefile.objs +1 -1
index 688002cac1..f25854730d 100644
@@ -1,3 +1,3 @@
 obj-$(CONFIG_AN5206) += an5206.o mcf5206.o
 obj-$(CONFIG_MCF5208) += mcf5208.o mcf_intc.o
-obj-$(CONFIG_NEXTCUBE) += next-kbd.o
+obj-$(CONFIG_NEXTCUBE) += next-kbd.o next-cube.o
hw/m68k/next-cube.c new file +941 -0

941 lines not on this page · raw message

include/hw/m68k/next-cube.h +38 -0
index 37f7ce3e34..a3be2b32ab 100644
@@ -6,4 +6,42 @@
 
 #define TYPE_NEXTKBD "next-kbd"
 
+enum next_dma_chan {
+    NEXTDMA_FD,
+    NEXTDMA_ENRX,
+    NEXTDMA_ENTX,
+    NEXTDMA_SCSI,
+    NEXTDMA_SCC,
+    NEXTDMA_SND
+};
+
+#define DMA_ENABLE      0x01000000
+#define DMA_SUPDATE     0x02000000
+#define DMA_COMPLETE    0x08000000
+
+#define DMA_M2DEV       0x0
+#define DMA_SETENABLE   0x00010000
+#define DMA_SETSUPDATE  0x00020000
+#define DMA_DEV2M       0x00040000
+#define DMA_CLRCOMPLETE 0x00080000
+#define DMA_RESET       0x00100000
+
+enum next_irqs {
+    NEXT_FD_I,
+    NEXT_KBD_I,
+    NEXT_PWR_I,
+    NEXT_ENRX_I,
+    NEXT_ENTX_I,
+    NEXT_SCSI_I,
+    NEXT_CLK_I,
+    NEXT_SCC_I,
+    NEXT_ENTX_DMA_I,
+    NEXT_ENRX_DMA_I,
+    NEXT_SCSI_DMA_I,
+    NEXT_SCC_DMA_I,
+    NEXT_SND_I
+};
+
+void next_irq(void *opaque, int number, int level);
+
 #endif /* NEXT_CUBE_H */
Signature · 1 line
2.21.0
#4 lore raw

Re: [Qemu-devel] [PULL 3/8] m68k: Add NeXTcube machine

Quoted 7 lines · Thomas Huth

It is still quite incomplete (no SCSI, no floppy emulation, no network, etc.), but the firmware already shows up the debug monitor prompt in the framebuffer display, so at least the very basics are already working.

This code has been taken from Bryce Lanham's GSoC 2011 NeXT branch at

Quoted 8 lines

https://github.com/blanham/qemu-NeXT/blob/next-cube/hw/next-cube.c

and altered quite a bit to fit the latest interface and coding conventions of the current QEMU.

Message-Id: <[email protected]>

Hi; Coverity spotted an issue in this function (CID 1405664):

Quoted 8 lines
hw/m68k/next-cube.c new file +8 -0
+static void nextscr2_write(NeXTState *s, uint32_t val, int size)
+{
+    static int led;
+    static int phase;
+    static uint8_t old_scr2;
+    static uint8_t rtc_command;
+    static uint8_t rtc_value;
+    static uint8_t rtc_status = 0x90;

hw/m68k/next-cube.c line 167

Quoted 10 lines
hw/m68k/next-cube.c new file +8 -0
+    static uint8_t rtc_return;
+    uint8_t scr2_2;
+
 
 
+                /* read the status 0x31 */
+                if (rtc_command == 0x31) {
+                    scr2_2 = scr2_2 & (~SCR2_RTDATA);
+                    /* for now 0x00 */
+                    if (0x00 & (0x80 >> (phase - 8))) {

0 & anything can never be true, so the line below here is dead code.

hw/m68k/next-cube.c line 159

Quoted 6 lines
hw/m68k/next-cube.c new file +6 -0
+                        scr2_2 |= SCR2_RTDATA;
+                    }
+                    rtc_return = (rtc_return << 1) |
+                                 ((scr2_2 & SCR2_RTDATA) ? 1 : 0);
+                }
+

Incidentally, I see that this file has quite a lot of what seems to be essentially device emulation code in it (a bunch of IO MemoryRegions defined locally) -- ideally these could be split out into proper device objects at some point.

thanks
-- PMM

#5 lore raw

Re: [Qemu-devel] [PULL 3/8] m68k: Add NeXTcube machine

Quoted 34 lines · Peter Maydell
Quoted 7 lines · Thomas Huth

It is still quite incomplete (no SCSI, no floppy emulation, no network, etc.), but the firmware already shows up the debug monitor prompt in the framebuffer display, so at least the very basics are already working.

This code has been taken from Bryce Lanham's GSoC 2011 NeXT branch at

Quoted 8 lines

https://github.com/blanham/qemu-NeXT/blob/next-cube/hw/next-cube.c

and altered quite a bit to fit the latest interface and coding conventions of the current QEMU.

Message-Id: <[email protected]>

Hi; Coverity spotted an issue in this function (CID 1405664):

Quoted 11 lines
hw/m68k/next-cube.c new file +11 -0
+static void nextscr2_write(NeXTState *s, uint32_t val, int size)
+{
+    static int led;
+    static int phase;
+    static uint8_t old_scr2;
+    static uint8_t rtc_command;
+    static uint8_t rtc_value;
+    static uint8_t rtc_status = 0x90;
+    static uint8_t rtc_return;
+    uint8_t scr2_2;
+
Quoted 7 lines

hw/m68k/next-cube.c line 167

Quoted 5 lines
hw/m68k/next-cube.c new file +5 -0
+                /* read the status 0x31 */
+                if (rtc_command == 0x31) {
+                    scr2_2 = scr2_2 & (~SCR2_RTDATA);
+                    /* for now 0x00 */
+                    if (0x00 & (0x80 >> (phase - 8))) {

0 & anything can never be true, so the line below here is dead code.

Right. I'm going to have a closer look at this at the weekend, to see what's the best way to fix it or whether it should simply be removed.

Quoted 7 lines

hw/m68k/next-cube.c line 159

Quoted 6 lines
hw/m68k/next-cube.c new file +6 -0
+                        scr2_2 |= SCR2_RTDATA;
+                    }
+                    rtc_return = (rtc_return << 1) |
+                                 ((scr2_2 & SCR2_RTDATA) ? 1 : 0);
+                }
+
Quoted 5 lines

Incidentally, I see that this file has quite a lot of what seems to be essentially device emulation code in it (a bunch of IO MemoryRegions defined locally) -- ideally these could be split out into proper device objects at some point.

Yeah, it's all old code from 2011 ... I'll keep this in mind for future clean-ups!

Thanks,
Thomas

#6 lore raw

[Qemu-devel] [PULL 8/8] .travis.yml: Let the avocado job run the NeXTcube tests

In reply to Thomas Huth

From: Philippe Mathieu-Daudé <[email protected]>

Message-Id: <[email protected]>

[huth: Rebased patch to master branch]
---
 .travis.yml | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
.travis.yml +6 -1
index 92b00927d4..106f9b5d01 100644
@@ -232,15 +232,20 @@ matrix:
 
     # Acceptance (Functional) tests
     - env:
-        - CONFIG="--python=/usr/bin/python3 --target-list=x86_64-softmmu,mips-softmmu,mips64el-softmmu,aarch64-softmmu,arm-softmmu,s390x-softmmu,alpha-softmmu,ppc64-softmmu"
+        - CONFIG="--python=/usr/bin/python3 --target-list=x86_64-softmmu,mips-softmmu,mips64el-softmmu,aarch64-softmmu,arm-softmmu,s390x-softmmu,alpha-softmmu,ppc64-softmmu,m68k-softmmu"
         - TEST_CMD="make check-acceptance"
       after_failure:
         - cat tests/results/latest/job.log
       addons:
         apt:
           packages:
+            - python3-pil
             - python3-pip
             - python3.5-venv
+            - tesseract-ocr
+            - tesseract-ocr-eng
+
+
     # Using newer GCC with sanitizers
     - addons:
         apt:
Signature · 1 line
2.21.0
#7 lore raw

[Qemu-devel] [PULL 2/8] m68k: Add NeXTcube keyboard device

In reply to Thomas Huth

It is likely still quite incomplete (e.g. mouse and interrupts are not implemented yet), but it is good enough for keyboard input at the firmware monitor.
This code has been taken from Bryce Lanham's GSoC 2011 NeXT branch at

https://github.com/blanham/qemu-NeXT/blob/next-cube/hw/next-kbd.c

and altered to fit the latest interface of the current QEMU (e.g. to use memory_region_init_io() instead of cpu_register_physical_memory()).

Message-Id: <[email protected]>

---
 hw/m68k/Makefile.objs       |   1 +
 hw/m68k/next-kbd.c          | 291 ++++++++++++++++++++++++++++++++++++
 include/hw/m68k/next-cube.h |   2 +
 3 files changed, 294 insertions(+)
 create mode 100644 hw/m68k/next-kbd.c
hw/m68k/Makefile.objs +1 -0
index 482f8477b4..688002cac1 100644
@@ -1,2 +1,3 @@
 obj-$(CONFIG_AN5206) += an5206.o mcf5206.o
 obj-$(CONFIG_MCF5208) += mcf5208.o mcf_intc.o
+obj-$(CONFIG_NEXTCUBE) += next-kbd.o
hw/m68k/next-kbd.c new file +291 -0

291 lines not on this page · raw message

include/hw/m68k/next-cube.h +2 -0
index 090c7c51aa..37f7ce3e34 100644
@@ -4,4 +4,6 @@
 
 #define TYPE_NEXTFB "next-fb"
 
+#define TYPE_NEXTKBD "next-kbd"
+
 #endif /* NEXT_CUBE_H */
Signature · 1 line
2.21.0
#8 lore raw

[Qemu-devel] [PULL 6/8] m68k: Add an entry for the NeXTcube machine to the MAINTAINERS file

In reply to Thomas Huth

I don't have much clue about the NeXT hardware, but at least I know now the source files a little bit, so I volunteer to pick up patches and send PULL requests for them until someone else with more knowledge steps up to do this job instead.

Message-Id: <[email protected]>

---
 MAINTAINERS | 7 +++++++
 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
index 65d8a7c2d2..50eaf005f4 100644
@@ -910,6 +910,13 @@ F: hw/char/mcf_uart.c
 F: hw/net/mcf_fec.c
 F: include/hw/m68k/mcf*.h
 
+NeXTcube
+M: Thomas Huth <[email protected]>
+S: Odd Fixes
+F: hw/m68k/next-*.c
+F: hw/display/next-fb.c
+F: include/hw/m68k/next-cube.h
+
 MicroBlaze Machines
 -------------------
 petalogix_s3adsp1800
Signature · 1 line
2.21.0
#9 lore raw

[Qemu-devel] [PULL 5/8] m68k: Add serial controller to the NeXTcube machine

In reply to Thomas Huth

The NeXTcube uses a normal 8530 serial controller, so we can simply use our normal "escc" device here.
While we're at it, also add a boot-serial-test for the next-cube machine, now that the serial output works.

Message-Id: <[email protected]>

---
 hw/m68k/Kconfig          |  1 +
 hw/m68k/next-cube.c      | 41 ++++++++++++++++++++++++++++++++++++++--
 tests/boot-serial-test.c | 12 ++++++++++++
 3 files changed, 52 insertions(+), 2 deletions(-)
hw/m68k/Kconfig +1 -0
index ec58a2eb06..a74fac5abd 100644
@@ -11,3 +11,4 @@ config MCF5208
 config NEXTCUBE
     bool
     select FRAMEBUFFER
+    select ESCC
hw/m68k/next-cube.c +39 -2

70 lines not on this page · raw message

tests/boot-serial-test.c +12 -0
index a54d007298..d3a54a0ba5 100644
@@ -24,6 +24,17 @@ static const uint8_t kernel_mcf5208[] = {
     0x60, 0xfa                              /* bra.s  loop */
 };
 
+static const uint8_t bios_nextcube[] = {
+    0x06, 0x00, 0x00, 0x00,                 /* Initial SP */
+    0x01, 0x00, 0x00, 0x08,                 /* Initial PC */
+    0x41, 0xf9, 0x02, 0x11, 0x80, 0x00,     /* lea 0x02118000,%a0 */
+    0x10, 0x3c, 0x00, 0x54,                 /* move.b #'T',%d0 */
+    0x11, 0x7c, 0x00, 0x05, 0x00, 0x01,     /* move.b #5,1(%a0)    Sel TXCTRL */
+    0x11, 0x7c, 0x00, 0x68, 0x00, 0x01,     /* move.b #0x68,1(%a0) Enable TX */
+    0x11, 0x40, 0x00, 0x03,                 /* move.b %d0,3(%a0)   Print 'T' */
+    0x60, 0xfa                              /* bra.s  loop */
+};
+
 static const uint8_t kernel_pls3adsp1800[] = {
     0xb0, 0x00, 0x84, 0x00,                 /* imm   0x8400 */
     0x30, 0x60, 0x00, 0x04,                 /* addik r3,r0,4 */
@@ -117,6 +128,7 @@ static testdef_t tests[] = {
     { "sparc64", "sun4u", "", "UltraSPARC" },
     { "s390x", "s390-ccw-virtio", "", "device" },
     { "m68k", "mcf5208evb", "", "TT", sizeof(kernel_mcf5208), kernel_mcf5208 },
+    { "m68k", "next-cube", "", "TT", sizeof(bios_nextcube), 0, bios_nextcube },
     { "microblaze", "petalogix-s3adsp1800", "", "TT",
       sizeof(kernel_pls3adsp1800), kernel_pls3adsp1800 },
     { "microblazeel", "petalogix-ml605", "", "TT",
Signature · 1 line
2.21.0
#10 lore raw

[Qemu-devel] [PULL 7/8] tests/acceptance: Add test of NeXTcube framebuffer using OCR

In reply to Thomas Huth

From: Philippe Mathieu-Daudé <[email protected]>

Add a test of the NeXTcube framebuffer using the Tesseract OCR engine on a screenshot of the framebuffer device.

The test is very quick:

  $ avocado --show=app,console run tests/acceptance/machine_m68k_nextcube.py
  JOB ID     : 78844a92424cc495bd068c3874d542d1e20f24bc
  JOB LOG    : /home/phil/avocado/job-results/job-2019-08-13T13.16-78844a9/job.log
   (1/3) tests/acceptance/machine_m68k_nextcube.py:NextCubeMachine.test_bootrom_framebuffer_size: PASS (2.16 s)
   (2/3) tests/acceptance/machine_m68k_nextcube.py:NextCubeMachine.test_bootrom_framebuffer_ocr_with_tesseract_v3: -
  ue r pun Honl'flx ; 5‘ 55‘
  avg ncaaaaa 25 MHZ, memary jag m
  Backplane slat «a
  Ethernet address a a r a r3 2
  Memgry sackets aea canflqured far 16MB Darlly page made stMs but have 16MB page made stMs )nstalled
  Memgry sackets a and 1 canflqured far 16MB Darlly page made stMs but have 16MB page made stMs )nstalled
  [...]
  Yestlnq the rpu, 5::
  system test raneg Errar egge 51
  Egg: cammand
  Default pggc devlce nut fauna
  NEXY>I
  PASS (2.64 s)
   (3/3) tests/acceptance/machine_m68k_nextcube.py:NextCubeMachine.test_bootrom_framebuffer_ocr_with_tesseract_v4: SKIP: tesseract v4 OCR tool not available
  RESULTS    : PASS 2 | ERROR 0 | FAIL 0 | SKIP 1 | WARN 0 | INTERRUPT 0 | CANCEL 0
  JOB TIME   : 5.35 s

Documentation on how to install tesseract:
https://github.com/tesseract-ocr/tesseract/wiki#installation

Message-Id: <[email protected]>

---
 tests/acceptance/machine_m68k_nextcube.py | 121 ++++++++++++++++++++++
 1 file changed, 121 insertions(+)
 create mode 100644 tests/acceptance/machine_m68k_nextcube.py
tests/acceptance/machine_m68k_nextcube.py new file +121 -0
new file mode 100644
index 0000000000..e09cab9f20
@@ -0,0 +1,121 @@
+# Functional test that boots a VM and run OCR on the framebuffer
+#
+# Copyright (c) Philippe Mathieu-Daudé <[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.
+
+import os
+import re
+import time
+import logging
+import distutils.spawn
+
+from avocado_qemu import Test
+from avocado import skipUnless
+from avocado.utils import process
+from avocado.utils.path import find_command, CmdNotFoundError
+
+PIL_AVAILABLE = True
+try:
+    from PIL import Image
+except ImportError:
+    PIL_AVAILABLE = False
+
+
+def tesseract_available(expected_version):
+    try:
+        find_command('tesseract')
+    except CmdNotFoundError:
+        return False
+    res = process.run('tesseract --version')
+    try:
+        version = res.stdout_text.split()[1]
+    except IndexError:
+        version = res.stderr_text.split()[1]
+    return int(version.split('.')[0]) == expected_version
+
+    match = re.match(r'tesseract\s(\d)', res)
+    if match is None:
+        return False
+    # now this is guaranteed to be a digit
+    return int(match.groups()[0]) == expected_version
+
+
+class NextCubeMachine(Test):
+
+    timeout = 15
+
+    def check_bootrom_framebuffer(self, screenshot_path):
+        rom_url = ('http://www.nextcomputers.org/NeXTfiles/Software/ROM_Files/'
+                   '68040_Non-Turbo_Chipset/Rev_2.5_v66.BIN')
+        rom_hash = 'b3534796abae238a0111299fc406a9349f7fee24'
+        rom_path = self.fetch_asset(rom_url, asset_hash=rom_hash)
+
+        self.vm.set_machine('next-cube')
+        self.vm.add_args('-bios', rom_path)
+        self.vm.launch()
+
+        self.log.info('VM launched, waiting for display')
+        # TODO: Use avocado.utils.wait.wait_for to catch the
+        #       'displaysurface_create 1120x832' trace-event.
+        time.sleep(2)
+
+        self.vm.command('human-monitor-command',
+                        command_line='screendump %s' % screenshot_path)
+
+    @skipUnless(PIL_AVAILABLE, 'Python PIL not installed')
+    def test_bootrom_framebuffer_size(self):
+        """
+        :avocado: tags=arch:m68k
+        :avocado: tags=machine:next_cube
+        :avocado: tags=device:framebuffer
+        """
+        screenshot_path = os.path.join(self.workdir, "dump.png")
+        self.check_bootrom_framebuffer(screenshot_path)
+
+        width, height = Image.open(screenshot_path).size
+        self.assertEqual(width, 1120)
+        self.assertEqual(height, 832)
+
+    @skipUnless(tesseract_available(3), 'tesseract v3 OCR tool not available')
+    def test_bootrom_framebuffer_ocr_with_tesseract_v3(self):
+        """
+        :avocado: tags=arch:m68k
+        :avocado: tags=machine:next_cube
+        :avocado: tags=device:framebuffer
+        """
+        screenshot_path = os.path.join(self.workdir, "dump.png")
+        self.check_bootrom_framebuffer(screenshot_path)
+
+        console_logger = logging.getLogger('console')
+        text = process.run("tesseract %s stdout" % screenshot_path).stdout_text
+        for line in text.split('\n'):
+            if len(line):
+                console_logger.debug(line)
+        self.assertIn('Backplane', text)
+        self.assertIn('Ethernet address', text)
+
+    # Tesseract 4 adds a new OCR engine based on LSTM neural networks. The
+    # new version is faster and more accurate than version 3. The drawback is
+    # that it is still alpha-level software.
+    @skipUnless(tesseract_available(4), 'tesseract v4 OCR tool not available')
+    def test_bootrom_framebuffer_ocr_with_tesseract_v4(self):
+        """
+        :avocado: tags=arch:m68k
+        :avocado: tags=machine:next_cube
+        :avocado: tags=device:framebuffer
+        """
+        screenshot_path = os.path.join(self.workdir, "dump.png")
+        self.check_bootrom_framebuffer(screenshot_path)
+
+        console_logger = logging.getLogger('console')
+        proc = process.run("tesseract --oem 1 %s stdout" % screenshot_path)
+        text = proc.stdout_text
+        for line in text.split('\n'):
+            if len(line):
+                console_logger.debug(line)
+        self.assertIn('Testing the FPU, SCC', text)
+        self.assertIn('System test failed. Error code 51', text)
+        self.assertIn('Boot command', text)
+        self.assertIn('Next>', text)
Signature · 1 line
2.21.0
#11 lore raw

Re: [Qemu-devel] [PULL 7/8] tests/acceptance: Add test of NeXTcube framebuffer using OCR

Quoted 8 lines · Thomas Huth

From: Philippe Mathieu-Daudé <[email protected]>

Add a test of the NeXTcube framebuffer using the Tesseract OCR engine on a screenshot of the framebuffer device.

The test is very quick:

Quoted 10 lines
  $ avocado --show=app,console run tests/acceptance/machine_m68k_nextcube.py
  JOB ID     : 78844a92424cc495bd068c3874d542d1e20f24bc
  JOB LOG    : /home/phil/avocado/job-results/job-2019-08-13T13.16-78844a9/job.log
   (1/3) tests/acceptance/machine_m68k_nextcube.py:NextCubeMachine.test_bootrom_framebuffer_size: PASS (2.16 s)
   (2/3) tests/acceptance/machine_m68k_nextcube.py:NextCubeMachine.test_bootrom_framebuffer_ocr_with_tesseract_v3: -
  ue r pun Honl'flx ; 5‘ 55‘
  avg ncaaaaa 25 MHZ, memary jag m
  Backplane slat «a
  Ethernet address a a r a r3 2
  Memgry sackets aea canflqured far 16MB Darlly page made stMs but have 16MB page made stMs )nstalled

By the way, do we know why the output from this test case is garbled like this ? It suggests that something's not right somewhere...

thanks
-- PMM

#12 lore raw

Re: [Qemu-devel] [PULL 7/8] tests/acceptance: Add test of NeXTcube framebuffer using OCR

Quoted 20 lines · Peter Maydell
Quoted 8 lines · Thomas Huth

From: Philippe Mathieu-Daudé <[email protected]>

Add a test of the NeXTcube framebuffer using the Tesseract OCR engine on a screenshot of the framebuffer device.

The test is very quick:

Quoted 10 lines
  $ avocado --show=app,console run tests/acceptance/machine_m68k_nextcube.py
  JOB ID     : 78844a92424cc495bd068c3874d542d1e20f24bc
  JOB LOG    : /home/phil/avocado/job-results/job-2019-08-13T13.16-78844a9/job.log
   (1/3) tests/acceptance/machine_m68k_nextcube.py:NextCubeMachine.test_bootrom_framebuffer_size: PASS (2.16 s)
   (2/3) tests/acceptance/machine_m68k_nextcube.py:NextCubeMachine.test_bootrom_framebuffer_ocr_with_tesseract_v3: -
  ue r pun Honl'flx ; 5‘ 55‘
  avg ncaaaaa 25 MHZ, memary jag m
  Backplane slat «a
  Ethernet address a a r a r3 2
  Memgry sackets aea canflqured far 16MB Darlly page made stMs but have 16MB page made stMs )nstalled
Quoted 3 lines

By the way, do we know why the output from this test case is garbled like this ? It suggests that something's not right somewhere...

The text is created from the framebuffer with the OCR-tool Tesseract - which is just not good enough to recognize all words properly here.

Thomas

#13 lore raw

Re: [Qemu-devel] [PULL 7/8] tests/acceptance: Add test of NeXTcube framebuffer using OCR

Quoted 21 lines · Thomas Huth
Quoted 20 lines · Peter Maydell
Quoted 18 lines · Thomas Huth

From: Philippe Mathieu-Daudé <[email protected]>

Add a test of the NeXTcube framebuffer using the Tesseract OCR engine on a screenshot of the framebuffer device.

The test is very quick:

  $ avocado --show=app,console run tests/acceptance/machine_m68k_nextcube.py
  JOB ID     : 78844a92424cc495bd068c3874d542d1e20f24bc
  JOB LOG    : /home/phil/avocado/job-results/job-2019-08-13T13.16-78844a9/job.log
   (1/3) tests/acceptance/machine_m68k_nextcube.py:NextCubeMachine.test_bootrom_framebuffer_size: PASS (2.16 s)
   (2/3) tests/acceptance/machine_m68k_nextcube.py:NextCubeMachine.test_bootrom_framebuffer_ocr_with_tesseract_v3: -
  ue r pun Honl'flx ; 5‘ 55‘
  avg ncaaaaa 25 MHZ, memary jag m
  Backplane slat «a
  Ethernet address a a r a r3 2
  Memgry sackets aea canflqured far 16MB Darlly page made stMs but have 16MB page made stMs )nstalled
Quoted 3 lines
Quoted 3 lines

By the way, do we know why the output from this test case is garbled like this ? It suggests that something's not right somewhere...

I got better result using few options to tune, but later noticed they differ on Fedora/Ubuntu.
Tesseract v4 has better result but it is alpha and we need to install train data. Not that big, 15MiB:
https://github.com/tesseract-ocr/tessdata_best/blob/master/eng.traineddata
I preferred to keep the simplest tests with acceptable result, we are not interested in fully understandable text output: we only want to know the framebuffer model works. Reading "Ethernet address" is good and quick enough.

Quoted 5 lines

The text is created from the framebuffer with the OCR-tool Tesseract - which is just not good enough to recognize all words properly here.

Thomas

#14 lore raw
In reply to Thomas Huth
Quoted 11 lines · Thomas Huth

Hi Peter,

the following changes since commit 90b1e3afd33226b6078fec6d77a18373712a975c:

Merge remote-tracking branch 'remotes/huth-gitlab/tags/pull-request-2019-09-05-v2' into staging (2019-09-05 17:09:13 +0100)

are available in the Git repository at:

https://gitlab.com/huth/qemu.git tags/m68k-pull-2019-09-07

Quoted 7 lines

for you to fetch changes up to 25311649592f5584b1e1012d69c7327ef87473f4:

.travis.yml: Let the avocado job run the NeXTcube tests (2019-09-07 08:35:41 +0200)

----------------------------------------------------------------
Add the m68k next-cube machine
----------------------------------------------------------------

Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/4.2
for any user-visible changes.

-- PMM