diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/boot/bootdev.c | 1 | ||||
-rw-r--r-- | test/boot/bootflow.c | 5 | ||||
-rw-r--r-- | test/dm/acpi.c | 59 | ||||
-rw-r--r-- | test/dm/acpigen.c | 115 | ||||
-rw-r--r-- | test/lib/lmb.c | 103 | ||||
-rw-r--r-- | test/py/conftest.py | 22 | ||||
-rw-r--r-- | test/py/console_base.py | 25 | ||||
-rw-r--r-- | test/py/pytest.ini | 1 | ||||
-rw-r--r-- | test/py/requirements.txt | 1 | ||||
-rw-r--r-- | test/py/tests/fs_helper.py | 10 | ||||
-rw-r--r-- | test/py/tests/test_distro.py | 61 | ||||
-rw-r--r-- | test/py/tests/test_fs/conftest.py | 44 | ||||
-rw-r--r-- | test/py/tests/test_fs/fstest_helpers.py | 2 | ||||
-rw-r--r-- | test/py/tests/test_fs/test_basic.py | 71 | ||||
-rw-r--r-- | test/py/tests/test_fs/test_ext.py | 176 | ||||
-rw-r--r-- | test/py/tests/test_fs/test_mkdir.py | 42 | ||||
-rw-r--r-- | test/py/tests/test_fs/test_unlink.py | 38 | ||||
-rw-r--r-- | test/py/tests/test_ut.py | 17 |
18 files changed, 558 insertions, 235 deletions
diff --git a/test/boot/bootdev.c b/test/boot/bootdev.c index 5f07430714e..d5499918249 100644 --- a/test/boot/bootdev.c +++ b/test/boot/bootdev.c @@ -509,6 +509,7 @@ static int bootdev_test_bootable(struct unit_test_state *uts) iter.part = 0; ut_assertok(uclass_get_device_by_name(UCLASS_BLK, "mmc1.blk", &blk)); iter.dev = blk; + iter.flags = BOOTFLOWIF_ONLY_BOOTABLE; ut_assertok(device_find_next_child(&iter.dev)); uclass_first_device(UCLASS_BOOTMETH, &bflow.method); diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c index eb7f00af39a..5f9c037ff53 100644 --- a/test/boot/bootflow.c +++ b/test/boot/bootflow.c @@ -297,8 +297,9 @@ static int bootflow_iter(struct unit_test_state *uts) /* The first device is mmc2.bootdev which has no media */ ut_asserteq(-EPROTONOSUPPORT, - bootflow_scan_first(NULL, NULL, &iter, - BOOTFLOWIF_ALL | BOOTFLOWIF_SKIP_GLOBAL, &bflow)); + bootflow_scan_first(NULL, NULL, &iter, BOOTFLOWIF_ALL | + BOOTFLOWIF_SKIP_GLOBAL | + BOOTFLOWIF_ONLY_BOOTABLE, &bflow)); ut_asserteq(2, iter.num_methods); ut_asserteq(0, iter.cur_method); ut_asserteq(0, iter.part); diff --git a/test/dm/acpi.c b/test/dm/acpi.c index 39a26bbb492..db012b6d2f1 100644 --- a/test/dm/acpi.c +++ b/test/dm/acpi.c @@ -309,6 +309,8 @@ static int dm_test_acpi_write_tables(struct unit_test_state *uts) } ut_asserteq(0, ctx.rsdt->entry[3]); ut_asserteq(0, ctx.xsdt->entry[3]); + unmap_sysmem(buf); + free(buf); return 0; } @@ -386,6 +388,8 @@ static int dm_test_acpi_ctx_and_base_tables(struct unit_test_state *uts) ut_asserteq(nomap_to_sysmem(rsdt), rsdp->rsdt_address); ut_asserteq(nomap_to_sysmem(xsdt), rsdp->xsdt_address); + unmap_sysmem(buf); + free(buf); return 0; } @@ -428,11 +432,59 @@ static int dm_test_acpi_cmd_list(struct unit_test_state *uts) ut_assert_nextline("DMAR %16lx %5zx v01 U-BOOT U-BOOTBL %x INTL 0", addr, sizeof(struct acpi_dmar), OEM_REVISION); ut_assert_console_end(); + unmap_sysmem(buf); + free(buf); return 0; } DM_TEST(dm_test_acpi_cmd_list, UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_CONSOLE); +/* Test 'acpi list -c' command */ +static int dm_test_acpi_cmd_list_chksum(struct unit_test_state *uts) +{ + struct acpi_ctx ctx; + ulong addr; + void *buf; + + buf = memalign(16, BUF_SIZE); + ut_assertnonnull(buf); + addr = map_to_sysmem(buf); + ut_assertok(setup_ctx_and_base_tables(uts, &ctx, addr)); + + ut_assertok(acpi_write_dev_tables(&ctx)); + + run_command("acpi list -c", 0); + ut_assert_nextline("Name Base Size Detail"); + ut_assert_nextline("---- ---------------- ----- ----------------------------"); + ut_assert_nextline("RSDP %16lx %5zx v02 U-BOOT OK OK", addr, + sizeof(struct acpi_rsdp)); + addr = ALIGN(addr + sizeof(struct acpi_rsdp), 16); + ut_assert_nextline("RSDT %16lx %5zx v01 U-BOOT U-BOOTBL %x INTL 0 OK", + addr, sizeof(struct acpi_table_header) + + 3 * sizeof(u32), OEM_REVISION); + addr = ALIGN(addr + sizeof(struct acpi_rsdt), 16); + ut_assert_nextline("XSDT %16lx %5zx v01 U-BOOT U-BOOTBL %x INTL 0 OK", + addr, sizeof(struct acpi_table_header) + + 3 * sizeof(u64), OEM_REVISION); + addr = ALIGN(addr + sizeof(struct acpi_xsdt), 64); + ut_assert_nextline("DMAR %16lx %5zx v01 U-BOOT U-BOOTBL %x INTL 0 OK", + addr, sizeof(struct acpi_dmar), OEM_REVISION); + addr = ALIGN(addr + sizeof(struct acpi_dmar), 16); + ut_assert_nextline("DMAR %16lx %5zx v01 U-BOOT U-BOOTBL %x INTL 0 OK", + addr, sizeof(struct acpi_dmar), OEM_REVISION); + addr = ALIGN(addr + sizeof(struct acpi_dmar), 16); + ut_assert_nextline("DMAR %16lx %5zx v01 U-BOOT U-BOOTBL %x INTL 0 OK", + addr, sizeof(struct acpi_dmar), OEM_REVISION); + ut_assert_console_end(); + ut_assert_console_end(); + unmap_sysmem(buf); + free(buf); + + return 0; +} +DM_TEST(dm_test_acpi_cmd_list_chksum, + UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_CONSOLE); + /* Test 'acpi dump' command */ static int dm_test_acpi_cmd_dump(struct unit_test_state *uts) { @@ -458,6 +510,8 @@ static int dm_test_acpi_cmd_dump(struct unit_test_state *uts) ut_assert_nextline("DMAR @ %16lx", addr); ut_assert_nextlines_are_dump(0x30); ut_assert_console_end(); + unmap_sysmem(buf); + free(buf); return 0; } @@ -642,6 +696,8 @@ static int dm_test_acpi_cmd_items(struct unit_test_state *uts) ut_assert_nextlines_are_dump(2); ut_assert_nextline("%s", ""); ut_assert_console_end(); + unmap_sysmem(buf); + free(buf); return 0; } @@ -679,6 +735,8 @@ static int dm_test_acpi_cmd_set(struct unit_test_state *uts) ut_asserteq(addr, gd_acpi_start()); ut_assert_console_end(); + unmap_sysmem(buf); + free(buf); return 0; } @@ -774,6 +832,7 @@ static int dm_test_acpi_find_table(struct unit_test_state *uts) /* Restore previous ACPI tables */ gd_set_acpi_start(acpi_start); + unmap_sysmem(buf); free(buf); return 0; diff --git a/test/dm/acpigen.c b/test/dm/acpigen.c index 23c16bd9866..ee9517f9c29 100644 --- a/test/dm/acpigen.c +++ b/test/dm/acpigen.c @@ -1742,3 +1742,118 @@ static int dm_test_acpi_write_tsd_package(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_acpi_write_tsd_package, 0); + +static int dm_test_acpi_iort_smmu_v3(struct unit_test_state *uts) +{ + struct acpi_ctx *ctx; + int smmu_offset; + u8 *ptr; + + ut_assertok(alloc_context(&ctx)); + ctx->tab_start = ctx->current; + acpi_inc(ctx, sizeof(struct acpi_table_iort)); + + ptr = acpigen_get_current(ctx); + + smmu_offset = acpi_iort_add_smmu_v3(ctx, + 0xaabbccddeeffULL, // Base address + 1, // Flags + 0xffeeddccaabbULL, // VATOS address + 0, // SMMUv3 Model + 3, // Event + 4, // Pri + 5, // Gerror + 6, // Sync + 7, // Proximity domain + 8, // DevIDMappingIndex + 0, + NULL); + ut_assert(smmu_offset); + + ut_asserteq(ACPI_IORT_NODE_SMMU_V3, ptr[0]); + ut_asserteq(68, get_unaligned((u16 *)(ptr + 1))); + ut_asserteq(0, get_unaligned((u16 *)(ptr + 4))); + ut_asserteq(0, get_unaligned((u32 *)(ptr + 8))); + ut_asserteq(0, get_unaligned((u32 *)(ptr + 12))); + + ut_asserteq_64(0xaabbccddeeffULL, get_unaligned((u64 *)(ptr + 16))); + ut_asserteq(1, get_unaligned((u32 *)(ptr + 24))); + ut_asserteq(0, get_unaligned((u32 *)(ptr + 28))); + ut_asserteq_64(0xffeeddccaabbULL, get_unaligned((u64 *)(ptr + 32))); + ut_asserteq(0, get_unaligned((u32 *)(ptr + 40))); + ut_asserteq(3, get_unaligned((u32 *)(ptr + 44))); + ut_asserteq(4, get_unaligned((u32 *)(ptr + 48))); + ut_asserteq(5, get_unaligned((u32 *)(ptr + 52))); + ut_asserteq(6, get_unaligned((u32 *)(ptr + 56))); + ut_asserteq(7, get_unaligned((u32 *)(ptr + 60))); + ut_asserteq(8, get_unaligned((u32 *)(ptr + 64))); + + free_context(&ctx); + + return 0; +} +DM_TEST(dm_test_acpi_iort_smmu_v3, 0); + +static int dm_test_acpi_iort_rc(struct unit_test_state *uts) +{ + struct acpi_ctx *ctx; + int its_group_offset, offset; + u8 *ptr; + + ut_assertok(alloc_context(&ctx)); + ctx->tab_start = ctx->current; + acpi_inc(ctx, sizeof(struct acpi_table_iort)); + + u32 identifiers[] = { 0 }; + + its_group_offset = acpi_iort_add_its_group(ctx, ARRAY_SIZE(identifiers), + identifiers); + + ptr = acpigen_get_current(ctx); + + struct acpi_iort_id_mapping map_rc[] = { + {0, 0xfff, 0, its_group_offset, 0}, + {0x1000, 0xffff, 0x1000, its_group_offset, 0} + }; + + offset = acpi_iort_add_rc(ctx, + 0xaabbccddeeffULL, // Mem Access Properties + 2, // ATS attributes + 3, // PCI segment + 4, // Memory address size limit + ARRAY_SIZE(map_rc), + map_rc); + + ut_assert(offset); + ut_asserteq(ACPI_IORT_NODE_PCI_ROOT_COMPLEX, ptr[0]); + ut_asserteq(36 + ARRAY_SIZE(map_rc) * sizeof(struct acpi_iort_id_mapping), + get_unaligned((u16 *)(ptr + 1))); + ut_asserteq(0, get_unaligned((u16 *)(ptr + 4))); + ut_asserteq(2, get_unaligned((u32 *)(ptr + 8))); + ut_asserteq(36, get_unaligned((u32 *)(ptr + 12))); + + ut_asserteq_64(0xaabbccddeeffULL, get_unaligned((u64 *)(ptr + 16))); + ut_asserteq(2, get_unaligned((u32 *)(ptr + 24))); + ut_asserteq(3, get_unaligned((u32 *)(ptr + 28))); + ut_asserteq(4, ptr[32]); + ut_asserteq(0, ptr[33]); + ut_asserteq(0, ptr[34]); + ut_asserteq(0, ptr[35]); + + ut_asserteq(0, get_unaligned((u32 *)(ptr + 36))); + ut_asserteq(0xfff, get_unaligned((u32 *)(ptr + 40))); + ut_asserteq(0, get_unaligned((u32 *)(ptr + 44))); + ut_asserteq(its_group_offset, get_unaligned((u32 *)(ptr + 48))); + ut_asserteq(0, get_unaligned((u32 *)(ptr + 52))); + + ut_asserteq(0x1000, get_unaligned((u32 *)(ptr + 56))); + ut_asserteq(0xffff, get_unaligned((u32 *)(ptr + 60))); + ut_asserteq(0x1000, get_unaligned((u32 *)(ptr + 64))); + ut_asserteq(its_group_offset, get_unaligned((u32 *)(ptr + 68))); + ut_asserteq(0, get_unaligned((u32 *)(ptr + 72))); + + free_context(&ctx); + + return 0; +} +DM_TEST(dm_test_acpi_iort_rc, 0);
\ No newline at end of file diff --git a/test/lib/lmb.c b/test/lib/lmb.c index 24416e83491..3bf558f7f4f 100644 --- a/test/lib/lmb.c +++ b/test/lib/lmb.c @@ -566,21 +566,21 @@ static int test_alloc_addr(struct unit_test_state *uts, const phys_addr_t ram) /* Try to allocate a page twice */ b = lmb_alloc_addr(alloc_addr_a, 0x1000, LMB_NONE); - ut_asserteq(b, alloc_addr_a); - b = lmb_alloc_addr(alloc_addr_a, 0x1000, LMB_NOOVERWRITE); ut_asserteq(b, 0); + b = lmb_alloc_addr(alloc_addr_a, 0x1000, LMB_NOOVERWRITE); + ut_asserteq(b, -1); b = lmb_alloc_addr(alloc_addr_a, 0x1000, LMB_NONE); - ut_asserteq(b, alloc_addr_a); + ut_asserteq(b, 0); b = lmb_alloc_addr(alloc_addr_a, 0x2000, LMB_NONE); - ut_asserteq(b, alloc_addr_a); + ut_asserteq(b, 0); ret = lmb_free(alloc_addr_a, 0x2000); ut_asserteq(ret, 0); b = lmb_alloc_addr(alloc_addr_a, 0x1000, LMB_NOOVERWRITE); - ut_asserteq(b, alloc_addr_a); - b = lmb_alloc_addr(alloc_addr_a, 0x1000, LMB_NONE); ut_asserteq(b, 0); + b = lmb_alloc_addr(alloc_addr_a, 0x1000, LMB_NONE); + ut_asserteq(b, -1); b = lmb_alloc_addr(alloc_addr_a, 0x1000, LMB_NOOVERWRITE); - ut_asserteq(b, 0); + ut_asserteq(b, -1); ret = lmb_free(alloc_addr_a, 0x1000); ut_asserteq(ret, 0); @@ -591,21 +591,21 @@ static int test_alloc_addr(struct unit_test_state *uts, const phys_addr_t ram) * region 2. Should fail. */ a = lmb_alloc_addr(alloc_addr_a, 0x1000, LMB_NONE); - ut_asserteq(a, alloc_addr_a); + ut_asserteq(a, 0); b = lmb_alloc_addr(alloc_addr_a + 0x4000, 0x1000, LMB_NOOVERWRITE); - ut_asserteq(b, alloc_addr_a + 0x4000); - ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, a, 0x1000, - b, 0x1000, 0, 0); + ut_asserteq(b, 0); + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, alloc_addr_a, 0x1000, + alloc_addr_a + 0x4000, 0x1000, 0, 0); c = lmb_alloc_addr(alloc_addr_a + 0x1000, 0x5000, LMB_NONE); - ut_asserteq(c, 0); - ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, a, 0x1000, - b, 0x1000, 0, 0); + ut_asserteq(c, -1); + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, alloc_addr_a, 0x1000, + alloc_addr_a + 0x4000, 0x1000, 0, 0); - ret = lmb_free(a, 0x1000); + ret = lmb_free(alloc_addr_a, 0x1000); ut_asserteq(ret, 0); - ret = lmb_free(b, 0x1000); + ret = lmb_free(alloc_addr_a + 0x4000, 0x1000); ut_asserteq(ret, 0); /* @@ -616,19 +616,19 @@ static int test_alloc_addr(struct unit_test_state *uts, const phys_addr_t ram) * single region. */ a = lmb_alloc_addr(alloc_addr_a, 0x1000, LMB_NONE); - ut_asserteq(a, alloc_addr_a); + ut_asserteq(a, 0); b = lmb_alloc_addr(alloc_addr_a + 0x4000, 0x1000, LMB_NONE); - ut_asserteq(b, alloc_addr_a + 0x4000); - ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, a, 0x1000, - b, 0x1000, 0, 0); + ut_asserteq(b, 0); + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, alloc_addr_a, 0x1000, + alloc_addr_a + 0x4000, 0x1000, 0, 0); c = lmb_alloc_addr(alloc_addr_a + 0x1000, 0x5000, LMB_NONE); - ut_asserteq(c, alloc_addr_a + 0x1000); - ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, a, 0x6000, + ut_asserteq(c, 0); + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, alloc_addr_a, 0x6000, 0, 0, 0, 0); - ret = lmb_free(a, 0x6000); + ret = lmb_free(alloc_addr_a, 0x6000); ut_asserteq(ret, 0); /* @@ -638,21 +638,21 @@ static int test_alloc_addr(struct unit_test_state *uts, const phys_addr_t ram) * region 2. Should fail. */ a = lmb_alloc_addr(alloc_addr_a, 0x1000, LMB_NOOVERWRITE); - ut_asserteq(a, alloc_addr_a); + ut_asserteq(a, 0); b = lmb_alloc_addr(alloc_addr_a + 0x4000, 0x1000, LMB_NOOVERWRITE); - ut_asserteq(b, alloc_addr_a + 0x4000); - ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, a, 0x1000, - b, 0x1000, 0, 0); + ut_asserteq(b, 0); + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, alloc_addr_a, 0x1000, + alloc_addr_a + 0x4000, 0x1000, 0, 0); c = lmb_alloc_addr(alloc_addr_a + 0x1000, 0x5000, LMB_NOOVERWRITE); - ut_asserteq(c, 0); - ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, a, 0x1000, - b, 0x1000, 0, 0); + ut_asserteq(c, -1); + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, alloc_addr_a, 0x1000, + alloc_addr_a + 0x4000, 0x1000, 0, 0); - ret = lmb_free(a, 0x1000); + ret = lmb_free(alloc_addr_a, 0x1000); ut_asserteq(ret, 0); - ret = lmb_free(b, 0x1000); + ret = lmb_free(alloc_addr_a + 0x4000, 0x1000); ut_asserteq(ret, 0); /* reserve 3 blocks */ @@ -667,22 +667,22 @@ static int test_alloc_addr(struct unit_test_state *uts, const phys_addr_t ram) /* allocate blocks */ a = lmb_alloc_addr(ram, alloc_addr_a - ram, LMB_NONE); - ut_asserteq(a, ram); + ut_asserteq(a, 0); ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 3, ram, 0x8010000, alloc_addr_b, 0x10000, alloc_addr_c, 0x10000); b = lmb_alloc_addr(alloc_addr_a + 0x10000, alloc_addr_b - alloc_addr_a - 0x10000, LMB_NONE); - ut_asserteq(b, alloc_addr_a + 0x10000); + ut_asserteq(b, 0); ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, ram, 0x10010000, alloc_addr_c, 0x10000, 0, 0); c = lmb_alloc_addr(alloc_addr_b + 0x10000, alloc_addr_c - alloc_addr_b - 0x10000, LMB_NONE); - ut_asserteq(c, alloc_addr_b + 0x10000); + ut_asserteq(c, 0); ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram, 0x18010000, 0, 0, 0, 0); d = lmb_alloc_addr(alloc_addr_c + 0x10000, ram_end - alloc_addr_c - 0x10000, LMB_NONE); - ut_asserteq(d, alloc_addr_c + 0x10000); + ut_asserteq(d, 0); ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram, ram_size, 0, 0, 0, 0); @@ -692,57 +692,58 @@ static int test_alloc_addr(struct unit_test_state *uts, const phys_addr_t ram) ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram, ram_size, 0, 0, 0, 0); - ret = lmb_free(d, ram_end - alloc_addr_c - 0x10000); + /* free thge allocation from d */ + ret = lmb_free(alloc_addr_c + 0x10000, ram_end - alloc_addr_c - 0x10000); ut_asserteq(ret, 0); /* allocate at 3 points in free range */ d = lmb_alloc_addr(ram_end - 4, 4, LMB_NONE); - ut_asserteq(d, ram_end - 4); + ut_asserteq(d, 0); ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, ram, 0x18010000, - d, 4, 0, 0); - ret = lmb_free(d, 4); + ram_end - 4, 4, 0, 0); + ret = lmb_free(ram_end - 4, 4); ut_asserteq(ret, 0); ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram, 0x18010000, 0, 0, 0, 0); d = lmb_alloc_addr(ram_end - 128, 4, LMB_NONE); - ut_asserteq(d, ram_end - 128); + ut_asserteq(d, 0); ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, ram, 0x18010000, - d, 4, 0, 0); - ret = lmb_free(d, 4); + ram_end - 128, 4, 0, 0); + ret = lmb_free(ram_end - 128, 4); ut_asserteq(ret, 0); ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram, 0x18010000, 0, 0, 0, 0); d = lmb_alloc_addr(alloc_addr_c + 0x10000, 4, LMB_NONE); - ut_asserteq(d, alloc_addr_c + 0x10000); + ut_asserteq(d, 0); ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram, 0x18010004, 0, 0, 0, 0); - ret = lmb_free(d, 4); + ret = lmb_free(alloc_addr_c + 0x10000, 4); ut_asserteq(ret, 0); ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram, 0x18010000, 0, 0, 0, 0); - /* allocate at the bottom */ - ret = lmb_free(a, alloc_addr_a - ram); + /* allocate at the bottom a was assigned to ram at the top */ + ret = lmb_free(ram, alloc_addr_a - ram); ut_asserteq(ret, 0); ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram + 0x8000000, 0x10010000, 0, 0, 0, 0); d = lmb_alloc_addr(ram, 4, LMB_NONE); - ut_asserteq(d, ram); - ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, d, 4, + ut_asserteq(d, 0); + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, ram, 4, ram + 0x8000000, 0x10010000, 0, 0); /* check that allocating outside memory fails */ if (ram_end != 0) { ret = lmb_alloc_addr(ram_end, 1, LMB_NONE); - ut_asserteq(ret, 0); + ut_asserteq(ret, -1); } if (ram != 0) { ret = lmb_alloc_addr(ram - 1, 1, LMB_NONE); - ut_asserteq(ret, 0); + ut_asserteq(ret, -1); } lmb_pop(&store); diff --git a/test/py/conftest.py b/test/py/conftest.py index e59897c1f78..5aea85647af 100644 --- a/test/py/conftest.py +++ b/test/py/conftest.py @@ -334,6 +334,7 @@ def pytest_configure(config): ubconfig.dtb = build_dir + '/arch/sandbox/dts/test.dtb' ubconfig.connection_ok = True ubconfig.timing = config.getoption('timing') + ubconfig.role = config.getoption('role') env_vars = ( 'board_type', @@ -760,6 +761,26 @@ def setup_singlethread(item): if worker_id and worker_id != 'master': pytest.skip('must run single-threaded') +def setup_role(item): + """Process any 'role' marker for a test. + + Skip this test if the role does not match. + + Args: + item (pytest.Item): The pytest test item + """ + required_roles = [] + for roles in item.iter_markers('role'): + role = roles.args[0] + if role.startswith('!'): + if ubconfig.role == role[1:]: + pytest.skip(f'role "{ubconfig.role}" not supported') + return + else: + required_roles.append(role) + if required_roles and ubconfig.role not in required_roles: + pytest.skip(f'board "{ubconfig.role}" not supported') + def start_test_section(item): anchors[item.name] = log.start_section(item.name) @@ -781,6 +802,7 @@ def pytest_runtest_setup(item): setup_buildconfigspec(item) setup_requiredtool(item) setup_singlethread(item) + setup_role(item) def pytest_runtest_protocol(item, nextitem): """pytest hook: Called to execute a test. diff --git a/test/py/console_base.py b/test/py/console_base.py index 260df773bac..88d444b44b8 100644 --- a/test/py/console_base.py +++ b/test/py/console_base.py @@ -370,21 +370,30 @@ class ConsoleBase(object): output.append(self.run_command(cmd)) return output - def ctrlc(self): - """Send a CTRL-C character to U-Boot. + def send(self, msg): + """Send characters without waiting for echo, etc.""" + self.run_command(msg, wait_for_prompt=False, wait_for_echo=False, + send_nl=False) + + def ctrl(self, char): + """Send a CTRL- character to U-Boot. This is useful in order to stop execution of long-running synchronous commands such as "ums". Args: - None. - - Returns: - Nothing. + char (str): Character to send, e.g. 'C' to send Ctrl-C """ + self.log.action(f'Sending Ctrl-{char}') + self.send(chr(ord(char) - ord('@'))) - self.log.action('Sending Ctrl-C') - self.run_command(chr(3), wait_for_echo=False, send_nl=False) + def ctrlc(self): + """Send a CTRL-C character to U-Boot. + + This is useful in order to stop execution of long-running synchronous + commands such as "ums". + """ + self.ctrl('C') def wait_for(self, text): """Wait for a pattern to be emitted by U-Boot. diff --git a/test/py/pytest.ini b/test/py/pytest.ini index 26d83f83e00..361be0178ee 100644 --- a/test/py/pytest.ini +++ b/test/py/pytest.ini @@ -12,3 +12,4 @@ markers = requiredtool: U-Boot: Required host tools for a test. slow: U-Boot: Specific test will run slowly. singlethread: Cannot run in parallel + role: U-Boot: Indicates the lab 'role' which can execute this test diff --git a/test/py/requirements.txt b/test/py/requirements.txt index acfe17dce9f..804a427b351 100644 --- a/test/py/requirements.txt +++ b/test/py/requirements.txt @@ -2,3 +2,4 @@ filelock==3.0.12 pycryptodomex==3.21.0 pytest==6.2.5 pytest-xdist==2.5.0 +FATtools==1.0.42 diff --git a/test/py/tests/fs_helper.py b/test/py/tests/fs_helper.py index ccfc0201a49..9c459fccf97 100644 --- a/test/py/tests/fs_helper.py +++ b/test/py/tests/fs_helper.py @@ -35,7 +35,9 @@ def mk_fs(config, fs_type, size, prefix, src_dir=None, size_gran = 0x100000): else: mkfs_opt = '' - if re.match('fat', fs_type): + if fs_type == 'exfat': + fs_lnxtype = 'exfat' + elif re.match('fat', fs_type) or fs_type == 'fs_generic': fs_lnxtype = 'vfat' else: fs_lnxtype = fs_type @@ -43,7 +45,7 @@ def mk_fs(config, fs_type, size, prefix, src_dir=None, size_gran = 0x100000): if src_dir: if fs_lnxtype == 'ext4': mkfs_opt = mkfs_opt + ' -d ' + src_dir - elif fs_lnxtype != 'vfat': + elif fs_lnxtype != 'vfat' and fs_lnxtype != 'exfat': raise ValueError(f'src_dir not implemented for fs {fs_lnxtype}') count = (size + size_gran - 1) // size_gran @@ -54,7 +56,7 @@ def mk_fs(config, fs_type, size, prefix, src_dir=None, size_gran = 0x100000): try: check_call(f'rm -f {fs_img}', shell=True) - check_call(f'dd if=/dev/zero of={fs_img} bs={size_gran} count={count}', + check_call(f'truncate -s $(( {size_gran} * {count} )) {fs_img}', shell=True) check_call(f'mkfs.{fs_lnxtype} {mkfs_opt} {fs_img}', shell=True) if fs_type == 'ext4': @@ -64,6 +66,8 @@ def mk_fs(config, fs_type, size, prefix, src_dir=None, size_gran = 0x100000): check_call(f'tune2fs -O ^metadata_csum {fs_img}', shell=True) elif fs_lnxtype == 'vfat' and src_dir: check_call(f'mcopy -i {fs_img} -vsmpQ {src_dir}/* ::/', shell=True) + elif fs_lnxtype == 'exfat' and src_dir: + check_call(f'fattools cp {src_dir}/* {fs_img}', shell=True) return fs_img except CalledProcessError: call(f'rm -f {fs_img}', shell=True) diff --git a/test/py/tests/test_distro.py b/test/py/tests/test_distro.py new file mode 100644 index 00000000000..bdf4ab657d1 --- /dev/null +++ b/test/py/tests/test_distro.py @@ -0,0 +1,61 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright 2025 Canonical Ltd. +# Written by Simon Glass <simon.glass@canonical.com> + +import pytest + +# Enable early console so that the test can see if something goes wrong +CONSOLE = 'earlycon=uart8250,io,0x3f8 console=uart8250,io,0x3f8' + +@pytest.mark.boardspec('qemu-x86_64') +@pytest.mark.role('qemu-x86_64') +def test_distro(ubman): + """Test that of-platdata can be generated and used in sandbox""" + with ubman.log.section('boot'): + ubman.run_command('boot', wait_for_prompt=False) + + with ubman.log.section('Grub'): + # Wait for grub to come up and offset a menu + ubman.p.expect(['Try or Install Ubuntu']) + + # Press 'e' to edit the command line + ubman.log.info("Pressing 'e'") + ubman.run_command('e', wait_for_prompt=False, send_nl=False) + + # Wait until we see the editor appear + ubman.p.expect(['/casper/initrd']) + + # Go down to the 'linux' line. Avoid using down-arrow as that includes + # an Escape character, which may be parsed by Grub as such, causing it + # to return to the top menu + ubman.log.info("Going DOWN") + ubman.ctrl('N') + ubman.ctrl('N') + ubman.ctrl('N') + + # Go to end of line + ubman.log.info("Going to EOL") + ubman.ctrl('E') + + # Backspace to remove 'quiet splash' + ubman.log.info("Erasing quiet and splash") + ubman.send('\b' * len('quiet splash')) + + # Send our noisy console + ubman.log.info("Noisy console") + ubman.send(CONSOLE) + + # Tell grub to boot + ubman.log.info("boot") + ubman.ctrl('X') + ubman.p.expect(['Booting a command list']) + + with ubman.log.section('Linux'): + # Linux should start immediately + ubman.p.expect(['Linux version']) + + with ubman.log.section('Ubuntu'): + # Shortly later, we should see this banner + ubman.p.expect(['Welcome to .*Ubuntu 24.04.1 LTS.*!']) + + ubman.restart_uboot() diff --git a/test/py/tests/test_fs/conftest.py b/test/py/tests/test_fs/conftest.py index 47a584ffe7c..c73fb4abbcb 100644 --- a/test/py/tests/test_fs/conftest.py +++ b/test/py/tests/test_fs/conftest.py @@ -11,11 +11,11 @@ from fstest_defs import * # pylint: disable=E0611 from tests import fs_helper -supported_fs_basic = ['fat16', 'fat32', 'ext4'] -supported_fs_ext = ['fat12', 'fat16', 'fat32'] +supported_fs_basic = ['fat16', 'fat32', 'exfat', 'ext4', 'fs_generic'] +supported_fs_ext = ['fat12', 'fat16', 'fat32', 'exfat', 'fs_generic'] supported_fs_fat = ['fat12', 'fat16'] -supported_fs_mkdir = ['fat12', 'fat16', 'fat32'] -supported_fs_unlink = ['fat12', 'fat16', 'fat32'] +supported_fs_mkdir = ['fat12', 'fat16', 'fat32', 'exfat', 'fs_generic'] +supported_fs_unlink = ['fat12', 'fat16', 'fat32', 'exfat', 'fs_generic'] supported_fs_symlink = ['ext4'] supported_fs_rename = ['fat12', 'fat16', 'fat32'] @@ -108,6 +108,22 @@ def pytest_generate_tests(metafunc): # # Helper functions # +def fstype_to_prefix(fs_type): + """Convert a file system type to an U-Boot command prefix + + Args: + fs_type: File system type. + + Return: + A corresponding command prefix for file system type. + """ + if fs_type == 'fs_generic' or fs_type == 'exfat': + return '' + elif re.match('fat', fs_type): + return 'fat' + else: + return fs_type + def fstype_to_ubname(fs_type): """Convert a file system type to an U-Boot specific string @@ -139,8 +155,12 @@ def check_ubconfig(config, fs_type): Return: Nothing. """ - if not config.buildconfig.get('config_cmd_%s' % fs_type, None): + if fs_type == 'exfat' and not config.buildconfig.get('config_fs_%s' % fs_type, None): + pytest.skip('.config feature "FS_%s" not enabled' % fs_type.upper()) + if fs_type != 'exfat' and not config.buildconfig.get('config_cmd_%s' % fs_type, None): pytest.skip('.config feature "CMD_%s" not enabled' % fs_type.upper()) + if fs_type == 'fs_generic' or fs_type == 'exfat': + return if not config.buildconfig.get('config_%s_write' % fs_type, None): pytest.skip('.config feature "%s_WRITE" not enabled' % fs_type.upper()) @@ -178,6 +198,8 @@ def fs_obj_basic(request, u_boot_config): volume file name and a list of MD5 hashes. """ fs_type = request.param + fs_cmd_prefix = fstype_to_prefix(fs_type) + fs_cmd_write = 'save' if fs_type == 'fs_generic' or fs_type == 'exfat' else 'write' fs_img = '' fs_ubtype = fstype_to_ubname(fs_type) @@ -267,7 +289,7 @@ def fs_obj_basic(request, u_boot_config): pytest.skip('Setup failed for filesystem: ' + fs_type + '. {}'.format(err)) return else: - yield [fs_ubtype, fs_img, md5val] + yield [fs_ubtype, fs_cmd_prefix, fs_cmd_write, fs_img, md5val] finally: call('rm -rf %s' % scratch_dir, shell=True) call('rm -f %s' % fs_img, shell=True) @@ -288,6 +310,8 @@ def fs_obj_ext(request, u_boot_config): volume file name and a list of MD5 hashes. """ fs_type = request.param + fs_cmd_prefix = fstype_to_prefix(fs_type) + fs_cmd_write = 'save' if fs_type == 'fs_generic' or fs_type == 'exfat' else 'write' fs_img = '' fs_ubtype = fstype_to_ubname(fs_type) @@ -357,7 +381,7 @@ def fs_obj_ext(request, u_boot_config): pytest.skip('Setup failed for filesystem: ' + fs_type) return else: - yield [fs_ubtype, fs_img, md5val] + yield [fs_ubtype, fs_cmd_prefix, fs_cmd_write, fs_img, md5val] finally: call('rm -rf %s' % scratch_dir, shell=True) call('rm -f %s' % fs_img, shell=True) @@ -378,6 +402,7 @@ def fs_obj_mkdir(request, u_boot_config): volume file name. """ fs_type = request.param + fs_cmd_prefix = fstype_to_prefix(fs_type) fs_img = '' fs_ubtype = fstype_to_ubname(fs_type) @@ -390,7 +415,7 @@ def fs_obj_mkdir(request, u_boot_config): pytest.skip('Setup failed for filesystem: ' + fs_type) return else: - yield [fs_ubtype, fs_img] + yield [fs_ubtype, fs_cmd_prefix, fs_img] call('rm -f %s' % fs_img, shell=True) # @@ -409,6 +434,7 @@ def fs_obj_unlink(request, u_boot_config): volume file name. """ fs_type = request.param + fs_cmd_prefix = fstype_to_prefix(fs_type) fs_img = '' fs_ubtype = fstype_to_ubname(fs_type) @@ -456,7 +482,7 @@ def fs_obj_unlink(request, u_boot_config): pytest.skip('Setup failed for filesystem: ' + fs_type) return else: - yield [fs_ubtype, fs_img] + yield [fs_ubtype, fs_cmd_prefix, fs_img] finally: call('rm -rf %s' % scratch_dir, shell=True) call('rm -f %s' % fs_img, shell=True) diff --git a/test/py/tests/test_fs/fstest_helpers.py b/test/py/tests/test_fs/fstest_helpers.py index c1447b4d43e..d25326ee993 100644 --- a/test/py/tests/test_fs/fstest_helpers.py +++ b/test/py/tests/test_fs/fstest_helpers.py @@ -9,6 +9,8 @@ def assert_fs_integrity(fs_type, fs_img): try: if fs_type == 'ext4': check_call('fsck.ext4 -n -f %s' % fs_img, shell=True) + elif fs_type == 'exfat': + check_call('fsck.exfat -n %s' % fs_img, shell=True) elif fs_type in ['fat12', 'fat16', 'fat32']: check_call('fsck.fat -n %s' % fs_img, shell=True) except CalledProcessError: diff --git a/test/py/tests/test_fs/test_basic.py b/test/py/tests/test_fs/test_basic.py index 5a02348bb94..64a3b50f52a 100644 --- a/test/py/tests/test_fs/test_basic.py +++ b/test/py/tests/test_fs/test_basic.py @@ -20,32 +20,32 @@ class TestFsBasic(object): """ Test Case 1 - ls command, listing a root directory and invalid directory """ - fs_type,fs_img,md5val = fs_obj_basic + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic with ubman.log.section('Test Case 1a - ls'): # Test Case 1 - ls output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%sls host 0:0' % fs_type]) + '%sls host 0:0' % fs_cmd_prefix]) assert(re.search('2621440000 *%s' % BIG_FILE, ''.join(output))) assert(re.search('1048576 *%s' % SMALL_FILE, ''.join(output))) with ubman.log.section('Test Case 1b - ls (invalid dir)'): # In addition, test with a nonexistent directory to see if we crash. output = ubman.run_command( - '%sls host 0:0 invalid_d' % fs_type) + '%sls host 0:0 invalid_d' % fs_cmd_prefix) assert('' == output) def test_fs2(self, ubman, fs_obj_basic): """ Test Case 2 - size command for a small file """ - fs_type,fs_img,md5val = fs_obj_basic + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic with ubman.log.section('Test Case 2a - size (small)'): # 1MB is 0x0010 0000 # Test Case 2a - size of small file output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%ssize host 0:0 /%s' % (fs_type, SMALL_FILE), + '%ssize host 0:0 /%s' % (fs_cmd_prefix, SMALL_FILE), 'printenv filesize', 'setenv filesize']) assert('filesize=100000' in ''.join(output)) @@ -53,7 +53,7 @@ class TestFsBasic(object): with ubman.log.section('Test Case 2b - size (/../<file>)'): # Test Case 2b - size of small file via a path using '..' output = ubman.run_command_list([ - '%ssize host 0:0 /SUBDIR/../%s' % (fs_type, SMALL_FILE), + '%ssize host 0:0 /SUBDIR/../%s' % (fs_cmd_prefix, SMALL_FILE), 'printenv filesize', 'setenv filesize']) assert('filesize=100000' in ''.join(output)) @@ -62,13 +62,13 @@ class TestFsBasic(object): """ Test Case 3 - size command for a large file """ - fs_type,fs_img,md5val = fs_obj_basic + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic with ubman.log.section('Test Case 3 - size (large)'): # 2.5GB (1024*1024*2500) is 0x9C40 0000 # Test Case 3 - size of big file output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%ssize host 0:0 /%s' % (fs_type, BIG_FILE), + '%ssize host 0:0 /%s' % (fs_cmd_prefix, BIG_FILE), 'printenv filesize', 'setenv filesize']) assert('filesize=9c400000' in ''.join(output)) @@ -77,12 +77,12 @@ class TestFsBasic(object): """ Test Case 4 - load a small file, 1MB """ - fs_type,fs_img,md5val = fs_obj_basic + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic with ubman.log.section('Test Case 4 - load (small)'): # Test Case 4a - Read full 1MB of small file output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%sload host 0:0 %x /%s' % (fs_type, ADDR, SMALL_FILE), + '%sload host 0:0 %x /%s' % (fs_cmd_prefix, ADDR, SMALL_FILE), 'printenv filesize']) assert('filesize=100000' in ''.join(output)) @@ -96,12 +96,12 @@ class TestFsBasic(object): """ Test Case 5 - load, reading first 1MB of 3GB file """ - fs_type,fs_img,md5val = fs_obj_basic + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic with ubman.log.section('Test Case 5 - load (first 1MB)'): # Test Case 5a - First 1MB of big file output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%sload host 0:0 %x /%s %x 0x0' % (fs_type, ADDR, BIG_FILE, LENGTH), + '%sload host 0:0 %x /%s %x 0x0' % (fs_cmd_prefix, ADDR, BIG_FILE, LENGTH), 'printenv filesize']) assert('filesize=100000' in ''.join(output)) @@ -115,14 +115,14 @@ class TestFsBasic(object): """ Test Case 6 - load, reading last 1MB of 3GB file """ - fs_type,fs_img,md5val = fs_obj_basic + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic with ubman.log.section('Test Case 6 - load (last 1MB)'): # fails for ext as no offset support # Test Case 6a - Last 1MB of big file output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, '%sload host 0:0 %x /%s %x 0x9c300000' - % (fs_type, ADDR, BIG_FILE, LENGTH), + % (fs_cmd_prefix, ADDR, BIG_FILE, LENGTH), 'printenv filesize']) assert('filesize=100000' in ''.join(output)) @@ -136,14 +136,14 @@ class TestFsBasic(object): """ Test Case 7 - load, 1MB from the last 1MB in 2GB """ - fs_type,fs_img,md5val = fs_obj_basic + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic with ubman.log.section('Test Case 7 - load (last 1MB in 2GB)'): # fails for ext as no offset support # Test Case 7a - One from the last 1MB chunk of 2GB output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, '%sload host 0:0 %x /%s %x 0x7ff00000' - % (fs_type, ADDR, BIG_FILE, LENGTH), + % (fs_cmd_prefix, ADDR, BIG_FILE, LENGTH), 'printenv filesize']) assert('filesize=100000' in ''.join(output)) @@ -157,14 +157,14 @@ class TestFsBasic(object): """ Test Case 8 - load, reading first 1MB in 2GB """ - fs_type,fs_img,md5val = fs_obj_basic + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic with ubman.log.section('Test Case 8 - load (first 1MB in 2GB)'): # fails for ext as no offset support # Test Case 8a - One from the start 1MB chunk from 2GB output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, '%sload host 0:0 %x /%s %x 0x80000000' - % (fs_type, ADDR, BIG_FILE, LENGTH), + % (fs_cmd_prefix, ADDR, BIG_FILE, LENGTH), 'printenv filesize']) assert('filesize=100000' in ''.join(output)) @@ -178,14 +178,14 @@ class TestFsBasic(object): """ Test Case 9 - load, 1MB crossing 2GB boundary """ - fs_type,fs_img,md5val = fs_obj_basic + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic with ubman.log.section('Test Case 9 - load (crossing 2GB boundary)'): # fails for ext as no offset support # Test Case 9a - One 1MB chunk crossing the 2GB boundary output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, '%sload host 0:0 %x /%s %x 0x7ff80000' - % (fs_type, ADDR, BIG_FILE, LENGTH), + % (fs_cmd_prefix, ADDR, BIG_FILE, LENGTH), 'printenv filesize']) assert('filesize=100000' in ''.join(output)) @@ -199,14 +199,14 @@ class TestFsBasic(object): """ Test Case 10 - load, reading beyond file end'): """ - fs_type,fs_img,md5val = fs_obj_basic + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic with ubman.log.section('Test Case 10 - load (beyond file end)'): # Generic failure case # Test Case 10 - 2MB chunk from the last 1MB of big file output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, '%sload host 0:0 %x /%s 0x00200000 0x9c300000' - % (fs_type, ADDR, BIG_FILE), + % (fs_cmd_prefix, ADDR, BIG_FILE), 'printenv filesize', 'md5sum %x $filesize' % ADDR, 'setenv filesize']) @@ -216,22 +216,22 @@ class TestFsBasic(object): """ Test Case 11 - write' """ - fs_type,fs_img,md5val = fs_obj_basic + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic with ubman.log.section('Test Case 11 - write'): # Read 1MB from small file # Write it back to test the writes # Test Case 11a - Check that the write succeeded output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%sload host 0:0 %x /%s' % (fs_type, ADDR, SMALL_FILE), - '%swrite host 0:0 %x /%s.w $filesize' - % (fs_type, ADDR, SMALL_FILE)]) + '%sload host 0:0 %x /%s' % (fs_cmd_prefix, ADDR, SMALL_FILE), + '%s%s host 0:0 %x /%s.w $filesize' + % (fs_cmd_prefix, fs_cmd_write, ADDR, SMALL_FILE)]) assert('1048576 bytes written' in ''.join(output)) # Test Case 11b - Check md5 of written to is same # as the one read from output = ubman.run_command_list([ - '%sload host 0:0 %x /%s.w' % (fs_type, ADDR, SMALL_FILE), + '%sload host 0:0 %x /%s.w' % (fs_cmd_prefix, ADDR, SMALL_FILE), 'md5sum %x $filesize' % ADDR, 'setenv filesize']) assert(md5val[0] in ''.join(output)) @@ -241,7 +241,7 @@ class TestFsBasic(object): """ Test Case 12 - write to "." directory """ - fs_type,fs_img,md5val = fs_obj_basic + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic with ubman.log.section('Test Case 12 - write (".")'): # Next test case checks writing a file whose dirent # is the first in the block, which is always true for "." @@ -249,7 +249,8 @@ class TestFsBasic(object): # Test Case 12 - Check directory traversal output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%swrite host 0:0 %x /. 0x10' % (fs_type, ADDR)]) + '%s%s host 0:0 %x /. 0x10' + % (fs_cmd_prefix, fs_cmd_write, ADDR)]) assert('Unable to write' in ''.join(output)) assert_fs_integrity(fs_type, fs_img) @@ -257,23 +258,23 @@ class TestFsBasic(object): """ Test Case 13 - write to a file with "/./<filename>" """ - fs_type,fs_img,md5val = fs_obj_basic + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_basic with ubman.log.section('Test Case 13 - write ("./<file>")'): # Read 1MB from small file # Write it via "same directory", i.e. "." dirent # Test Case 13a - Check directory traversal output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%sload host 0:0 %x /%s' % (fs_type, ADDR, SMALL_FILE), - '%swrite host 0:0 %x /./%s2 $filesize' - % (fs_type, ADDR, SMALL_FILE)]) + '%sload host 0:0 %x /%s' % (fs_cmd_prefix, ADDR, SMALL_FILE), + '%s%s host 0:0 %x /./%s2 $filesize' + % (fs_cmd_prefix, fs_cmd_write, ADDR, SMALL_FILE)]) assert('1048576 bytes written' in ''.join(output)) # Test Case 13b - Check md5 of written to is same # as the one read from output = ubman.run_command_list([ 'mw.b %x 00 100' % ADDR, - '%sload host 0:0 %x /./%s2' % (fs_type, ADDR, SMALL_FILE), + '%sload host 0:0 %x /./%s2' % (fs_cmd_prefix, ADDR, SMALL_FILE), 'md5sum %x $filesize' % ADDR, 'setenv filesize']) assert(md5val[0] in ''.join(output)) @@ -282,7 +283,7 @@ class TestFsBasic(object): # as the one read from output = ubman.run_command_list([ 'mw.b %x 00 100' % ADDR, - '%sload host 0:0 %x /%s2' % (fs_type, ADDR, SMALL_FILE), + '%sload host 0:0 %x /%s2' % (fs_cmd_prefix, ADDR, SMALL_FILE), 'md5sum %x $filesize' % ADDR, 'setenv filesize']) assert(md5val[0] in ''.join(output)) diff --git a/test/py/tests/test_fs/test_ext.py b/test/py/tests/test_fs/test_ext.py index 9c213f2da55..41f126e7876 100644 --- a/test/py/tests/test_fs/test_ext.py +++ b/test/py/tests/test_fs/test_ext.py @@ -33,20 +33,20 @@ class TestFsExt(object): """ Test Case 1 - write a file with absolute path """ - fs_type,fs_img,md5val = fs_obj_ext + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_ext with ubman.log.section('Test Case 1 - write with abs path'): # Test Case 1a - Check if command successfully returned output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE), - '%swrite host 0:0 %x /dir1/%s.w1 $filesize' - % (fs_type, ADDR, MIN_FILE)]) + '%sload host 0:0 %x /%s' % (fs_cmd_prefix, ADDR, MIN_FILE), + '%s%s host 0:0 %x /dir1/%s.w1 $filesize' + % (fs_cmd_prefix, fs_cmd_write, ADDR, MIN_FILE)]) assert('20480 bytes written' in ''.join(output)) # Test Case 1b - Check md5 of file content output = ubman.run_command_list([ 'mw.b %x 00 100' % ADDR, - '%sload host 0:0 %x /dir1/%s.w1' % (fs_type, ADDR, MIN_FILE), + '%sload host 0:0 %x /dir1/%s.w1' % (fs_cmd_prefix, ADDR, MIN_FILE), 'md5sum %x $filesize' % ADDR, 'setenv filesize']) assert(md5val[0] in ''.join(output)) @@ -56,20 +56,20 @@ class TestFsExt(object): """ Test Case 2 - write to a file with relative path """ - fs_type,fs_img,md5val = fs_obj_ext + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_ext with ubman.log.section('Test Case 2 - write with rel path'): # Test Case 2a - Check if command successfully returned output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE), - '%swrite host 0:0 %x dir1/%s.w2 $filesize' - % (fs_type, ADDR, MIN_FILE)]) + '%sload host 0:0 %x /%s' % (fs_cmd_prefix, ADDR, MIN_FILE), + '%s%s host 0:0 %x dir1/%s.w2 $filesize' + % (fs_cmd_prefix, fs_cmd_write, ADDR, MIN_FILE)]) assert('20480 bytes written' in ''.join(output)) # Test Case 2b - Check md5 of file content output = ubman.run_command_list([ 'mw.b %x 00 100' % ADDR, - '%sload host 0:0 %x dir1/%s.w2' % (fs_type, ADDR, MIN_FILE), + '%sload host 0:0 %x dir1/%s.w2' % (fs_cmd_prefix, ADDR, MIN_FILE), 'md5sum %x $filesize' % ADDR, 'setenv filesize']) assert(md5val[0] in ''.join(output)) @@ -79,14 +79,14 @@ class TestFsExt(object): """ Test Case 3 - write to a file with invalid path """ - fs_type,fs_img,md5val = fs_obj_ext + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_ext with ubman.log.section('Test Case 3 - write with invalid path'): # Test Case 3 - Check if command expectedly failed output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE), - '%swrite host 0:0 %x /dir1/none/%s.w3 $filesize' - % (fs_type, ADDR, MIN_FILE)]) + '%sload host 0:0 %x /%s' % (fs_cmd_prefix, ADDR, MIN_FILE), + '%s%s host 0:0 %x /dir1/none/%s.w3 $filesize' + % (fs_cmd_prefix, fs_cmd_write, ADDR, MIN_FILE)]) assert('Unable to write file /dir1/none/' in ''.join(output)) assert_fs_integrity(fs_type, fs_img) @@ -94,22 +94,22 @@ class TestFsExt(object): """ Test Case 4 - write at non-zero offset, enlarging file size """ - fs_type,fs_img,md5val = fs_obj_ext + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_ext with ubman.log.section('Test Case 4 - write at non-zero offset, enlarging file size'): # Test Case 4a - Check if command successfully returned output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE), - '%swrite host 0:0 %x /dir1/%s.w4 $filesize' - % (fs_type, ADDR, MIN_FILE)]) + '%sload host 0:0 %x /%s' % (fs_cmd_prefix, ADDR, MIN_FILE), + '%s%s host 0:0 %x /dir1/%s.w4 $filesize' + % (fs_cmd_prefix, fs_cmd_write, ADDR, MIN_FILE)]) output = ubman.run_command( - '%swrite host 0:0 %x /dir1/%s.w4 $filesize 0x1400' - % (fs_type, ADDR, MIN_FILE)) + '%s%s host 0:0 %x /dir1/%s.w4 $filesize 0x1400' + % (fs_cmd_prefix, fs_cmd_write, ADDR, MIN_FILE)) assert('20480 bytes written' in output) # Test Case 4b - Check size of written file output = ubman.run_command_list([ - '%ssize host 0:0 /dir1/%s.w4' % (fs_type, MIN_FILE), + '%ssize host 0:0 /dir1/%s.w4' % (fs_cmd_prefix, MIN_FILE), 'printenv filesize', 'setenv filesize']) assert('filesize=6400' in ''.join(output)) @@ -117,7 +117,7 @@ class TestFsExt(object): # Test Case 4c - Check md5 of file content output = ubman.run_command_list([ 'mw.b %x 00 100' % ADDR, - '%sload host 0:0 %x /dir1/%s.w4' % (fs_type, ADDR, MIN_FILE), + '%sload host 0:0 %x /dir1/%s.w4' % (fs_cmd_prefix, ADDR, MIN_FILE), 'md5sum %x $filesize' % ADDR, 'setenv filesize']) assert(md5val[1] in ''.join(output)) @@ -127,22 +127,22 @@ class TestFsExt(object): """ Test Case 5 - write at non-zero offset, shrinking file size """ - fs_type,fs_img,md5val = fs_obj_ext + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_ext with ubman.log.section('Test Case 5 - write at non-zero offset, shrinking file size'): # Test Case 5a - Check if command successfully returned output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE), - '%swrite host 0:0 %x /dir1/%s.w5 $filesize' - % (fs_type, ADDR, MIN_FILE)]) + '%sload host 0:0 %x /%s' % (fs_cmd_prefix, ADDR, MIN_FILE), + '%s%s host 0:0 %x /dir1/%s.w5 $filesize' + % (fs_cmd_prefix, fs_cmd_write, ADDR, MIN_FILE)]) output = ubman.run_command( - '%swrite host 0:0 %x /dir1/%s.w5 0x1400 0x1400' - % (fs_type, ADDR, MIN_FILE)) + '%s%s host 0:0 %x /dir1/%s.w5 0x1400 0x1400' + % (fs_cmd_prefix, fs_cmd_write, ADDR, MIN_FILE)) assert('5120 bytes written' in output) # Test Case 5b - Check size of written file output = ubman.run_command_list([ - '%ssize host 0:0 /dir1/%s.w5' % (fs_type, MIN_FILE), + '%ssize host 0:0 /dir1/%s.w5' % (fs_cmd_prefix, MIN_FILE), 'printenv filesize', 'setenv filesize']) assert('filesize=2800' in ''.join(output)) @@ -150,7 +150,7 @@ class TestFsExt(object): # Test Case 5c - Check md5 of file content output = ubman.run_command_list([ 'mw.b %x 00 100' % ADDR, - '%sload host 0:0 %x /dir1/%s.w5' % (fs_type, ADDR, MIN_FILE), + '%sload host 0:0 %x /dir1/%s.w5' % (fs_cmd_prefix, ADDR, MIN_FILE), 'md5sum %x $filesize' % ADDR, 'setenv filesize']) assert(md5val[2] in ''.join(output)) @@ -160,22 +160,22 @@ class TestFsExt(object): """ Test Case 6 - write nothing at the start, truncating to zero """ - fs_type,fs_img,md5val = fs_obj_ext + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_ext with ubman.log.section('Test Case 6 - write nothing at the start, truncating to zero'): # Test Case 6a - Check if command successfully returned output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE), - '%swrite host 0:0 %x /dir1/%s.w6 $filesize' - % (fs_type, ADDR, MIN_FILE)]) + '%sload host 0:0 %x /%s' % (fs_cmd_prefix, ADDR, MIN_FILE), + '%s%s host 0:0 %x /dir1/%s.w6 $filesize' + % (fs_cmd_prefix, fs_cmd_write, ADDR, MIN_FILE)]) output = ubman.run_command( - '%swrite host 0:0 %x /dir1/%s.w6 0 0' - % (fs_type, ADDR, MIN_FILE)) + '%s%s host 0:0 %x /dir1/%s.w6 0 0' + % (fs_cmd_prefix, fs_cmd_write, ADDR, MIN_FILE)) assert('0 bytes written' in output) # Test Case 6b - Check size of written file output = ubman.run_command_list([ - '%ssize host 0:0 /dir1/%s.w6' % (fs_type, MIN_FILE), + '%ssize host 0:0 /dir1/%s.w6' % (fs_cmd_prefix, MIN_FILE), 'printenv filesize', 'setenv filesize']) assert('filesize=0' in ''.join(output)) @@ -185,22 +185,22 @@ class TestFsExt(object): """ Test Case 7 - write at the end (append) """ - fs_type,fs_img,md5val = fs_obj_ext + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_ext with ubman.log.section('Test Case 7 - write at the end (append)'): # Test Case 7a - Check if command successfully returned output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE), - '%swrite host 0:0 %x /dir1/%s.w7 $filesize' - % (fs_type, ADDR, MIN_FILE)]) + '%sload host 0:0 %x /%s' % (fs_cmd_prefix, ADDR, MIN_FILE), + '%s%s host 0:0 %x /dir1/%s.w7 $filesize' + % (fs_cmd_prefix, fs_cmd_write, ADDR, MIN_FILE)]) output = ubman.run_command( - '%swrite host 0:0 %x /dir1/%s.w7 $filesize $filesize' - % (fs_type, ADDR, MIN_FILE)) + '%s%s host 0:0 %x /dir1/%s.w7 $filesize $filesize' + % (fs_cmd_prefix, fs_cmd_write, ADDR, MIN_FILE)) assert('20480 bytes written' in output) # Test Case 7b - Check size of written file output = ubman.run_command_list([ - '%ssize host 0:0 /dir1/%s.w7' % (fs_type, MIN_FILE), + '%ssize host 0:0 /dir1/%s.w7' % (fs_cmd_prefix, MIN_FILE), 'printenv filesize', 'setenv filesize']) assert('filesize=a000' in ''.join(output)) @@ -208,7 +208,7 @@ class TestFsExt(object): # Test Case 7c - Check md5 of file content output = ubman.run_command_list([ 'mw.b %x 00 100' % ADDR, - '%sload host 0:0 %x /dir1/%s.w7' % (fs_type, ADDR, MIN_FILE), + '%sload host 0:0 %x /dir1/%s.w7' % (fs_cmd_prefix, ADDR, MIN_FILE), 'md5sum %x $filesize' % ADDR, 'setenv filesize']) assert(md5val[3] in ''.join(output)) @@ -218,17 +218,17 @@ class TestFsExt(object): """ Test Case 8 - write at offset beyond the end of file """ - fs_type,fs_img,md5val = fs_obj_ext + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_ext with ubman.log.section('Test Case 8 - write beyond the end'): # Test Case 8a - Check if command expectedly failed output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE), - '%swrite host 0:0 %x /dir1/%s.w8 $filesize' - % (fs_type, ADDR, MIN_FILE)]) + '%sload host 0:0 %x /%s' % (fs_cmd_prefix, ADDR, MIN_FILE), + '%s%s host 0:0 %x /dir1/%s.w8 $filesize' + % (fs_cmd_prefix, fs_cmd_write, ADDR, MIN_FILE)]) output = ubman.run_command( - '%swrite host 0:0 %x /dir1/%s.w8 0x1400 %x' - % (fs_type, ADDR, MIN_FILE, 0x100000 + 0x1400)) + '%s%s host 0:0 %x /dir1/%s.w8 0x1400 %x' + % (fs_cmd_prefix, fs_cmd_write, ADDR, MIN_FILE, 0x100000 + 0x1400)) assert('Unable to write file /dir1' in output) assert_fs_integrity(fs_type, fs_img) @@ -236,14 +236,14 @@ class TestFsExt(object): """ Test Case 9 - write to a non-existing file at non-zero offset """ - fs_type,fs_img,md5val = fs_obj_ext + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_ext with ubman.log.section('Test Case 9 - write to non-existing file with non-zero offset'): # Test Case 9a - Check if command expectedly failed output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE), - '%swrite host 0:0 %x /dir1/%s.w9 0x1400 0x1400' - % (fs_type, ADDR, MIN_FILE)]) + '%sload host 0:0 %x /%s' % (fs_cmd_prefix, ADDR, MIN_FILE), + '%s%s host 0:0 %x /dir1/%s.w9 0x1400 0x1400' + % (fs_cmd_prefix, fs_cmd_write, ADDR, MIN_FILE)]) assert('Unable to write file /dir1' in ''.join(output)) assert_fs_integrity(fs_type, fs_img) @@ -252,7 +252,7 @@ class TestFsExt(object): 'Test Case 10 - create/delete as many directories under root directory as amount of directory entries goes beyond one cluster size)' """ - fs_type,fs_img,md5val = fs_obj_ext + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_ext with ubman.log.section('Test Case 10 - create/delete (many)'): # Test Case 10a - Create many files # Please note that the size of directory entry is 32 bytes. @@ -262,9 +262,9 @@ class TestFsExt(object): for i in range(0, 66): output = ubman.run_command( - '%swrite host 0:0 %x /FILE0123456789_%02x 100' - % (fs_type, ADDR, i)) - output = ubman.run_command('%sls host 0:0 /' % fs_type) + '%s%s host 0:0 %x /FILE0123456789_%02x 100' + % (fs_cmd_prefix, fs_cmd_write, ADDR, i)) + output = ubman.run_command('%sls host 0:0 /' % fs_cmd_prefix) assert('FILE0123456789_00' in output) assert('FILE0123456789_41' in output) @@ -272,8 +272,8 @@ class TestFsExt(object): for i in range(0, 66): output = ubman.run_command( '%srm host 0:0 /FILE0123456789_%02x' - % (fs_type, i)) - output = ubman.run_command('%sls host 0:0 /' % fs_type) + % (fs_cmd_prefix, i)) + output = ubman.run_command('%sls host 0:0 /' % fs_cmd_prefix) assert(not 'FILE0123456789_00' in output) assert(not 'FILE0123456789_41' in output) @@ -281,9 +281,9 @@ class TestFsExt(object): # Please note no.64 and 65 are intentionally re-created for i in range(64, 128): output = ubman.run_command( - '%swrite host 0:0 %x /FILE0123456789_%02x 100' - % (fs_type, ADDR, i)) - output = ubman.run_command('%sls host 0:0 /' % fs_type) + '%s%s host 0:0 %x /FILE0123456789_%02x 100' + % (fs_cmd_prefix, fs_cmd_write, ADDR, i)) + output = ubman.run_command('%sls host 0:0 /' % fs_cmd_prefix) assert('FILE0123456789_40' in output) assert('FILE0123456789_79' in output) @@ -294,7 +294,7 @@ class TestFsExt(object): 'Test Case 11 - create/delete as many directories under non-root directory as amount of directory entries goes beyond one cluster size)' """ - fs_type,fs_img,md5val = fs_obj_ext + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_ext with ubman.log.section('Test Case 11 - create/delete (many)'): # Test Case 11a - Create many files # Please note that the size of directory entry is 32 bytes. @@ -304,9 +304,9 @@ class TestFsExt(object): for i in range(0, 66): output = ubman.run_command( - '%swrite host 0:0 %x /dir1/FILE0123456789_%02x 100' - % (fs_type, ADDR, i)) - output = ubman.run_command('%sls host 0:0 /dir1' % fs_type) + '%s%s host 0:0 %x /dir1/FILE0123456789_%02x 100' + % (fs_cmd_prefix, fs_cmd_write, ADDR, i)) + output = ubman.run_command('%sls host 0:0 /dir1' % fs_cmd_prefix) assert('FILE0123456789_00' in output) assert('FILE0123456789_41' in output) @@ -314,8 +314,8 @@ class TestFsExt(object): for i in range(0, 66): output = ubman.run_command( '%srm host 0:0 /dir1/FILE0123456789_%02x' - % (fs_type, i)) - output = ubman.run_command('%sls host 0:0 /dir1' % fs_type) + % (fs_cmd_prefix, i)) + output = ubman.run_command('%sls host 0:0 /dir1' % fs_cmd_prefix) assert(not 'FILE0123456789_00' in output) assert(not 'FILE0123456789_41' in output) @@ -323,9 +323,9 @@ class TestFsExt(object): # Please note no.64 and 65 are intentionally re-created for i in range(64, 128): output = ubman.run_command( - '%swrite host 0:0 %x /dir1/FILE0123456789_%02x 100' - % (fs_type, ADDR, i)) - output = ubman.run_command('%sls host 0:0 /dir1' % fs_type) + '%s%s host 0:0 %x /dir1/FILE0123456789_%02x 100' + % (fs_cmd_prefix, fs_cmd_write, ADDR, i)) + output = ubman.run_command('%sls host 0:0 /dir1' % fs_cmd_prefix) assert('FILE0123456789_40' in output) assert('FILE0123456789_79' in output) @@ -335,21 +335,29 @@ class TestFsExt(object): """ Test Case 12 - write plain and mangle file """ - fs_type,fs_img,md5val = fs_obj_ext + fs_type,fs_cmd_prefix,fs_cmd_write,fs_img,md5val = fs_obj_ext with ubman.log.section('Test Case 12 - write plain and mangle file'): # Test Case 12a - Check if command successfully returned output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%swrite host 0:0 %x /%s 0' - % (fs_type, ADDR, PLAIN_FILE), - '%swrite host 0:0 %x /%s 0' - % (fs_type, ADDR, MANGLE_FILE)]) + '%s%s host 0:0 %x /%s 0' + % (fs_cmd_prefix, fs_cmd_write, ADDR, PLAIN_FILE), + '%s%s host 0:0 %x /%s 0' + % (fs_cmd_prefix, fs_cmd_write, ADDR, MANGLE_FILE)]) assert('0 bytes written' in ''.join(output)) - # Test Case 12b - Read file system content - output = check_output('mdir -i %s' % fs_img, shell=True).decode() - # Test Case 12c - Check if short filename is not mangled - assert(str2fat(PLAIN_FILE) in ''.join(output)) - # Test Case 12d - Check if long filename is mangled - assert(str2fat(MANGLE_FILE) in ''.join(output)) + if fs_type == 'exfat': + # Test Case 12b - Read file system content + output = check_output('fattools ls %s' % fs_img, shell=True).decode() + # Test Case 12c - Check if short filename is not mangled + assert(PLAIN_FILE in ''.join(output)) + # Test Case 12d - Check if long filename is mangled + assert(MANGLE_FILE in ''.join(output)) + else: + # Test Case 12b - Read file system content + output = check_output('mdir -i %s' % fs_img, shell=True).decode() + # Test Case 12c - Check if short filename is not mangled + assert(str2fat(PLAIN_FILE) in ''.join(output)) + # Test Case 12d - Check if long filename is mangled + assert(str2fat(MANGLE_FILE) in ''.join(output)) assert_fs_integrity(fs_type, fs_img) diff --git a/test/py/tests/test_fs/test_mkdir.py b/test/py/tests/test_fs/test_mkdir.py index df680a87d57..1578c3cba3a 100644 --- a/test/py/tests/test_fs/test_mkdir.py +++ b/test/py/tests/test_fs/test_mkdir.py @@ -18,16 +18,16 @@ class TestMkdir(object): """ Test Case 1 - create a directory under a root """ - fs_type,fs_img = fs_obj_mkdir + fs_type,fs_cmd_prefix,fs_img = fs_obj_mkdir with ubman.log.section('Test Case 1 - mkdir'): output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%smkdir host 0:0 dir1' % fs_type, - '%sls host 0:0 /' % fs_type]) + '%smkdir host 0:0 dir1' % fs_cmd_prefix, + '%sls host 0:0 /' % fs_cmd_prefix]) assert('dir1/' in ''.join(output)) output = ubman.run_command( - '%sls host 0:0 dir1' % fs_type) + '%sls host 0:0 dir1' % fs_cmd_prefix) assert('./' in output) assert('../' in output) assert_fs_integrity(fs_type, fs_img) @@ -37,16 +37,16 @@ class TestMkdir(object): """ Test Case 2 - create a directory under a sub-directory """ - fs_type,fs_img = fs_obj_mkdir + fs_type,fs_cmd_prefix,fs_img = fs_obj_mkdir with ubman.log.section('Test Case 2 - mkdir (sub-sub directory)'): output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%smkdir host 0:0 dir1/dir2' % fs_type, - '%sls host 0:0 dir1' % fs_type]) + '%smkdir host 0:0 dir1/dir2' % fs_cmd_prefix, + '%sls host 0:0 dir1' % fs_cmd_prefix]) assert('dir2/' in ''.join(output)) output = ubman.run_command( - '%sls host 0:0 dir1/dir2' % fs_type) + '%sls host 0:0 dir1/dir2' % fs_cmd_prefix) assert('./' in output) assert('../' in output) assert_fs_integrity(fs_type, fs_img) @@ -56,11 +56,11 @@ class TestMkdir(object): Test Case 3 - trying to create a directory with a non-existing path should fail """ - fs_type,fs_img = fs_obj_mkdir + fs_type,fs_cmd_prefix,fs_img = fs_obj_mkdir with ubman.log.section('Test Case 3 - mkdir (non-existing path)'): output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%smkdir host 0:0 none/dir3' % fs_type]) + '%smkdir host 0:0 none/dir3' % fs_cmd_prefix]) assert('Unable to create a directory' in ''.join(output)) assert_fs_integrity(fs_type, fs_img) @@ -68,11 +68,11 @@ class TestMkdir(object): """ Test Case 4 - trying to create "." should fail """ - fs_type,fs_img = fs_obj_mkdir + fs_type,fs_cmd_prefix,fs_img = fs_obj_mkdir with ubman.log.section('Test Case 4 - mkdir (".")'): output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%smkdir host 0:0 .' % fs_type]) + '%smkdir host 0:0 .' % fs_cmd_prefix]) assert('Unable to create a directory' in ''.join(output)) assert_fs_integrity(fs_type, fs_img) @@ -80,11 +80,11 @@ class TestMkdir(object): """ Test Case 5 - trying to create ".." should fail """ - fs_type,fs_img = fs_obj_mkdir + fs_type,fs_cmd_prefix,fs_img = fs_obj_mkdir with ubman.log.section('Test Case 5 - mkdir ("..")'): output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%smkdir host 0:0 ..' % fs_type]) + '%smkdir host 0:0 ..' % fs_cmd_prefix]) assert('Unable to create a directory' in ''.join(output)) assert_fs_integrity(fs_type, fs_img) @@ -93,29 +93,29 @@ class TestMkdir(object): 'Test Case 6 - create as many directories as amount of directory entries goes beyond a cluster size)' """ - fs_type,fs_img = fs_obj_mkdir + fs_type,fs_cmd_prefix,fs_img = fs_obj_mkdir with ubman.log.section('Test Case 6 - mkdir (create many)'): output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%smkdir host 0:0 dir6' % fs_type, - '%sls host 0:0 /' % fs_type]) + '%smkdir host 0:0 dir6' % fs_cmd_prefix, + '%sls host 0:0 /' % fs_cmd_prefix]) assert('dir6/' in ''.join(output)) for i in range(0, 20): output = ubman.run_command( '%smkdir host 0:0 dir6/0123456789abcdef%02x' - % (fs_type, i)) - output = ubman.run_command('%sls host 0:0 dir6' % fs_type) + % (fs_cmd_prefix, i)) + output = ubman.run_command('%sls host 0:0 dir6' % fs_cmd_prefix) assert('0123456789abcdef00/' in output) assert('0123456789abcdef13/' in output) output = ubman.run_command( - '%sls host 0:0 dir6/0123456789abcdef13/.' % fs_type) + '%sls host 0:0 dir6/0123456789abcdef13/.' % fs_cmd_prefix) assert('./' in output) assert('../' in output) output = ubman.run_command( - '%sls host 0:0 dir6/0123456789abcdef13/..' % fs_type) + '%sls host 0:0 dir6/0123456789abcdef13/..' % fs_cmd_prefix) assert('0123456789abcdef00/' in output) assert('0123456789abcdef13/' in output) assert_fs_integrity(fs_type, fs_img) diff --git a/test/py/tests/test_fs/test_unlink.py b/test/py/tests/test_fs/test_unlink.py index 7e911f02413..1e2df3dbfd8 100644 --- a/test/py/tests/test_fs/test_unlink.py +++ b/test/py/tests/test_fs/test_unlink.py @@ -19,16 +19,16 @@ class TestUnlink(object): """ Test Case 1 - delete a file """ - fs_type,fs_img = fs_obj_unlink + fs_type,fs_cmd_prefix,fs_img = fs_obj_unlink with ubman.log.section('Test Case 1 - unlink (file)'): output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%srm host 0:0 dir1/file1' % fs_type, - '%sls host 0:0 dir1/file1' % fs_type]) + '%srm host 0:0 dir1/file1' % fs_cmd_prefix, + '%sls host 0:0 dir1/file1' % fs_cmd_prefix]) assert('' == ''.join(output)) output = ubman.run_command( - '%sls host 0:0 dir1/' % fs_type) + '%sls host 0:0 dir1/' % fs_cmd_prefix) assert(not 'file1' in output) assert('file2' in output) assert_fs_integrity(fs_type, fs_img) @@ -37,18 +37,18 @@ class TestUnlink(object): """ Test Case 2 - delete many files """ - fs_type,fs_img = fs_obj_unlink + fs_type,fs_cmd_prefix,fs_img = fs_obj_unlink with ubman.log.section('Test Case 2 - unlink (many)'): output = ubman.run_command('host bind 0 %s' % fs_img) for i in range(0, 20): output = ubman.run_command_list([ - '%srm host 0:0 dir2/0123456789abcdef%02x' % (fs_type, i), - '%sls host 0:0 dir2/0123456789abcdef%02x' % (fs_type, i)]) + '%srm host 0:0 dir2/0123456789abcdef%02x' % (fs_cmd_prefix, i), + '%sls host 0:0 dir2/0123456789abcdef%02x' % (fs_cmd_prefix, i)]) assert('' == ''.join(output)) output = ubman.run_command( - '%sls host 0:0 dir2' % fs_type) + '%sls host 0:0 dir2' % fs_cmd_prefix) assert('0 file(s), 2 dir(s)' in output) assert_fs_integrity(fs_type, fs_img) @@ -56,11 +56,11 @@ class TestUnlink(object): """ Test Case 3 - trying to delete a non-existing file should fail """ - fs_type,fs_img = fs_obj_unlink + fs_type,fs_cmd_prefix,fs_img = fs_obj_unlink with ubman.log.section('Test Case 3 - unlink (non-existing)'): output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%srm host 0:0 dir1/nofile' % fs_type]) + '%srm host 0:0 dir1/nofile' % fs_cmd_prefix]) assert('nofile: doesn\'t exist' in ''.join(output)) assert_fs_integrity(fs_type, fs_img) @@ -68,15 +68,15 @@ class TestUnlink(object): """ Test Case 4 - delete an empty directory """ - fs_type,fs_img = fs_obj_unlink + fs_type,fs_cmd_prefix,fs_img = fs_obj_unlink with ubman.log.section('Test Case 4 - unlink (directory)'): output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%srm host 0:0 dir4' % fs_type]) + '%srm host 0:0 dir4' % fs_cmd_prefix]) assert('' == ''.join(output)) output = ubman.run_command( - '%sls host 0:0 /' % fs_type) + '%sls host 0:0 /' % fs_cmd_prefix) assert(not 'dir4' in output) assert_fs_integrity(fs_type, fs_img) @@ -85,11 +85,11 @@ class TestUnlink(object): Test Case 5 - trying to deleting a non-empty directory ".." should fail """ - fs_type,fs_img = fs_obj_unlink + fs_type,fs_cmd_prefix,fs_img = fs_obj_unlink with ubman.log.section('Test Case 5 - unlink ("non-empty directory")'): output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%srm host 0:0 dir5' % fs_type]) + '%srm host 0:0 dir5' % fs_cmd_prefix]) assert('directory is not empty' in ''.join(output)) assert_fs_integrity(fs_type, fs_img) @@ -97,11 +97,11 @@ class TestUnlink(object): """ Test Case 6 - trying to deleting a "." should fail """ - fs_type,fs_img = fs_obj_unlink + fs_type,fs_cmd_prefix,fs_img = fs_obj_unlink with ubman.log.section('Test Case 6 - unlink (".")'): output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%srm host 0:0 dir5/.' % fs_type]) + '%srm host 0:0 dir5/.' % fs_cmd_prefix]) assert('directory is not empty' in ''.join(output)) assert_fs_integrity(fs_type, fs_img) @@ -109,10 +109,10 @@ class TestUnlink(object): """ Test Case 7 - trying to deleting a ".." should fail """ - fs_type,fs_img = fs_obj_unlink + fs_type,fs_cmd_prefix,fs_img = fs_obj_unlink with ubman.log.section('Test Case 7 - unlink ("..")'): output = ubman.run_command_list([ 'host bind 0 %s' % fs_img, - '%srm host 0:0 dir5/..' % fs_type]) + '%srm host 0:0 dir5/..' % fs_cmd_prefix]) assert('directory is not empty' in ''.join(output)) assert_fs_integrity(fs_type, fs_img) diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py index ea0c43cd4fc..b8adb597e11 100644 --- a/test/py/tests/test_ut.py +++ b/test/py/tests/test_ut.py @@ -57,6 +57,17 @@ def setup_image(ubman, devnum, part_type, img_size=20, second_part=False, stdin=spec.encode('utf-8')) return fname, mnt +def copy_partition(ubman, fsfile, outname): + """Copy a partition into a disk iamge + + Args: + ubman (ConsoleBase): U-Boot fixture + fsfile (str): Name of partition file + outname (str): Name of full-disk file to update + """ + utils.run_and_log(ubman, + f'dd if={fsfile} of={outname} bs=1M seek=1 conv=notrunc') + def setup_bootmenu_image(ubman): """Create a 20MB disk image with a single ext4 partition @@ -172,7 +183,7 @@ booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r} fsfile = 'ext18M.img' utils.run_and_log(ubman, f'fallocate -l 18M {fsfile}') utils.run_and_log(ubman, f'mkfs.ext4 {fsfile} -d {mnt}') - utils.run_and_log(ubman, f'dd if={fsfile} of={fname} bs=1M seek=1') + copy_partition(ubman, fsfile, fname) utils.run_and_log(ubman, f'rm -rf {mnt}') utils.run_and_log(ubman, f'rm -f {fsfile}') @@ -224,7 +235,7 @@ label Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl) utils.run_and_log(ubman, f'fallocate -l 18M {fsfile}') utils.run_and_log(ubman, f'mkfs.vfat {fsfile}') utils.run_and_log(ubman, ['sh', '-c', f'mcopy -i {fsfile} {mnt}/* ::/']) - utils.run_and_log(ubman, f'dd if={fsfile} of={fname} bs=1M seek=1') + copy_partition(ubman, fsfile, fname) utils.run_and_log(ubman, f'rm -rf {mnt}') utils.run_and_log(ubman, f'rm -f {fsfile}') @@ -562,7 +573,7 @@ def setup_efi_image(ubman): utils.run_and_log(ubman, f'fallocate -l 18M {fsfile}') utils.run_and_log(ubman, f'mkfs.vfat {fsfile}') utils.run_and_log(ubman, ['sh', '-c', f'mcopy -vs -i {fsfile} {mnt}/* ::/']) - utils.run_and_log(ubman, f'dd if={fsfile} of={fname} bs=1M seek=1') + copy_partition(ubman, fsfile, fname) utils.run_and_log(ubman, f'rm -rf {mnt}') utils.run_and_log(ubman, f'rm -f {fsfile}') |