test: Add framebuffer test
cover test: Add framebuffer test
QEMU allows taking screenshots of screen. Make use of this to enable doing some rudimentary graphic tests.
Ahmad Fatoum (7):
ARM: multi_v8_defconfig: enable QEMU ramfb driver
test: enable VirtIO keyboard
commands: fbtest: add flush for single pattern
test: conftest: don't call .startswith on int
test: conftest: set -display none when non-interactive
test: conftest: add qemu feature
test: add framebuffer screenshot testing via QMP screendump
arch/arm/configs/multi_v8_defconfig | 1 + commands/fbtest.c | 1 + conftest.py | 37 +++++++------- test/arm/virt@multi_v8_defconfig.yaml | 2 + test/py/helper.py | 53 +++++++++++++++++++ test/py/test_fbtest.py | 74 +++++++++++++++++++++++++++ 6 files changed, 149 insertions(+), 19 deletions(-) create mode 100644 test/py/test_fbtest.py
Signature · 1 line
2.47.3
PATCH 1/7 ARM: multi_v8_defconfig: enable QEMU ramfb driver
Enable CONFIG_DRIVER_VIDEO_RAMFB so that barebox can drive the QEMU ramfb display device. All dependencies (CONFIG_VIDEO, CONFIG_QEMU_FW_CFG, CONFIG_FS_QEMU_FW_CFG) are already enabled.
This will allow framebuffer testing with --graphics on the QEMU Virt platform later.
--- arch/arm/configs/multi_v8_defconfig | 1 + test/arm/virt@multi_v8_defconfig.yaml | 2 ++ 2 files changed, 3 insertions(+)
arch/arm/configs/multi_v8_defconfig +1 -0
@@ -222,6 +222,7 @@ CONFIG_USB_GADGET_MASS_STORAGE=y CONFIG_VIDEO=y CONFIG_FRAMEBUFFER_CONSOLE=y CONFIG_DRIVER_VIDEO_BOCHS_PCI=y +CONFIG_DRIVER_VIDEO_RAMFB=y CONFIG_SOUND=y CONFIG_MCI=y CONFIG_MCI_MMC_BOOT_PARTITIONS=y
test/arm/virt@multi_v8_defconfig.yaml +2 -0
@@ -17,6 +17,8 @@ targets: - network - barebox-state - testfs + env: + nv/dev.fb0.enable: 1 images: barebox-qemu-virt.img: !template "$LG_BUILDDIR/images/barebox-qemu-virt.img" imports:
Signature · 1 line
2.47.3
PATCH 2/7 test: enable VirtIO keyboard
In reply to Ahmad FatoumThe QEMU ARM64 Virt machine has no input method by default. As we already had VirtIO input for the web demo, enable it when --graphic is enabled.
The barebox VirtIO input driver was ported from Linux and both support only VirtIO v1 devices, so we need to explicitly set virtio-mmio.force-legacy=false for this to work.
--- conftest.py | 2 ++ 1 file changed, 2 insertions(+)
conftest.py +2 -0
@@ -175,6 +175,7 @@ def strategy(request, target, pytestconfig): # noqa: max-complexity=30 if "virtio-mmio" in features: virtio = "device" + strategy.append_qemu_args('-global virtio-mmio.force-legacy=false') if "virtio-pci" in features: virtio = "pci,disable-modern=off" features.append("pci")
@@ -210,6 +211,7 @@ def strategy(request, target, pytestconfig): # noqa: max-complexity=30 graphics = '-device VGA' elif virtio: graphics = '-vga none -device ramfb' + graphics += f' -device virtio-keyboard-{virtio}' else: pytest.exit("--graphics unsupported for target\n", 1)
Signature · 1 line
2.47.3
PATCH 3/7 commands: fbtest: add flush for single pattern
In reply to Ahmad FatoumThe single-pattern else-branch calls gu_screen_blit() to copy the render buffer to the framebuffer in-memory image, but never called fb_flush() to make sure the image makes it to display RAM.
Add fb_flush(sc->info) after gu_screen_blit(), matching the cycling path above.
--- commands/fbtest.c | 1 + 1 file changed, 1 insertion(+)
commands/fbtest.c +1 -0
@@ -297,6 +297,7 @@ static int do_fbtest(int argc, char *argv[]) }else {pattern (sc, color);gu_screen_blit (sc); +fb_flush (sc->info); } done:fb_close (sc);
Signature · 1 line
2.47.3
PATCH 4/7 test: conftest: don't call .startswith on int
In reply to Ahmad FatoumThe returned YAML value may be an integer if quotes are missing, which will lead to an error when .startswith() is called on it.
Check that the value is a string first and while at it, combine the two loops to reduce the duplicate code.
--- conftest.py | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-)
conftest.py +9 -17
@@ -226,25 +226,17 @@ def strategy(request, target, pytestconfig): # noqa: max-complexity=30 else: pytest.exit("--blk unsupported for target\n", 1) + envopts = {} + for i, fw_cfg in enumerate(pytestconfig.option.qemu_fw_cfg): + value = fw_cfg.pop() + envpath = fw_cfg.pop() if fw_cfg else f"data/fw_cfg{i}" + + envopts[envpath] = value + + for envpath, value in (yaml_env | envopts).items(): if virtio: - value = fw_cfg.pop() - envpath = fw_cfg.pop() if fw_cfg else f"data/fw_cfg{i}" - - if value.startswith('@'): - source = f"file='{value[1:]}'" - else: - source = f"string='{value}'" - - strategy.append_qemu_args( - '-fw_cfg', f'name=opt/org.barebox.env/{envpath},{source}' - ) - else: - pytest.exit("--env unsupported for target\n", 1) - - for envpath, value in yaml_env.items(): - if virtio: - if value.startswith('@'): + if isinstance(value, str) and value.startswith('@'): source = f"file='{value[1:]}'" else: source = f"string='{value}'"
Signature · 1 line
2.47.3
PATCH 5/7 test: conftest: set -display none when non-interactive
In reply to Ahmad FatoumWhen running QEMU with --graphic, but in a non graphical session, running QEMU may fail because it fails to start e.g. the GTK window.
Allow headless tests for these configurations by adding -display none.
--- conftest.py | 4 ++++ 1 file changed, 4 insertions(+)
conftest.py +4 -0
@@ -215,6 +215,10 @@ def strategy(request, target, pytestconfig): # noqa: max-complexity=30 else: pytest.exit("--graphics unsupported for target\n", 1) + if graphics is not None and \ + pytestconfig.option.lg_initial_state != 'qemu_interactive': + graphics += ' -display none' + strategy.append_qemu_args(graphics) for i, blk in enumerate(pytestconfig.option.qemu_block):
Signature · 1 line
2.47.3
PATCH 6/7 test: conftest: add qemu feature
In reply to Ahmad FatoumThis will allow skipping tests that explicitly require qemu features, like the incoming screendump in the grpahical tests.
--- conftest.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
conftest.py +3 -2
@@ -168,8 +168,9 @@ def strategy(request, target, pytestconfig): # noqa: max-complexity=30 try: main = target.env.config.data["targets"]["main"] qemu_bin = main["drivers"]["QEMUDriver"]["qemu_bin"] + features.append("qemu") except KeyError: - qemu_bin = None + pass virtio = None
@@ -202,7 +203,7 @@ def strategy(request, target, pytestconfig): # noqa: max-complexity=30 else: pytest.exit("barebox currently supports only a single extra virtio console\n", 1) - if qemu_bin is not None: + if "qemu" in features: if not pytestconfig.option.qemu_graphics: graphics = '-nographic' elif qemu_bin == "qemu-system-x86_64":
Signature · 1 line
2.47.3
PATCH 7/7 test: add framebuffer screenshot testing via QMP screendump
In reply to Ahmad FatoumAdd screendump() and parse_ppm() helpers to capture and parse QEMU framebuffer screenshots using the QMP screendump command. Use them in a new test that draws a solid color with fbtest and verifies the pixels match. The test auto-skips when no framebuffer is available (e.g. without --graphics).
--- test/py/helper.py | 53 ++++++++++++++++++++++++++++++ test/py/test_fbtest.py | 74 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 test/py/test_fbtest.py
test/py/helper.py +53 -0
@@ -6,6 +6,7 @@ import os import re import shlex import subprocess +import tempfile def parse_config(lines):
@@ -200,6 +201,58 @@ def skip_disabled(config, *options): pytest.skip("skipping test due to disabled " + (",".join(undefined)) + " dependency") +def parse_ppm(path): + """Parse a PPM P6 (binary) image file. + + Returns (width, height, data) where data is bytes of RGB pixel values. + Pixel (x, y) starts at offset (y * width + x) * 3. + """ + with open(path, 'rb') as f: + magic = f.readline().strip() + assert magic == b'P6', f"Expected P6, got {magic}" + + line = f.readline() + while line.startswith(b'#'): + line = f.readline() + + width, height = map(int, line.split()) + maxval = int(f.readline().strip()) + assert maxval == 255 + + data = f.read() + expected = width * height * 3 + assert len(data) == expected, \ + f"Expected {expected} bytes, got {len(data)}" + + return width, height, data + + +def screendump(qemu, path=None): + """Capture a QEMU framebuffer screenshot via QMP screendump. + + Args: + qemu: A labgrid QEMUDriver instance. + path: Optional host path for the PPM file. If None, a temp file is used. + + Returns: + (width, height, data) tuple from parse_ppm(). + """ + if qemu is None: + pytest.skip("screendump requires a QEMU target") + + cleanup = path is None + if path is None: + fd, path = tempfile.mkstemp(suffix='.ppm') + os.close(fd) + + try: + qemu.monitor_command('screendump', {'filename': path}) + return parse_ppm(path) + finally: + if cleanup: + os.unlink(path) + + def ensure_debian_iso(env, destdir): """ Extract Debian kernel and initrd from ISO into destdir.
test/py/test_fbtest.py new file +74 -0
74 lines not on this page · raw message
Signature · 1 line
2.47.3
Sascha Hauer
AppliedQuoted 12 lines · Ahmad Fatoum
QEMU allows taking screenshots of screen. Make use of this to enable doing some rudimentary graphic tests.
Ahmad Fatoum (7):
ARM:multi_v8_defconfig: enable QEMU ramfb driver
test: enable VirtIO keyboard
commands: fbtest: add flush for single pattern
test: conftest: don't call .startswith on int
test: conftest: set -display none when non-interactive
test: conftest: add qemu feature
test: add framebuffer screenshot testing via QMP screendump
Quoted 1 line
[...]
Applied, thanks!
[1/7] ARM: multi_v8_defconfig: enable QEMU ramfb driver
https://git.pengutronix.de/cgit/barebox/commit/?id=1e1b3b66677a (link may not be stable)
[2/7] test: enable VirtIO keyboard
https://git.pengutronix.de/cgit/barebox/commit/?id=50c2aabc574b (link may not be stable)
[3/7] commands: fbtest: add flush for single pattern
https://git.pengutronix.de/cgit/barebox/commit/?id=af2a6133e535 (link may not be stable)
[4/7] test: conftest: don't call .startswith on int
https://git.pengutronix.de/cgit/barebox/commit/?id=80554888f677 (link may not be stable) [5/7] test: conftest: set -display none when non-interactive https://git.pengutronix.de/cgit/barebox/commit/?id=74693d62342f (link may not be stable)
[6/7] test: conftest: add qemu feature
https://git.pengutronix.de/cgit/barebox/commit/?id=af5b226aa085 (link may not be stable)
[7/7] test: add framebuffer screenshot testing via QMP screendump
https://git.pengutronix.de/cgit/barebox/commit/?id=3fb451e0110a (link may not be stable)
Best regards,
Signature · 1 line
Sascha Hauer <[email protected]>