diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/dm/blk.c | 46 | ||||
-rw-r--r-- | test/dm/core.c | 143 | ||||
-rw-r--r-- | test/lib/abuf.c | 46 | ||||
-rw-r--r-- | test/py/tests/test_fit_mkimage_validate.py | 45 |
4 files changed, 110 insertions, 170 deletions
diff --git a/test/dm/blk.c b/test/dm/blk.c index aa5cbc63777..1b928b27d9c 100644 --- a/test/dm/blk.c +++ b/test/dm/blk.c @@ -229,30 +229,7 @@ static int dm_test_blk_flags(struct unit_test_state *uts) { struct udevice *dev; - /* Iterate through devices without probing them */ - ut_assertok(blk_find_first(BLKF_BOTH, &dev)); - ut_assertnonnull(dev); - ut_asserteq_str("mmc2.blk", dev->name); - - ut_assertok(blk_find_next(BLKF_BOTH, &dev)); - ut_assertnonnull(dev); - ut_asserteq_str("mmc1.blk", dev->name); - - ut_assertok(blk_find_next(BLKF_BOTH, &dev)); - ut_assertnonnull(dev); - ut_asserteq_str("mmc0.blk", dev->name); - - ut_asserteq(-ENODEV, blk_find_next(BLKF_BOTH, &dev)); - ut_assertnull(dev); - - /* All devices are removable until probed */ - ut_asserteq(-ENODEV, blk_find_first(BLKF_FIXED, &dev)); - - ut_assertok(blk_find_first(BLKF_REMOVABLE, &dev)); - ut_assertnonnull(dev); - ut_asserteq_str("mmc2.blk", dev->name); - - /* Now probe them and iterate again */ + /* Probe and look through block devices */ ut_assertok(blk_first_device_err(BLKF_BOTH, &dev)); ut_assertnonnull(dev); ut_asserteq_str("mmc2.blk", dev->name); @@ -289,30 +266,13 @@ static int dm_test_blk_flags(struct unit_test_state *uts) } DM_TEST(dm_test_blk_flags, UTF_SCAN_PDATA | UTF_SCAN_FDT); -/* Test blk_foreach() and friend */ +/* Test blk_foreach_probe() */ static int dm_test_blk_foreach(struct unit_test_state *uts) { struct udevice *dev; int found; - /* Test blk_foreach() - use the 3rd bytes of the name (0/1/2) */ - found = 0; - blk_foreach(BLKF_BOTH, dev) - found |= 1 << dectoul(&dev->name[3], NULL); - ut_asserteq(7, found); - - /* All devices are removable until probed */ - found = 0; - blk_foreach(BLKF_FIXED, dev) - found |= 1 << dectoul(&dev->name[3], NULL); - ut_asserteq(0, found); - - found = 0; - blk_foreach(BLKF_REMOVABLE, dev) - found |= 1 << dectoul(&dev->name[3], NULL); - ut_asserteq(7, found); - - /* Now try again with the probing functions */ + /* The test device tree has two fixed and one removable block device(s) */ found = 0; blk_foreach_probe(BLKF_BOTH, dev) found |= 1 << dectoul(&dev->name[3], NULL); diff --git a/test/dm/core.c b/test/dm/core.c index 959b834576f..53693f4f7ed 100644 --- a/test/dm/core.c +++ b/test/dm/core.c @@ -167,8 +167,6 @@ static int dm_test_autobind_uclass_pdata_alloc(struct unit_test_state *uts) for (uclass_find_first_device(UCLASS_TEST, &dev); dev; uclass_find_next_device(&dev)) { - ut_assertnonnull(dev); - uc_pdata = dev_get_uclass_plat(dev); ut_assert(uc_pdata); } @@ -223,8 +221,6 @@ static int dm_test_autobind_uclass_pdata_valid(struct unit_test_state *uts) for (uclass_find_first_device(UCLASS_TEST, &dev); dev; uclass_find_next_device(&dev)) { - ut_assertnonnull(dev); - uc_pdata = dev_get_uclass_plat(dev); ut_assert(uc_pdata); ut_assert(uc_pdata->intval1 == TEST_UC_PDATA_INTVAL1); @@ -734,114 +730,90 @@ static int dm_test_device_reparent(struct unit_test_state *uts) /* Re-parent top-level children with no grandchildren. */ ut_assertok(device_reparent(top[3], top[0])); + /* try to get devices */ - for (ret = uclass_find_first_device(UCLASS_TEST, &dev); - dev; - ret = uclass_find_next_device(&dev)) { - ut_assert(!ret); - ut_assertnonnull(dev); - } + ret = uclass_find_first_device(UCLASS_TEST, &dev); + ut_assert(!ret); + ut_assertnonnull(dev); ut_assertok(device_reparent(top[4], top[0])); + /* try to get devices */ - for (ret = uclass_find_first_device(UCLASS_TEST, &dev); - dev; - ret = uclass_find_next_device(&dev)) { - ut_assert(!ret); - ut_assertnonnull(dev); - } + ret = uclass_find_first_device(UCLASS_TEST, &dev); + ut_assert(!ret); + ut_assertnonnull(dev); /* Re-parent top-level children with grandchildren. */ ut_assertok(device_reparent(top[2], top[0])); + /* try to get devices */ - for (ret = uclass_find_first_device(UCLASS_TEST, &dev); - dev; - ret = uclass_find_next_device(&dev)) { - ut_assert(!ret); - ut_assertnonnull(dev); - } + ret = uclass_find_first_device(UCLASS_TEST, &dev); + ut_assert(!ret); + ut_assertnonnull(dev); ut_assertok(device_reparent(top[5], top[2])); + /* try to get devices */ - for (ret = uclass_find_first_device(UCLASS_TEST, &dev); - dev; - ret = uclass_find_next_device(&dev)) { - ut_assert(!ret); - ut_assertnonnull(dev); - } + ret = uclass_find_first_device(UCLASS_TEST, &dev); + ut_assert(!ret); + ut_assertnonnull(dev); /* Re-parent grandchildren. */ ut_assertok(device_reparent(grandchild[0], top[1])); + /* try to get devices */ - for (ret = uclass_find_first_device(UCLASS_TEST, &dev); - dev; - ret = uclass_find_next_device(&dev)) { - ut_assert(!ret); - ut_assertnonnull(dev); - } + ret = uclass_find_first_device(UCLASS_TEST, &dev); + ut_assert(!ret); + ut_assertnonnull(dev); ut_assertok(device_reparent(grandchild[1], top[1])); + /* try to get devices */ - for (ret = uclass_find_first_device(UCLASS_TEST, &dev); - dev; - ret = uclass_find_next_device(&dev)) { - ut_assert(!ret); - ut_assertnonnull(dev); - } + ret = uclass_find_first_device(UCLASS_TEST, &dev); + ut_assert(!ret); + ut_assertnonnull(dev); /* Remove re-pareneted devices. */ ut_assertok(device_remove(top[3], DM_REMOVE_NORMAL)); + /* try to get devices */ - for (ret = uclass_find_first_device(UCLASS_TEST, &dev); - dev; - ret = uclass_find_next_device(&dev)) { - ut_assert(!ret); - ut_assertnonnull(dev); - } + ret = uclass_find_first_device(UCLASS_TEST, &dev); + ut_assert(!ret); + ut_assertnonnull(dev); ut_assertok(device_remove(top[4], DM_REMOVE_NORMAL)); + /* try to get devices */ - for (ret = uclass_find_first_device(UCLASS_TEST, &dev); - dev; - ret = uclass_find_next_device(&dev)) { - ut_assert(!ret); - ut_assertnonnull(dev); - } + ret = uclass_find_first_device(UCLASS_TEST, &dev); + ut_assert(!ret); + ut_assertnonnull(dev); ut_assertok(device_remove(top[5], DM_REMOVE_NORMAL)); + /* try to get devices */ - for (ret = uclass_find_first_device(UCLASS_TEST, &dev); - dev; - ret = uclass_find_next_device(&dev)) { - ut_assert(!ret); - ut_assertnonnull(dev); - } + ret = uclass_find_first_device(UCLASS_TEST, &dev); + ut_assert(!ret); + ut_assertnonnull(dev); ut_assertok(device_remove(top[2], DM_REMOVE_NORMAL)); - for (ret = uclass_find_first_device(UCLASS_TEST, &dev); - dev; - ret = uclass_find_next_device(&dev)) { - ut_assert(!ret); - ut_assertnonnull(dev); - } + + ret = uclass_find_first_device(UCLASS_TEST, &dev); + ut_assert(!ret); + ut_assertnonnull(dev); ut_assertok(device_remove(grandchild[0], DM_REMOVE_NORMAL)); + /* try to get devices */ - for (ret = uclass_find_first_device(UCLASS_TEST, &dev); - dev; - ret = uclass_find_next_device(&dev)) { - ut_assert(!ret); - ut_assertnonnull(dev); - } + ret = uclass_find_first_device(UCLASS_TEST, &dev); + ut_assert(!ret); + ut_assertnonnull(dev); ut_assertok(device_remove(grandchild[1], DM_REMOVE_NORMAL)); + /* try to get devices */ - for (ret = uclass_find_first_device(UCLASS_TEST, &dev); - dev; - ret = uclass_find_next_device(&dev)) { - ut_assert(!ret); - ut_assertnonnull(dev); - } + ret = uclass_find_first_device(UCLASS_TEST, &dev); + ut_assert(!ret); + ut_assertnonnull(dev); /* Try the same with unbind */ ut_assertok(device_unbind(top[3])); @@ -1090,12 +1062,9 @@ static int dm_test_uclass_devices_find(struct unit_test_state *uts) struct udevice *dev; int ret; - for (ret = uclass_find_first_device(UCLASS_TEST, &dev); - dev; - ret = uclass_find_next_device(&dev)) { - ut_assert(!ret); - ut_assertnonnull(dev); - } + ret = uclass_find_first_device(UCLASS_TEST, &dev); + ut_assert(!ret); + ut_assertnonnull(dev); ut_assertok(uclass_find_first_device(UCLASS_TEST_DUMMY, &dev)); ut_assertnull(dev); @@ -1121,18 +1090,16 @@ static int dm_test_uclass_devices_find_by_name(struct unit_test_state *uts) * this will fail on checking condition: testdev == finddev, since the * uclass_find_device_by_name(), returns the first device by given name. */ - for (ret = uclass_find_first_device(UCLASS_TEST_FDT, &testdev); - testdev; - ret = uclass_find_next_device(&testdev)) { - ut_assertok(ret); - ut_assertnonnull(testdev); + ret = uclass_find_first_device(UCLASS_TEST_FDT, &testdev); + ut_assertok(ret); + ut_assertnonnull(testdev); + for (; testdev; uclass_find_next_device(&testdev)) { findret = uclass_find_device_by_name(UCLASS_TEST_FDT, testdev->name, &finddev); ut_assertok(findret); - ut_assert(testdev); ut_asserteq_str(testdev->name, finddev->name); ut_asserteq_ptr(testdev, finddev); } diff --git a/test/lib/abuf.c b/test/lib/abuf.c index 97b128c01c0..3dced1ddb11 100644 --- a/test/lib/abuf.c +++ b/test/lib/abuf.c @@ -12,6 +12,7 @@ static char test_data[] = "1234"; #define TEST_DATA_LEN sizeof(test_data) +#define HUGE_ALLOC_SIZE 0x60000000 /* Test abuf_set() */ static int lib_test_abuf_set(struct unit_test_state *uts) @@ -93,13 +94,6 @@ static int lib_test_abuf_realloc(struct unit_test_state *uts) { struct abuf buf; ulong start; - void *ptr; - - /* - * TODO: crashes on sandbox sometimes due to an apparent bug in - * realloc(). - */ - return 0; start = ut_check_free(); @@ -116,23 +110,18 @@ static int lib_test_abuf_realloc(struct unit_test_state *uts) ut_assertnonnull(buf.data); ut_asserteq(TEST_DATA_LEN, buf.size); ut_asserteq(true, buf.alloced); - ptr = buf.data; /* - * Make it smaller; the pointer should remain the same. Note this relies - * on knowledge of how U-Boot's realloc() works + * Make it smaller. */ ut_asserteq(true, abuf_realloc(&buf, TEST_DATA_LEN - 1)); ut_asserteq(TEST_DATA_LEN - 1, buf.size); ut_asserteq(true, buf.alloced); - ut_asserteq_ptr(ptr, buf.data); /* - * Make it larger, forcing reallocation. Note this relies on knowledge - * of how U-Boot's realloc() works + * Make it larger. */ ut_asserteq(true, abuf_realloc(&buf, 0x1000)); - ut_assert(buf.data != ptr); ut_asserteq(0x1000, buf.size); ut_asserteq(true, buf.alloced); @@ -210,19 +199,12 @@ static int lib_test_abuf_large(struct unit_test_state *uts) ulong start; size_t size; int delta; - void *ptr; - - /* - * This crashes at present due to trying to allocate more memory than - * available, which breaks something on sandbox. - */ - return 0; start = ut_check_free(); /* Try an impossible size */ abuf_init(&buf); - ut_asserteq(false, abuf_realloc(&buf, CONFIG_SYS_MALLOC_LEN)); + ut_asserteq(false, abuf_realloc(&buf, HUGE_ALLOC_SIZE)); ut_assertnull(buf.data); ut_asserteq(0, buf.size); ut_asserteq(false, buf.alloced); @@ -237,13 +219,11 @@ static int lib_test_abuf_large(struct unit_test_state *uts) ut_assertnonnull(buf.data); ut_asserteq(TEST_DATA_LEN, buf.size); ut_asserteq(true, buf.alloced); - ptr = buf.data; delta = ut_check_delta(start); ut_assert(delta > 0); /* try to increase it */ - ut_asserteq(false, abuf_realloc(&buf, CONFIG_SYS_MALLOC_LEN)); - ut_asserteq_ptr(ptr, buf.data); + ut_asserteq(false, abuf_realloc(&buf, HUGE_ALLOC_SIZE)); ut_asserteq(TEST_DATA_LEN, buf.size); ut_asserteq(true, buf.alloced); ut_asserteq(delta, ut_check_delta(start)); @@ -254,8 +234,8 @@ static int lib_test_abuf_large(struct unit_test_state *uts) /* Start with a huge unallocated buf and try to move it */ abuf_init(&buf); - abuf_map_sysmem(&buf, 0, CONFIG_SYS_MALLOC_LEN); - ut_asserteq(CONFIG_SYS_MALLOC_LEN, buf.size); + abuf_map_sysmem(&buf, 0, HUGE_ALLOC_SIZE); + ut_asserteq(HUGE_ALLOC_SIZE, buf.size); ut_asserteq(false, buf.alloced); ut_assertnull(abuf_uninit_move(&buf, &size)); @@ -278,12 +258,6 @@ static int lib_test_abuf_uninit_move(struct unit_test_state *uts) start = ut_check_free(); - /* - * TODO: crashes on sandbox sometimes due to an apparent bug in - * realloc(). - */ - return 0; - /* Move an empty buffer */ abuf_init(&buf); ut_assertnull(abuf_uninit_move(&buf, &size)); @@ -383,12 +357,6 @@ static int lib_test_abuf_init_move(struct unit_test_state *uts) struct abuf buf; void *ptr; - /* - * TODO: crashes on sandbox sometimes due to an apparent bug in - * realloc(). - */ - return 0; - ptr = strdup(test_data); ut_assertnonnull(ptr); 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@1 { + description = "Test Kernel"; + data = /incbin/("kernel.bin"); + type = "kernel"; + arch = "sandbox"; + os = "linux"; + compression = "none"; + load = <0x40000>; + entry = <0x40000>; + }; + }; + + configurations { + default = "conf@1"; + conf@2 { + kernel = "kernel@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) |