mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Stefan Kerkmann <s.kerkmann@pengutronix.de>,
	Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 2/4] test: py: add FIT boot test
Date: Thu, 12 Jun 2025 10:56:01 +0200	[thread overview]
Message-ID: <20250612085603.4190573-3-a.fatoum@barebox.org> (raw)
In-Reply-To: <20250612085603.4190573-1-a.fatoum@barebox.org>

This test verifies that FIT image can be booted and device tree is fixed
up with command line, initrd location, generic and custom fixups.

It already caught a regression in next that broke initrd loading on
ARM64 & RISC-V.

Cc: Stefan Kerkmann <s.kerkmann@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 test/arm/virt@multi_v7_defconfig.yaml |  1 +
 test/arm/virt@multi_v8_defconfig.yaml |  1 +
 test/py/helper.py                     | 15 +++++++
 test/py/test_fit.py                   | 63 +++++++++++++++++++++++++++
 4 files changed, 80 insertions(+)
 create mode 100644 test/py/test_fit.py

diff --git a/test/arm/virt@multi_v7_defconfig.yaml b/test/arm/virt@multi_v7_defconfig.yaml
index 203f17bfc7f0..637d132d3967 100644
--- a/test/arm/virt@multi_v7_defconfig.yaml
+++ b/test/arm/virt@multi_v7_defconfig.yaml
@@ -14,6 +14,7 @@ targets:
       BareboxTestStrategy: {}
     features:
       - virtio-mmio
+      - testfs
 images:
   barebox-dt-2nd.img: !template "$LG_BUILDDIR/images/barebox-dt-2nd.img"
 imports:
diff --git a/test/arm/virt@multi_v8_defconfig.yaml b/test/arm/virt@multi_v8_defconfig.yaml
index 42ce10328d7c..d018af06aa53 100644
--- a/test/arm/virt@multi_v8_defconfig.yaml
+++ b/test/arm/virt@multi_v8_defconfig.yaml
@@ -15,6 +15,7 @@ targets:
     features:
       - virtio-mmio
       - network
+      - testfs
     runner:
       tuxmake_arch: arm64
 images:
diff --git a/test/py/helper.py b/test/py/helper.py
index 4a68e83669ba..cfcc9c337fec 100644
--- a/test/py/helper.py
+++ b/test/py/helper.py
@@ -30,6 +30,21 @@ def get_config(command):
     return options
 
 
+def of_get_property(barebox, path):
+    node, prop = os.path.split(path)
+
+    stdout = barebox.run_check(f"of_dump -p {node}")
+    for line in stdout:
+        if line == '{prop};':
+            return True
+
+        prefix = f'{prop} = '
+        if line.startswith(prefix):
+            # Also drop the semicolon
+            return line[len(prefix):-1]
+    return False
+
+
 def skip_disabled(config, *options):
     if bool(config):
         undefined = list(filterfalse(config.__contains__, options))
diff --git a/test/py/test_fit.py b/test/py/test_fit.py
new file mode 100644
index 000000000000..c53a1ece1445
--- /dev/null
+++ b/test/py/test_fit.py
@@ -0,0 +1,63 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+import re
+import pytest
+from .helper import of_get_property
+
+
+def fit_name(suffix):
+    return f"/mnt/9p/testfs/barebox-{suffix}.fit"
+
+
+def generate_bootscript(barebox, image, name="test"):
+    barebox.run_check(f"echo -o /env/boot/{name} '#!/bin/sh'")
+    barebox.run_check(f"echo -a /env/boot/{name}  bootm {image}")
+    return name
+
+
+def test_fit(barebox, env, target, barebox_config):
+    if 'testfs' not in env.get_target_features():
+        pytest.xfail("testfs feature not specified")
+
+    _, _, returncode = barebox.run("ls /mnt/9p/testfs")
+    if returncode != 0:
+        pytest.xfail("skipping test due to missing --fs testfs=")
+
+    barebox.run_check(f"ls {fit_name('gzipped')}")
+
+    # Sanity check, this is only fixed up on first boot
+    assert of_get_property(barebox, "/chosen/barebox-version") is False
+    [ver] = barebox.run_check("echo barebox-$global.version")
+    assert ver.startswith('barebox-2')
+
+    barebox.run_check("of_property -s /chosen barebox,boot-count '<0x0>'")
+    assert of_get_property(barebox, "/chosen/barebox,boot-count") == '<0x0>'
+
+    barebox.run_check("of_property -fs /chosen barebox,boot-count '<0x1>'")
+    assert of_get_property(barebox, "/chosen/barebox,boot-count") == '<0x0>'
+
+    barebox.run_check("global linux.bootargs.testarg=barebox.chainloaded")
+
+    boottarget = generate_bootscript(barebox, fit_name('gzipped'))
+    barebox.boot(boottarget)
+    target.deactivate(barebox)
+    target.activate(barebox)
+
+    assert of_get_property(barebox, "/chosen/barebox-version") == f'"{ver}"', \
+           "/chosen/barebox-version suggests we did not chainload"
+
+    assert of_get_property(barebox, "/chosen/barebox,boot-count") == '<0x1>', \
+           "/chosen/barebox,boot-count suggests we got bultin DT"
+
+    # Check that command line arguments were fixed up
+    bootargs = of_get_property(barebox, "/chosen/bootargs")
+    assert "barebox.chainloaded" in bootargs
+
+    initrd_start = of_get_property(barebox, "/chosen/linux,initrd-start")
+    initrd_end = of_get_property(barebox, "/chosen/linux,initrd-end")
+
+    addr_regex = r"<(0x[0-9a-f]{1,8} ?)+>"
+    assert re.search(addr_regex, initrd_start), \
+        f"initrd start {initrd_start} malformed"
+    assert re.search(addr_regex, initrd_end), \
+        f"initrd end {initrd_end} malformed"
-- 
2.39.5




  parent reply	other threads:[~2025-06-12 10:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-12  8:55 [PATCH 0/4] test: py: add FIT image " Ahmad Fatoum
2025-06-12  8:56 ` [PATCH 1/4] ci: pytest: mount virtfs with signed FIT image into VMs Ahmad Fatoum
2025-06-12  8:56 ` Ahmad Fatoum [this message]
2025-06-12  8:56 ` [PATCH 3/4] ci: pytest: multi_v8_defconfig: pass --runxfail Ahmad Fatoum
2025-06-12  8:56 ` [PATCH 4/4] ci: container: add device-tree-compiler Ahmad Fatoum
2025-06-17  7:29 ` [PATCH 0/4] test: py: add FIT image boot test Sascha Hauer

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=20250612085603.4190573-3-a.fatoum@barebox.org \
    --to=a.fatoum@barebox.org \
    --cc=barebox@lists.infradead.org \
    --cc=s.kerkmann@pengutronix.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox