[PATCH v3 4/4] test: py: add mkimage test for undefined image references in FIT configs
Aristo Chen
jj251510319013 at gmail.com
Wed May 21 08:27:45 CEST 2025
Add a test case to verify that mkimage correctly rejects a FIT source
that references a non-existent image from a configuration node.
This test introduces a minimal ITS that defines a valid kernel image
but references a missing "fdt" image under the /configurations section.
The test asserts that mkimage fails with a clear error message, as
introduced in the new validation logic.
This helps ensure the validation logic behaves correctly and prevents
regressions in future FIT enhancements.
Signed-off-by: Aristo Chen <aristo.chen at canonical.com>
---
test/py/tests/test_fit_mkimage_validate.py | 58 ++++++++++++++++++++++
1 file changed, 58 insertions(+)
create mode 100644 test/py/tests/test_fit_mkimage_validate.py
diff --git a/test/py/tests/test_fit_mkimage_validate.py b/test/py/tests/test_fit_mkimage_validate.py
new file mode 100644
index 00000000000..af56f08ca10
--- /dev/null
+++ b/test/py/tests/test_fit_mkimage_validate.py
@@ -0,0 +1,58 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (c) 2025
+#
+# Test that mkimage validates image references in configurations
+
+import os
+import subprocess
+import pytest
+import fit_util
+
+ at pytest.mark.boardspec('sandbox')
+ at pytest.mark.requiredtool('dtc')
+def test_fit_invalid_image_reference(ubman):
+ """Test that mkimage fails when configuration references a missing image"""
+
+ 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 image
+ 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 1 {
+ kernel = "kernel at 1";
+ fdt = "notexist";
+ };
+ };
+};
+'''
+
+ 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 image reference"
+ assert "references undefined image 'notexist'" in result.stderr
+
--
2.43.0
More information about the U-Boot
mailing list