diff options
Diffstat (limited to 'test')
39 files changed, 1291 insertions, 554 deletions
diff --git a/test/boot/Makefile b/test/boot/Makefile index 8ec5daa7bfe..d8eded20d4f 100644 --- a/test/boot/Makefile +++ b/test/boot/Makefile @@ -2,12 +2,15 @@ # # Copyright 2021 Google LLC +ifdef CONFIG_UT_BOOTSTD obj-$(CONFIG_BOOTSTD) += bootdev.o bootstd_common.o bootflow.o bootmeth.o obj-$(CONFIG_FIT) += image.o -obj-$(CONFIG_MEASURED_BOOT) += measurement.o obj-$(CONFIG_EXPO) += expo.o obj-$(CONFIG_CEDIT) += cedit.o +endif + +obj-$(CONFIG_MEASURED_BOOT) += measurement.o ifdef CONFIG_OF_LIVE obj-$(CONFIG_BOOTMETH_VBE_SIMPLE) += vbe_simple.o diff --git a/test/boot/expo.c b/test/boot/expo.c index 4b24f504e21..9b4aa803eb1 100644 --- a/test/boot/expo.c +++ b/test/boot/expo.c @@ -702,9 +702,7 @@ static int expo_test_build(struct unit_test_state *uts) txt = scene_obj_find(scn, item->label_id, SCENEOBJT_NONE); ut_asserteq_str("2 GHz", expo_get_str(exp, txt->str_id)); - count = 0; - list_for_each_entry(item, &menu->item_head, sibling) - count++; + count = list_count_nodes(&menu->item_head); ut_asserteq(3, count); expo_destroy(exp); diff --git a/test/cmd/Makefile b/test/cmd/Makefile index 478ef4c6f05..8f2134998ad 100644 --- a/test/cmd/Makefile +++ b/test/cmd/Makefile @@ -30,7 +30,7 @@ ifdef CONFIG_SANDBOX obj-$(CONFIG_CMD_MBR) += mbr.o obj-$(CONFIG_CMD_READ) += rw.o obj-$(CONFIG_CMD_SETEXPR) += setexpr.o +obj-$(CONFIG_CMD_WGET) += wget.o obj-$(CONFIG_ARM_FFA_TRANSPORT) += armffa.o endif obj-$(CONFIG_CMD_TEMPERATURE) += temperature.o -obj-$(CONFIG_CMD_WGET) += wget.o diff --git a/test/cmd/bdinfo.c b/test/cmd/bdinfo.c index 810174fe8d1..770b3bfb560 100644 --- a/test/cmd/bdinfo.c +++ b/test/cmd/bdinfo.c @@ -5,6 +5,7 @@ * Copyright 2023 Marek Vasut <marek.vasut+renesas@mailbox.org> */ +#include <alist.h> #include <console.h> #include <mapmem.h> #include <asm/global_data.h> @@ -99,44 +100,39 @@ static int test_video_info(struct unit_test_state *uts) } static int lmb_test_dump_region(struct unit_test_state *uts, - struct lmb_region *rgn, char *name) + struct alist *lmb_rgn_lst, char *name) { + struct lmb_region *rgn = lmb_rgn_lst->data; unsigned long long base, size, end; enum lmb_flags flags; int i; - ut_assert_nextline(" %s.cnt = 0x%lx / max = 0x%lx", name, rgn->cnt, rgn->max); + ut_assert_nextline(" %s.count = 0x%hx", name, lmb_rgn_lst->count); - for (i = 0; i < rgn->cnt; i++) { - base = rgn->region[i].base; - size = rgn->region[i].size; + for (i = 0; i < lmb_rgn_lst->count; i++) { + base = rgn[i].base; + size = rgn[i].size; end = base + size - 1; - flags = rgn->region[i].flags; - - /* - * this entry includes the stack (get_sp()) on many platforms - * so will different each time lmb_init_and_reserve() is called. - * We could instead have the bdinfo command put its lmb region - * in a known location, so we can check it directly, rather than - * calling lmb_init_and_reserve() to create a new (and hopefully - * identical one). But for now this seems good enough. - */ + flags = rgn[i].flags; + if (!IS_ENABLED(CONFIG_SANDBOX) && i == 3) { ut_assert_nextlinen(" %s[%d]\t[", name, i); continue; } - ut_assert_nextline(" %s[%d]\t[0x%llx-0x%llx], 0x%08llx bytes flags: %x", - name, i, base, end, size, flags); + ut_assert_nextlinen(" %s[%d]\t[0x%llx-0x%llx], 0x%08llx bytes flags: ", + name, i, base, end, size); } return 0; } -static int lmb_test_dump_all(struct unit_test_state *uts, struct lmb *lmb) +static int lmb_test_dump_all(struct unit_test_state *uts) { + struct lmb *lmb = lmb_get(); + ut_assert_nextline("lmb_dump_all:"); - ut_assertok(lmb_test_dump_region(uts, &lmb->memory, "memory")); - ut_assertok(lmb_test_dump_region(uts, &lmb->reserved, "reserved")); + ut_assertok(lmb_test_dump_region(uts, &lmb->free_mem, "memory")); + ut_assertok(lmb_test_dump_region(uts, &lmb->used_mem, "reserved")); return 0; } @@ -185,9 +181,6 @@ static int bdinfo_test_all(struct unit_test_state *uts) ut_assert(map_to_sysmem(gd->fdt_blob) == env_get_hex("fdtcontroladdr", 0x1234)); ut_assertok(test_num_l(uts, "fdt_blob", (ulong)map_to_sysmem(gd->fdt_blob))); - ut_assertok(test_num_l(uts, "new_fdt", - (ulong)map_to_sysmem(gd->new_fdt))); - ut_assertok(test_num_l(uts, "fdt_size", (ulong)gd->fdt_size)); if (IS_ENABLED(CONFIG_VIDEO)) ut_assertok(test_video_info(uts)); @@ -198,10 +191,7 @@ static int bdinfo_test_all(struct unit_test_state *uts) #endif if (IS_ENABLED(CONFIG_LMB) && gd->fdt_blob) { - struct lmb lmb; - - lmb_init_and_reserve(&lmb, gd->bd, (void *)gd->fdt_blob); - ut_assertok(lmb_test_dump_all(uts, &lmb)); + ut_assertok(lmb_test_dump_all(uts)); if (IS_ENABLED(CONFIG_OF_REAL)) ut_assert_nextline("devicetree = %s", fdtdec_get_srcname()); } @@ -239,7 +229,7 @@ static int bdinfo_test_full(struct unit_test_state *uts) ut_assertok(bdinfo_test_all(uts)); ut_assertok(run_commandf("bdinfo -a")); ut_assertok(bdinfo_test_all(uts)); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } @@ -259,7 +249,7 @@ static int bdinfo_test_help(struct unit_test_state *uts) ut_assert_nextlinen("Usage:"); ut_assert_nextlinen("bdinfo"); } - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } @@ -273,7 +263,7 @@ static int bdinfo_test_memory(struct unit_test_state *uts) ut_assertok(bdinfo_test_all(uts)); else ut_assertok(bdinfo_check_mem(uts)); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } @@ -287,7 +277,7 @@ static int bdinfo_test_eth(struct unit_test_state *uts) ut_assertok(bdinfo_test_all(uts)); else if (IS_ENABLED(CONFIG_CMD_NET)) ut_assertok(test_eth(uts)); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } diff --git a/test/cmd/exit.c b/test/cmd/exit.c index 093f51b4dfc..af58a57fca7 100644 --- a/test/cmd/exit.c +++ b/test/cmd/exit.c @@ -36,14 +36,14 @@ static int cmd_exit_test(struct unit_test_state *uts) ut_assertok(run_commandf("setenv foo 'echo bar ; exit %d ; echo baz' ; run foo ; echo $?", i)); ut_assert_nextline("bar"); ut_assert_nextline("%d", i > 0 ? i : 0); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); ut_assertok(run_commandf("setenv foo 'echo bar ; exit %d ; echo baz' ; run foo && echo quux ; echo $?", i)); ut_assert_nextline("bar"); if (i <= 0) ut_assert_nextline("quux"); ut_assert_nextline("%d", i > 0 ? i : 0); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); ut_assertok(run_commandf("setenv foo 'echo bar ; exit %d ; echo baz' ; run foo || echo quux ; echo $?", i)); ut_assert_nextline("bar"); @@ -51,61 +51,61 @@ static int cmd_exit_test(struct unit_test_state *uts) ut_assert_nextline("quux"); /* Either 'exit' returns 0, or 'echo quux' returns 0 */ ut_assert_nextline("0"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); } /* Validate that 'exit' behaves the same way as 'exit 0' */ ut_assertok(run_commandf("setenv foo 'echo bar ; exit ; echo baz' ; run foo ; echo $?")); ut_assert_nextline("bar"); ut_assert_nextline("0"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); ut_assertok(run_commandf("setenv foo 'echo bar ; exit ; echo baz' ; run foo && echo quux ; echo $?")); ut_assert_nextline("bar"); ut_assert_nextline("quux"); ut_assert_nextline("0"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); ut_assertok(run_commandf("setenv foo 'echo bar ; exit ; echo baz' ; run foo || echo quux ; echo $?")); ut_assert_nextline("bar"); /* Either 'exit' returns 0, or 'echo quux' returns 0 */ ut_assert_nextline("0"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Validate that return value still propagates from 'run' command */ ut_assertok(run_commandf("setenv foo 'echo bar ; true' ; run foo ; echo $?")); ut_assert_nextline("bar"); ut_assert_nextline("0"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); ut_assertok(run_commandf("setenv foo 'echo bar ; true' ; run foo && echo quux ; echo $?")); ut_assert_nextline("bar"); ut_assert_nextline("quux"); ut_assert_nextline("0"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); ut_assertok(run_commandf("setenv foo 'echo bar ; true' ; run foo || echo quux ; echo $?")); ut_assert_nextline("bar"); /* The 'true' returns 0 */ ut_assert_nextline("0"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); ut_assertok(run_commandf("setenv foo 'echo bar ; false' ; run foo ; echo $?")); ut_assert_nextline("bar"); ut_assert_nextline("1"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); ut_assertok(run_commandf("setenv foo 'echo bar ; false' ; run foo && echo quux ; echo $?")); ut_assert_nextline("bar"); ut_assert_nextline("1"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); ut_assertok(run_commandf("setenv foo 'echo bar ; false' ; run foo || echo quux ; echo $?")); ut_assert_nextline("bar"); ut_assert_nextline("quux"); /* The 'echo quux' returns 0 */ ut_assert_nextline("0"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c index ac0d6f06150..e64785101cd 100644 --- a/test/cmd/fdt.c +++ b/test/cmd/fdt.c @@ -171,7 +171,7 @@ static int fdt_test_addr(struct unit_test_state *uts) ut_assertok(run_command("fdt addr -c", 0)); ut_assert_nextline("Control fdt: %08lx", (ulong)map_to_sysmem(gd->fdt_blob)); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* The working fdt is not set, so this should fail */ set_working_fdt_addr(0); @@ -184,13 +184,13 @@ static int fdt_test_addr(struct unit_test_state *uts) */ if (IS_ENABLED(CONFIG_SANDBOX)) ut_assert_nextline("libfdt fdt_check_header(): FDT_ERR_BADMAGIC"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Set up a working FDT and try again */ ut_assertok(make_test_fdt(uts, fdt, sizeof(fdt), &addr)); ut_assertok(run_command("fdt addr", 0)); ut_assert_nextline("Working fdt: %08lx", (ulong)map_to_sysmem(fdt)); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Set the working FDT */ set_working_fdt_addr(0); @@ -198,7 +198,7 @@ static int fdt_test_addr(struct unit_test_state *uts) ut_assertok(run_commandf("fdt addr %08lx", addr)); ut_assert_nextline("Working FDT set to %lx", addr); ut_asserteq(addr, map_to_sysmem(working_fdt)); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); set_working_fdt_addr(0); ut_assert_nextline("Working FDT set to 0"); @@ -210,13 +210,13 @@ static int fdt_test_addr(struct unit_test_state *uts) gd->fdt_blob = fdt_blob; ut_assertok(ret); ut_asserteq(addr, map_to_sysmem(new_fdt)); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test setting an invalid FDT */ fdt[0] = 123; ut_asserteq(1, run_commandf("fdt addr %08lx", addr)); ut_assert_nextline("libfdt fdt_check_header(): FDT_ERR_BADMAGIC"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test detecting an invalid FDT */ fdt[0] = 123; @@ -224,7 +224,7 @@ static int fdt_test_addr(struct unit_test_state *uts) ut_assert_nextline("Working FDT set to %lx", addr); ut_asserteq(1, run_commandf("fdt addr")); ut_assert_nextline("libfdt fdt_check_header(): FDT_ERR_BADMAGIC"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } @@ -242,18 +242,18 @@ static int fdt_test_addr_resize(struct unit_test_state *uts) /* Test setting and resizing the working FDT to a larger size */ ut_assertok(run_commandf("fdt addr %08lx %x", addr, newsize)); ut_assert_nextline("Working FDT set to %lx", addr); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Try shrinking it */ ut_assertok(run_commandf("fdt addr %08lx %zx", addr, sizeof(fdt) / 4)); ut_assert_nextline("Working FDT set to %lx", addr); ut_assert_nextline("New length %d < existing length %d, ignoring", (int)sizeof(fdt) / 4, newsize); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* ...quietly */ ut_assertok(run_commandf("fdt addr -q %08lx %zx", addr, sizeof(fdt) / 4)); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* We cannot easily provoke errors in fdt_open_into(), so ignore that */ @@ -280,12 +280,12 @@ static int fdt_test_move(struct unit_test_state *uts) /* Test moving the working FDT to a new location */ ut_assertok(run_commandf("fdt move %08lx %08lx %x", addr, newaddr, ts)); ut_assert_nextline("Working FDT set to %lx", newaddr); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Compare the source and destination DTs */ ut_assertok(run_commandf("cmp.b %08lx %08lx %x", addr, newaddr, ts)); ut_assert_nextline("Total of %d byte(s) were the same", ts); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } @@ -306,7 +306,7 @@ static int fdt_test_resize(struct unit_test_state *uts) /* Test resizing the working FDT and verify the new space was added */ ut_assertok(run_commandf("fdt resize %x", newsize)); ut_asserteq(ts + newsize, fdt_totalsize(fdt)); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } @@ -325,7 +325,7 @@ static int fdt_test_print_list_common(struct unit_test_state *uts, ut_assert_nextline("\t#size-cells = <0x00000000>;"); ut_assert_nextline("\tcompatible = \"u-boot,fdt-subnode-test-device\";"); ut_assert_nextline("};"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* * Test printing/listing the working FDT @@ -333,7 +333,7 @@ static int fdt_test_print_list_common(struct unit_test_state *uts, */ ut_assertok(run_commandf("fdt %s / model", opc)); ut_assert_nextline("model = \"U-Boot FDT test\""); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* * Test printing/listing the working FDT @@ -341,7 +341,7 @@ static int fdt_test_print_list_common(struct unit_test_state *uts, */ ut_assertok(run_commandf("fdt %s %s compatible", opc, node)); ut_assert_nextline("compatible = \"u-boot,fdt-test-device1\""); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* * Test printing/listing the working FDT @@ -349,7 +349,7 @@ static int fdt_test_print_list_common(struct unit_test_state *uts, */ ut_assertok(run_commandf("fdt %s %s clock-names", opc, node)); ut_assert_nextline("clock-names = \"fixed\", \"i2c\", \"spi\", \"uart2\", \"uart1\""); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* * Test printing/listing the working FDT @@ -357,7 +357,7 @@ static int fdt_test_print_list_common(struct unit_test_state *uts, */ ut_assertok(run_commandf("fdt %s %s clock-frequency", opc, node)); ut_assert_nextline("clock-frequency = <0x00fde800>"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* * Test printing/listing the working FDT @@ -370,7 +370,7 @@ static int fdt_test_print_list_common(struct unit_test_state *uts, * since the beginning of the command 'fdt', keep it. */ ut_assert_nextline("%s u-boot,empty-property", node); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* * Test printing/listing the working FDT @@ -378,7 +378,7 @@ static int fdt_test_print_list_common(struct unit_test_state *uts, */ ut_assertok(run_commandf("fdt %s %s regs", opc, node)); ut_assert_nextline("regs = <0x00001234 0x00001000>"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } @@ -424,7 +424,7 @@ static int fdt_test_print_list(struct unit_test_state *uts, bool print) } ut_assert_nextline("\t};"); ut_assert_nextline("};"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); ret = fdt_test_print_list_common(uts, opc, "/test-node@1234"); if (!ret) @@ -457,7 +457,7 @@ static int fdt_test_get_value_string(struct unit_test_state *uts, ut_asserteq_str(strres, env_get("var")); else ut_asserteq(intres, env_get_hex("var", 0x1234)); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } @@ -501,16 +501,16 @@ static int fdt_test_get_value_common(struct unit_test_state *uts, /* Test missing 10th element of $node node clock-names property */ ut_asserteq(1, run_commandf("fdt get value ften %s clock-names 10", node)); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test missing 10th element of $node node regs property */ ut_asserteq(1, run_commandf("fdt get value ften %s regs 10", node)); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test getting default element of $node node nonexistent property */ ut_asserteq(1, run_commandf("fdt get value fnone %s nonexistent", node)); ut_assert_nextline("libfdt fdt_getprop(): FDT_ERR_NOTFOUND"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } @@ -528,17 +528,17 @@ static int fdt_test_get_value(struct unit_test_state *uts) /* Test getting default element of /nonexistent node */ ut_asserteq(1, run_command("fdt get value fnode /nonexistent nonexistent", 1)); ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test getting default element of bad alias */ ut_asserteq(1, run_command("fdt get value vbadalias badalias nonexistent", 1)); ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test getting default element of nonexistent alias */ ut_asserteq(1, run_command("fdt get value vnoalias noalias nonexistent", 1)); ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_BADPATH"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } @@ -554,58 +554,58 @@ static int fdt_test_get_name(struct unit_test_state *uts) /* Test getting name of node 0 in /, which is /aliases node */ ut_assertok(run_command("fdt get name nzero / 0", 0)); ut_asserteq_str("aliases", env_get("nzero")); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test getting name of node 1 in /, which is /test-node@1234 node */ ut_assertok(run_command("fdt get name none / 1", 0)); ut_asserteq_str("test-node@1234", env_get("none")); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test getting name of node -1 in /, which is /aliases node, same as 0 */ ut_assertok(run_command("fdt get name nmone / -1", 0)); ut_asserteq_str("aliases", env_get("nmone")); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test getting name of node 2 in /, which does not exist */ ut_asserteq(1, run_command("fdt get name ntwo / 2", 1)); ut_assert_nextline("libfdt node not found"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test getting name of node 0 in /test-node@1234, which is /subnode node */ ut_assertok(run_command("fdt get name snzero /test-node@1234 0", 0)); ut_asserteq_str("subnode", env_get("snzero")); ut_assertok(run_command("fdt get name asnzero testnodealias 0", 0)); ut_asserteq_str("subnode", env_get("asnzero")); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test getting name of node 1 in /test-node@1234, which does not exist */ ut_asserteq(1, run_command("fdt get name snone /test-node@1234 1", 1)); ut_assert_nextline("libfdt node not found"); ut_asserteq(1, run_command("fdt get name asnone testnodealias 1", 1)); ut_assert_nextline("libfdt node not found"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test getting name of node -1 in /test-node@1234, which is /subnode node, same as 0 */ ut_assertok(run_command("fdt get name snmone /test-node@1234 -1", 0)); ut_asserteq_str("subnode", env_get("snmone")); ut_assertok(run_command("fdt get name asnmone testnodealias -1", 0)); ut_asserteq_str("subnode", env_get("asnmone")); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test getting name of nonexistent node */ ut_asserteq(1, run_command("fdt get name nonode /nonexistent 0", 1)); ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test getting name of bad alias */ ut_asserteq(1, run_command("fdt get name vbadalias badalias 0", 1)); ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test getting name of nonexistent alias */ ut_asserteq(1, run_command("fdt get name vnoalias noalias 0", 1)); ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_BADPATH"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } @@ -628,7 +628,7 @@ static int fdt_test_get_addr_common(struct unit_test_state *uts, char *fdt, ut_assertok(run_commandf("fdt get addr pstr %s %s", path, prop)); ut_asserteq((ulong)map_sysmem(env_get_hex("fdtaddr", 0x1234), 0), (ulong)(map_sysmem(env_get_hex("pstr", 0x1234), 0) - offset)); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } @@ -670,12 +670,12 @@ static int fdt_test_get_addr(struct unit_test_state *uts) /* Test getting address of node /test-node@1234/subnode non-existent property "noprop" */ ut_asserteq(1, run_command("fdt get addr pnoprop /test-node@1234/subnode noprop", 1)); ut_assert_nextline("libfdt fdt_getprop(): FDT_ERR_NOTFOUND"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test getting address of non-existent node /test-node@1234/nonode@1 property "noprop" */ ut_asserteq(1, run_command("fdt get addr pnonode /test-node@1234/nonode@1 noprop", 1)); ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } @@ -691,7 +691,7 @@ static int fdt_test_get_size_common(struct unit_test_state *uts, ut_assertok(run_commandf("fdt get size sstr %s", path)); } ut_asserteq(val, env_get_hex("sstr", 0x1234)); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } @@ -742,27 +742,27 @@ static int fdt_test_get_size(struct unit_test_state *uts) ut_assert_nextline("libfdt fdt_getprop(): FDT_ERR_NOTFOUND"); ut_asserteq(1, run_command("fdt get size pnoprop subnodealias noprop", 1)); ut_assert_nextline("libfdt fdt_getprop(): FDT_ERR_NOTFOUND"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test getting size of non-existent node /test-node@1234/nonode@1 property "noprop" */ ut_asserteq(1, run_command("fdt get size pnonode /test-node@1234/nonode@1 noprop", 1)); ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test getting node count of non-existent node /test-node@1234/nonode@1 */ ut_asserteq(1, run_command("fdt get size pnonode /test-node@1234/nonode@1", 1)); ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test getting node count of bad alias badalias */ ut_asserteq(1, run_command("fdt get size pnonode badalias noprop", 1)); ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test getting node count of non-existent alias noalias */ ut_asserteq(1, run_command("fdt get size pnonode noalias", 1)); ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_BADPATH"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } @@ -793,7 +793,7 @@ static int fdt_test_set_single(struct unit_test_state *uts, ut_asserteq(ival, env_get_hex("svar", 0x1234)); else ut_assertnull(env_get("svar")); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } @@ -842,7 +842,7 @@ static int fdt_test_set_multi(struct unit_test_state *uts, ut_asserteq(ival2, env_get_hex("svar2", 0x1234)); ut_assertnull(env_get("svarn")); } - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } @@ -889,17 +889,17 @@ static int fdt_test_set(struct unit_test_state *uts) /* Test setting property of non-existent node */ ut_asserteq(1, run_command("fdt set /no-node noprop", 1)); ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test setting property of non-existent alias */ ut_asserteq(1, run_command("fdt set noalias noprop", 1)); ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_BADPATH"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test setting property of bad alias */ ut_asserteq(1, run_command("fdt set badalias noprop", 1)); ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } @@ -918,46 +918,46 @@ static int fdt_test_mknode(struct unit_test_state *uts) ut_assertok(run_commandf("fdt list /newnode")); ut_assert_nextline("newnode {"); ut_assert_nextline("};"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test creation of new node in /test-node@1234 */ ut_assertok(run_commandf("fdt mknode /test-node@1234 newsubnode")); ut_assertok(run_commandf("fdt list /test-node@1234/newsubnode")); ut_assert_nextline("newsubnode {"); ut_assert_nextline("};"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test creation of new node in /test-node@1234 by alias */ ut_assertok(run_commandf("fdt mknode testnodealias newersubnode")); ut_assertok(run_commandf("fdt list testnodealias/newersubnode")); ut_assert_nextline("newersubnode {"); ut_assert_nextline("};"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test creation of new node in /test-node@1234 over existing node */ ut_asserteq(1, run_commandf("fdt mknode testnodealias newsubnode")); ut_assert_nextline("libfdt fdt_add_subnode(): FDT_ERR_EXISTS"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test creation of new node in /test-node@1234 by alias over existing node */ ut_asserteq(1, run_commandf("fdt mknode testnodealias newersubnode")); ut_assert_nextline("libfdt fdt_add_subnode(): FDT_ERR_EXISTS"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test creation of new node in non-existent node */ ut_asserteq(1, run_commandf("fdt mknode /no-node newnosubnode")); ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test creation of new node in non-existent alias */ ut_asserteq(1, run_commandf("fdt mknode noalias newfailsubnode")); ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_BADPATH"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test creation of new node in bad alias */ ut_asserteq(1, run_commandf("fdt mknode badalias newbadsubnode")); ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } @@ -976,7 +976,7 @@ static int fdt_test_rm(struct unit_test_state *uts) ut_assertok(run_commandf("fdt rm / compatible")); ut_asserteq(1, run_commandf("fdt print / compatible")); ut_assert_nextline("libfdt fdt_getprop(): FDT_ERR_NOTFOUND"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test removal of property clock-names in subnode /test-node@1234 */ ut_assertok(run_commandf("fdt print /test-node@1234 clock-names")); @@ -984,7 +984,7 @@ static int fdt_test_rm(struct unit_test_state *uts) ut_assertok(run_commandf("fdt rm /test-node@1234 clock-names")); ut_asserteq(1, run_commandf("fdt print /test-node@1234 clock-names")); ut_assert_nextline("libfdt fdt_getprop(): FDT_ERR_NOTFOUND"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test removal of property u-boot,empty-property in subnode /test-node@1234 by alias */ ut_assertok(run_commandf("fdt print testnodealias u-boot,empty-property")); @@ -992,44 +992,44 @@ static int fdt_test_rm(struct unit_test_state *uts) ut_assertok(run_commandf("fdt rm testnodealias u-boot,empty-property")); ut_asserteq(1, run_commandf("fdt print testnodealias u-boot,empty-property")); ut_assert_nextline("libfdt fdt_getprop(): FDT_ERR_NOTFOUND"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test removal of non-existent property noprop in subnode /test-node@1234 */ ut_asserteq(1, run_commandf("fdt rm /test-node@1234 noprop")); ut_assert_nextline("libfdt fdt_delprop(): FDT_ERR_NOTFOUND"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test removal of non-existent node /no-node@5678 */ ut_asserteq(1, run_commandf("fdt rm /no-node@5678")); ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test removal of subnode /test-node@1234/subnode by alias */ ut_assertok(run_commandf("fdt rm subnodealias")); ut_asserteq(1, run_commandf("fdt print /test-node@1234/subnode")); ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test removal of node by non-existent alias */ ut_asserteq(1, run_commandf("fdt rm noalias")); ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_BADPATH"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test removal of node by bad alias */ ut_asserteq(1, run_commandf("fdt rm noalias")); ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_BADPATH"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test removal of node /test-node@1234 */ ut_assertok(run_commandf("fdt rm /test-node@1234")); ut_asserteq(1, run_commandf("fdt print /test-node@1234")); ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test removal of node / */ ut_assertok(run_commandf("fdt rm /")); ut_asserteq(1, run_commandf("fdt print /")); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } @@ -1046,17 +1046,17 @@ static int fdt_test_bootcpu(struct unit_test_state *uts) /* Test getting default bootcpu entry */ ut_assertok(run_commandf("fdt header get bootcpu boot_cpuid_phys")); ut_asserteq(0, env_get_ulong("bootcpu", 10, 0x1234)); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test setting and getting new bootcpu entry, twice, to test overwrite */ for (i = 42; i <= 43; i++) { ut_assertok(run_commandf("fdt bootcpu %d", i)); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test getting new bootcpu entry */ ut_assertok(run_commandf("fdt header get bootcpu boot_cpuid_phys")); ut_asserteq(i, env_get_ulong("bootcpu", 10, 0x1234)); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); } return 0; @@ -1069,11 +1069,11 @@ static int fdt_test_header_get(struct unit_test_state *uts, /* Test getting valid header entry */ ut_assertok(run_commandf("fdt header get fvar %s", field)); ut_asserteq(val, env_get_hex("fvar", 0x1234)); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test getting malformed header entry */ ut_asserteq(1, run_commandf("fdt header get fvar typo%stypo", field)); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } @@ -1099,7 +1099,7 @@ static int fdt_test_header(struct unit_test_state *uts) ut_assert_nextline("size_dt_struct:\t\t0x%x", fdt_size_dt_struct(fdt)); ut_assert_nextline("number mem_rsv:\t\t0x%x", fdt_num_mem_rsv(fdt)); ut_assert_nextline_empty(); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test header get */ ut_assertok(fdt_test_header_get(uts, "magic", fdt_magic(fdt))); @@ -1175,7 +1175,7 @@ static int fdt_test_memory_cells(struct unit_test_state *uts, ut_assert_nextline("\tdevice_type = \"memory\";"); ut_assert_nextline("\treg = <%s %s>;", pada, pads); ut_assert_nextline("};"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); free(sets); free(seta); @@ -1223,7 +1223,7 @@ static int fdt_test_rsvmem(struct unit_test_state *uts) ut_assert_nextline("------------------------------------------------"); ut_assert_nextline(" %x\t%016x\t%016x", 0, 0x42, 0x1701); ut_assert_nextline(" %x\t%016x\t%016x", 1, 0x74656, 0x9); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test add new reserved memory node */ ut_assertok(run_commandf("fdt rsvmem add 0x1234 0x5678")); @@ -1233,7 +1233,7 @@ static int fdt_test_rsvmem(struct unit_test_state *uts) ut_assert_nextline(" %x\t%016x\t%016x", 0, 0x42, 0x1701); ut_assert_nextline(" %x\t%016x\t%016x", 1, 0x74656, 0x9); ut_assert_nextline(" %x\t%016x\t%016x", 2, 0x1234, 0x5678); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test delete reserved memory node */ ut_assertok(run_commandf("fdt rsvmem delete 0")); @@ -1242,7 +1242,7 @@ static int fdt_test_rsvmem(struct unit_test_state *uts) ut_assert_nextline("------------------------------------------------"); ut_assert_nextline(" %x\t%016x\t%016x", 0, 0x74656, 0x9); ut_assert_nextline(" %x\t%016x\t%016x", 1, 0x1234, 0x5678); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test re-add new reserved memory node */ ut_assertok(run_commandf("fdt rsvmem add 0x42 0x1701")); @@ -1252,12 +1252,12 @@ static int fdt_test_rsvmem(struct unit_test_state *uts) ut_assert_nextline(" %x\t%016x\t%016x", 0, 0x74656, 0x9); ut_assert_nextline(" %x\t%016x\t%016x", 1, 0x1234, 0x5678); ut_assert_nextline(" %x\t%016x\t%016x", 2, 0x42, 0x1701); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test delete nonexistent reserved memory node */ ut_asserteq(1, run_commandf("fdt rsvmem delete 10")); ut_assert_nextline("libfdt fdt_del_mem_rsv(): FDT_ERR_NOTFOUND"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } @@ -1275,7 +1275,7 @@ static int fdt_test_chosen(struct unit_test_state *uts) /* Test default chosen node presence, fail as there is no /chosen node */ ut_asserteq(1, run_commandf("fdt print /chosen")); ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_NOTFOUND"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test add new chosen node without initrd */ ut_assertok(run_commandf("fdt chosen")); @@ -1289,7 +1289,7 @@ static int fdt_test_chosen(struct unit_test_state *uts) !IS_ENABLED(CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT)) ut_assert_nextlinen("\tkaslr-seed = "); ut_assert_nextline("};"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test add new chosen node with initrd */ ut_assertok(run_commandf("fdt chosen 0x1234 0x5678")); @@ -1308,7 +1308,7 @@ static int fdt_test_chosen(struct unit_test_state *uts) !IS_ENABLED(CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT)) ut_assert_nextlinen("\tkaslr-seed = "); ut_assert_nextline("};"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } @@ -1351,7 +1351,7 @@ static int fdt_test_apply(struct unit_test_state *uts) ut_assert_nextline("\t__symbols__ {"); ut_assert_nextline("\t};"); ut_assert_nextline("};"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test simple DTO application */ ut_assertok(run_commandf("fdt apply 0x%08lx", addro)); @@ -1361,7 +1361,7 @@ static int fdt_test_apply(struct unit_test_state *uts) ut_assert_nextline("\t__symbols__ {"); ut_assert_nextline("\t};"); ut_assert_nextline("};"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* * Create complex DTO which: @@ -1414,7 +1414,7 @@ static int fdt_test_apply(struct unit_test_state *uts) ut_assert_nextline("\t\tsubnodephandle = \"/subnode\";"); ut_assert_nextline("\t};"); ut_assert_nextline("};"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* * Create complex DTO which: @@ -1457,7 +1457,7 @@ static int fdt_test_apply(struct unit_test_state *uts) ut_assert_nextline("\t\tsubnodephandle = \"/subnode\";"); ut_assert_nextline("\t};"); ut_assert_nextline("};"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } diff --git a/test/cmd/font.c b/test/cmd/font.c index 6f4e54e7f3f..25d365dedd2 100644 --- a/test/cmd/font.c +++ b/test/cmd/font.c @@ -30,7 +30,7 @@ static int font_test_base(struct unit_test_state *uts) ut_assert_nextline("nimbus_sans_l_regular"); if (IS_ENABLED(CONFIG_CONSOLE_TRUETYPE_CANTORAONE)) ut_assert_nextline("cantoraone_regular"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); ut_assertok(vidconsole_get_font_size(dev, &name, &size)); ut_asserteq_str("nimbus_sans_l_regular", name); @@ -48,19 +48,19 @@ static int font_test_base(struct unit_test_state *uts) if (max_metrics < 2) { ut_asserteq(1, ret); ut_assert_nextline("Failed (error -7)"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } ut_assertok(ret); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); ut_assertok(vidconsole_get_font_size(dev, &name, &size)); ut_asserteq_str("cantoraone_regular", name); ut_asserteq(40, size); ut_assertok(run_command("font size 30", 0)); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); ut_assertok(vidconsole_get_font_size(dev, &name, &size)); ut_asserteq_str("cantoraone_regular", name); diff --git a/test/cmd/mbr.c b/test/cmd/mbr.c index 8c9d01130a3..e1a9cdffb04 100644 --- a/test/cmd/mbr.c +++ b/test/cmd/mbr.c @@ -264,7 +264,7 @@ static int mbr_test_run(struct unit_test_state *uts) ut_assertok(run_commandf("mmc dev 6")); ut_assert_nextline("switch to partitions #0, OK"); ut_assert_nextline("mmc6 is current device"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Make sure mmc6 is 12+ MiB in size */ ut_assertok(run_commandf("mmc read 0x%lx 0x%lx 1", ra, (ulong)0xBFFE00 / 0x200)); @@ -289,7 +289,7 @@ static int mbr_test_run(struct unit_test_state *uts) memset(rbuf, 0, sizeof(rbuf)); ut_assertok(run_commandf("read mmc 6:0 0x%lx 0x%lx 1", ra, ebr_blk)); ut_assertok(memcmp(ebr_wbuf, rbuf, 512)); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* 000001b0 00 00 00 00 00 00 00 00 78 56 34 12 00 00 80 05 |........xV4.....| 000001c0 05 01 0e 25 24 01 00 40 00 00 00 08 00 00 00 00 |...%$..@........| @@ -324,7 +324,7 @@ static int mbr_test_run(struct unit_test_state *uts) memset(rbuf, 0, sizeof(rbuf)); ut_assertok(run_commandf("read mmc 6:0 0x%lx 0x%lx 1", ra, ebr_blk)); ut_assertok(memcmp(ebr_wbuf, rbuf, 512)); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* 000001b0 00 00 00 00 00 00 00 00 78 56 34 12 00 00 80 05 |........xV4.....| 000001c0 05 01 0e 25 24 01 00 40 00 00 00 08 00 00 00 25 |...%$..@.......%| @@ -359,7 +359,7 @@ static int mbr_test_run(struct unit_test_state *uts) memset(rbuf, 0, sizeof(rbuf)); ut_assertok(run_commandf("read mmc 6:0 0x%lx 0x%lx 1", ra, ebr_blk)); ut_assertok(memcmp(ebr_wbuf, rbuf, 512)); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* 000001b0 00 00 00 00 00 00 00 00 78 56 34 12 00 00 80 05 |........xV4.....| 000001c0 05 01 0e 25 24 01 00 40 00 00 00 08 00 00 00 25 |...%$..@.......%| @@ -394,7 +394,7 @@ static int mbr_test_run(struct unit_test_state *uts) memset(rbuf, 0, sizeof(rbuf)); ut_assertok(run_commandf("read mmc 6:0 0x%lx 0x%lx 1", ra, ebr_blk)); ut_assertok(memcmp(ebr_wbuf, rbuf, 512)); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* 000001b0 00 00 00 00 00 00 00 00 78 56 34 12 00 00 80 05 |........xV4.....| 000001c0 05 01 0e 25 24 01 00 40 00 00 00 08 00 00 00 25 |...%$..@.......%| @@ -426,7 +426,7 @@ static int mbr_test_run(struct unit_test_state *uts) ut_assert_nextline("MBR: write success!"); ut_assertok(run_commandf("mbr verify mmc 6")); ut_assert_nextline("MBR: verify success!"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* 000001b0 00 00 00 00 00 00 00 00 78 56 34 12 00 00 80 05 |........xV4.....| 000001c0 05 01 0e 25 24 01 00 40 00 00 00 08 00 00 00 25 |...%$..@.......%| diff --git a/test/cmd/pinmux.c b/test/cmd/pinmux.c index be39dbc61bd..65974d03f88 100644 --- a/test/cmd/pinmux.c +++ b/test/cmd/pinmux.c @@ -27,7 +27,13 @@ static int dm_test_cmd_pinmux_status_pinname(struct unit_test_state *uts) ut_assert_console_end(); run_command("pinmux status P9", 0); - ut_assert_nextlinen("single-pinctrl pinctrl-single-no-width: missing register width"); + if (IS_ENABLED(CONFIG_LOGF_FUNC)) { + ut_assert_nextlinen( + " single_of_to_plat() single-pinctrl pinctrl-single-no-width: missing register width"); + } else { + ut_assert_nextlinen( + "single-pinctrl pinctrl-single-no-width: missing register width"); + } ut_assert_nextlinen("P9 not found"); ut_assert_console_end(); diff --git a/test/cmd/test_echo.c b/test/cmd/test_echo.c index b829f71c591..8b306cc907f 100644 --- a/test/cmd/test_echo.c +++ b/test/cmd/test_echo.c @@ -49,7 +49,7 @@ static int lib_test_hush_echo(struct unit_test_state *uts) console_record_readline(uts->actual_str, sizeof(uts->actual_str)); ut_asserteq_str(echo_data[i].expected, uts->actual_str); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); } return 0; } diff --git a/test/cmd/test_pause.c b/test/cmd/test_pause.c index 927fe174d74..174c31a3852 100644 --- a/test/cmd/test_pause.c +++ b/test/cmd/test_pause.c @@ -19,7 +19,7 @@ static int lib_test_hush_pause(struct unit_test_state *uts) ut_assertok(run_command("pause", 0)); console_record_readline(uts->actual_str, sizeof(uts->actual_str)); ut_asserteq_str("Press any key to continue...", uts->actual_str); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test provided message */ /* Cook a newline when the command is expected to pause */ @@ -27,7 +27,7 @@ static int lib_test_hush_pause(struct unit_test_state *uts) ut_assertok(run_command("pause 'Prompt for pause...'", 0)); console_record_readline(uts->actual_str, sizeof(uts->actual_str)); ut_asserteq_str("Prompt for pause...", uts->actual_str); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Test providing more than one params */ /* No newline cooked here since the command is expected to fail */ diff --git a/test/cmd/wget.c b/test/cmd/wget.c index 1660d2bdcb0..fe26fee54c9 100644 --- a/test/cmd/wget.c +++ b/test/cmd/wget.c @@ -221,7 +221,7 @@ static int net_test_wget(struct unit_test_state *uts) run_command("md5sum ${loadaddr} ${filesize}", 0); ut_assert_nextline("md5 for 00020000 ... 0002001f ==> 234af48e94b0085060249ecb5942ab57"); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } diff --git a/test/common/cread.c b/test/common/cread.c index e159caed041..4926c216803 100644 --- a/test/common/cread.c +++ b/test/common/cread.c @@ -66,8 +66,6 @@ static int cread_test(struct unit_test_state *uts) * print_buffer(0, buf, 1, 7, 0); */ - console_record_reset_enable(); - /* simple input */ *buf = '\0'; ut_asserteq(4, console_in_puts("abc\n")); @@ -102,4 +100,4 @@ static int cread_test(struct unit_test_state *uts) return 0; } -COMMON_TEST(cread_test, 0); +COMMON_TEST(cread_test, UTF_CONSOLE); diff --git a/test/common/test_autoboot.c b/test/common/test_autoboot.c index a556cbf8e33..e3050d02c60 100644 --- a/test/common/test_autoboot.c +++ b/test/common/test_autoboot.c @@ -20,7 +20,6 @@ static int check_for_input(struct unit_test_state *uts, const char *in, const char *autoboot_prompt = "Enter password \"a\" in 1 seconds to stop autoboot"; - console_record_reset_enable(); console_in_puts(in); /* turn on keyed autoboot for the test, if possible */ @@ -91,4 +90,4 @@ static int test_autoboot(struct unit_test_state *uts) return CMD_RET_SUCCESS; } -COMMON_TEST(test_autoboot, 0); +COMMON_TEST(test_autoboot, UTF_CONSOLE); diff --git a/test/dm/acpi_dp.c b/test/dm/acpi_dp.c index eaeda2b8a7a..038806004b5 100644 --- a/test/dm/acpi_dp.c +++ b/test/dm/acpi_dp.c @@ -7,7 +7,7 @@ */ #include <dm.h> -#include <uuid.h> +#include <u-boot/uuid.h> #include <acpi/acpigen.h> #include <acpi/acpi_dp.h> #include <asm/unaligned.h> diff --git a/test/dm/acpigen.c b/test/dm/acpigen.c index 3e912fadaef..23c16bd9866 100644 --- a/test/dm/acpigen.c +++ b/test/dm/acpigen.c @@ -9,7 +9,7 @@ #include <dm.h> #include <irq.h> #include <malloc.h> -#include <uuid.h> +#include <u-boot/uuid.h> #include <acpi/acpigen.h> #include <acpi/acpi_device.h> #include <acpi/acpi_table.h> diff --git a/test/dm/phy.c b/test/dm/phy.c index 9b4cff60e6a..194cad0bf70 100644 --- a/test/dm/phy.c +++ b/test/dm/phy.c @@ -243,20 +243,27 @@ static int dm_test_phy_setup(struct unit_test_state *uts) "gen_phy_user", &parent)); /* normal */ - ut_assertok(generic_setup_phy(parent, &phy, 0)); + ut_assertok(generic_setup_phy(parent, &phy, 0, PHY_MODE_USB_HOST, 0)); + ut_assertok(generic_shutdown_phy(&phy)); + + /* set_mode as USB Host passes, anything else is not supported */ + ut_assertok(generic_setup_phy(parent, &phy, 0, PHY_MODE_USB_HOST, 0)); + ut_assertok(generic_phy_set_mode(&phy, PHY_MODE_USB_HOST, 0)); + ut_asserteq(-EOPNOTSUPP, generic_phy_set_mode(&phy, PHY_MODE_USB_HOST, 1)); + ut_asserteq(-EINVAL, generic_phy_set_mode(&phy, PHY_MODE_USB_DEVICE, 0)); ut_assertok(generic_shutdown_phy(&phy)); /* power_off fail with -EIO */ - ut_assertok(generic_setup_phy(parent, &phy, 1)); + ut_assertok(generic_setup_phy(parent, &phy, 1, PHY_MODE_USB_HOST, 0)); ut_asserteq(-EIO, generic_shutdown_phy(&phy)); /* power_on fail with -EIO */ - ut_asserteq(-EIO, generic_setup_phy(parent, &phy, 2)); + ut_asserteq(-EIO, generic_setup_phy(parent, &phy, 2, PHY_MODE_USB_HOST, 0)); ut_assertok(generic_shutdown_phy(&phy)); /* generic_phy_get_by_index fail with -ENOENT */ ut_asserteq(-ENOENT, generic_phy_get_by_index(parent, 3, &phy)); - ut_assertok(generic_setup_phy(parent, &phy, 3)); + ut_assertok(generic_setup_phy(parent, &phy, 3, PHY_MODE_USB_HOST, 0)); ut_assertok(generic_shutdown_phy(&phy)); return 0; diff --git a/test/hush/dollar.c b/test/hush/dollar.c index cfcb1bd3e1d..077dcd62c0e 100644 --- a/test/hush/dollar.c +++ b/test/hush/dollar.c @@ -14,7 +14,6 @@ DECLARE_GLOBAL_DATA_PTR; static int hush_test_simple_dollar(struct unit_test_state *uts) { - console_record_reset_enable(); ut_assertok(run_command("echo $dollar_foo", 0)); ut_assert_nextline_empty(); ut_assert_console_end(); @@ -114,12 +113,11 @@ static int hush_test_simple_dollar(struct unit_test_state *uts) return 0; } -HUSH_TEST(hush_test_simple_dollar, 0); +HUSH_TEST(hush_test_simple_dollar, UTF_CONSOLE); static int hush_test_env_dollar(struct unit_test_state *uts) { env_set("env_foo", "bar"); - console_record_reset_enable(); ut_assertok(run_command("echo $env_foo", 0)); ut_assert_nextline("bar"); @@ -147,12 +145,10 @@ static int hush_test_env_dollar(struct unit_test_state *uts) return 0; } -HUSH_TEST(hush_test_env_dollar, 0); +HUSH_TEST(hush_test_env_dollar, UTF_CONSOLE); static int hush_test_command_dollar(struct unit_test_state *uts) { - console_record_reset_enable(); - ut_assertok(run_command("dollar_bar=\"echo bar\"", 0)); ut_assertok(run_command("$dollar_bar", 0)); @@ -215,4 +211,4 @@ static int hush_test_command_dollar(struct unit_test_state *uts) return 0; } -HUSH_TEST(hush_test_command_dollar, 0); +HUSH_TEST(hush_test_command_dollar, UTF_CONSOLE); diff --git a/test/hush/loop.c b/test/hush/loop.c index d734abf136d..a9b6a8edf24 100644 --- a/test/hush/loop.c +++ b/test/hush/loop.c @@ -14,8 +14,6 @@ DECLARE_GLOBAL_DATA_PTR; static int hush_test_for(struct unit_test_state *uts) { - console_record_reset_enable(); - ut_assertok(run_command("for loop_i in foo bar quux quux; do echo $loop_i; done", 0)); ut_assert_nextline("foo"); ut_assert_nextline("bar"); @@ -32,12 +30,10 @@ static int hush_test_for(struct unit_test_state *uts) return 0; } -HUSH_TEST(hush_test_for, 0); +HUSH_TEST(hush_test_for, UTF_CONSOLE); static int hush_test_while(struct unit_test_state *uts) { - console_record_reset_enable(); - if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) { /* * Hush 2021 always returns 0 from while loop... @@ -65,11 +61,10 @@ static int hush_test_while(struct unit_test_state *uts) return 0; } -HUSH_TEST(hush_test_while, 0); +HUSH_TEST(hush_test_while, UTF_CONSOLE); static int hush_test_until(struct unit_test_state *uts) { - console_record_reset_enable(); env_set("loop_bar", "bar"); /* @@ -87,4 +82,4 @@ static int hush_test_until(struct unit_test_state *uts) env_set("loop_bar", NULL); return 0; } -HUSH_TEST(hush_test_until, 0); +HUSH_TEST(hush_test_until, UTF_CONSOLE); diff --git a/test/image/spl_load.c b/test/image/spl_load.c index 7cbad40ea0c..3b6206955d3 100644 --- a/test/image/spl_load.c +++ b/test/image/spl_load.c @@ -343,9 +343,7 @@ static int spl_test_image(struct unit_test_state *uts, const char *test_name, } else { struct spl_load_info load; - spl_set_bl_len(&load, 1); - load.priv = img; - load.read = spl_test_read; + spl_load_init(&load, spl_test_read, img, 1); if (type == IMX8) ut_assertok(spl_load_imx_container(&info_read, &load, 0)); diff --git a/test/image/spl_load_os.c b/test/image/spl_load_os.c index 56105a59236..d17cf116a0e 100644 --- a/test/image/spl_load_os.c +++ b/test/image/spl_load_os.c @@ -20,3 +20,4 @@ static int spl_test_load(struct unit_test_state *uts) return 0; } SPL_TEST(spl_test_load, 0); + diff --git a/test/lib/lmb.c b/test/lib/lmb.c index 3c66138f732..b2c54fb4bcb 100644 --- a/test/lib/lmb.c +++ b/test/lib/lmb.c @@ -3,6 +3,7 @@ * (C) Copyright 2018 Simon Goldschmidt */ +#include <alist.h> #include <dm.h> #include <lmb.h> #include <log.h> @@ -12,50 +13,64 @@ #include <test/test.h> #include <test/ut.h> -static inline bool lmb_is_nomap(struct lmb_property *m) +static inline bool lmb_is_nomap(struct lmb_region *m) { return m->flags & LMB_NOMAP; } -static int check_lmb(struct unit_test_state *uts, struct lmb *lmb, - phys_addr_t ram_base, phys_size_t ram_size, - unsigned long num_reserved, +static int check_lmb(struct unit_test_state *uts, struct alist *mem_lst, + struct alist *used_lst, phys_addr_t ram_base, + phys_size_t ram_size, unsigned long num_reserved, phys_addr_t base1, phys_size_t size1, phys_addr_t base2, phys_size_t size2, phys_addr_t base3, phys_size_t size3) { + struct lmb_region *mem, *used; + + mem = mem_lst->data; + used = used_lst->data; + if (ram_size) { - ut_asserteq(lmb->memory.cnt, 1); - ut_asserteq(lmb->memory.region[0].base, ram_base); - ut_asserteq(lmb->memory.region[0].size, ram_size); + ut_asserteq(mem_lst->count, 1); + ut_asserteq(mem[0].base, ram_base); + ut_asserteq(mem[0].size, ram_size); } - ut_asserteq(lmb->reserved.cnt, num_reserved); + ut_asserteq(used_lst->count, num_reserved); if (num_reserved > 0) { - ut_asserteq(lmb->reserved.region[0].base, base1); - ut_asserteq(lmb->reserved.region[0].size, size1); + ut_asserteq(used[0].base, base1); + ut_asserteq(used[0].size, size1); } if (num_reserved > 1) { - ut_asserteq(lmb->reserved.region[1].base, base2); - ut_asserteq(lmb->reserved.region[1].size, size2); + ut_asserteq(used[1].base, base2); + ut_asserteq(used[1].size, size2); } if (num_reserved > 2) { - ut_asserteq(lmb->reserved.region[2].base, base3); - ut_asserteq(lmb->reserved.region[2].size, size3); + ut_asserteq(used[2].base, base3); + ut_asserteq(used[2].size, size3); } return 0; } -#define ASSERT_LMB(lmb, ram_base, ram_size, num_reserved, base1, size1, \ +#define ASSERT_LMB(mem_lst, used_lst, ram_base, ram_size, num_reserved, base1, size1, \ base2, size2, base3, size3) \ - ut_assert(!check_lmb(uts, lmb, ram_base, ram_size, \ + ut_assert(!check_lmb(uts, mem_lst, used_lst, ram_base, ram_size, \ num_reserved, base1, size1, base2, size2, base3, \ size3)) -/* - * Test helper function that reserves 64 KiB somewhere in the simulated RAM and - * then does some alloc + free tests. - */ +static int setup_lmb_test(struct unit_test_state *uts, struct lmb *store, + struct alist **mem_lstp, struct alist **used_lstp) +{ + struct lmb *lmb; + + ut_assertok(lmb_push(store)); + lmb = lmb_get(); + *mem_lstp = &lmb->free_mem; + *used_lstp = &lmb->used_mem; + + return 0; +} + static int test_multi_alloc(struct unit_test_state *uts, const phys_addr_t ram, const phys_size_t ram_size, const phys_addr_t ram0, const phys_size_t ram0_size, @@ -64,9 +79,11 @@ static int test_multi_alloc(struct unit_test_state *uts, const phys_addr_t ram, const phys_addr_t ram_end = ram + ram_size; const phys_addr_t alloc_64k_end = alloc_64k_addr + 0x10000; - struct lmb lmb; long ret; + struct alist *mem_lst, *used_lst; + struct lmb_region *mem, *used; phys_addr_t a, a2, b, b2, c, d; + struct lmb store; /* check for overflow */ ut_assert(ram_end == 0 || ram_end > ram); @@ -75,106 +92,110 @@ static int test_multi_alloc(struct unit_test_state *uts, const phys_addr_t ram, ut_assert(alloc_64k_addr >= ram + 8); ut_assert(alloc_64k_end <= ram_end - 8); - lmb_init(&lmb); + ut_assertok(setup_lmb_test(uts, &store, &mem_lst, &used_lst)); + mem = mem_lst->data; + used = used_lst->data; if (ram0_size) { - ret = lmb_add(&lmb, ram0, ram0_size); + ret = lmb_add(ram0, ram0_size); ut_asserteq(ret, 0); } - ret = lmb_add(&lmb, ram, ram_size); + ret = lmb_add(ram, ram_size); ut_asserteq(ret, 0); if (ram0_size) { - ut_asserteq(lmb.memory.cnt, 2); - ut_asserteq(lmb.memory.region[0].base, ram0); - ut_asserteq(lmb.memory.region[0].size, ram0_size); - ut_asserteq(lmb.memory.region[1].base, ram); - ut_asserteq(lmb.memory.region[1].size, ram_size); + ut_asserteq(mem_lst->count, 2); + ut_asserteq(mem[0].base, ram0); + ut_asserteq(mem[0].size, ram0_size); + ut_asserteq(mem[1].base, ram); + ut_asserteq(mem[1].size, ram_size); } else { - ut_asserteq(lmb.memory.cnt, 1); - ut_asserteq(lmb.memory.region[0].base, ram); - ut_asserteq(lmb.memory.region[0].size, ram_size); + ut_asserteq(mem_lst->count, 1); + ut_asserteq(mem[0].base, ram); + ut_asserteq(mem[0].size, ram_size); } /* reserve 64KiB somewhere */ - ret = lmb_reserve(&lmb, alloc_64k_addr, 0x10000); + ret = lmb_reserve(alloc_64k_addr, 0x10000); ut_asserteq(ret, 0); - ASSERT_LMB(&lmb, 0, 0, 1, alloc_64k_addr, 0x10000, + ASSERT_LMB(mem_lst, used_lst, 0, 0, 1, alloc_64k_addr, 0x10000, 0, 0, 0, 0); /* allocate somewhere, should be at the end of RAM */ - a = lmb_alloc(&lmb, 4, 1); + a = lmb_alloc(4, 1); ut_asserteq(a, ram_end - 4); - ASSERT_LMB(&lmb, 0, 0, 2, alloc_64k_addr, 0x10000, + ASSERT_LMB(mem_lst, used_lst, 0, 0, 2, alloc_64k_addr, 0x10000, ram_end - 4, 4, 0, 0); /* alloc below end of reserved region -> below reserved region */ - b = lmb_alloc_base(&lmb, 4, 1, alloc_64k_end); + b = lmb_alloc_base(4, 1, alloc_64k_end); ut_asserteq(b, alloc_64k_addr - 4); - ASSERT_LMB(&lmb, 0, 0, 2, + ASSERT_LMB(mem_lst, used_lst, 0, 0, 2, alloc_64k_addr - 4, 0x10000 + 4, ram_end - 4, 4, 0, 0); /* 2nd time */ - c = lmb_alloc(&lmb, 4, 1); + c = lmb_alloc(4, 1); ut_asserteq(c, ram_end - 8); - ASSERT_LMB(&lmb, 0, 0, 2, + ASSERT_LMB(mem_lst, used_lst, 0, 0, 2, alloc_64k_addr - 4, 0x10000 + 4, ram_end - 8, 8, 0, 0); - d = lmb_alloc_base(&lmb, 4, 1, alloc_64k_end); + d = lmb_alloc_base(4, 1, alloc_64k_end); ut_asserteq(d, alloc_64k_addr - 8); - ASSERT_LMB(&lmb, 0, 0, 2, + ASSERT_LMB(mem_lst, used_lst, 0, 0, 2, alloc_64k_addr - 8, 0x10000 + 8, ram_end - 8, 8, 0, 0); - ret = lmb_free(&lmb, a, 4); + ret = lmb_free(a, 4); ut_asserteq(ret, 0); - ASSERT_LMB(&lmb, 0, 0, 2, + ASSERT_LMB(mem_lst, used_lst, 0, 0, 2, alloc_64k_addr - 8, 0x10000 + 8, ram_end - 8, 4, 0, 0); /* allocate again to ensure we get the same address */ - a2 = lmb_alloc(&lmb, 4, 1); + a2 = lmb_alloc(4, 1); ut_asserteq(a, a2); - ASSERT_LMB(&lmb, 0, 0, 2, + ASSERT_LMB(mem_lst, used_lst, 0, 0, 2, alloc_64k_addr - 8, 0x10000 + 8, ram_end - 8, 8, 0, 0); - ret = lmb_free(&lmb, a2, 4); + ret = lmb_free(a2, 4); ut_asserteq(ret, 0); - ASSERT_LMB(&lmb, 0, 0, 2, + ASSERT_LMB(mem_lst, used_lst, 0, 0, 2, alloc_64k_addr - 8, 0x10000 + 8, ram_end - 8, 4, 0, 0); - ret = lmb_free(&lmb, b, 4); + ret = lmb_free(b, 4); ut_asserteq(ret, 0); - ASSERT_LMB(&lmb, 0, 0, 3, + ASSERT_LMB(mem_lst, used_lst, 0, 0, 3, alloc_64k_addr - 8, 4, alloc_64k_addr, 0x10000, ram_end - 8, 4); /* allocate again to ensure we get the same address */ - b2 = lmb_alloc_base(&lmb, 4, 1, alloc_64k_end); + b2 = lmb_alloc_base(4, 1, alloc_64k_end); ut_asserteq(b, b2); - ASSERT_LMB(&lmb, 0, 0, 2, + ASSERT_LMB(mem_lst, used_lst, 0, 0, 2, alloc_64k_addr - 8, 0x10000 + 8, ram_end - 8, 4, 0, 0); - ret = lmb_free(&lmb, b2, 4); + ret = lmb_free(b2, 4); ut_asserteq(ret, 0); - ASSERT_LMB(&lmb, 0, 0, 3, + ASSERT_LMB(mem_lst, used_lst, 0, 0, 3, alloc_64k_addr - 8, 4, alloc_64k_addr, 0x10000, ram_end - 8, 4); - ret = lmb_free(&lmb, c, 4); + ret = lmb_free(c, 4); ut_asserteq(ret, 0); - ASSERT_LMB(&lmb, 0, 0, 2, + ASSERT_LMB(mem_lst, used_lst, 0, 0, 2, alloc_64k_addr - 8, 4, alloc_64k_addr, 0x10000, 0, 0); - ret = lmb_free(&lmb, d, 4); + ret = lmb_free(d, 4); ut_asserteq(ret, 0); - ASSERT_LMB(&lmb, 0, 0, 1, alloc_64k_addr, 0x10000, + ASSERT_LMB(mem_lst, used_lst, 0, 0, 1, alloc_64k_addr, 0x10000, 0, 0, 0, 0); if (ram0_size) { - ut_asserteq(lmb.memory.cnt, 2); - ut_asserteq(lmb.memory.region[0].base, ram0); - ut_asserteq(lmb.memory.region[0].size, ram0_size); - ut_asserteq(lmb.memory.region[1].base, ram); - ut_asserteq(lmb.memory.region[1].size, ram_size); + ut_asserteq(mem_lst->count, 2); + ut_asserteq(mem[0].base, ram0); + ut_asserteq(mem[0].size, ram0_size); + ut_asserteq(mem[1].base, ram); + ut_asserteq(mem[1].size, ram_size); } else { - ut_asserteq(lmb.memory.cnt, 1); - ut_asserteq(lmb.memory.region[0].base, ram); - ut_asserteq(lmb.memory.region[0].size, ram_size); + ut_asserteq(mem_lst->count, 1); + ut_asserteq(mem[0].base, ram); + ut_asserteq(mem[0].size, ram_size); } + lmb_pop(&store); + return 0; } @@ -229,48 +250,51 @@ static int test_bigblock(struct unit_test_state *uts, const phys_addr_t ram) const phys_size_t big_block_size = 0x10000000; const phys_addr_t ram_end = ram + ram_size; const phys_addr_t alloc_64k_addr = ram + 0x10000000; - struct lmb lmb; + struct alist *mem_lst, *used_lst; long ret; phys_addr_t a, b; + struct lmb store; /* check for overflow */ ut_assert(ram_end == 0 || ram_end > ram); - lmb_init(&lmb); + ut_assertok(setup_lmb_test(uts, &store, &mem_lst, &used_lst)); - ret = lmb_add(&lmb, ram, ram_size); + ret = lmb_add(ram, ram_size); ut_asserteq(ret, 0); /* reserve 64KiB in the middle of RAM */ - ret = lmb_reserve(&lmb, alloc_64k_addr, 0x10000); + ret = lmb_reserve(alloc_64k_addr, 0x10000); ut_asserteq(ret, 0); - ASSERT_LMB(&lmb, ram, ram_size, 1, alloc_64k_addr, 0x10000, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, alloc_64k_addr, 0x10000, 0, 0, 0, 0); /* allocate a big block, should be below reserved */ - a = lmb_alloc(&lmb, big_block_size, 1); + a = lmb_alloc(big_block_size, 1); ut_asserteq(a, ram); - ASSERT_LMB(&lmb, ram, ram_size, 1, a, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, a, big_block_size + 0x10000, 0, 0, 0, 0); /* allocate 2nd big block */ /* This should fail, printing an error */ - b = lmb_alloc(&lmb, big_block_size, 1); + b = lmb_alloc(big_block_size, 1); ut_asserteq(b, 0); - ASSERT_LMB(&lmb, ram, ram_size, 1, a, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, a, big_block_size + 0x10000, 0, 0, 0, 0); - ret = lmb_free(&lmb, a, big_block_size); + ret = lmb_free(a, big_block_size); ut_asserteq(ret, 0); - ASSERT_LMB(&lmb, ram, ram_size, 1, alloc_64k_addr, 0x10000, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, alloc_64k_addr, 0x10000, 0, 0, 0, 0); /* allocate too big block */ /* This should fail, printing an error */ - a = lmb_alloc(&lmb, ram_size, 1); + a = lmb_alloc(ram_size, 1); ut_asserteq(a, 0); - ASSERT_LMB(&lmb, ram, ram_size, 1, alloc_64k_addr, 0x10000, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, alloc_64k_addr, 0x10000, 0, 0, 0, 0); + lmb_pop(&store); + return 0; } @@ -294,56 +318,62 @@ static int test_noreserved(struct unit_test_state *uts, const phys_addr_t ram, { const phys_size_t ram_size = 0x20000000; const phys_addr_t ram_end = ram + ram_size; - struct lmb lmb; long ret; phys_addr_t a, b; + struct lmb store; + struct alist *mem_lst, *used_lst; const phys_addr_t alloc_size_aligned = (alloc_size + align - 1) & ~(align - 1); /* check for overflow */ ut_assert(ram_end == 0 || ram_end > ram); - lmb_init(&lmb); + ut_assertok(setup_lmb_test(uts, &store, &mem_lst, &used_lst)); - ret = lmb_add(&lmb, ram, ram_size); + ret = lmb_add(ram, ram_size); ut_asserteq(ret, 0); - ASSERT_LMB(&lmb, ram, ram_size, 0, 0, 0, 0, 0, 0, 0); + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 0, 0, 0, 0, 0, 0, 0); /* allocate a block */ - a = lmb_alloc(&lmb, alloc_size, align); + a = lmb_alloc(alloc_size, align); ut_assert(a != 0); - ASSERT_LMB(&lmb, ram, ram_size, 1, ram + ram_size - alloc_size_aligned, - alloc_size, 0, 0, 0, 0); + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, + ram + ram_size - alloc_size_aligned, alloc_size, 0, 0, 0, 0); + /* allocate another block */ - b = lmb_alloc(&lmb, alloc_size, align); + b = lmb_alloc(alloc_size, align); ut_assert(b != 0); if (alloc_size == alloc_size_aligned) { - ASSERT_LMB(&lmb, ram, ram_size, 1, ram + ram_size - + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram + ram_size - (alloc_size_aligned * 2), alloc_size * 2, 0, 0, 0, 0); } else { - ASSERT_LMB(&lmb, ram, ram_size, 2, ram + ram_size - + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, ram + ram_size - (alloc_size_aligned * 2), alloc_size, ram + ram_size - alloc_size_aligned, alloc_size, 0, 0); } /* and free them */ - ret = lmb_free(&lmb, b, alloc_size); + ret = lmb_free(b, alloc_size); ut_asserteq(ret, 0); - ASSERT_LMB(&lmb, ram, ram_size, 1, ram + ram_size - alloc_size_aligned, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, + ram + ram_size - alloc_size_aligned, alloc_size, 0, 0, 0, 0); - ret = lmb_free(&lmb, a, alloc_size); + ret = lmb_free(a, alloc_size); ut_asserteq(ret, 0); - ASSERT_LMB(&lmb, ram, ram_size, 0, 0, 0, 0, 0, 0, 0); + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 0, 0, 0, 0, 0, 0, 0); /* allocate a block with base*/ - b = lmb_alloc_base(&lmb, alloc_size, align, ram_end); + b = lmb_alloc_base(alloc_size, align, ram_end); ut_assert(a == b); - ASSERT_LMB(&lmb, ram, ram_size, 1, ram + ram_size - alloc_size_aligned, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, + ram + ram_size - alloc_size_aligned, alloc_size, 0, 0, 0, 0); /* and free it */ - ret = lmb_free(&lmb, b, alloc_size); + ret = lmb_free(b, alloc_size); ut_asserteq(ret, 0); - ASSERT_LMB(&lmb, ram, ram_size, 0, 0, 0, 0, 0, 0, 0); + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 0, 0, 0, 0, 0, 0, 0); + + lmb_pop(&store); return 0; } @@ -384,36 +414,39 @@ static int lib_test_lmb_at_0(struct unit_test_state *uts) { const phys_addr_t ram = 0; const phys_size_t ram_size = 0x20000000; - struct lmb lmb; + struct lmb store; + struct alist *mem_lst, *used_lst; long ret; phys_addr_t a, b; - lmb_init(&lmb); + ut_assertok(setup_lmb_test(uts, &store, &mem_lst, &used_lst)); - ret = lmb_add(&lmb, ram, ram_size); + ret = lmb_add(ram, ram_size); ut_asserteq(ret, 0); /* allocate nearly everything */ - a = lmb_alloc(&lmb, ram_size - 4, 1); + a = lmb_alloc(ram_size - 4, 1); ut_asserteq(a, ram + 4); - ASSERT_LMB(&lmb, ram, ram_size, 1, a, ram_size - 4, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, a, ram_size - 4, 0, 0, 0, 0); /* allocate the rest */ /* This should fail as the allocated address would be 0 */ - b = lmb_alloc(&lmb, 4, 1); + b = lmb_alloc(4, 1); ut_asserteq(b, 0); /* check that this was an error by checking lmb */ - ASSERT_LMB(&lmb, ram, ram_size, 1, a, ram_size - 4, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, a, ram_size - 4, 0, 0, 0, 0); /* check that this was an error by freeing b */ - ret = lmb_free(&lmb, b, 4); + ret = lmb_free(b, 4); ut_asserteq(ret, -1); - ASSERT_LMB(&lmb, ram, ram_size, 1, a, ram_size - 4, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, a, ram_size - 4, 0, 0, 0, 0); - ret = lmb_free(&lmb, a, ram_size - 4); + ret = lmb_free(a, ram_size - 4); ut_asserteq(ret, 0); - ASSERT_LMB(&lmb, ram, ram_size, 0, 0, 0, 0, 0, 0, 0); + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 0, 0, 0, 0, 0, 0, 0); + + lmb_pop(&store); return 0; } @@ -424,45 +457,50 @@ static int lib_test_lmb_overlapping_reserve(struct unit_test_state *uts) { const phys_addr_t ram = 0x40000000; const phys_size_t ram_size = 0x20000000; - struct lmb lmb; + struct lmb store; + struct alist *mem_lst, *used_lst; long ret; - lmb_init(&lmb); + ut_assertok(setup_lmb_test(uts, &store, &mem_lst, &used_lst)); - ret = lmb_add(&lmb, ram, ram_size); + ret = lmb_add(ram, ram_size); ut_asserteq(ret, 0); - ret = lmb_reserve(&lmb, 0x40010000, 0x10000); + ret = lmb_reserve(0x40010000, 0x10000); ut_asserteq(ret, 0); - ASSERT_LMB(&lmb, ram, ram_size, 1, 0x40010000, 0x10000, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40010000, 0x10000, 0, 0, 0, 0); - /* allocate overlapping region should fail */ - ret = lmb_reserve(&lmb, 0x40011000, 0x10000); - ut_asserteq(ret, -1); - ASSERT_LMB(&lmb, ram, ram_size, 1, 0x40010000, 0x10000, + + /* allocate overlapping region should return the coalesced count */ + ret = lmb_reserve(0x40011000, 0x10000); + ut_asserteq(ret, 1); + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40010000, 0x11000, 0, 0, 0, 0); /* allocate 3nd region */ - ret = lmb_reserve(&lmb, 0x40030000, 0x10000); + ret = lmb_reserve(0x40030000, 0x10000); ut_asserteq(ret, 0); - ASSERT_LMB(&lmb, ram, ram_size, 2, 0x40010000, 0x10000, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, 0x40010000, 0x11000, 0x40030000, 0x10000, 0, 0); /* allocate 2nd region , This should coalesced all region into one */ - ret = lmb_reserve(&lmb, 0x40020000, 0x10000); + ret = lmb_reserve(0x40020000, 0x10000); ut_assert(ret >= 0); - ASSERT_LMB(&lmb, ram, ram_size, 1, 0x40010000, 0x30000, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40010000, 0x30000, 0, 0, 0, 0); /* allocate 2nd region, which should be added as first region */ - ret = lmb_reserve(&lmb, 0x40000000, 0x8000); + ret = lmb_reserve(0x40000000, 0x8000); ut_assert(ret >= 0); - ASSERT_LMB(&lmb, ram, ram_size, 2, 0x40000000, 0x8000, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, 0x40000000, 0x8000, 0x40010000, 0x30000, 0, 0); /* allocate 3rd region, coalesce with first and overlap with second */ - ret = lmb_reserve(&lmb, 0x40008000, 0x10000); + ret = lmb_reserve(0x40008000, 0x10000); ut_assert(ret >= 0); - ASSERT_LMB(&lmb, ram, ram_size, 1, 0x40000000, 0x40000, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40000000, 0x40000, 0, 0, 0, 0); + + lmb_pop(&store); + return 0; } LIB_TEST(lib_test_lmb_overlapping_reserve, 0); @@ -473,112 +511,116 @@ LIB_TEST(lib_test_lmb_overlapping_reserve, 0); */ static int test_alloc_addr(struct unit_test_state *uts, const phys_addr_t ram) { + struct lmb store; + struct alist *mem_lst, *used_lst; const phys_size_t ram_size = 0x20000000; const phys_addr_t ram_end = ram + ram_size; const phys_size_t alloc_addr_a = ram + 0x8000000; const phys_size_t alloc_addr_b = ram + 0x8000000 * 2; const phys_size_t alloc_addr_c = ram + 0x8000000 * 3; - struct lmb lmb; long ret; phys_addr_t a, b, c, d, e; /* check for overflow */ ut_assert(ram_end == 0 || ram_end > ram); - lmb_init(&lmb); + ut_assertok(setup_lmb_test(uts, &store, &mem_lst, &used_lst)); - ret = lmb_add(&lmb, ram, ram_size); + ret = lmb_add(ram, ram_size); ut_asserteq(ret, 0); /* reserve 3 blocks */ - ret = lmb_reserve(&lmb, alloc_addr_a, 0x10000); + ret = lmb_reserve(alloc_addr_a, 0x10000); ut_asserteq(ret, 0); - ret = lmb_reserve(&lmb, alloc_addr_b, 0x10000); + ret = lmb_reserve(alloc_addr_b, 0x10000); ut_asserteq(ret, 0); - ret = lmb_reserve(&lmb, alloc_addr_c, 0x10000); + ret = lmb_reserve(alloc_addr_c, 0x10000); ut_asserteq(ret, 0); - ASSERT_LMB(&lmb, ram, ram_size, 3, alloc_addr_a, 0x10000, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 3, alloc_addr_a, 0x10000, alloc_addr_b, 0x10000, alloc_addr_c, 0x10000); /* allocate blocks */ - a = lmb_alloc_addr(&lmb, ram, alloc_addr_a - ram); + a = lmb_alloc_addr(ram, alloc_addr_a - ram); ut_asserteq(a, ram); - ASSERT_LMB(&lmb, ram, ram_size, 3, ram, 0x8010000, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 3, ram, 0x8010000, alloc_addr_b, 0x10000, alloc_addr_c, 0x10000); - b = lmb_alloc_addr(&lmb, alloc_addr_a + 0x10000, + b = lmb_alloc_addr(alloc_addr_a + 0x10000, alloc_addr_b - alloc_addr_a - 0x10000); ut_asserteq(b, alloc_addr_a + 0x10000); - ASSERT_LMB(&lmb, ram, ram_size, 2, ram, 0x10010000, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, ram, 0x10010000, alloc_addr_c, 0x10000, 0, 0); - c = lmb_alloc_addr(&lmb, alloc_addr_b + 0x10000, + c = lmb_alloc_addr(alloc_addr_b + 0x10000, alloc_addr_c - alloc_addr_b - 0x10000); ut_asserteq(c, alloc_addr_b + 0x10000); - ASSERT_LMB(&lmb, ram, ram_size, 1, ram, 0x18010000, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram, 0x18010000, 0, 0, 0, 0); - d = lmb_alloc_addr(&lmb, alloc_addr_c + 0x10000, + d = lmb_alloc_addr(alloc_addr_c + 0x10000, ram_end - alloc_addr_c - 0x10000); ut_asserteq(d, alloc_addr_c + 0x10000); - ASSERT_LMB(&lmb, ram, ram_size, 1, ram, ram_size, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram, ram_size, 0, 0, 0, 0); /* allocating anything else should fail */ - e = lmb_alloc(&lmb, 1, 1); + e = lmb_alloc(1, 1); ut_asserteq(e, 0); - ASSERT_LMB(&lmb, ram, ram_size, 1, ram, ram_size, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram, ram_size, 0, 0, 0, 0); - ret = lmb_free(&lmb, d, ram_end - alloc_addr_c - 0x10000); + ret = lmb_free(d, ram_end - alloc_addr_c - 0x10000); ut_asserteq(ret, 0); /* allocate at 3 points in free range */ - d = lmb_alloc_addr(&lmb, ram_end - 4, 4); + d = lmb_alloc_addr(ram_end - 4, 4); ut_asserteq(d, ram_end - 4); - ASSERT_LMB(&lmb, ram, ram_size, 2, ram, 0x18010000, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, ram, 0x18010000, d, 4, 0, 0); - ret = lmb_free(&lmb, d, 4); + ret = lmb_free(d, 4); ut_asserteq(ret, 0); - ASSERT_LMB(&lmb, ram, ram_size, 1, ram, 0x18010000, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram, 0x18010000, 0, 0, 0, 0); - d = lmb_alloc_addr(&lmb, ram_end - 128, 4); + d = lmb_alloc_addr(ram_end - 128, 4); ut_asserteq(d, ram_end - 128); - ASSERT_LMB(&lmb, ram, ram_size, 2, ram, 0x18010000, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, ram, 0x18010000, d, 4, 0, 0); - ret = lmb_free(&lmb, d, 4); + ret = lmb_free(d, 4); ut_asserteq(ret, 0); - ASSERT_LMB(&lmb, ram, ram_size, 1, ram, 0x18010000, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram, 0x18010000, 0, 0, 0, 0); - d = lmb_alloc_addr(&lmb, alloc_addr_c + 0x10000, 4); + d = lmb_alloc_addr(alloc_addr_c + 0x10000, 4); ut_asserteq(d, alloc_addr_c + 0x10000); - ASSERT_LMB(&lmb, ram, ram_size, 1, ram, 0x18010004, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram, 0x18010004, 0, 0, 0, 0); - ret = lmb_free(&lmb, d, 4); + ret = lmb_free(d, 4); ut_asserteq(ret, 0); - ASSERT_LMB(&lmb, ram, ram_size, 1, ram, 0x18010000, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram, 0x18010000, 0, 0, 0, 0); /* allocate at the bottom */ - ret = lmb_free(&lmb, a, alloc_addr_a - ram); + ret = lmb_free(a, alloc_addr_a - ram); ut_asserteq(ret, 0); - ASSERT_LMB(&lmb, ram, ram_size, 1, ram + 0x8000000, 0x10010000, - 0, 0, 0, 0); - d = lmb_alloc_addr(&lmb, ram, 4); + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram + 0x8000000, + 0x10010000, 0, 0, 0, 0); + + d = lmb_alloc_addr(ram, 4); ut_asserteq(d, ram); - ASSERT_LMB(&lmb, ram, ram_size, 2, d, 4, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, d, 4, ram + 0x8000000, 0x10010000, 0, 0); /* check that allocating outside memory fails */ if (ram_end != 0) { - ret = lmb_alloc_addr(&lmb, ram_end, 1); + ret = lmb_alloc_addr(ram_end, 1); ut_asserteq(ret, 0); } if (ram != 0) { - ret = lmb_alloc_addr(&lmb, ram - 1, 1); + ret = lmb_alloc_addr(ram - 1, 1); ut_asserteq(ret, 0); } + lmb_pop(&store); + return 0; } @@ -600,55 +642,57 @@ LIB_TEST(lib_test_lmb_alloc_addr, 0); static int test_get_unreserved_size(struct unit_test_state *uts, const phys_addr_t ram) { + struct lmb store; + struct alist *mem_lst, *used_lst; const phys_size_t ram_size = 0x20000000; const phys_addr_t ram_end = ram + ram_size; const phys_size_t alloc_addr_a = ram + 0x8000000; const phys_size_t alloc_addr_b = ram + 0x8000000 * 2; const phys_size_t alloc_addr_c = ram + 0x8000000 * 3; - struct lmb lmb; long ret; phys_size_t s; /* check for overflow */ ut_assert(ram_end == 0 || ram_end > ram); + ut_assertok(setup_lmb_test(uts, &store, &mem_lst, &used_lst)); - lmb_init(&lmb); - - ret = lmb_add(&lmb, ram, ram_size); + ret = lmb_add(ram, ram_size); ut_asserteq(ret, 0); /* reserve 3 blocks */ - ret = lmb_reserve(&lmb, alloc_addr_a, 0x10000); + ret = lmb_reserve(alloc_addr_a, 0x10000); ut_asserteq(ret, 0); - ret = lmb_reserve(&lmb, alloc_addr_b, 0x10000); + ret = lmb_reserve(alloc_addr_b, 0x10000); ut_asserteq(ret, 0); - ret = lmb_reserve(&lmb, alloc_addr_c, 0x10000); + ret = lmb_reserve(alloc_addr_c, 0x10000); ut_asserteq(ret, 0); - ASSERT_LMB(&lmb, ram, ram_size, 3, alloc_addr_a, 0x10000, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 3, alloc_addr_a, 0x10000, alloc_addr_b, 0x10000, alloc_addr_c, 0x10000); /* check addresses in between blocks */ - s = lmb_get_free_size(&lmb, ram); + s = lmb_get_free_size(ram); ut_asserteq(s, alloc_addr_a - ram); - s = lmb_get_free_size(&lmb, ram + 0x10000); + s = lmb_get_free_size(ram + 0x10000); ut_asserteq(s, alloc_addr_a - ram - 0x10000); - s = lmb_get_free_size(&lmb, alloc_addr_a - 4); + s = lmb_get_free_size(alloc_addr_a - 4); ut_asserteq(s, 4); - s = lmb_get_free_size(&lmb, alloc_addr_a + 0x10000); + s = lmb_get_free_size(alloc_addr_a + 0x10000); ut_asserteq(s, alloc_addr_b - alloc_addr_a - 0x10000); - s = lmb_get_free_size(&lmb, alloc_addr_a + 0x20000); + s = lmb_get_free_size(alloc_addr_a + 0x20000); ut_asserteq(s, alloc_addr_b - alloc_addr_a - 0x20000); - s = lmb_get_free_size(&lmb, alloc_addr_b - 4); + s = lmb_get_free_size(alloc_addr_b - 4); ut_asserteq(s, 4); - s = lmb_get_free_size(&lmb, alloc_addr_c + 0x10000); + s = lmb_get_free_size(alloc_addr_c + 0x10000); ut_asserteq(s, ram_end - alloc_addr_c - 0x10000); - s = lmb_get_free_size(&lmb, alloc_addr_c + 0x20000); + s = lmb_get_free_size(alloc_addr_c + 0x20000); ut_asserteq(s, ram_end - alloc_addr_c - 0x20000); - s = lmb_get_free_size(&lmb, ram_end - 4); + s = lmb_get_free_size(ram_end - 4); ut_asserteq(s, 4); + lmb_pop(&store); + return 0; } @@ -666,158 +710,94 @@ static int lib_test_lmb_get_free_size(struct unit_test_state *uts) } LIB_TEST(lib_test_lmb_get_free_size, 0); -#ifdef CONFIG_LMB_USE_MAX_REGIONS -static int lib_test_lmb_max_regions(struct unit_test_state *uts) -{ - const phys_addr_t ram = 0x00000000; - /* - * All of 32bit memory space will contain regions for this test, so - * we need to scale ram_size (which in this case is the size of the lmb - * region) to match. - */ - const phys_size_t ram_size = ((0xFFFFFFFF >> CONFIG_LMB_MAX_REGIONS) - + 1) * CONFIG_LMB_MAX_REGIONS; - const phys_size_t blk_size = 0x10000; - phys_addr_t offset; - struct lmb lmb; - int ret, i; - - lmb_init(&lmb); - - ut_asserteq(lmb.memory.cnt, 0); - ut_asserteq(lmb.memory.max, CONFIG_LMB_MAX_REGIONS); - ut_asserteq(lmb.reserved.cnt, 0); - ut_asserteq(lmb.reserved.max, CONFIG_LMB_MAX_REGIONS); - - /* Add CONFIG_LMB_MAX_REGIONS memory regions */ - for (i = 0; i < CONFIG_LMB_MAX_REGIONS; i++) { - offset = ram + 2 * i * ram_size; - ret = lmb_add(&lmb, offset, ram_size); - ut_asserteq(ret, 0); - } - ut_asserteq(lmb.memory.cnt, CONFIG_LMB_MAX_REGIONS); - ut_asserteq(lmb.reserved.cnt, 0); - - /* error for the (CONFIG_LMB_MAX_REGIONS + 1) memory regions */ - offset = ram + 2 * (CONFIG_LMB_MAX_REGIONS + 1) * ram_size; - ret = lmb_add(&lmb, offset, ram_size); - ut_asserteq(ret, -1); - - ut_asserteq(lmb.memory.cnt, CONFIG_LMB_MAX_REGIONS); - ut_asserteq(lmb.reserved.cnt, 0); - - /* reserve CONFIG_LMB_MAX_REGIONS regions */ - for (i = 0; i < CONFIG_LMB_MAX_REGIONS; i++) { - offset = ram + 2 * i * blk_size; - ret = lmb_reserve(&lmb, offset, blk_size); - ut_asserteq(ret, 0); - } - - ut_asserteq(lmb.memory.cnt, CONFIG_LMB_MAX_REGIONS); - ut_asserteq(lmb.reserved.cnt, CONFIG_LMB_MAX_REGIONS); - - /* error for the 9th reserved blocks */ - offset = ram + 2 * (CONFIG_LMB_MAX_REGIONS + 1) * blk_size; - ret = lmb_reserve(&lmb, offset, blk_size); - ut_asserteq(ret, -1); - - ut_asserteq(lmb.memory.cnt, CONFIG_LMB_MAX_REGIONS); - ut_asserteq(lmb.reserved.cnt, CONFIG_LMB_MAX_REGIONS); - - /* check each regions */ - for (i = 0; i < CONFIG_LMB_MAX_REGIONS; i++) - ut_asserteq(lmb.memory.region[i].base, ram + 2 * i * ram_size); - - for (i = 0; i < CONFIG_LMB_MAX_REGIONS; i++) - ut_asserteq(lmb.reserved.region[i].base, ram + 2 * i * blk_size); - - return 0; -} -LIB_TEST(lib_test_lmb_max_regions, 0); -#endif - static int lib_test_lmb_flags(struct unit_test_state *uts) { + struct lmb store; + struct lmb_region *mem, *used; + struct alist *mem_lst, *used_lst; const phys_addr_t ram = 0x40000000; const phys_size_t ram_size = 0x20000000; - struct lmb lmb; long ret; - lmb_init(&lmb); + ut_assertok(setup_lmb_test(uts, &store, &mem_lst, &used_lst)); + mem = mem_lst->data; + used = used_lst->data; - ret = lmb_add(&lmb, ram, ram_size); + ret = lmb_add(ram, ram_size); ut_asserteq(ret, 0); /* reserve, same flag */ - ret = lmb_reserve_flags(&lmb, 0x40010000, 0x10000, LMB_NOMAP); + ret = lmb_reserve_flags(0x40010000, 0x10000, LMB_NOMAP); ut_asserteq(ret, 0); - ASSERT_LMB(&lmb, ram, ram_size, 1, 0x40010000, 0x10000, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40010000, 0x10000, 0, 0, 0, 0); /* reserve again, same flag */ - ret = lmb_reserve_flags(&lmb, 0x40010000, 0x10000, LMB_NOMAP); + ret = lmb_reserve_flags(0x40010000, 0x10000, LMB_NOMAP); ut_asserteq(ret, 0); - ASSERT_LMB(&lmb, ram, ram_size, 1, 0x40010000, 0x10000, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40010000, 0x10000, 0, 0, 0, 0); /* reserve again, new flag */ - ret = lmb_reserve_flags(&lmb, 0x40010000, 0x10000, LMB_NONE); + ret = lmb_reserve_flags(0x40010000, 0x10000, LMB_NONE); ut_asserteq(ret, -1); - ASSERT_LMB(&lmb, ram, ram_size, 1, 0x40010000, 0x10000, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40010000, 0x10000, 0, 0, 0, 0); - ut_asserteq(lmb_is_nomap(&lmb.reserved.region[0]), 1); + ut_asserteq(lmb_is_nomap(&used[0]), 1); /* merge after */ - ret = lmb_reserve_flags(&lmb, 0x40020000, 0x10000, LMB_NOMAP); + ret = lmb_reserve_flags(0x40020000, 0x10000, LMB_NOMAP); ut_asserteq(ret, 1); - ASSERT_LMB(&lmb, ram, ram_size, 1, 0x40010000, 0x20000, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40010000, 0x20000, 0, 0, 0, 0); /* merge before */ - ret = lmb_reserve_flags(&lmb, 0x40000000, 0x10000, LMB_NOMAP); + ret = lmb_reserve_flags(0x40000000, 0x10000, LMB_NOMAP); ut_asserteq(ret, 1); - ASSERT_LMB(&lmb, ram, ram_size, 1, 0x40000000, 0x30000, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40000000, 0x30000, 0, 0, 0, 0); - ut_asserteq(lmb_is_nomap(&lmb.reserved.region[0]), 1); + ut_asserteq(lmb_is_nomap(&used[0]), 1); - ret = lmb_reserve_flags(&lmb, 0x40030000, 0x10000, LMB_NONE); + ret = lmb_reserve_flags(0x40030000, 0x10000, LMB_NONE); ut_asserteq(ret, 0); - ASSERT_LMB(&lmb, ram, ram_size, 2, 0x40000000, 0x30000, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, 0x40000000, 0x30000, 0x40030000, 0x10000, 0, 0); - ut_asserteq(lmb_is_nomap(&lmb.reserved.region[0]), 1); - ut_asserteq(lmb_is_nomap(&lmb.reserved.region[1]), 0); + ut_asserteq(lmb_is_nomap(&used[0]), 1); + ut_asserteq(lmb_is_nomap(&used[1]), 0); /* test that old API use LMB_NONE */ - ret = lmb_reserve(&lmb, 0x40040000, 0x10000); + ret = lmb_reserve(0x40040000, 0x10000); ut_asserteq(ret, 1); - ASSERT_LMB(&lmb, ram, ram_size, 2, 0x40000000, 0x30000, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, 0x40000000, 0x30000, 0x40030000, 0x20000, 0, 0); - ut_asserteq(lmb_is_nomap(&lmb.reserved.region[0]), 1); - ut_asserteq(lmb_is_nomap(&lmb.reserved.region[1]), 0); + ut_asserteq(lmb_is_nomap(&used[0]), 1); + ut_asserteq(lmb_is_nomap(&used[1]), 0); - ret = lmb_reserve_flags(&lmb, 0x40070000, 0x10000, LMB_NOMAP); + ret = lmb_reserve_flags(0x40070000, 0x10000, LMB_NOMAP); ut_asserteq(ret, 0); - ASSERT_LMB(&lmb, ram, ram_size, 3, 0x40000000, 0x30000, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 3, 0x40000000, 0x30000, 0x40030000, 0x20000, 0x40070000, 0x10000); - ret = lmb_reserve_flags(&lmb, 0x40050000, 0x10000, LMB_NOMAP); + ret = lmb_reserve_flags(0x40050000, 0x10000, LMB_NOMAP); ut_asserteq(ret, 0); - ASSERT_LMB(&lmb, ram, ram_size, 4, 0x40000000, 0x30000, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 4, 0x40000000, 0x30000, 0x40030000, 0x20000, 0x40050000, 0x10000); /* merge with 2 adjacent regions */ - ret = lmb_reserve_flags(&lmb, 0x40060000, 0x10000, LMB_NOMAP); + ret = lmb_reserve_flags(0x40060000, 0x10000, LMB_NOMAP); ut_asserteq(ret, 2); - ASSERT_LMB(&lmb, ram, ram_size, 3, 0x40000000, 0x30000, + ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 3, 0x40000000, 0x30000, 0x40030000, 0x20000, 0x40050000, 0x30000); - ut_asserteq(lmb_is_nomap(&lmb.reserved.region[0]), 1); - ut_asserteq(lmb_is_nomap(&lmb.reserved.region[1]), 0); - ut_asserteq(lmb_is_nomap(&lmb.reserved.region[2]), 1); + ut_asserteq(lmb_is_nomap(&used[0]), 1); + ut_asserteq(lmb_is_nomap(&used[1]), 0); + ut_asserteq(lmb_is_nomap(&used[2]), 1); + + lmb_pop(&store); return 0; } diff --git a/test/lib/test_print.c b/test/lib/test_print.c index e356afc22ba..cd7f3f85769 100644 --- a/test/lib/test_print.c +++ b/test/lib/test_print.c @@ -17,13 +17,10 @@ DECLARE_GLOBAL_DATA_PTR; static int test_print_freq(struct unit_test_state *uts, uint64_t freq, char *expected) { - ut_silence_console(uts); - console_record_reset_enable(); print_freq(freq, ";\n"); - ut_unsilence_console(uts); console_record_readline(uts->actual_str, sizeof(uts->actual_str)); ut_asserteq_str(expected, uts->actual_str); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } @@ -41,18 +38,15 @@ static int lib_test_print_freq(struct unit_test_state *uts) ut_assertok(test_print_freq(uts, 54321987654321, "54321.99 GHz;")); return 0; } -LIB_TEST(lib_test_print_freq, 0); +LIB_TEST(lib_test_print_freq, UTF_CONSOLE); static int test_print_size(struct unit_test_state *uts, uint64_t freq, char *expected) { - ut_silence_console(uts); - console_record_reset_enable(); print_size(freq, ";\n"); - ut_unsilence_console(uts); console_record_readline(uts->actual_str, sizeof(uts->actual_str)); ut_asserteq_str(expected, uts->actual_str); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } @@ -73,4 +67,4 @@ static int lib_test_print_size(struct unit_test_state *uts) ut_assertok(test_print_size(uts, 54321987654321, "49.4 TiB;")); return 0; } -LIB_TEST(lib_test_print_size, 0); +LIB_TEST(lib_test_print_size, UTF_CONSOLE); diff --git a/test/lib/uuid.c b/test/lib/uuid.c index 8fe65dbf78b..d00e9563a47 100644 --- a/test/lib/uuid.c +++ b/test/lib/uuid.c @@ -8,13 +8,18 @@ * Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com> */ -#include <uuid.h> +#include <charset.h> +#include <u-boot/uuid.h> #include <test/lib.h> #include <test/test.h> #include <test/ut.h> +#include <efi.h> + /* test UUID */ #define TEST_SVC_UUID "ed32d533-4209-99e6-2d72-cdd998a79cc0" +/* U-Boot default fw image namespace */ +#define DEFAULT_FW_IMAGE_NAMESPACE "8c9f137e-91dc-427b-b2d6-b420faebaf2a" #define UUID_SIZE 16 @@ -37,3 +42,120 @@ static int lib_test_uuid_to_le(struct unit_test_state *uts) return 0; } LIB_TEST(lib_test_uuid_to_le, 0); + +#if defined(CONFIG_RANDOM_UUID) || defined(CONFIG_CMD_UUID) +/* Test UUID attribute bits (version, variant) */ +static int lib_test_uuid_bits(struct unit_test_state *uts) +{ + unsigned char uuid[16]; + efi_guid_t guid; + int i; + + /* + * Reduce the chance of a randomly generated UUID disguising + * a regression by testing multiple times. + */ + for (i = 0; i < 5; i++) { + /* Test UUID v4 */ + gen_rand_uuid((unsigned char *)&uuid); + + printf("v4 UUID: %pUb\n", (efi_guid_t *)uuid); + + /* version 4 */ + ut_assert((uuid[6] & 0xf0) == 0x40); + /* variant 1 */ + ut_assert((uuid[8] & UUID_VARIANT_MASK) == (UUID_VARIANT << UUID_VARIANT_SHIFT)); + + /* Test v5, use the v4 UUID as the namespace */ + gen_v5_guid((struct uuid *)uuid, + &guid, "test", 4, NULL); + + printf("v5 GUID: %pUl\n", (efi_guid_t *)uuid); + + /* This is a GUID so bits 6 and 7 are swapped (little endian). Version 5 */ + ut_assert((guid.b[7] & 0xf0) == 0x50); + /* variant 1 */ + ut_assert((guid.b[8] & UUID_VARIANT_MASK) == (UUID_VARIANT << UUID_VARIANT_SHIFT)); + } + + return 0; +} + +LIB_TEST(lib_test_uuid_bits, 0); +#endif + +struct dynamic_uuid_test_data { + const char *compatible; + const u16 *images[4]; + const char *expected_uuids[4]; +}; + +static int lib_test_dynamic_uuid_case(struct unit_test_state *uts, + const struct dynamic_uuid_test_data *data) +{ + struct uuid namespace; + int j; + + ut_assertok(uuid_str_to_bin(DEFAULT_FW_IMAGE_NAMESPACE, (unsigned char *)&namespace, + UUID_STR_FORMAT_GUID)); + + for (j = 0; data->images[j]; j++) { + const char *expected_uuid = data->expected_uuids[j]; + const u16 *image = data->images[j]; + efi_guid_t uuid; + char uuid_str[37]; + + gen_v5_guid(&namespace, &uuid, + data->compatible, strlen(data->compatible), + image, u16_strlen(image) * sizeof(uint16_t), + NULL); + uuid_bin_to_str((unsigned char *)&uuid, uuid_str, UUID_STR_FORMAT_GUID); + + ut_asserteq_str(expected_uuid, uuid_str); + } + + return 0; +} + +static int lib_test_dynamic_uuid(struct unit_test_state *uts) +{ + int ret, i; + const struct dynamic_uuid_test_data test_data[] = { + { + .compatible = "sandbox", + .images = { + u"SANDBOX-UBOOT", + u"SANDBOX-UBOOT-ENV", + u"SANDBOX-FIT", + NULL, + }, + .expected_uuids = { + "985f2937-7c2e-5e9a-8a5e-8e063312964b", + "9e339473-c2eb-530a-a69b-0cd6bbbed40e", + "46610520-469e-59dc-a8dd-c11832b877ea", + NULL, + } + }, + { + .compatible = "qcom,qrb4210-rb2", + .images = { + u"QUALCOMM-UBOOT", + NULL, + }, + .expected_uuids = { + "d5021fac-8dd0-5ed7-90c2-763c304aaf86", + NULL, + } + }, + }; + + for (i = 0; i < ARRAY_SIZE(test_data); i++) { + ret = lib_test_dynamic_uuid_case(uts, &test_data[i]); + if (ret) + return ret; + } + + return 0; +} + +LIB_TEST(lib_test_dynamic_uuid, 0); diff --git a/test/log/cont_test.c b/test/log/cont_test.c index 036d44b9d73..32b1c792367 100644 --- a/test/log/cont_test.c +++ b/test/log/cont_test.c @@ -25,7 +25,6 @@ static int log_test_cont(struct unit_test_state *uts) /* Write two messages, the second continuing the first */ gd->log_fmt = (1 << LOGF_CAT) | (1 << LOGF_LEVEL) | (1 << LOGF_MSG); gd->default_log_level = LOGL_INFO; - console_record_reset_enable(); log(LOGC_ARCH, LOGL_ERR, "ea%d\n", 1); log(LOGC_CONT, LOGL_CONT, "cc%d\n", 2); gd->default_log_level = log_level; @@ -33,7 +32,7 @@ static int log_test_cont(struct unit_test_state *uts) gd->flags &= ~GD_FLG_RECORD; ut_assertok(ut_check_console_line(uts, "ERR.arch, ea1")); ut_assertok(ut_check_console_line(uts, "ERR.arch, cc2")); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Write a third message which is not a continuation */ gd->log_fmt = (1 << LOGF_CAT) | (1 << LOGF_LEVEL) | (1 << LOGF_MSG); @@ -44,7 +43,7 @@ static int log_test_cont(struct unit_test_state *uts) gd->log_fmt = log_fmt; gd->flags &= ~GD_FLG_RECORD; ut_assertok(ut_check_console_line(uts, "INFO.efi, ie3")); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); /* Write two messages without a newline between them */ gd->log_fmt = (1 << LOGF_CAT) | (1 << LOGF_LEVEL) | (1 << LOGF_MSG); @@ -56,7 +55,7 @@ static int log_test_cont(struct unit_test_state *uts) gd->log_fmt = log_fmt; gd->flags &= ~GD_FLG_RECORD; ut_assertok(ut_check_console_line(uts, "ERR.arch, ea1 cc2")); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } diff --git a/test/log/log_filter.c b/test/log/log_filter.c index e175f409c9b..d36e9d9714e 100644 --- a/test/log/log_filter.c +++ b/test/log/log_filter.c @@ -38,7 +38,6 @@ static int log_test_filter(struct unit_test_state *uts) ulong filt1, filt2; #define create_filter(args, filter_num) do {\ - ut_assertok(console_record_reset_enable()); \ ut_assertok(run_command("log filter-add -p " args, 0)); \ ut_assert_skipline(); \ ut_assertok(strict_strtoul(uts->actual_str, 10, &(filter_num))); \ @@ -72,7 +71,6 @@ static int log_test_filter(struct unit_test_state *uts) ut_asserteq(true, filt2_found); #define remove_filter(filter_num) do { \ - ut_assertok(console_record_reset_enable()); \ snprintf(cmd, sizeof(cmd), "log filter-remove %lu", filter_num); \ ut_assertok(run_command(cmd, 0)); \ ut_assert_console_end(); \ @@ -95,7 +93,6 @@ static int log_test_filter(struct unit_test_state *uts) create_filter("", filt1); create_filter("", filt2); - ut_assertok(console_record_reset_enable()); ut_assertok(run_command("log filter-remove -a", 0)); ut_assert_console_end(); diff --git a/test/log/log_test.c b/test/log/log_test.c index 357a3b57feb..1c89df4ef18 100644 --- a/test/log/log_test.c +++ b/test/log/log_test.c @@ -110,11 +110,9 @@ int log_test_cat_allow(struct unit_test_state *uts) filt = log_add_filter("console", cat_list, LOGL_MAX, NULL); ut_assert(filt >= 0); - ut_assertok(console_record_reset_enable()); log_run_cat(UCLASS_MMC); check_log_entries_extra(); - ut_assertok(console_record_reset_enable()); log_run_cat(UCLASS_SPI); check_log_entries_extra(); @@ -134,7 +132,6 @@ int log_test_cat_deny_implicit(struct unit_test_state *uts) filt = log_add_filter("console", cat_list, LOGL_MAX, NULL); ut_assert(filt >= 0); - ut_assertok(console_record_reset_enable()); log_run_cat(UCLASS_SPI); check_log_entries_none(); @@ -151,11 +148,9 @@ int log_test_file(struct unit_test_state *uts) filt = log_add_filter("console", NULL, LOGL_MAX, "file"); ut_assert(filt >= 0); - ut_assertok(console_record_reset_enable()); log_run_file("file"); check_log_entries_flags(EXPECT_DIRECT | EXPECT_EXTRA | EXPECT_FORCE); - ut_assertok(console_record_reset_enable()); log_run_file("file2"); check_log_entries_none(); @@ -172,7 +167,6 @@ int log_test_file_second(struct unit_test_state *uts) filt = log_add_filter("console", NULL, LOGL_MAX, "file,file2"); ut_assert(filt >= 0); - ut_assertok(console_record_reset_enable()); log_run_file("file2"); check_log_entries_flags(EXPECT_DIRECT | EXPECT_EXTRA | EXPECT_FORCE); @@ -190,7 +184,6 @@ int log_test_file_mid(struct unit_test_state *uts) "file,file2,log/log_test.c"); ut_assert(filt >= 0); - ut_assertok(console_record_reset_enable()); log_run_file("file2"); check_log_entries_extra(); @@ -207,7 +200,6 @@ int log_test_level(struct unit_test_state *uts) filt = log_add_filter("console", NULL, LOGL_WARNING, NULL); ut_assert(filt >= 0); - ut_assertok(console_record_reset_enable()); log_run(); check_log_entries_flags_levels(EXPECT_LOG | EXPECT_DIRECT | EXPECT_FORCE, LOGL_FIRST, LOGL_WARNING); @@ -227,7 +219,6 @@ int log_test_double(struct unit_test_state *uts) filt2 = log_add_filter("console", NULL, LOGL_MAX, NULL); ut_assert(filt2 >= 0); - ut_assertok(console_record_reset_enable()); log_run(); check_log_entries_extra(); @@ -249,7 +240,6 @@ int log_test_triple(struct unit_test_state *uts) filt3 = log_add_filter("console", NULL, LOGL_MAX, "log/log_test.c"); ut_assert(filt3 >= 0); - ut_assertok(console_record_reset_enable()); log_run_file("file2"); check_log_entries_extra(); @@ -264,7 +254,6 @@ int do_log_test_helpers(struct unit_test_state *uts) { int i; - ut_assertok(console_record_reset_enable()); log_err("level %d\n", LOGL_EMERG); log_err("level %d\n", LOGL_ALERT); log_err("level %d\n", LOGL_CRIT); @@ -296,7 +285,6 @@ LOG_TEST_FLAGS(log_test_helpers, UTF_CONSOLE); int do_log_test_disable(struct unit_test_state *uts) { - ut_assertok(console_record_reset_enable()); log_err("default\n"); ut_assert_nextline("%*s() default", CONFIG_LOGF_FUNC_PAD, __func__); @@ -335,7 +323,6 @@ int log_test_cat_deny(struct unit_test_state *uts) LOGFF_DENY); ut_assert(filt2 >= 0); - ut_assertok(console_record_reset_enable()); log_run_cat(UCLASS_SPI); check_log_entries_none(); @@ -356,7 +343,6 @@ int log_test_file_deny(struct unit_test_state *uts) LOGFF_DENY); ut_assert(filt2 >= 0); - ut_assertok(console_record_reset_enable()); log_run_file("file"); check_log_entries_none(); @@ -377,11 +363,10 @@ int log_test_level_deny(struct unit_test_state *uts) LOGFF_DENY); ut_assert(filt2 >= 0); - ut_assertok(console_record_reset_enable()); log_run(); - check_log_entries_flags_levels(EXPECT_LOG | EXPECT_DIRECT | EXPECT_FORCE, - LOGL_WARNING + 1, - min(gd->default_log_level, LOGL_INFO)); + check_log_entries_flags_levels( + EXPECT_LOG | EXPECT_DIRECT | EXPECT_FORCE, + LOGL_WARNING + 1, min((int)gd->default_log_level, LOGL_INFO)); ut_assertok(log_remove_filter("console", filt1)); ut_assertok(log_remove_filter("console", filt2)); @@ -401,7 +386,6 @@ int log_test_min(struct unit_test_state *uts) LOGFF_DENY | LOGFF_LEVEL_MIN); ut_assert(filt2 >= 0); - ut_assertok(console_record_reset_enable()); log_run(); check_log_entries_flags_levels(EXPECT_LOG | EXPECT_DIRECT | EXPECT_FORCE, LOGL_WARNING, LOGL_INFO - 1); @@ -419,8 +403,6 @@ int log_test_dropped(struct unit_test_state *uts) gd->flags &= ~(GD_FLG_LOG_READY); gd->log_drop_count = 0; - ut_assertok(console_record_reset_enable()); - log_run(); ut_asserteq(2 * (LOGL_COUNT - LOGL_FIRST) + _LOG_MAX_LEVEL - LOGL_FIRST + 1, @@ -446,14 +428,15 @@ int log_test_buffer(struct unit_test_state *uts) for (i = 0; i < 0x11; i++) buf[i] = i * 0x11; - ut_assertok(console_record_reset_enable()); log_buffer(LOGC_BOOT, LOGL_INFO, 0, buf, 1, 0x12, 0); /* This one should product no output due to the debug level */ log_buffer(LOGC_BOOT, LOGL_DEBUG, 0, buf, 1, 0x12, 0); - ut_assert_nextline("00000000: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff ..\"3DUfw........"); - ut_assert_nextline("00000010: 10 00 .."); + ut_assert_nextline( + " log_test_buffer() 00000000: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff ..\"3DUfw........"); + ut_assert_nextline( + " log_test_buffer() 00000010: 10 00 .."); ut_assert_console_end(); free(buf); diff --git a/test/log/nolog_ndebug.c b/test/log/nolog_ndebug.c index b714a16d2e7..4dc0f2d3a33 100644 --- a/test/log/nolog_ndebug.c +++ b/test/log/nolog_ndebug.c @@ -21,7 +21,6 @@ static int log_test_log_disabled_ndebug(struct unit_test_state *uts) int i; memset(buf, 0, BUFFSIZE); - console_record_reset_enable(); /* Output a log record at every level */ for (i = LOGL_EMERG; i < LOGL_COUNT; i++) @@ -31,7 +30,7 @@ static int log_test_log_disabled_ndebug(struct unit_test_state *uts) /* Since DEBUG is not defined, we expect to not get debug output */ for (i = LOGL_EMERG; i < LOGL_DEBUG; i++) ut_assertok(ut_check_console_line(uts, "testing level %d", i)); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } diff --git a/test/log/nolog_test.c b/test/log/nolog_test.c index c4c0fa6cf81..341dbfc9310 100644 --- a/test/log/nolog_test.c +++ b/test/log/nolog_test.c @@ -25,11 +25,10 @@ static int log_test_nolog_err(struct unit_test_state *uts) char buf[BUFFSIZE]; memset(buf, 0, BUFFSIZE); - console_record_reset_enable(); log_err("testing %s\n", "log_err"); gd->flags &= ~GD_FLG_RECORD; ut_assertok(ut_check_console_line(uts, "testing log_err")); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } LOG_TEST(log_test_nolog_err); @@ -39,11 +38,10 @@ static int log_test_nolog_warning(struct unit_test_state *uts) char buf[BUFFSIZE]; memset(buf, 0, BUFFSIZE); - console_record_reset_enable(); log_warning("testing %s\n", "log_warning"); gd->flags &= ~GD_FLG_RECORD; ut_assertok(ut_check_console_line(uts, "testing log_warning")); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } LOG_TEST(log_test_nolog_warning); @@ -53,11 +51,10 @@ static int log_test_nolog_notice(struct unit_test_state *uts) char buf[BUFFSIZE]; memset(buf, 0, BUFFSIZE); - console_record_reset_enable(); log_notice("testing %s\n", "log_notice"); gd->flags &= ~GD_FLG_RECORD; ut_assertok(ut_check_console_line(uts, "testing log_notice")); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } LOG_TEST(log_test_nolog_notice); @@ -67,11 +64,10 @@ static int log_test_nolog_info(struct unit_test_state *uts) char buf[BUFFSIZE]; memset(buf, 0, BUFFSIZE); - console_record_reset_enable(); log_err("testing %s\n", "log_info"); gd->flags &= ~GD_FLG_RECORD; ut_assertok(ut_check_console_line(uts, "testing log_info")); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } LOG_TEST(log_test_nolog_info); @@ -83,10 +79,9 @@ static int nolog_test_nodebug(struct unit_test_state *uts) char buf[BUFFSIZE]; memset(buf, 0, BUFFSIZE); - console_record_reset_enable(); debug("testing %s\n", "debug"); gd->flags &= ~GD_FLG_RECORD; - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } LOG_TEST(nolog_test_nodebug); @@ -96,11 +91,10 @@ static int log_test_nolog_nodebug(struct unit_test_state *uts) char buf[BUFFSIZE]; memset(buf, 0, BUFFSIZE); - console_record_reset_enable(); log_debug("testing %s\n", "log_debug"); gd->flags &= ~GD_FLG_RECORD; ut_assert(!strcmp(buf, "")); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } LOG_TEST(log_test_nolog_nodebug); @@ -112,11 +106,10 @@ static int nolog_test_debug(struct unit_test_state *uts) char buf[BUFFSIZE]; memset(buf, 0, BUFFSIZE); - console_record_reset_enable(); debug("testing %s\n", "debug"); gd->flags &= ~GD_FLG_RECORD; ut_assertok(ut_check_console_line(uts, "testing debug")); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } LOG_TEST(nolog_test_debug); @@ -126,13 +119,12 @@ static int log_test_nolog_debug(struct unit_test_state *uts) char buf[BUFFSIZE]; memset(buf, 0, BUFFSIZE); - console_record_reset_enable(); log_debug("testing %s\n", "log_debug"); log(LOGC_NONE, LOGL_DEBUG, "more %s\n", "log_debug"); gd->flags &= ~GD_FLG_RECORD; ut_assertok(ut_check_console_line(uts, "testing log_debug")); ut_assertok(ut_check_console_line(uts, "more log_debug")); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } LOG_TEST(log_test_nolog_debug); diff --git a/test/log/pr_cont_test.c b/test/log/pr_cont_test.c index 30f30d98fe1..7734e927f98 100644 --- a/test/log/pr_cont_test.c +++ b/test/log/pr_cont_test.c @@ -28,14 +28,13 @@ static int log_test_pr_cont(struct unit_test_state *uts) /* Write two messages, the second continuing the first */ gd->log_fmt = BIT(LOGF_MSG); gd->default_log_level = LOGL_INFO; - console_record_reset_enable(); pr_err("ea%d ", 1); pr_cont("cc%d\n", 2); gd->default_log_level = log_level; gd->log_fmt = log_fmt; gd->flags &= ~GD_FLG_RECORD; ut_assertok(ut_check_console_line(uts, "ea1 cc2")); - ut_assertok(ut_check_console_end(uts)); + ut_assert_console_end(); return 0; } diff --git a/test/overlay/Kconfig b/test/overlay/Kconfig index a4f154415db..881848968bb 100644 --- a/test/overlay/Kconfig +++ b/test/overlay/Kconfig @@ -1,6 +1,6 @@ config UT_OVERLAY bool "Enable Device Tree Overlays Unit Tests" - depends on UNIT_TEST && OF_CONTROL + depends on UNIT_TEST && OF_CONTROL && SANDBOX default y select OF_LIBFDT_OVERLAY help diff --git a/test/print_ut.c b/test/print_ut.c index cf0d5929508..f5e607b21a3 100644 --- a/test/print_ut.c +++ b/test/print_ut.c @@ -180,14 +180,12 @@ static int print_display_buffer(struct unit_test_state *uts) buf[i] = i * 0x11; /* bytes */ - console_record_reset(); print_buffer(0, buf, 1, 0x12, 0); ut_assert_nextline("00000000: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff ..\"3DUfw........"); ut_assert_nextline("00000010: 10 00 .."); ut_assert_console_end(); /* line length */ - console_record_reset(); print_buffer(0, buf, 1, 0x12, 8); ut_assert_nextline("00000000: 00 11 22 33 44 55 66 77 ..\"3DUfw"); ut_assert_nextline("00000008: 88 99 aa bb cc dd ee ff ........"); @@ -195,7 +193,6 @@ static int print_display_buffer(struct unit_test_state *uts) ut_assert_console_end(); /* long line */ - console_record_reset(); buf[0x41] = 0x41; print_buffer(0, buf, 1, 0x42, 0x40); ut_assert_nextline("00000000: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ..\"3DUfw........................................................"); @@ -203,35 +200,30 @@ static int print_display_buffer(struct unit_test_state *uts) ut_assert_console_end(); /* address */ - console_record_reset(); print_buffer(0x12345678, buf, 1, 0x12, 0); ut_assert_nextline("12345678: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff ..\"3DUfw........"); ut_assert_nextline("12345688: 10 00 .."); ut_assert_console_end(); /* 16-bit */ - console_record_reset(); print_buffer(0, buf, 2, 9, 0); ut_assert_nextline("00000000: 1100 3322 5544 7766 9988 bbaa ddcc ffee ..\"3DUfw........"); ut_assert_nextline("00000010: 0010 .."); ut_assert_console_end(); /* 32-bit */ - console_record_reset(); print_buffer(0, buf, 4, 5, 0); ut_assert_nextline("00000000: 33221100 77665544 bbaa9988 ffeeddcc ..\"3DUfw........"); ut_assert_nextline("00000010: 00000010 ...."); ut_assert_console_end(); /* 64-bit */ - console_record_reset(); print_buffer(0, buf, 8, 3, 0); ut_assert_nextline("00000000: 7766554433221100 ffeeddccbbaa9988 ..\"3DUfw........"); ut_assert_nextline("00000010: 0000000000000010 ........"); ut_assert_console_end(); /* ASCII */ - console_record_reset(); buf[1] = 31; buf[2] = 32; buf[3] = 33; @@ -289,7 +281,6 @@ static int print_do_hex_dump(struct unit_test_state *uts) buf[i] = i * 0x11; /* bytes */ - console_record_reset(); print_hex_dump_bytes("", DUMP_PREFIX_ADDRESS, buf, 0x12); ut_assert_nextline("%0*lx: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff ..\"3DUfw........", IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, 0x0UL); @@ -298,7 +289,6 @@ static int print_do_hex_dump(struct unit_test_state *uts) ut_assert_console_end(); /* line length */ - console_record_reset(); print_hex_dump("", DUMP_PREFIX_ADDRESS, 8, 1, buf, 0x12, true); ut_assert_nextline("%0*lx: 00 11 22 33 44 55 66 77 ..\"3DUfw", IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, 0x0UL); @@ -310,7 +300,6 @@ static int print_do_hex_dump(struct unit_test_state *uts) unmap_sysmem(buf); /* long line */ - console_record_reset(); buf[0x41] = 0x41; print_hex_dump("", DUMP_PREFIX_ADDRESS, 0x40, 1, buf, 0x42, true); ut_assert_nextline("%0*lx: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ..\"3DUfw........................................................", @@ -320,7 +309,6 @@ static int print_do_hex_dump(struct unit_test_state *uts) ut_assert_console_end(); /* 16-bit */ - console_record_reset(); print_hex_dump("", DUMP_PREFIX_ADDRESS, 0, 2, buf, 0x12, true); ut_assert_nextline("%0*lx: 1100 3322 5544 7766 9988 bbaa ddcc ffee ..\"3DUfw........", IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, 0x0UL); @@ -330,7 +318,6 @@ static int print_do_hex_dump(struct unit_test_state *uts) unmap_sysmem(buf); /* 32-bit */ - console_record_reset(); print_hex_dump("", DUMP_PREFIX_ADDRESS, 0, 4, buf, 0x14, true); ut_assert_nextline("%0*lx: 33221100 77665544 bbaa9988 ffeeddcc ..\"3DUfw........", IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, 0x0UL); @@ -340,7 +327,6 @@ static int print_do_hex_dump(struct unit_test_state *uts) unmap_sysmem(buf); /* 64-bit */ - console_record_reset(); print_hex_dump("", DUMP_PREFIX_ADDRESS, 16, 8, buf, 0x18, true); ut_assert_nextline("%0*lx: 7766554433221100 ffeeddccbbaa9988 ..\"3DUfw........", IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, 0x0UL); @@ -350,7 +336,6 @@ static int print_do_hex_dump(struct unit_test_state *uts) unmap_sysmem(buf); /* ASCII */ - console_record_reset(); buf[1] = 31; buf[2] = 32; buf[3] = 33; diff --git a/test/py/requirements.txt b/test/py/requirements.txt index 2b1489808c0..75760f96e56 100644 --- a/test/py/requirements.txt +++ b/test/py/requirements.txt @@ -1,14 +1,14 @@ atomicwrites==1.4.1 attrs==19.3.0 concurrencytest==0.1.2 -coverage==4.5.4 +coverage==6.2 extras==1.0.0 filelock==3.0.12 fixtures==3.0.0 importlib-metadata==0.23 linecache2==1.0.0 more-itertools==7.2.0 -packaging==23.2 +packaging==24.1 pbr==5.4.3 pluggy==0.13.0 py==1.11.0 @@ -20,7 +20,7 @@ pytest==6.2.5 pytest-xdist==2.5.0 python-mimeparse==1.6.0 python-subunit==1.3.0 -requests==2.32.2 +requests==2.32.3 setuptools==70.3.0 six==1.16.0 testtools==2.3.0 diff --git a/test/py/tests/test_efi_capsule/test_capsule_firmware_fit.py b/test/py/tests/test_efi_capsule/test_capsule_firmware_fit.py index 11bcdc2bb29..a726c71c113 100644 --- a/test/py/tests/test_efi_capsule/test_capsule_firmware_fit.py +++ b/test/py/tests/test_efi_capsule/test_capsule_firmware_fit.py @@ -147,7 +147,7 @@ class TestEfiCapsuleFirmwareFit(): verify_content(u_boot_console, '150000', 'u-boot-env:Old') else: # ensure that SANDBOX_UBOOT_IMAGE_GUID is in the ESRT. - assert '3673B45D-6A7C-46F3-9E60-ADABB03F7937' in ''.join(output) + assert '985F2937-7C2E-5E9A-8A5E-8E063312964B' in ''.join(output) assert 'ESRT: fw_version=5' in ''.join(output) assert 'ESRT: lowest_supported_fw_version=3' in ''.join(output) diff --git a/test/py/tests/test_efi_capsule/test_capsule_firmware_raw.py b/test/py/tests/test_efi_capsule/test_capsule_firmware_raw.py index f3a2dff5c2c..8a790405c7c 100644 --- a/test/py/tests/test_efi_capsule/test_capsule_firmware_raw.py +++ b/test/py/tests/test_efi_capsule/test_capsule_firmware_raw.py @@ -145,10 +145,10 @@ class TestEfiCapsuleFirmwareRaw: 'efidebug capsule esrt']) # ensure that SANDBOX_UBOOT_ENV_IMAGE_GUID is in the ESRT. - assert '5A7021F5-FEF2-48B4-AABA-832E777418C0' in ''.join(output) + assert '9E339473-C2EB-530A-A69B-0CD6BBBED40E' in ''.join(output) # ensure that SANDBOX_UBOOT_IMAGE_GUID is in the ESRT. - assert '09D7CF52-0720-4710-91D1-08469B7FE9C8' in ''.join(output) + assert '985F2937-7C2E-5E9A-8A5E-8E063312964B' in ''.join(output) check_file_removed(u_boot_console, disk_img, capsule_files) @@ -199,12 +199,12 @@ class TestEfiCapsuleFirmwareRaw: verify_content(u_boot_console, '150000', 'u-boot-env:Old') else: # ensure that SANDBOX_UBOOT_IMAGE_GUID is in the ESRT. - assert '09D7CF52-0720-4710-91D1-08469B7FE9C8' in ''.join(output) + assert '985F2937-7C2E-5E9A-8A5E-8E063312964B' in ''.join(output) assert 'ESRT: fw_version=5' in ''.join(output) assert 'ESRT: lowest_supported_fw_version=3' in ''.join(output) # ensure that SANDBOX_UBOOT_ENV_IMAGE_GUID is in the ESRT. - assert '5A7021F5-FEF2-48B4-AABA-832E777418C0' in ''.join(output) + assert '9E339473-C2EB-530A-A69B-0CD6BBBED40E' in ''.join(output) assert 'ESRT: fw_version=10' in ''.join(output) assert 'ESRT: lowest_supported_fw_version=7' in ''.join(output) diff --git a/test/py/tests/test_efi_capsule/test_capsule_firmware_signed_fit.py b/test/py/tests/test_efi_capsule/test_capsule_firmware_signed_fit.py index 44a58baa310..debbce8bdbd 100644 --- a/test/py/tests/test_efi_capsule/test_capsule_firmware_signed_fit.py +++ b/test/py/tests/test_efi_capsule/test_capsule_firmware_signed_fit.py @@ -157,7 +157,7 @@ class TestEfiCapsuleFirmwareSignedFit(): 'efidebug capsule esrt']) # ensure that SANDBOX_UBOOT_IMAGE_GUID is in the ESRT. - assert '3673B45D-6A7C-46F3-9E60-ADABB03F7937' in ''.join(output) + assert '46610520-469E-59DC-A8DD-C11832B877EA' in ''.join(output) assert 'ESRT: fw_version=5' in ''.join(output) assert 'ESRT: lowest_supported_fw_version=3' in ''.join(output) diff --git a/test/py/tests/test_efi_capsule/test_capsule_firmware_signed_raw.py b/test/py/tests/test_efi_capsule/test_capsule_firmware_signed_raw.py index 83a10e160b8..439bd71b3a7 100644 --- a/test/py/tests/test_efi_capsule/test_capsule_firmware_signed_raw.py +++ b/test/py/tests/test_efi_capsule/test_capsule_firmware_signed_raw.py @@ -151,12 +151,12 @@ class TestEfiCapsuleFirmwareSignedRaw(): 'efidebug capsule esrt']) # ensure that SANDBOX_UBOOT_IMAGE_GUID is in the ESRT. - assert '09D7CF52-0720-4710-91D1-08469B7FE9C8' in ''.join(output) + assert '985F2937-7C2E-5E9A-8A5E-8E063312964B' in ''.join(output) assert 'ESRT: fw_version=5' in ''.join(output) assert 'ESRT: lowest_supported_fw_version=3' in ''.join(output) # ensure that SANDBOX_UBOOT_ENV_IMAGE_GUID is in the ESRT. - assert '5A7021F5-FEF2-48B4-AABA-832E777418C0' in ''.join(output) + assert '9E339473-C2EB-530A-A69B-0CD6BBBED40E' in ''.join(output) assert 'ESRT: fw_version=10' in ''.join(output) assert 'ESRT: lowest_supported_fw_version=7' in ''.join(output) diff --git a/test/py/tests/test_efi_capsule/version.dtso b/test/py/tests/test_efi_capsule/version.dtso index 07850cc6064..3aebb5b64fb 100644 --- a/test/py/tests/test_efi_capsule/version.dtso +++ b/test/py/tests/test_efi_capsule/version.dtso @@ -8,17 +8,17 @@ image1 { lowest-supported-version = <3>; image-index = <1>; - image-type-id = "09D7CF52-0720-4710-91D1-08469B7FE9C8"; + image-type-id = "985F2937-7C2E-5E9A-8A5E-8E063312964B"; }; image2 { lowest-supported-version = <7>; image-index = <2>; - image-type-id = "5A7021F5-FEF2-48B4-AABA-832E777418C0"; + image-type-id = "9E339473-C2EB-530A-A69B-0CD6BBBED40E"; }; image3 { lowest-supported-version = <3>; image-index = <1>; - image-type-id = "3673B45D-6A7C-46F3-9E60-ADABB03F7937"; + image-type-id = "46610520-469E-59DC-A8DD-C11832B877EA"; }; }; }; diff --git a/test/py/tests/test_spi.py b/test/py/tests/test_spi.py new file mode 100644 index 00000000000..3160d58540f --- /dev/null +++ b/test/py/tests/test_spi.py @@ -0,0 +1,696 @@ +# SPDX-License-Identifier: GPL-2.0 +# (C) Copyright 2024, Advanced Micro Devices, Inc. + +""" +Note: This test relies on boardenv_* containing configuration values to define +spi minimum and maximum frequencies at which the flash part can operate on and +these tests run at different spi frequency randomised values in the range +multiple times based on the user defined iteration value. +It also defines the SPI bus number containing the SPI-flash chip, SPI +chip-select, SPI mode, SPI flash part name and timeout parameters. If minimum +and maximum frequency is not defined, it will run on freq 0 by default. + +Without the boardenv_* configuration, this test will be automatically skipped. + +It also relies on configuration values for supported flashes for lock and +unlock cases for SPI family flash. It will run lock-unlock cases only for the +supported flash parts. + +For Example: + +# Details of SPI device test parameters required for SPI device testing: + +# bus - SPI bus number to init the flash device +# chip_select - SPI chip select number to init the flash device +# min_freq - Minimum frequency in hz at which the flash part can operate, set 0 +# or None for default frequency +# max_freq - Maximum frequency in hz at which the flash part can operate, set 0 +# or None for default frequency +# mode - SPI mode to init the flash device +# part_name - SPI flash part name to be detected +# timeout - Default timeout to run the sf commands +# iteration - No of iteration to run SPI flash test + +env__spi_device_test = { + 'bus': 0, + 'chip_select': 0, + 'min_freq': 10000000, + 'max_freq': 100000000, + 'mode': 0, + 'part_name': 'n25q00a', + 'timeout': 100000, + 'iteration': 5, +} + +# supported_flash - Flash parts name which support lock-unlock functionality +env__spi_lock_unlock = { + 'supported_flash': 'mt25qu512a, n25q00a, n25q512ax3', +} +""" + +import random +import re +import pytest +import u_boot_utils + +SPI_DATA = {} +EXPECTED_ERASE = 'Erased: OK' +EXPECTED_WRITE = 'Written: OK' +EXPECTED_READ = 'Read: OK' +EXPECTED_ERASE_ERRORS = [ + 'Erase operation failed', + 'Attempted to modify a protected sector', + 'Erased: ERROR', + 'is protected and cannot be erased', + 'ERROR: flash area is locked', +] +EXPECTED_WRITE_ERRORS = [ + 'ERROR: flash area is locked', + 'Program operation failed', + 'Attempted to modify a protected sector', + 'Written: ERROR', +] + +def get_params_spi(u_boot_console): + ''' Get SPI device test parameters from boardenv file ''' + f = u_boot_console.config.env.get('env__spi_device_test', None) + if not f: + pytest.skip('No env file to read for SPI family device test') + + bus = f.get('bus', 0) + cs = f.get('chip_select', 0) + mode = f.get('mode', 0) + part_name = f.get('part_name', None) + timeout = f.get('timeout', None) + + if not part_name: + pytest.skip('No env file to read SPI family flash part name') + + return bus, cs, mode, part_name, timeout + +def spi_find_freq_range(u_boot_console): + '''Find out minimum and maximum frequnecies that SPI device can operate''' + f = u_boot_console.config.env.get('env__spi_device_test', None) + if not f: + pytest.skip('No env file to read for SPI family device test') + + min_f = f.get('min_freq', None) + max_f = f.get('max_freq', None) + iterations = f.get('iteration', 1) + + if not min_f: + min_f = 0 + if not max_f: + max_f = 0 + + max_f = max(max_f, min_f) + + return min_f, max_f, iterations + +def spi_pre_commands(u_boot_console, freq): + ''' Find out SPI family flash memory parameters ''' + bus, cs, mode, part_name, timeout = get_params_spi(u_boot_console) + + output = u_boot_console.run_command(f'sf probe {bus}:{cs} {freq} {mode}') + if not 'SF: Detected' in output: + pytest.fail('No SPI device available') + + if not part_name in output: + pytest.fail('SPI flash part name not recognized') + + m = re.search('page size (.+?) Bytes', output) + if m: + try: + page_size = int(m.group(1)) + except ValueError: + pytest.fail('SPI page size not recognized') + + m = re.search('erase size (.+?) KiB', output) + if m: + try: + erase_size = int(m.group(1)) + except ValueError: + pytest.fail('SPI erase size not recognized') + + erase_size *= 1024 + + m = re.search('total (.+?) MiB', output) + if m: + try: + total_size = int(m.group(1)) + except ValueError: + pytest.fail('SPI total size not recognized') + + total_size *= 1024 * 1024 + + m = re.search('Detected (.+?) with', output) + if m: + try: + flash_part = m.group(1) + assert flash_part == part_name + except ValueError: + pytest.fail('SPI flash part not recognized') + + global SPI_DATA + SPI_DATA = { + 'page_size': page_size, + 'erase_size': erase_size, + 'total_size': total_size, + 'flash_part': flash_part, + 'timeout': timeout, + } + +def get_page_size(): + ''' Get the SPI page size from spi data ''' + return SPI_DATA['page_size'] + +def get_erase_size(): + ''' Get the SPI erase size from spi data ''' + return SPI_DATA['erase_size'] + +def get_total_size(): + ''' Get the SPI total size from spi data ''' + return SPI_DATA['total_size'] + +def get_flash_part(): + ''' Get the SPI flash part name from spi data ''' + return SPI_DATA['flash_part'] + +def get_timeout(): + ''' Get the SPI timeout from spi data ''' + return SPI_DATA['timeout'] + +def spi_erase_block(u_boot_console, erase_size, total_size): + ''' Erase SPI flash memory block wise ''' + for start in range(0, total_size, erase_size): + output = u_boot_console.run_command(f'sf erase {hex(start)} {hex(erase_size)}') + assert EXPECTED_ERASE in output + +@pytest.mark.buildconfigspec('cmd_sf') +def test_spi_erase_block(u_boot_console): + ''' Test case to check SPI erase functionality by erasing memory regions + block-wise ''' + + min_f, max_f, loop = spi_find_freq_range(u_boot_console) + i = 0 + while i < loop: + spi_pre_commands(u_boot_console, random.randint(min_f, max_f)) + spi_erase_block(u_boot_console, get_erase_size(), get_total_size()) + i = i + 1 + +def spi_write_twice(u_boot_console, page_size, erase_size, total_size, timeout): + ''' Random write till page size, random till size and full size ''' + addr = u_boot_utils.find_ram_base(u_boot_console) + + old_size = 0 + for size in ( + random.randint(4, page_size), + random.randint(page_size, total_size), + total_size, + ): + offset = random.randint(4, page_size) + offset = offset & ~3 + size = size & ~3 + size = size - old_size + output = u_boot_console.run_command(f'crc32 {hex(addr + total_size)} {hex(size)}') + m = re.search('==> (.+?)$', output) + if not m: + pytest.fail('CRC32 failed') + + expected_crc32 = m.group(1) + if old_size % page_size: + old_size = int(old_size / page_size) + old_size *= page_size + + if size % erase_size: + erasesize = int(size / erase_size + 1) + erasesize *= erase_size + + eraseoffset = int(old_size / erase_size) + eraseoffset *= erase_size + + timeout = 100000000 + with u_boot_console.temporary_timeout(timeout): + output = u_boot_console.run_command( + f'sf erase {hex(eraseoffset)} {hex(erasesize)}' + ) + assert EXPECTED_ERASE in output + + with u_boot_console.temporary_timeout(timeout): + output = u_boot_console.run_command( + f'sf write {hex(addr + total_size)} {hex(old_size)} {hex(size)}' + ) + assert EXPECTED_WRITE in output + with u_boot_console.temporary_timeout(timeout): + output = u_boot_console.run_command( + f'sf read {hex(addr + total_size + offset)} {hex(old_size)} {hex(size)}' + ) + assert EXPECTED_READ in output + output = u_boot_console.run_command( + f'crc32 {hex(addr + total_size + offset)} {hex(size)}' + ) + assert expected_crc32 in output + old_size = size + +@pytest.mark.buildconfigspec('cmd_bdi') +@pytest.mark.buildconfigspec('cmd_sf') +@pytest.mark.buildconfigspec('cmd_memory') +def test_spi_write_twice(u_boot_console): + ''' Test to write data with random size twice for SPI ''' + min_f, max_f, loop = spi_find_freq_range(u_boot_console) + i = 0 + while i < loop: + spi_pre_commands(u_boot_console, random.randint(min_f, max_f)) + spi_write_twice( + u_boot_console, + get_page_size(), + get_erase_size(), + get_total_size(), + get_timeout() + ) + i = i + 1 + +def spi_write_continues(u_boot_console, page_size, erase_size, total_size, timeout): + ''' Write with random size of data to continue SPI write case ''' + spi_erase_block(u_boot_console, erase_size, total_size) + addr = u_boot_utils.find_ram_base(u_boot_console) + + output = u_boot_console.run_command(f'crc32 {hex(addr + 0x10000)} {hex(total_size)}') + m = re.search('==> (.+?)$', output) + if not m: + pytest.fail('CRC32 failed') + expected_crc32 = m.group(1) + + old_size = 0 + for size in ( + random.randint(4, page_size), + random.randint(page_size, total_size), + total_size, + ): + size = size & ~3 + size = size - old_size + with u_boot_console.temporary_timeout(timeout): + output = u_boot_console.run_command( + f'sf write {hex(addr + 0x10000 + old_size)} {hex(old_size)} {hex(size)}' + ) + assert EXPECTED_WRITE in output + old_size += size + + with u_boot_console.temporary_timeout(timeout): + output = u_boot_console.run_command( + f'sf read {hex(addr + 0x10000 + total_size)} 0 {hex(total_size)}' + ) + assert EXPECTED_READ in output + + output = u_boot_console.run_command( + f'crc32 {hex(addr + 0x10000 + total_size)} {hex(total_size)}' + ) + assert expected_crc32 in output + +@pytest.mark.buildconfigspec('cmd_bdi') +@pytest.mark.buildconfigspec('cmd_sf') +@pytest.mark.buildconfigspec('cmd_memory') +def test_spi_write_continues(u_boot_console): + ''' Test to write more random size data for SPI ''' + min_f, max_f, loop = spi_find_freq_range(u_boot_console) + i = 0 + while i < loop: + spi_pre_commands(u_boot_console, random.randint(min_f, max_f)) + spi_write_twice( + u_boot_console, + get_page_size(), + get_erase_size(), + get_total_size(), + get_timeout(), + ) + i = i + 1 + +def spi_read_twice(u_boot_console, page_size, total_size, timeout): + ''' Read the whole SPI flash twice, random_size till full flash size, + random till page size ''' + for size in random.randint(4, page_size), random.randint(4, total_size), total_size: + addr = u_boot_utils.find_ram_base(u_boot_console) + size = size & ~3 + with u_boot_console.temporary_timeout(timeout): + output = u_boot_console.run_command( + f'sf read {hex(addr + total_size)} 0 {hex(size)}' + ) + assert EXPECTED_READ in output + output = u_boot_console.run_command(f'crc32 {hex(addr + total_size)} {hex(size)}') + m = re.search('==> (.+?)$', output) + if not m: + pytest.fail('CRC32 failed') + expected_crc32 = m.group(1) + with u_boot_console.temporary_timeout(timeout): + output = u_boot_console.run_command( + f'sf read {hex(addr + total_size + 10)} 0 {hex(size)}' + ) + assert EXPECTED_READ in output + output = u_boot_console.run_command( + f'crc32 {hex(addr + total_size + 10)} {hex(size)}' + ) + assert expected_crc32 in output + +@pytest.mark.buildconfigspec('cmd_sf') +@pytest.mark.buildconfigspec('cmd_bdi') +@pytest.mark.buildconfigspec('cmd_memory') +def test_spi_read_twice(u_boot_console): + ''' Test to read random data twice from SPI ''' + min_f, max_f, loop = spi_find_freq_range(u_boot_console) + i = 0 + while i < loop: + spi_pre_commands(u_boot_console, random.randint(min_f, max_f)) + spi_read_twice(u_boot_console, get_page_size(), get_total_size(), get_timeout()) + i = i + 1 + +def spi_erase_all(u_boot_console, total_size, timeout): + ''' Erase the full chip SPI ''' + start = 0 + with u_boot_console.temporary_timeout(timeout): + output = u_boot_console.run_command(f'sf erase {start} {hex(total_size)}') + assert EXPECTED_ERASE in output + +@pytest.mark.buildconfigspec('cmd_sf') +def test_spi_erase_all(u_boot_console): + ''' Test to check full chip erase for SPI ''' + min_f, max_f, loop = spi_find_freq_range(u_boot_console) + i = 0 + while i < loop: + spi_pre_commands(u_boot_console, random.randint(min_f, max_f)) + spi_erase_all(u_boot_console, get_total_size(), get_timeout()) + i = i + 1 + +def flash_ops( + u_boot_console, ops, start, size, offset=0, exp_ret=0, exp_str='', not_exp_str='' +): + ''' Flash operations: erase, write and read ''' + + f = u_boot_console.config.env.get('env__spi_device_test', None) + if not f: + timeout = 1000000 + + timeout = f.get('timeout', 1000000) + + if ops == 'erase': + with u_boot_console.temporary_timeout(timeout): + output = u_boot_console.run_command(f'sf erase {hex(start)} {hex(size)}') + else: + with u_boot_console.temporary_timeout(timeout): + output = u_boot_console.run_command( + f'sf {ops} {hex(offset)} {hex(start)} {hex(size)}' + ) + + if exp_str: + assert exp_str in output + if not_exp_str: + assert not_exp_str not in output + + ret_code = u_boot_console.run_command('echo $?') + if exp_ret >= 0: + assert ret_code.endswith(str(exp_ret)) + + return output, ret_code + +def spi_unlock_exit(u_boot_console, addr, size): + ''' Unlock the flash before making it fail ''' + u_boot_console.run_command(f'sf protect unlock {hex(addr)} {hex(size)}') + assert False, 'FAIL: Flash lock is unable to protect the data!' + +def find_prot_region(lock_addr, lock_size): + ''' Get the protected and un-protected region of flash ''' + total_size = get_total_size() + erase_size = get_erase_size() + + if lock_addr < (total_size // 2): + sect_num = (lock_addr + lock_size) // erase_size + x = 1 + while x < sect_num: + x *= 2 + prot_start = 0 + prot_size = x * erase_size + unprot_start = prot_start + prot_size + unprot_size = total_size - unprot_start + else: + sect_num = (total_size - lock_addr) // erase_size + x = 1 + while x < sect_num: + x *= 2 + prot_start = total_size - (x * erase_size) + prot_size = total_size - prot_start + unprot_start = 0 + unprot_size = prot_start + + return prot_start, prot_size, unprot_start, unprot_size + +def protect_ops(u_boot_console, lock_addr, lock_size, ops="unlock"): + ''' Run the command to lock or Unlock the flash ''' + u_boot_console.run_command(f'sf protect {ops} {hex(lock_addr)} {hex(lock_size)}') + output = u_boot_console.run_command('echo $?') + if ops == "lock" and not output.endswith('0'): + u_boot_console.run_command(f'sf protect unlock {hex(lock_addr)} {hex(lock_size)}') + assert False, "sf protect lock command exits with non-zero return code" + assert output.endswith('0') + +def erase_write_ops(u_boot_console, start, size): + ''' Basic erase and write operation for flash ''' + addr = u_boot_utils.find_ram_base(u_boot_console) + flash_ops(u_boot_console, 'erase', start, size, 0, 0, EXPECTED_ERASE) + flash_ops(u_boot_console, 'write', start, size, addr, 0, EXPECTED_WRITE) + +def spi_lock_unlock(u_boot_console, lock_addr, lock_size): + ''' Lock unlock operations for SPI family flash ''' + addr = u_boot_utils.find_ram_base(u_boot_console) + erase_size = get_erase_size() + + # Find the protected/un-protected region + prot_start, prot_size, unprot_start, unprot_size = find_prot_region(lock_addr, lock_size) + + # Check erase/write operation before locking + erase_write_ops(u_boot_console, prot_start, prot_size) + + # Locking the flash + protect_ops(u_boot_console, lock_addr, lock_size, 'lock') + + # Check erase/write operation after locking + output, ret_code = flash_ops(u_boot_console, 'erase', prot_start, prot_size, 0, -1) + if not any(error in output for error in EXPECTED_ERASE_ERRORS) or ret_code.endswith( + '0' + ): + spi_unlock_exit(u_boot_console, lock_addr, lock_size) + + output, ret_code = flash_ops( + u_boot_console, 'write', prot_start, prot_size, addr, -1 + ) + if not any(error in output for error in EXPECTED_WRITE_ERRORS) or ret_code.endswith( + '0' + ): + spi_unlock_exit(u_boot_console, lock_addr, lock_size) + + # Check locked sectors + sect_lock_start = random.randrange(prot_start, (prot_start + prot_size), erase_size) + if prot_size > erase_size: + sect_lock_size = random.randrange( + erase_size, (prot_start + prot_size - sect_lock_start), erase_size + ) + else: + sect_lock_size = erase_size + sect_write_size = random.randint(1, sect_lock_size) + + output, ret_code = flash_ops( + u_boot_console, 'erase', sect_lock_start, sect_lock_size, 0, -1 + ) + if not any(error in output for error in EXPECTED_ERASE_ERRORS) or ret_code.endswith( + '0' + ): + spi_unlock_exit(u_boot_console, lock_addr, lock_size) + + output, ret_code = flash_ops( + u_boot_console, 'write', sect_lock_start, sect_write_size, addr, -1 + ) + if not any(error in output for error in EXPECTED_WRITE_ERRORS) or ret_code.endswith( + '0' + ): + spi_unlock_exit(u_boot_console, lock_addr, lock_size) + + # Check unlocked sectors + if unprot_size != 0: + sect_unlock_start = random.randrange( + unprot_start, (unprot_start + unprot_size), erase_size + ) + if unprot_size > erase_size: + sect_unlock_size = random.randrange( + erase_size, (unprot_start + unprot_size - sect_unlock_start), erase_size + ) + else: + sect_unlock_size = erase_size + sect_write_size = random.randint(1, sect_unlock_size) + + output, ret_code = flash_ops( + u_boot_console, 'erase', sect_unlock_start, sect_unlock_size, 0, -1 + ) + if EXPECTED_ERASE not in output or ret_code.endswith('1'): + spi_unlock_exit(u_boot_console, lock_addr, lock_size) + + output, ret_code = flash_ops( + u_boot_console, 'write', sect_unlock_start, sect_write_size, addr, -1 + ) + if EXPECTED_WRITE not in output or ret_code.endswith('1'): + spi_unlock_exit(u_boot_console, lock_addr, lock_size) + + # Unlocking the flash + protect_ops(u_boot_console, lock_addr, lock_size, 'unlock') + + # Check erase/write operation after un-locking + erase_write_ops(u_boot_console, prot_start, prot_size) + + # Check previous locked sectors + sect_lock_start = random.randrange(prot_start, (prot_start + prot_size), erase_size) + if prot_size > erase_size: + sect_lock_size = random.randrange( + erase_size, (prot_start + prot_size - sect_lock_start), erase_size + ) + else: + sect_lock_size = erase_size + sect_write_size = random.randint(1, sect_lock_size) + + flash_ops( + u_boot_console, 'erase', sect_lock_start, sect_lock_size, 0, 0, EXPECTED_ERASE + ) + flash_ops( + u_boot_console, + 'write', + sect_lock_start, + sect_write_size, + addr, + 0, + EXPECTED_WRITE, + ) + +@pytest.mark.buildconfigspec('cmd_bdi') +@pytest.mark.buildconfigspec('cmd_sf') +@pytest.mark.buildconfigspec('cmd_memory') +def test_spi_lock_unlock(u_boot_console): + ''' Test to check the lock-unlock functionality for SPI family flash ''' + min_f, max_f, loop = spi_find_freq_range(u_boot_console) + flashes = u_boot_console.config.env.get('env__spi_lock_unlock', False) + if not flashes: + pytest.skip('No supported flash list for lock/unlock provided') + + i = 0 + while i < loop: + spi_pre_commands(u_boot_console, random.randint(min_f, max_f)) + total_size = get_total_size() + flash_part = get_flash_part() + + flashes_list = flashes.get('supported_flash', None).split(',') + flashes_list = [x.strip() for x in flashes_list] + if flash_part not in flashes_list: + pytest.skip('Detected flash does not support lock/unlock') + + # For lower half of memory + lock_addr = random.randint(0, (total_size // 2) - 1) + lock_size = random.randint(1, ((total_size // 2) - lock_addr)) + spi_lock_unlock(u_boot_console, lock_addr, lock_size) + + # For upper half of memory + lock_addr = random.randint((total_size // 2), total_size - 1) + lock_size = random.randint(1, (total_size - lock_addr)) + spi_lock_unlock(u_boot_console, lock_addr, lock_size) + + # For entire flash + lock_addr = random.randint(0, total_size - 1) + lock_size = random.randint(1, (total_size - lock_addr)) + spi_lock_unlock(u_boot_console, lock_addr, lock_size) + + i = i + 1 + +@pytest.mark.buildconfigspec('cmd_bdi') +@pytest.mark.buildconfigspec('cmd_sf') +@pytest.mark.buildconfigspec('cmd_memory') +def test_spi_negative(u_boot_console): + ''' Negative tests for SPI ''' + min_f, max_f, loop = spi_find_freq_range(u_boot_console) + spi_pre_commands(u_boot_console, random.randint(min_f, max_f)) + total_size = get_total_size() + erase_size = get_erase_size() + page_size = get_page_size() + addr = u_boot_utils.find_ram_base(u_boot_console) + i = 0 + while i < loop: + # Erase negative test + start = random.randint(0, total_size) + esize = erase_size + + # If erasesize is not multiple of flash's erase size + while esize % erase_size == 0: + esize = random.randint(0, total_size - start) + + error_msg = 'Erased: ERROR' + flash_ops( + u_boot_console, 'erase', start, esize, 0, 1, error_msg, EXPECTED_ERASE + ) + + # If eraseoffset exceeds beyond flash size + eoffset = random.randint(total_size, (total_size + int(0x1000000))) + error_msg = 'Offset exceeds device limit' + flash_ops( + u_boot_console, 'erase', eoffset, esize, 0, 1, error_msg, EXPECTED_ERASE + ) + + # If erasesize exceeds beyond flash size + esize = random.randint((total_size - start), (total_size + int(0x1000000))) + error_msg = 'ERROR: attempting erase past flash size' + flash_ops( + u_boot_console, 'erase', start, esize, 0, 1, error_msg, EXPECTED_ERASE + ) + + # If erase size is 0 + esize = 0 + error_msg = None + flash_ops( + u_boot_console, 'erase', start, esize, 0, 1, error_msg, EXPECTED_ERASE + ) + + # If erasesize is less than flash's page size + esize = random.randint(0, page_size) + start = random.randint(0, (total_size - page_size)) + error_msg = 'Erased: ERROR' + flash_ops( + u_boot_console, 'erase', start, esize, 0, 1, error_msg, EXPECTED_ERASE + ) + + # Write/Read negative test + # if Write/Read size exceeds beyond flash size + offset = random.randint(0, total_size) + size = random.randint((total_size - offset), (total_size + int(0x1000000))) + error_msg = 'Size exceeds partition or device limit' + flash_ops( + u_boot_console, 'write', offset, size, addr, 1, error_msg, EXPECTED_WRITE + ) + flash_ops( + u_boot_console, 'read', offset, size, addr, 1, error_msg, EXPECTED_READ + ) + + # if Write/Read offset exceeds beyond flash size + offset = random.randint(total_size, (total_size + int(0x1000000))) + size = random.randint(0, total_size) + error_msg = 'Offset exceeds device limit' + flash_ops( + u_boot_console, 'write', offset, size, addr, 1, error_msg, EXPECTED_WRITE + ) + flash_ops( + u_boot_console, 'read', offset, size, addr, 1, error_msg, EXPECTED_READ + ) + + # if Write/Read size is 0 + offset = random.randint(0, 2) + size = 0 + error_msg = None + flash_ops( + u_boot_console, 'write', offset, size, addr, 1, error_msg, EXPECTED_WRITE + ) + flash_ops( + u_boot_console, 'read', offset, size, addr, 1, error_msg, EXPECTED_READ + ) + + i = i + 1 |