From: Simon Glass <simon.glass@canonical.com> Add a test to verify that fit_print_contents() correctly handles a FIT image with a missing description property. To handle this a new FIT created with the description removed after mkimage has processed it, since mkimage will fail if the description is missing. Co-developed-by: Claude <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- test/boot/fit_print.c | 32 ++++++++++++++++++++++++ test/py/tests/test_fit_print.py | 43 +++++++++++++++++++++++++++------ 2 files changed, 68 insertions(+), 7 deletions(-) diff --git a/test/boot/fit_print.c b/test/boot/fit_print.c index 856cbfc6613..8e8d81e7f6b 100644 --- a/test/boot/fit_print.c +++ b/test/boot/fit_print.c @@ -158,3 +158,35 @@ static int test_fit_print_norun(struct unit_test_state *uts) return 0; } BOOTSTD_TEST(test_fit_print_norun, UTF_CONSOLE | UTF_MANUAL); + +/* Test fit_print_contents() with missing FIT description */ +static int test_fit_print_no_desc_norun(struct unit_test_state *uts) +{ + char fname[256]; + void *fit; + void *buf; + ulong addr; + int size; + + /* Load the FIT created by the Python test (with deleted description) */ + ut_assertok(os_persistent_file(fname, sizeof(fname), + "test-fit-nodesc.fit")); + ut_assertok(os_read_file(fname, &buf, &size)); + + /* Copy to address 0x10000 and print from there */ + addr = 0x10000; + fit = map_sysmem(addr, size); + memcpy(fit, buf, size); + + /* Print it and check just the first line */ + console_record_reset_enable(); + fit_print_contents(fit); + + /* Check the first line shows unavailable */ + ut_assert_nextline(" FIT description: unavailable"); + + os_free(buf); + + return 0; +} +BOOTSTD_TEST(test_fit_print_no_desc_norun, UTF_CONSOLE | UTF_MANUAL); diff --git a/test/py/tests/test_fit_print.py b/test/py/tests/test_fit_print.py index 25fada7d468..0ab8c0d4769 100644 --- a/test/py/tests/test_fit_print.py +++ b/test/py/tests/test_fit_print.py @@ -134,12 +134,14 @@ PRINT_ITS = ''' }; ''' -@pytest.mark.boardspec('sandbox') -@pytest.mark.buildconfigspec('fit_print') -@pytest.mark.requiredtool('dtc') -@pytest.mark.requiredtool('openssl') -def test_fit_print(ubman): - """Test fit_print_contents() via C unit test""" +def build_test_fit(ubman, fit): + """Build a test FIT image with all components + + Args: + ubman (ConsoleBase): U-Boot manager object + fit (str): Path where the FIT file should be created + """ + # pylint: disable=too-many-locals mkimage = os.path.join(ubman.config.build_dir, 'tools/mkimage') # Create test files (make kernel ~6.3K) @@ -189,7 +191,6 @@ def test_fit_print(ubman): } env = os.environ.copy() env['SOURCE_DATE_EPOCH'] = '1234567890' # 2009-02-13 23:31:30 UTC - fit = os.path.join(ubman.config.persistent_data_dir, 'test-fit.fit') its = fit_util.make_its(ubman, PRINT_ITS, params) utils.run_and_log(ubman, [mkimage, '-f', its, fit], env=env) @@ -247,7 +248,35 @@ S0n8gbs0Ht/ZckLk8mPclbk= utils.run_and_log(ubman, ['fdtput', '-d', fit, '/images/script/hash-1', 'algo']) + +@pytest.mark.boardspec('sandbox') +@pytest.mark.buildconfigspec('fit_print') +@pytest.mark.requiredtool('dtc') +@pytest.mark.requiredtool('openssl') +def test_fit_print(ubman): + """Test fit_print_contents() via C unit test""" + fit = os.path.join(ubman.config.persistent_data_dir, 'test-fit.fit') + build_test_fit(ubman, fit) + # Run the C test which will load and verify this FIT ubman.run_command('ut -f bootstd test_fit_print_norun') result = ubman.run_command('echo $?') assert '0' == result + + +@pytest.mark.boardspec('sandbox') +@pytest.mark.buildconfigspec('fit_print') +@pytest.mark.requiredtool('dtc') +@pytest.mark.requiredtool('openssl') +def test_fit_print_no_desc(ubman): + """Test fit_print_contents() with missing FIT description""" + fit = os.path.join(ubman.config.persistent_data_dir, 'test-fit-nodesc.fit') + build_test_fit(ubman, fit) + + # Delete the description property + utils.run_and_log(ubman, ['fdtput', '-d', fit, '/', 'description']) + + # Run the C test to check the missing description + ubman.run_command('ut -f bootstd test_fit_print_no_desc_norun') + result = ubman.run_command('echo $?') + assert '0' == result -- 2.43.0