[PATCH v1 3/3] test: fit: add test case for invalid default configuration reference
Aristo Chen
jj251510319013 at gmail.com
Tue Jul 15 04:52:54 CEST 2025
Recent changes to mkimage introduced a validation step to ensure that
the 'default' property under the /configurations node in a FIT image
references a valid configuration subnode. If the referenced node is
missing, mkimage will now return an error.
This patch adds a Python test case to verify that mkimage correctly
fails when the 'default' configuration does not exist. The test creates
a minimal ITS with an invalid default reference and checks that mkimage
produces the expected error message.
Signed-off-by: Aristo Chen <aristo.chen at canonical.com>
---
test/py/tests/test_fit_mkimage_validate.py | 45 ++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/test/py/tests/test_fit_mkimage_validate.py b/test/py/tests/test_fit_mkimage_validate.py
index af56f08ca10..ef974c8c762 100644
--- a/test/py/tests/test_fit_mkimage_validate.py
+++ b/test/py/tests/test_fit_mkimage_validate.py
@@ -7,6 +7,7 @@ import os
import subprocess
import pytest
import fit_util
+import re
@pytest.mark.boardspec('sandbox')
@pytest.mark.requiredtool('dtc')
@@ -56,3 +57,47 @@ def test_fit_invalid_image_reference(ubman):
assert result.returncode != 0, "mkimage should fail due to missing image reference"
assert "references undefined image 'notexist'" in result.stderr
+def test_fit_invalid_default_config(ubman):
+ """Test that mkimage fails when default config is missing"""
+
+ its_fname = fit_util.make_fname(ubman, "invalid.its")
+ itb_fname = fit_util.make_fname(ubman, "invalid.itb")
+ kernel = fit_util.make_kernel(ubman, 'kernel.bin', 'kernel')
+
+ # Write ITS with an invalid reference to a nonexistent default config
+ its_text = '''
+/dts-v1/;
+
+/ {
+ images {
+ kernel at 1 {
+ description = "Test Kernel";
+ data = /incbin/("kernel.bin");
+ type = "kernel";
+ arch = "sandbox";
+ os = "linux";
+ compression = "none";
+ load = <0x40000>;
+ entry = <0x40000>;
+ };
+ };
+
+ configurations {
+ default = "conf at 1";
+ conf at 2 {
+ kernel = "kernel at 1";
+ };
+ };
+};
+'''
+
+ with open(its_fname, 'w') as f:
+ f.write(its_text)
+
+ mkimage = os.path.join(ubman.config.build_dir, 'tools/mkimage')
+ cmd = [mkimage, '-f', its_fname, itb_fname]
+
+ result = subprocess.run(cmd, capture_output=True, text=True)
+
+ assert result.returncode != 0, "mkimage should fail due to missing default config"
+ assert re.search(r"Default configuration '.*' not found under /configurations", result.stderr)
--
2.43.0
More information about the U-Boot
mailing list