[PATCH v1 5/5] test: Add test case for FIT image load address overlap detection

Yannic Moog Y.Moog at phytec.de
Tue Aug 12 10:53:18 CEST 2025


Am Samstag, dem 09.08.2025 um 10:04 +0800 schrieb Aristo Chen:
> Yannic Moog <Y.Moog at phytec.de> 於 2025年7月31日 週四 下午7:48寫道:
> > 
> > Am Dienstag, dem 29.07.2025 um 12:48 +0000 schrieb Aristo Chen:
> > > Add a new test case to verify that mkimage properly detects and reports
> > > memory region overlaps in FIT image configurations.
> > > 
> > > The test creates a FIT image with kernel and FDT components that have
> > > the same load address (0x40000), which should trigger the overlap
> > > detection logic and cause mkimage to fail with an appropriate error
> > > message.
> > > 
> > > Test verifies:
> > > - mkimage returns non-zero exit code when overlap is detected
> > > - Error message contains "Error: Overlap detected:"
> > > - Error message identifies the specific overlapping components
> > >   (kernel at 1 and fdt at 1)
> > > 
> > > This test ensures the overlap detection feature works correctly and
> > > prevents deployment of FIT images with conflicting memory layouts
> > > that could cause runtime failures.
> > > 
> > > Signed-off-by: Aristo Chen <aristo.chen at canonical.com>
> > > ---
> > >  test/py/tests/test_fit_mkimage_validate.py | 65 ++++++++++++++++++++++
> > >  1 file changed, 65 insertions(+)
> > > 
> > > diff --git a/test/py/tests/test_fit_mkimage_validate.py
> > > b/test/py/tests/test_fit_mkimage_validate.py
> > > index ef974c8c762..51f7f64b257 100644
> > > --- a/test/py/tests/test_fit_mkimage_validate.py
> > > +++ b/test/py/tests/test_fit_mkimage_validate.py
> > > @@ -101,3 +101,68 @@ def test_fit_invalid_default_config(ubman):
> > > 
> > >      assert result.returncode != 0, "mkimage should fail due to missing
> > > default config"
> > >      assert re.search(r"Default configuration '.*' not found under
> > > /configurations", result.stderr)
> > > +
> > > +def test_fit_load_addr_overlap(ubman):
> > > +    """Test that mkimage fails when load address overlap"""
> > > +
> > > +    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')
> > > +    fdt = fit_util.make_dtb(ubman, '''
> > > +/dts-v1/;
> > > +/ {
> > > +    model = "Test FDT";
> > > +    compatible = "test";
> > > +};
> > > +''', 'test')
> > > +
> > > +    # 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>;
> > > +        };
> > > +        fdt at 1 {
> > > +            description = "Test FDT";
> > > +            data = /incbin/("test.dtb");
> > > +            type = "flat_dt";
> > > +            arch = "sandbox";
> > > +            os = "linux";
> > > +            compression = "none";
> > > +            load = <0x40000>;
> > > +            entry = <0x40000>;
> > > +        };
> > > +    };
> > > +
> > > +    configurations {
> > > +        default = "conf at 1";
> > > +        conf at 1 {
> > > +            kernel = "kernel at 1";
> > > +            fdt = "fdt at 1";
> > > +        };
> > > +    };
> > > +};
> > > +'''
> > 
> > Why do you create the dts here?
> > I think it is best to stay consistent: create a dts file and use existing
> > _DoReadFileDtb and the like for the test.
> If I understand correctly, _DoReadFileDtb is defined in
> tools/binman/ftest.py, and is only for binman related test.

That is correct. I misread the patch and thought this was a binman test, sorry.

> Also I found that in test/py/tests/test_fit.py, it also defined a dts
> file in itself, what is the best practice to create dts file?

I am not sure if there is a best practice. I think for the mkimage and test_fit
files, the file size is not large enough so that anyone bothered to outsource
the dts definition.

With that in mind, maybe the long-term solution is to use the same mechanism
that binman tests use to avoid files growing to large. Afaik you would be able
to reuse the function even though you only need mkimage and not binman.

For your patch however, I think it is fine they way you implemented it.

> > 


More information about the U-Boot mailing list