diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/boot/bootdev.c | 1 | ||||
-rw-r--r-- | test/boot/bootflow.c | 10 | ||||
-rw-r--r-- | test/boot/bootm.c | 1 | ||||
-rw-r--r-- | test/boot/bootmeth.c | 1 | ||||
-rw-r--r-- | test/boot/cedit.c | 217 | ||||
-rw-r--r-- | test/boot/expo.c | 214 | ||||
-rw-r--r-- | test/boot/measurement.c | 1 | ||||
-rw-r--r-- | test/boot/upl.c | 1 | ||||
-rw-r--r-- | test/cmd/fdt.c | 1 | ||||
-rw-r--r-- | test/cmd/hash.c | 1 | ||||
-rw-r--r-- | test/cmd/mem_copy.c | 1 | ||||
-rw-r--r-- | test/cmd/mem_search.c | 1 | ||||
-rw-r--r-- | test/cmd/setexpr.c | 1 | ||||
-rw-r--r-- | test/common/test_autoboot.c | 1 | ||||
-rw-r--r-- | test/dm/blkmap.c | 1 | ||||
-rw-r--r-- | test/dm/button.c | 1 | ||||
-rw-r--r-- | test/dm/clk_ccf.c | 30 | ||||
-rw-r--r-- | test/dm/dsa.c | 1 | ||||
-rw-r--r-- | test/dm/fastboot.c | 1 | ||||
-rw-r--r-- | test/dm/part.c | 1 | ||||
-rw-r--r-- | test/dm/tpm.c | 77 | ||||
-rw-r--r-- | test/env/fdt.c | 1 | ||||
-rw-r--r-- | test/hush/dollar.c | 1 | ||||
-rw-r--r-- | test/hush/if.c | 1 | ||||
-rw-r--r-- | test/hush/loop.c | 1 | ||||
-rw-r--r-- | test/lib/Makefile | 1 | ||||
-rw-r--r-- | test/lib/abuf.c | 105 | ||||
-rw-r--r-- | test/lib/slre.c | 58 | ||||
-rw-r--r-- | test/lib/string.c | 37 | ||||
-rw-r--r-- | test/py/conftest.py | 4 | ||||
-rw-r--r-- | test/py/tests/test_tpm2.py | 86 |
31 files changed, 716 insertions, 143 deletions
diff --git a/test/boot/bootdev.c b/test/boot/bootdev.c index 9af94786870..a5f3d4462a9 100644 --- a/test/boot/bootdev.c +++ b/test/boot/bootdev.c @@ -10,6 +10,7 @@ #include <dm.h> #include <bootdev.h> #include <bootflow.h> +#include <env.h> #include <mapmem.h> #include <os.h> #include <test/ut.h> diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c index b261bd5f620..8de5a310add 100644 --- a/test/boot/bootflow.c +++ b/test/boot/bootflow.c @@ -14,6 +14,7 @@ #include <dm.h> #include <efi.h> #include <efi_loader.h> +#include <env.h> #include <expo.h> #include <mapmem.h> #ifdef CONFIG_SANDBOX @@ -857,7 +858,7 @@ static int check_font(struct unit_test_state *uts, struct scene *scn, uint id, txt = scene_obj_find(scn, id, SCENEOBJT_TEXT); ut_assertnonnull(txt); - ut_asserteq(font_size, txt->font_size); + ut_asserteq(font_size, txt->gen.font_size); return 0; } @@ -877,9 +878,10 @@ static int bootflow_menu_theme(struct unit_test_state *uts) ut_assertok(scan_mmc4_bootdev(uts)); ut_assertok(bootflow_menu_new(&exp)); + ut_assertok(bootflow_menu_add_all(exp)); node = ofnode_path("/bootstd/theme"); ut_assert(ofnode_valid(node)); - ut_assertok(bootflow_menu_apply_theme(exp, node)); + ut_assertok(expo_apply_theme(exp, node)); scn = expo_lookup_scene_id(exp, MAIN); ut_assertnonnull(scn); @@ -890,8 +892,8 @@ static int bootflow_menu_theme(struct unit_test_state *uts) * * Check both menu items, since there are two bootflows */ - ut_assertok(check_font(uts, scn, OBJ_PROMPT, font_size)); - ut_assertok(check_font(uts, scn, OBJ_POINTER, font_size)); + for (i = OBJ_PROMPT1A; i <= OBJ_AUTOBOOT; i++) + ut_assertok(check_font(uts, scn, i, font_size)); for (i = 0; i < 2; i++) { ut_assertok(check_font(uts, scn, ITEM_DESC + i, font_size)); ut_assertok(check_font(uts, scn, ITEM_KEY + i, font_size)); diff --git a/test/boot/bootm.c b/test/boot/bootm.c index 1d1efe71ad5..ed60094f3c1 100644 --- a/test/boot/bootm.c +++ b/test/boot/bootm.c @@ -6,6 +6,7 @@ */ #include <bootm.h> +#include <env.h> #include <asm/global_data.h> #include <test/test.h> #include <test/ut.h> diff --git a/test/boot/bootmeth.c b/test/boot/bootmeth.c index 577f259fb37..2ef3569ad83 100644 --- a/test/boot/bootmeth.c +++ b/test/boot/bootmeth.c @@ -9,6 +9,7 @@ #include <bootmeth.h> #include <bootstd.h> #include <dm.h> +#include <env.h> #include <test/ut.h> #include "bootstd_common.h" diff --git a/test/boot/cedit.c b/test/boot/cedit.c index 4d1b99bc2ea..dbf781902fb 100644 --- a/test/boot/cedit.c +++ b/test/boot/cedit.c @@ -5,11 +5,13 @@ */ #include <cedit.h> +#include <dm.h> #include <env.h> #include <expo.h> #include <mapmem.h> #include <dm/ofnode.h> #include <test/ut.h> +#include <test/video.h> #include "bootstd_common.h" #include <test/cedit-test.h> #include "../../boot/scene_internal.h" @@ -46,7 +48,7 @@ static int cedit_base(struct unit_test_state *uts) txt = scene_obj_find(scn, menu->title_id, SCENEOBJT_NONE); ut_assertnonnull(txt); - ut_asserteq_str("AC Power", expo_get_str(exp, txt->str_id)); + ut_asserteq_str("AC Power", expo_get_str(exp, txt->gen.str_id)); ut_asserteq(ID_AC_ON, menu->cur_item_id); @@ -61,6 +63,7 @@ static int cedit_fdt(struct unit_test_state *uts) struct video_priv *vid_priv; extern struct expo *cur_exp; struct scene_obj_menu *menu; + struct udevice *dev; ulong addr = 0x1000; struct ofprop prop; struct scene *scn; @@ -70,9 +73,12 @@ static int cedit_fdt(struct unit_test_state *uts) void *fdt; int i; + ut_assertok(uclass_first_device_err(UCLASS_VIDEO, &dev)); + vid_priv = dev_get_uclass_priv(dev); + ut_assertok(run_command("cedit load hostfs - cedit.dtb", 0)); - ut_asserteq(ID_SCENE1, cedit_prepare(cur_exp, &vid_priv, &scn)); + ut_asserteq(ID_SCENE1, cedit_prepare(cur_exp, dev, &scn)); /* get a menu to fiddle with */ menu = scene_obj_find(scn, ID_CPU_SPEED, SCENEOBJT_MENU); @@ -132,12 +138,16 @@ static int cedit_env(struct unit_test_state *uts) struct video_priv *vid_priv; extern struct expo *cur_exp; struct scene_obj_menu *menu; + struct udevice *dev; struct scene *scn; char *str; ut_assertok(run_command("cedit load hostfs - cedit.dtb", 0)); - ut_asserteq(ID_SCENE1, cedit_prepare(cur_exp, &vid_priv, &scn)); + ut_assertok(uclass_first_device_err(UCLASS_VIDEO, &dev)); + vid_priv = dev_get_uclass_priv(dev); + + ut_asserteq(ID_SCENE1, cedit_prepare(cur_exp, dev, &scn)); /* get a menu to fiddle with */ menu = scene_obj_find(scn, ID_CPU_SPEED, SCENEOBJT_MENU); @@ -187,11 +197,14 @@ static int cedit_cmos(struct unit_test_state *uts) struct scene_obj_menu *menu, *menu2; struct video_priv *vid_priv; extern struct expo *cur_exp; + struct udevice *dev; struct scene *scn; ut_assertok(run_command("cedit load hostfs - cedit.dtb", 0)); - ut_asserteq(ID_SCENE1, cedit_prepare(cur_exp, &vid_priv, &scn)); + ut_assertok(uclass_first_device_err(UCLASS_VIDEO, &dev)); + vid_priv = dev_get_uclass_priv(dev); + ut_asserteq(ID_SCENE1, cedit_prepare(cur_exp, dev, &scn)); /* get the menus to fiddle with */ menu = scene_obj_find(scn, ID_CPU_SPEED, SCENEOBJT_MENU); @@ -220,3 +233,199 @@ static int cedit_cmos(struct unit_test_state *uts) return 0; } BOOTSTD_TEST(cedit_cmos, UTF_CONSOLE); + +/* Check the cedit displays correctly */ +static int cedit_render(struct unit_test_state *uts) +{ + struct scene_obj_menu *menu; + struct video_priv *vid_priv; + extern struct expo *cur_exp; + struct expo_action evt; + struct expo_action act; + struct udevice *dev, *con; + struct stdio_dev *sdev; + struct scene *scn; + struct expo *exp; + int i; + + ut_assertok(run_command("cedit load hostfs - cedit.dtb", 0)); + + exp = cur_exp; + sdev = stdio_get_by_name("vidconsole"); + ut_assertnonnull(sdev); + con = sdev->priv; + + dev = dev_get_parent(con); + vid_priv = dev_get_uclass_priv(dev); + ut_asserteq(ID_SCENE1, cedit_prepare(exp, dev, &scn)); + + menu = scene_obj_find(scn, ID_POWER_LOSS, SCENEOBJT_MENU); + ut_assertnonnull(menu); + ut_asserteq(ID_AC_OFF, menu->cur_item_id); + + ut_assertok(expo_render(exp)); + ut_asserteq(4929, video_compress_fb(uts, dev, false)); + ut_assertok(video_check_copy_fb(uts, dev)); + + /* move to the second menu */ + act.type = EXPOACT_POINT_OBJ; + act.select.id = ID_POWER_LOSS; + ut_assertok(cedit_do_action(exp, scn, vid_priv, &act)); + ut_assertok(expo_render(exp)); + ut_asserteq(4986, video_compress_fb(uts, dev, false)); + + /* open the menu */ + act.type = EXPOACT_OPEN; + act.select.id = ID_POWER_LOSS; + ut_assertok(cedit_do_action(exp, scn, vid_priv, &act)); + ut_assertok(expo_render(exp)); + ut_asserteq(5393, video_compress_fb(uts, dev, false)); + + /* close the menu */ + act.type = EXPOACT_CLOSE; + act.select.id = ID_POWER_LOSS; + ut_assertok(cedit_do_action(exp, scn, vid_priv, &act)); + ut_assertok(expo_render(exp)); + ut_asserteq(4986, video_compress_fb(uts, dev, false)); + + /* open the menu again to check it looks the same */ + act.type = EXPOACT_OPEN; + act.select.id = ID_POWER_LOSS; + ut_assertok(cedit_do_action(exp, scn, vid_priv, &act)); + ut_assertok(expo_render(exp)); + ut_asserteq(5393, video_compress_fb(uts, dev, false)); + + /* close the menu */ + act.type = EXPOACT_CLOSE; + act.select.id = ID_POWER_LOSS; + ut_assertok(cedit_do_action(exp, scn, vid_priv, &act)); + ut_assertok(expo_render(exp)); + ut_asserteq(4986, video_compress_fb(uts, dev, false)); + + act.type = EXPOACT_OPEN; + act.select.id = ID_POWER_LOSS; + ut_assertok(cedit_do_action(exp, scn, vid_priv, &act)); + ut_assertok(expo_render(exp)); + ut_asserteq(5393, video_compress_fb(uts, dev, false)); + + act.type = EXPOACT_POINT_ITEM; + act.select.id = ID_AC_ON; + ut_assertok(cedit_do_action(exp, scn, vid_priv, &act)); + ut_assertok(expo_render(exp)); + ut_asserteq(5365, video_compress_fb(uts, dev, false)); + + /* select it */ + act.type = EXPOACT_SELECT; + act.select.id = ID_AC_ON; + ut_assertok(cedit_do_action(exp, scn, vid_priv, &act)); + ut_assertok(expo_render(exp)); + ut_asserteq(4980, video_compress_fb(uts, dev, false)); + + ut_asserteq(ID_AC_ON, menu->cur_item_id); + + /* move to the line-edit field */ + act.type = EXPOACT_POINT_OBJ; + act.select.id = ID_MACHINE_NAME; + ut_assertok(cedit_do_action(exp, scn, vid_priv, &act)); + ut_assertok(expo_render(exp)); + ut_asserteq(4862, video_compress_fb(uts, dev, false)); + + /* open it */ + act.type = EXPOACT_OPEN; + act.select.id = ID_MACHINE_NAME; + ut_assertok(cedit_do_action(exp, scn, vid_priv, &act)); + ut_assertok(expo_render(exp)); + ut_asserteq(4851, video_compress_fb(uts, dev, false)); + + /* + * Send some keypresses. Note that the console must be enabled so that + * the characters actually reach the putc_xy() in console_truetype, + * since in scene_textline_send_key(), the lineedit restores the + * vidconsole state, outputs the character and then saves the state + * again. If the character is never output, then the state won't be + * updated and the lineedit will be inconsistent. + */ + ut_unsilence_console(uts); + for (i = 'a'; i < 'd'; i++) + ut_assertok(scene_send_key(scn, i, &evt)); + ut_silence_console(uts); + ut_assertok(cedit_arange(exp, vid_priv, scn->id)); + ut_assertok(expo_render(exp)); + ut_asserteq(4996, video_compress_fb(uts, dev, false)); + + expo_destroy(exp); + cur_exp = NULL; + + return 0; +} +BOOTSTD_TEST(cedit_render, UTF_DM | UTF_SCAN_FDT); + +/* Check the cedit displays lineedits correctly */ +static int cedit_render_lineedit(struct unit_test_state *uts) +{ + struct scene_obj_textline *tline; + struct video_priv *vid_priv; + extern struct expo *cur_exp; + struct expo_action evt; + struct expo_action act; + struct udevice *dev, *con; + struct stdio_dev *sdev; + struct scene *scn; + struct expo *exp; + char *str; + int i; + + ut_assertok(run_command("cedit load hostfs - cedit.dtb", 0)); + + exp = cur_exp; + sdev = stdio_get_by_name("vidconsole"); + ut_assertnonnull(sdev); + con = sdev->priv; + + dev = dev_get_parent(con); + vid_priv = dev_get_uclass_priv(dev); + ut_asserteq(ID_SCENE1, cedit_prepare(exp, dev, &scn)); + + /* set up an initial value for the textline */ + tline = scene_obj_find(scn, ID_MACHINE_NAME, SCENEOBJT_TEXTLINE); + ut_assertnonnull(tline); + str = abuf_data(&tline->buf); + strcpy(str, "my-machine"); + ut_asserteq(20, tline->pos); + + ut_assertok(expo_render(exp)); + ut_asserteq(5336, video_compress_fb(uts, dev, false)); + ut_assertok(video_check_copy_fb(uts, dev)); + + /* move to the line-edit field */ + act.type = EXPOACT_POINT_OBJ; + act.select.id = ID_MACHINE_NAME; + ut_assertok(cedit_do_action(exp, scn, vid_priv, &act)); + ut_assertok(expo_render(exp)); + ut_asserteq(5363, video_compress_fb(uts, dev, false)); + + /* open it */ + act.type = EXPOACT_OPEN; + act.select.id = ID_MACHINE_NAME; + ut_assertok(cedit_do_action(exp, scn, vid_priv, &act)); + // ut_asserteq(0, tline->pos); + ut_assertok(expo_render(exp)); + ut_asserteq(5283, video_compress_fb(uts, dev, false)); + + /* delete some characters */ + ut_unsilence_console(uts); + for (i = 0; i < 3; i++) + ut_assertok(scene_send_key(scn, '\b', &evt)); + ut_silence_console(uts); + ut_asserteq_str("my-mach", str); + + ut_assertok(cedit_arange(exp, vid_priv, scn->id)); + ut_assertok(expo_render(exp)); + ut_asserteq(5170, video_compress_fb(uts, dev, false)); + + expo_destroy(exp); + cur_exp = NULL; + + return 0; +} +BOOTSTD_TEST(cedit_render_lineedit, UTF_DM | UTF_SCAN_FDT); diff --git a/test/boot/expo.c b/test/boot/expo.c index 1d283a2ac95..ddfb739f9cf 100644 --- a/test/boot/expo.c +++ b/test/boot/expo.c @@ -11,6 +11,7 @@ #include <video.h> #include <linux/input.h> #include <test/ut.h> +#include <test/video.h> #include "bootstd_common.h" #include <test/cedit-test.h> #include "../../boot/scene_internal.h" @@ -24,14 +25,20 @@ enum { OBJ_LOGO, OBJ_TEXT, OBJ_TEXT2, + OBJ_TEXT3, OBJ_MENU, OBJ_MENU_TITLE, + OBJ_BOX, + OBJ_BOX2, + OBJ_TEXTED, /* strings */ STR_SCENE_TITLE, STR_TEXT, STR_TEXT2, + STR_TEXT3, + STR_TEXTED, STR_MENU_TITLE, STR_POINTER_TEXT, @@ -270,8 +277,8 @@ static int expo_object_attr(struct unit_test_state *uts) ut_assert(id > 0); ut_assertok(scene_obj_set_pos(scn, OBJ_LOGO, 123, 456)); - ut_asserteq(123, img->obj.dim.x); - ut_asserteq(456, img->obj.dim.y); + ut_asserteq(123, img->obj.bbox.x0); + ut_asserteq(456, img->obj.bbox.y0); ut_asserteq(-ENOENT, scene_obj_set_pos(scn, OBJ_TEXT2, 0, 0)); @@ -280,8 +287,8 @@ static int expo_object_attr(struct unit_test_state *uts) strcpy(name, "font2"); ut_assertok(scene_txt_set_font(scn, OBJ_TEXT, name, 42)); - ut_asserteq_ptr(name, txt->font_name); - ut_asserteq(42, txt->font_size); + ut_asserteq_ptr(name, txt->gen.font_name); + ut_asserteq(42, txt->gen.font_size); ut_asserteq(-ENOENT, scene_txt_set_font(scn, OBJ_TEXT2, name, 42)); @@ -296,7 +303,7 @@ static int expo_object_attr(struct unit_test_state *uts) node = ofnode_path("/bootstd/theme"); ut_assert(ofnode_valid(node)); ut_assertok(expo_apply_theme(exp, node)); - ut_asserteq(30, txt->font_size); + ut_asserteq(30, txt->gen.font_size); expo_destroy(exp); @@ -360,8 +367,8 @@ static int expo_object_menu(struct unit_test_state *uts) ut_asserteq(0, menu->pointer_id); ut_assertok(scene_obj_set_pos(scn, OBJ_MENU, 50, 400)); - ut_asserteq(50, menu->obj.dim.x); - ut_asserteq(400, menu->obj.dim.y); + ut_asserteq(50, menu->obj.bbox.x0); + ut_asserteq(400, menu->obj.bbox.y0); id = scene_txt_str(scn, "title", OBJ_MENU_TITLE, STR_MENU_TITLE, "Main Menu", &tit); @@ -407,24 +414,24 @@ static int expo_object_menu(struct unit_test_state *uts) ut_asserteq(id, menu->cur_item_id); /* the title should be at the top */ - ut_asserteq(menu->obj.dim.x, tit->obj.dim.x); - ut_asserteq(menu->obj.dim.y, tit->obj.dim.y); + ut_asserteq(menu->obj.bbox.x0, tit->obj.bbox.x0); + ut_asserteq(menu->obj.bbox.y0, tit->obj.bbox.y0); /* the first item should be next */ - ut_asserteq(menu->obj.dim.x, name1->obj.dim.x); - ut_asserteq(menu->obj.dim.y + 32, name1->obj.dim.y); + ut_asserteq(menu->obj.bbox.x0, name1->obj.bbox.x0); + ut_asserteq(menu->obj.bbox.y0 + 32, name1->obj.bbox.y0); - ut_asserteq(menu->obj.dim.x + 230, key1->obj.dim.x); - ut_asserteq(menu->obj.dim.y + 32, key1->obj.dim.y); + ut_asserteq(menu->obj.bbox.x0 + 230, key1->obj.bbox.x0); + ut_asserteq(menu->obj.bbox.y0 + 32, key1->obj.bbox.y0); - ut_asserteq(menu->obj.dim.x + 200, ptr->obj.dim.x); - ut_asserteq(menu->obj.dim.y + 32, ptr->obj.dim.y); + ut_asserteq(menu->obj.bbox.x0 + 200, ptr->obj.bbox.x0); + ut_asserteq(menu->obj.bbox.y0 + 32, ptr->obj.bbox.y0); - ut_asserteq(menu->obj.dim.x + 280, desc1->obj.dim.x); - ut_asserteq(menu->obj.dim.y + 32, desc1->obj.dim.y); + ut_asserteq(menu->obj.bbox.x0 + 280, desc1->obj.bbox.x0); + ut_asserteq(menu->obj.bbox.y0 + 32, desc1->obj.bbox.y0); - ut_asserteq(-4, prev1->obj.dim.x); - ut_asserteq(menu->obj.dim.y + 32, prev1->obj.dim.y); + ut_asserteq(-4, prev1->obj.bbox.x0); + ut_asserteq(menu->obj.bbox.y0 + 32, prev1->obj.bbox.y0); ut_asserteq(true, prev1->obj.flags & SCENEOF_HIDE); /* check iterating through scene items */ @@ -457,6 +464,7 @@ static int expo_render_image(struct unit_test_state *uts) { struct scene_obj_menu *menu; struct scene *scn, *scn2; + struct abuf orig, *text; struct expo_action act; struct scene_obj *obj; struct udevice *dev; @@ -487,6 +495,15 @@ static int expo_render_image(struct unit_test_state *uts) 60)); ut_assertok(scene_obj_set_pos(scn, OBJ_TEXT2, 200, 600)); + /* this string is clipped as it extends beyond its bottom bound */ + id = scene_txt_str(scn, "text", OBJ_TEXT3, STR_TEXT3, + "this is yet\nanother string, with word-wrap and it goes on for quite a while", + NULL); + ut_assert(id > 0); + ut_assertok(scene_txt_set_font(scn, OBJ_TEXT3, "nimbus_sans_l_regular", + 60)); + ut_assertok(scene_obj_set_bbox(scn, OBJ_TEXT3, 500, 200, 1000, 350)); + id = scene_menu(scn, "main", OBJ_MENU, &menu); ut_assert(id > 0); @@ -534,6 +551,22 @@ static int expo_render_image(struct unit_test_state *uts) ut_assertok(scene_obj_set_pos(scn, OBJ_MENU, 50, 400)); + id = scene_box(scn, "box", OBJ_BOX, 3, NULL); + ut_assert(id > 0); + ut_assertok(scene_obj_set_bbox(scn, OBJ_BOX, 40, 390, 1000, 510)); + + id = scene_box(scn, "box2", OBJ_BOX2, 1, NULL); + ut_assert(id > 0); + ut_assertok(scene_obj_set_bbox(scn, OBJ_BOX, 500, 200, 1000, 350)); + + id = scene_texted(scn, "editor", OBJ_TEXTED, STR_TEXTED, NULL); + ut_assert(id > 0); + ut_assertok(scene_obj_set_bbox(scn, OBJ_TEXTED, 100, 200, 400, 650)); + ut_assertok(expo_edit_str(exp, STR_TEXTED, &orig, &text)); + + abuf_printf(text, "This\nis the initial contents of the text editor " + "but it is quite likely that more will be added later"); + scn2 = expo_lookup_scene_id(exp, SCENE1); ut_asserteq_ptr(scn, scn2); scn2 = expo_lookup_scene_id(exp, SCENE2); @@ -548,46 +581,98 @@ static int expo_render_image(struct unit_test_state *uts) /* check dimensions of text */ obj = scene_obj_find(scn, OBJ_TEXT, SCENEOBJT_NONE); ut_assertnonnull(obj); - ut_asserteq(400, obj->dim.x); - ut_asserteq(100, obj->dim.y); - ut_asserteq(126, obj->dim.w); - ut_asserteq(40, obj->dim.h); + ut_asserteq(400, obj->bbox.x0); + ut_asserteq(100, obj->bbox.y0); + ut_asserteq(400 + 126, obj->bbox.x1); + ut_asserteq(100 + 40, obj->bbox.y1); /* check dimensions of image */ obj = scene_obj_find(scn, OBJ_LOGO, SCENEOBJT_NONE); ut_assertnonnull(obj); - ut_asserteq(50, obj->dim.x); - ut_asserteq(20, obj->dim.y); - ut_asserteq(160, obj->dim.w); - ut_asserteq(160, obj->dim.h); + ut_asserteq(50, obj->bbox.x0); + ut_asserteq(20, obj->bbox.y0); + ut_asserteq(50 + 160, obj->bbox.x1); + ut_asserteq(20 + 160, obj->bbox.y1); /* check dimensions of menu labels - both should be the same width */ obj = scene_obj_find(scn, ITEM1_LABEL, SCENEOBJT_NONE); ut_assertnonnull(obj); - ut_asserteq(50, obj->dim.x); - ut_asserteq(436, obj->dim.y); - ut_asserteq(29, obj->dim.w); - ut_asserteq(18, obj->dim.h); + ut_asserteq(50, obj->bbox.x0); + ut_asserteq(436, obj->bbox.y0); + ut_asserteq(50 + 29, obj->bbox.x1); + ut_asserteq(436 + 18, obj->bbox.y1); obj = scene_obj_find(scn, ITEM2_LABEL, SCENEOBJT_NONE); ut_assertnonnull(obj); - ut_asserteq(50, obj->dim.x); - ut_asserteq(454, obj->dim.y); - ut_asserteq(29, obj->dim.w); - ut_asserteq(18, obj->dim.h); + ut_asserteq(50, obj->bbox.x0); + ut_asserteq(454, obj->bbox.y0); + ut_asserteq(50 + 29, obj->bbox.x1); + ut_asserteq(454 + 18, obj->bbox.y1); + + /* same for the key */ + obj = scene_obj_find(scn, ITEM1_KEY, SCENEOBJT_NONE); + ut_assertnonnull(obj); + ut_asserteq(280, obj->bbox.x0); + ut_asserteq(436, obj->bbox.y0); + ut_asserteq(280 + 9, obj->bbox.x1); + ut_asserteq(436 + 18, obj->bbox.y1); + + obj = scene_obj_find(scn, ITEM2_KEY, SCENEOBJT_NONE); + ut_assertnonnull(obj); + ut_asserteq(280, obj->bbox.x0); + ut_asserteq(454, obj->bbox.y0); + ut_asserteq(280 + 9, obj->bbox.x1); + ut_asserteq(454 + 18, obj->bbox.y1); + + /* and the description */ + obj = scene_obj_find(scn, ITEM1_DESC, SCENEOBJT_NONE); + ut_assertnonnull(obj); + ut_asserteq(330, obj->bbox.x0); + ut_asserteq(436, obj->bbox.y0); + ut_asserteq(330 + 89, obj->bbox.x1); + ut_asserteq(436 + 18, obj->bbox.y1); + + obj = scene_obj_find(scn, ITEM2_DESC, SCENEOBJT_NONE); + ut_assertnonnull(obj); + ut_asserteq(330, obj->bbox.x0); + ut_asserteq(454, obj->bbox.y0); + ut_asserteq(330 + 89, obj->bbox.x1); + ut_asserteq(454 + 18, obj->bbox.y1); /* check dimensions of menu */ obj = scene_obj_find(scn, OBJ_MENU, SCENEOBJT_NONE); ut_assertnonnull(obj); - ut_asserteq(50, obj->dim.x); - ut_asserteq(400, obj->dim.y); - ut_asserteq(160, obj->dim.w); - ut_asserteq(160, obj->dim.h); + ut_asserteq(50, obj->bbox.x0); + ut_asserteq(400, obj->bbox.y0); + ut_asserteq(50 + 160, obj->bbox.x1); + ut_asserteq(400 + 160, obj->bbox.y1); + + scene_obj_set_width(scn, OBJ_MENU, 170); + ut_asserteq(50 + 170, obj->bbox.x1); + scene_obj_set_bbox(scn, OBJ_MENU, 60, 410, 50 + 160, 400 + 160); + ut_asserteq(60, obj->bbox.x0); + ut_asserteq(410, obj->bbox.y0); + ut_asserteq(50 + 160, obj->bbox.x1); + ut_asserteq(400 + 160, obj->bbox.y1); + + /* reset back to normal */ + scene_obj_set_bbox(scn, OBJ_MENU, 50, 400, 50 + 160, 400 + 160); /* render it */ expo_set_scene_id(exp, SCENE1); ut_assertok(expo_render(exp)); + ut_asserteq(0, scn->highlight_id); + ut_assertok(scene_arrange(scn)); + ut_asserteq(0, scn->highlight_id); + + scene_set_highlight_id(scn, OBJ_MENU); + ut_assertok(scene_arrange(scn)); + ut_asserteq(OBJ_MENU, scn->highlight_id); + ut_assertok(expo_render(exp)); + + ut_asserteq(19704, video_compress_fb(uts, dev, false)); + /* move down */ ut_assertok(expo_send_key(exp, BKEY_DOWN)); @@ -595,7 +680,31 @@ static int expo_render_image(struct unit_test_state *uts) ut_asserteq(EXPOACT_POINT_ITEM, act.type); ut_asserteq(ITEM2, act.select.id); + ut_assertok(scene_menu_select_item(scn, OBJ_MENU, act.select.id)); + ut_asserteq(ITEM2, scene_menu_get_cur_item(scn, OBJ_MENU)); + ut_assertok(scene_arrange(scn)); + ut_assertok(expo_render(exp)); + ut_asserteq(19673, video_compress_fb(uts, dev, false)); + ut_assertok(video_check_copy_fb(uts, dev)); + + /* hide the text editor since the following tets don't need it */ + scene_obj_set_hide(scn, OBJ_TEXTED, true); + + /* do some alignment checks */ + ut_assertok(scene_obj_set_halign(scn, OBJ_TEXT3, SCENEOA_CENTRE)); + ut_assertok(expo_render(exp)); + ut_asserteq(16368, video_compress_fb(uts, dev, false)); + ut_assertok(scene_obj_set_halign(scn, OBJ_TEXT3, SCENEOA_RIGHT)); + ut_assertok(expo_render(exp)); + ut_asserteq(16321, video_compress_fb(uts, dev, false)); + + ut_assertok(scene_obj_set_halign(scn, OBJ_TEXT3, SCENEOA_LEFT)); + ut_assertok(scene_obj_set_valign(scn, OBJ_TEXT3, SCENEOA_CENTRE)); + ut_assertok(expo_render(exp)); + ut_asserteq(18763, video_compress_fb(uts, dev, false)); + ut_assertok(scene_obj_set_valign(scn, OBJ_TEXT3, SCENEOA_BOTTOM)); ut_assertok(expo_render(exp)); + ut_asserteq(18714, video_compress_fb(uts, dev, false)); /* make sure only the preview for the second item is shown */ obj = scene_obj_find(scn, ITEM1_PREVIEW, SCENEOBJT_NONE); @@ -617,6 +726,12 @@ static int expo_render_image(struct unit_test_state *uts) /* make sure there was no console output */ ut_assert_console_end(); + /* now try with the highlight */ + exp->show_highlight = true; + ut_assertok(scene_arrange(scn)); + ut_assertok(expo_render(exp)); + ut_asserteq(18844, video_compress_fb(uts, dev, false)); + /* now try in text mode */ expo_set_text_mode(exp, true); ut_assertok(expo_render(exp)); @@ -635,6 +750,7 @@ static int expo_render_image(struct unit_test_state *uts) ut_asserteq(EXPOACT_POINT_ITEM, act.type); ut_asserteq(ITEM1, act.select.id); + ut_assertok(scene_menu_select_item(scn, OBJ_MENU, act.select.id)); ut_assertok(expo_render(exp)); ut_assert_nextline("U-Boot : Boot Menu"); @@ -658,6 +774,7 @@ static int expo_test_build(struct unit_test_state *uts) struct scene_obj_menu *menu; struct scene_menitem *item; struct scene_obj_txt *txt; + struct abuf orig, *copy; struct scene_obj *obj; struct scene *scn; struct expo *exp; @@ -678,7 +795,7 @@ static int expo_test_build(struct unit_test_state *uts) ut_assertnonnull(scn); ut_asserteq_str("main", scn->name); ut_asserteq(ID_SCENE1, scn->id); - ut_asserteq(ID_DYNAMIC_START + 1, scn->title_id); + ut_asserteq(ID_DYNAMIC_START, scn->title_id); ut_asserteq(0, scn->highlight_id); /* check the title */ @@ -690,7 +807,8 @@ static int expo_test_build(struct unit_test_state *uts) ut_asserteq(scn->title_id, obj->id); ut_asserteq(SCENEOBJT_TEXT, obj->type); ut_asserteq(0, obj->flags); - ut_asserteq_str("Test Configuration", expo_get_str(exp, txt->str_id)); + ut_asserteq_str("Test Configuration", + expo_get_str(exp, txt->gen.str_id)); /* check the menu */ menu = scene_obj_find(scn, ID_CPU_SPEED, SCENEOBJT_NONE); @@ -702,7 +820,7 @@ static int expo_test_build(struct unit_test_state *uts) ut_asserteq(0, obj->flags); txt = scene_obj_find(scn, menu->title_id, SCENEOBJT_NONE); - ut_asserteq_str("CPU speed", expo_get_str(exp, txt->str_id)); + ut_asserteq_str("CPU speed", expo_get_str(exp, txt->gen.str_id)); ut_asserteq(0, menu->cur_item_id); ut_asserteq(0, menu->pointer_id); @@ -719,11 +837,21 @@ static int expo_test_build(struct unit_test_state *uts) ut_asserteq(0, item->value); txt = scene_obj_find(scn, item->label_id, SCENEOBJT_NONE); - ut_asserteq_str("2 GHz", expo_get_str(exp, txt->str_id)); + ut_asserteq_str("2 GHz", expo_get_str(exp, txt->gen.str_id)); count = list_count_nodes(&menu->item_head); ut_asserteq(3, count); + /* try editing some text */ + ut_assertok(expo_edit_str(exp, txt->gen.str_id, &orig, ©)); + ut_asserteq_str("2 GHz", orig.data); + ut_asserteq_str("2 GHz", copy->data); + + /* change it and check that things look right */ + abuf_printf(copy, "atlantic %d", 123); + ut_asserteq_str("2 GHz", orig.data); + ut_asserteq_str("atlantic 123", copy->data); + expo_destroy(exp); return 0; diff --git a/test/boot/measurement.c b/test/boot/measurement.c index 1d38663fc0f..71f503f1567 100644 --- a/test/boot/measurement.c +++ b/test/boot/measurement.c @@ -7,6 +7,7 @@ */ #include <bootm.h> +#include <env.h> #include <malloc.h> #include <test/test.h> #include <test/ut.h> diff --git a/test/boot/upl.c b/test/boot/upl.c index eec89026fc3..e2dc3d51eda 100644 --- a/test/boot/upl.c +++ b/test/boot/upl.c @@ -7,6 +7,7 @@ */ #include <abuf.h> +#include <env.h> #include <mapmem.h> #include <upl.h> #include <dm/ofnode.h> diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c index c11c181c807..96a8488e172 100644 --- a/test/cmd/fdt.c +++ b/test/cmd/fdt.c @@ -6,6 +6,7 @@ */ #include <console.h> +#include <env.h> #include <fdt_support.h> #include <mapmem.h> #include <asm/global_data.h> diff --git a/test/cmd/hash.c b/test/cmd/hash.c index 296dd762b31..bb96380c351 100644 --- a/test/cmd/hash.c +++ b/test/cmd/hash.c @@ -6,6 +6,7 @@ */ #include <command.h> +#include <env.h> #include <dm.h> #include <dm/test.h> #include <test/test.h> diff --git a/test/cmd/mem_copy.c b/test/cmd/mem_copy.c index 3e904fc4e4b..8e551f18a85 100644 --- a/test/cmd/mem_copy.c +++ b/test/cmd/mem_copy.c @@ -4,6 +4,7 @@ */ #include <command.h> +#include <compiler.h> #include <console.h> #include <mapmem.h> #include <dm/test.h> diff --git a/test/cmd/mem_search.c b/test/cmd/mem_search.c index df8938bdb6c..61de0dfb9a9 100644 --- a/test/cmd/mem_search.c +++ b/test/cmd/mem_search.c @@ -7,6 +7,7 @@ */ #include <console.h> +#include <env.h> #include <mapmem.h> #include <dm/test.h> #include <test/ut.h> diff --git a/test/cmd/setexpr.c b/test/cmd/setexpr.c index 85803eb54b8..93b0c4b68f5 100644 --- a/test/cmd/setexpr.c +++ b/test/cmd/setexpr.c @@ -7,6 +7,7 @@ */ #include <console.h> +#include <env.h> #include <mapmem.h> #include <dm/test.h> #include <test/ut.h> diff --git a/test/common/test_autoboot.c b/test/common/test_autoboot.c index e3050d02c60..5feff57c271 100644 --- a/test/common/test_autoboot.c +++ b/test/common/test_autoboot.c @@ -6,6 +6,7 @@ */ #include <autoboot.h> +#include <env.h> #include <test/common.h> #include <test/test.h> #include <test/ut.h> diff --git a/test/dm/blkmap.c b/test/dm/blkmap.c index a6a0b4d4e20..d04b68b50ae 100644 --- a/test/dm/blkmap.c +++ b/test/dm/blkmap.c @@ -7,6 +7,7 @@ #include <blk.h> #include <blkmap.h> #include <dm.h> +#include <env.h> #include <asm/test.h> #include <dm/test.h> #include <test/test.h> diff --git a/test/dm/button.c b/test/dm/button.c index 3612f308f02..f05f4ca27ce 100644 --- a/test/dm/button.c +++ b/test/dm/button.c @@ -8,6 +8,7 @@ #include <dm.h> #include <adc.h> #include <button.h> +#include <env.h> #include <power/regulator.h> #include <power/sandbox_pmic.h> #include <asm/gpio.h> diff --git a/test/dm/clk_ccf.c b/test/dm/clk_ccf.c index ac56f17b775..64c21b10c3e 100644 --- a/test/dm/clk_ccf.c +++ b/test/dm/clk_ccf.c @@ -32,13 +32,13 @@ static int dm_test_clk_ccf(struct unit_test_state *uts) ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "clk-test", &test_dev)); /* Test for clk_get_by_id() */ - ret = clk_get_by_id(SANDBOX_CLK_ECSPI_ROOT, &clk); + ret = clk_get_by_id(CLK_ID(dev, SANDBOX_CLK_ECSPI_ROOT), &clk); ut_assertok(ret); ut_asserteq_str("ecspi_root", clk->dev->name); ut_asserteq(CLK_SET_RATE_PARENT, clk->flags); /* Test for clk_get_parent_rate() */ - ret = clk_get_by_id(SANDBOX_CLK_ECSPI1, &clk); + ret = clk_get_by_id(CLK_ID(dev, SANDBOX_CLK_ECSPI1), &clk); ut_assertok(ret); ut_asserteq_str("ecspi1", clk->dev->name); ut_asserteq(CLK_SET_RATE_PARENT, clk->flags); @@ -47,7 +47,7 @@ static int dm_test_clk_ccf(struct unit_test_state *uts) ut_asserteq(rate, 20000000); /* test the gate of CCF */ - ret = clk_get_by_id(SANDBOX_CLK_ECSPI0, &clk); + ret = clk_get_by_id(CLK_ID(dev, SANDBOX_CLK_ECSPI0), &clk); ut_assertok(ret); ut_asserteq_str("ecspi0", clk->dev->name); ut_asserteq(CLK_SET_RATE_PARENT, clk->flags); @@ -56,7 +56,7 @@ static int dm_test_clk_ccf(struct unit_test_state *uts) ut_asserteq(rate, 20000000); /* Test the mux of CCF */ - ret = clk_get_by_id(SANDBOX_CLK_USDHC1_SEL, &clk); + ret = clk_get_by_id(CLK_ID(dev, SANDBOX_CLK_USDHC1_SEL), &clk); ut_assertok(ret); ut_asserteq_str("usdhc1_sel", clk->dev->name); ut_asserteq(CLK_SET_RATE_NO_REPARENT, clk->flags); @@ -70,7 +70,7 @@ static int dm_test_clk_ccf(struct unit_test_state *uts) rate = clk_get_rate(clk); ut_asserteq(rate, 60000000); - ret = clk_get_by_id(SANDBOX_CLK_PLL3_80M, &pclk); + ret = clk_get_by_id(CLK_ID(dev, SANDBOX_CLK_PLL3_80M), &pclk); ut_assertok(ret); ret = clk_set_parent(clk, pclk); @@ -79,7 +79,7 @@ static int dm_test_clk_ccf(struct unit_test_state *uts) rate = clk_get_rate(clk); ut_asserteq(rate, 80000000); - ret = clk_get_by_id(SANDBOX_CLK_USDHC2_SEL, &clk); + ret = clk_get_by_id(CLK_ID(dev, SANDBOX_CLK_USDHC2_SEL), &clk); ut_assertok(ret); ut_asserteq_str("usdhc2_sel", clk->dev->name); ut_asserteq(CLK_SET_RATE_NO_REPARENT, clk->flags); @@ -97,7 +97,7 @@ static int dm_test_clk_ccf(struct unit_test_state *uts) rate = clk_get_rate(clk); ut_asserteq(rate, 80000000); - ret = clk_get_by_id(SANDBOX_CLK_PLL3_60M, &pclk); + ret = clk_get_by_id(CLK_ID(dev, SANDBOX_CLK_PLL3_60M), &pclk); ut_assertok(ret); ret = clk_set_parent(clk, pclk); @@ -107,7 +107,7 @@ static int dm_test_clk_ccf(struct unit_test_state *uts) ut_asserteq(rate, 60000000); /* Test the composite of CCF */ - ret = clk_get_by_id(SANDBOX_CLK_I2C, &clk); + ret = clk_get_by_id(CLK_ID(dev, SANDBOX_CLK_I2C), &clk); ut_assertok(ret); ut_asserteq_str("i2c", clk->dev->name); ut_asserteq(CLK_SET_RATE_UNGATE, clk->flags); @@ -124,12 +124,12 @@ static int dm_test_clk_ccf(struct unit_test_state *uts) ret = clk_get_by_index(test_dev, SANDBOX_CLK_TEST_ID_I2C_ROOT, &clk_ccf); ut_assertok(ret); ut_asserteq_str("clk-ccf", clk_ccf.dev->name); - ut_asserteq(clk_ccf.id, SANDBOX_CLK_I2C_ROOT); + ut_asserteq(clk_ccf.id, CLK_ID(clk_ccf.dev, SANDBOX_CLK_I2C_ROOT)); - ret = clk_get_by_id(SANDBOX_CLK_I2C_ROOT, &clk); + ret = clk_get_by_id(CLK_ID(dev, SANDBOX_CLK_I2C_ROOT), &clk); ut_assertok(ret); ut_asserteq_str("i2c_root", clk->dev->name); - ut_asserteq(clk->id, SANDBOX_CLK_I2C_ROOT); + ut_asserteq(clk_get_id(clk), SANDBOX_CLK_I2C_ROOT); ret = clk_enable(&clk_ccf); ut_assertok(ret); @@ -137,7 +137,7 @@ static int dm_test_clk_ccf(struct unit_test_state *uts) ret = sandbox_clk_enable_count(clk); ut_asserteq(ret, 1); - ret = clk_get_by_id(SANDBOX_CLK_I2C, &pclk); + ret = clk_get_by_id(CLK_ID(dev, SANDBOX_CLK_I2C), &pclk); ut_assertok(ret); ret = sandbox_clk_enable_count(pclk); @@ -153,7 +153,7 @@ static int dm_test_clk_ccf(struct unit_test_state *uts) ut_asserteq(ret, 0); /* Test clock re-parenting. */ - ret = clk_get_by_id(SANDBOX_CLK_USDHC1_SEL, &clk); + ret = clk_get_by_id(CLK_ID(dev, SANDBOX_CLK_USDHC1_SEL), &clk); ut_assertok(ret); ut_asserteq_str("usdhc1_sel", clk->dev->name); @@ -167,7 +167,7 @@ static int dm_test_clk_ccf(struct unit_test_state *uts) clkid = SANDBOX_CLK_PLL3_60M; } - ret = clk_get_by_id(clkid, &pclk); + ret = clk_get_by_id(CLK_ID(dev, clkid), &pclk); ut_assertok(ret); ret = clk_set_parent(clk, pclk); ut_assertok(ret); @@ -176,7 +176,7 @@ static int dm_test_clk_ccf(struct unit_test_state *uts) ut_asserteq_str(clkname, pclk->dev->name); /* Test disabling critical clock. */ - ret = clk_get_by_id(SANDBOX_CLK_I2C_ROOT, &clk); + ret = clk_get_by_id(CLK_ID(dev, SANDBOX_CLK_I2C_ROOT), &clk); ut_assertok(ret); ut_asserteq_str("i2c_root", clk->dev->name); diff --git a/test/dm/dsa.c b/test/dm/dsa.c index 9a31ae39d95..46e48741fba 100644 --- a/test/dm/dsa.c +++ b/test/dm/dsa.c @@ -3,6 +3,7 @@ * Copyright 2020-2021 NXP */ +#include <env.h> #include <net/dsa.h> #include <dm/test.h> #include <test/ut.h> diff --git a/test/dm/fastboot.c b/test/dm/fastboot.c index 73c43f82924..5b51b6bf9dd 100644 --- a/test/dm/fastboot.c +++ b/test/dm/fastboot.c @@ -4,6 +4,7 @@ */ #include <dm.h> +#include <env.h> #include <fastboot.h> #include <fb_mmc.h> #include <mmc.h> diff --git a/test/dm/part.c b/test/dm/part.c index c5c4b3fdba1..caae23bd4aa 100644 --- a/test/dm/part.c +++ b/test/dm/part.c @@ -4,6 +4,7 @@ */ #include <dm.h> +#include <env.h> #include <mmc.h> #include <part.h> #include <part_efi.h> diff --git a/test/dm/tpm.c b/test/dm/tpm.c index 962a3fd1943..87c5c416daa 100644 --- a/test/dm/tpm.c +++ b/test/dm/tpm.c @@ -49,14 +49,87 @@ static int test_tpm_init(struct unit_test_state *uts, enum tpm_version version) return 0; } -static int dm_test_tpm(struct unit_test_state *uts) +static int dm_test_tpm_init(struct unit_test_state *uts) { ut_assertok(test_tpm_init(uts, TPM_V1)); ut_assertok(test_tpm_init(uts, TPM_V2)); return 0; } -DM_TEST(dm_test_tpm, UTF_SCAN_FDT); +DM_TEST(dm_test_tpm_init, UTF_SCAN_FDT); + +/* check TPM startup */ +static int check_tpm_startup(struct unit_test_state *uts, + enum tpm_version version) +{ + struct udevice *dev; + + /* check probe success */ + ut_assertok(get_tpm_version(version, &dev)); + + ut_assertok(tpm_init(dev)); + ut_assertok(tpm_startup(dev, TPM_ST_CLEAR)); + + return 0; +} + +/* test TPM startup */ +static int dm_test_tpm_startup(struct unit_test_state *uts) +{ + ut_assertok(check_tpm_startup(uts, TPM_V1)); + ut_assertok(check_tpm_startup(uts, TPM_V2)); + + return 0; +} +DM_TEST(dm_test_tpm_startup, UTF_SCAN_FDT); + +static int check_tpm_self_test_full(struct unit_test_state *uts, + enum tpm_version version) +{ + struct udevice *dev; + + ut_assertok(check_tpm_startup(uts, version)); + + ut_assertok(get_tpm_version(version, &dev)); + ut_assertok(tpm_self_test_full(dev)); + + return 0; +} + +/* Test TPM self-test full */ +static int dm_test_tpm_self_test_full(struct unit_test_state *uts) +{ + ut_assertok(check_tpm_self_test_full(uts, TPM_V1)); + ut_assertok(check_tpm_self_test_full(uts, TPM_V2)); + + return 0; +} +DM_TEST(dm_test_tpm_self_test_full, UTF_SCAN_FDT); + +/* Test TPM self-test continue */ +static int test_tpm_self_test_cont(struct unit_test_state *uts, + enum tpm_version version) +{ + struct udevice *dev; + + /* check probe success */ + ut_assertok(get_tpm_version(version, &dev)); + + ut_assertok(tpm_init(dev)); + ut_assertok(tpm_startup(dev, TPM_ST_CLEAR)); + ut_assertok(tpm_continue_self_test(dev)); + + return 0; +} + +static int dm_test_tpm_self_test_cont(struct unit_test_state *uts) +{ + ut_assertok(test_tpm_self_test_cont(uts, TPM_V1)); + ut_assertok(test_tpm_self_test_cont(uts, TPM_V2)); + + return 0; +} +DM_TEST(dm_test_tpm_self_test_cont, UTF_SCAN_FDT); /* Test report_state */ static int dm_test_tpm_report_state(struct unit_test_state *uts) diff --git a/test/env/fdt.c b/test/env/fdt.c index c495ac7b307..3652563f330 100644 --- a/test/env/fdt.c +++ b/test/env/fdt.c @@ -1,4 +1,5 @@ #include <command.h> +#include <env.h> #include <env_attr.h> #include <test/env.h> #include <test/ut.h> diff --git a/test/hush/dollar.c b/test/hush/dollar.c index 820110799a2..b83a64d091d 100644 --- a/test/hush/dollar.c +++ b/test/hush/dollar.c @@ -5,6 +5,7 @@ */ #include <command.h> +#include <env.h> #include <env_attr.h> #include <test/hush.h> #include <test/ut.h> diff --git a/test/hush/if.c b/test/hush/if.c index 8939b7a6c86..ea615b246a9 100644 --- a/test/hush/if.c +++ b/test/hush/if.c @@ -5,6 +5,7 @@ */ #include <command.h> +#include <env.h> #include <env_attr.h> #include <vsprintf.h> #include <test/hush.h> diff --git a/test/hush/loop.c b/test/hush/loop.c index 7154b9bc0ae..ea72ac773ba 100644 --- a/test/hush/loop.c +++ b/test/hush/loop.c @@ -5,6 +5,7 @@ */ #include <command.h> +#include <env.h> #include <env_attr.h> #include <test/hush.h> #include <test/ut.h> diff --git a/test/lib/Makefile b/test/lib/Makefile index d620510f998..ff4ff63270d 100644 --- a/test/lib/Makefile +++ b/test/lib/Makefile @@ -29,6 +29,7 @@ obj-$(CONFIG_SHA256) += test_sha256_hmac.o obj-$(CONFIG_HKDF_MBEDTLS) += test_sha256_hkdf.o obj-$(CONFIG_GETOPT) += getopt.o obj-$(CONFIG_CRC8) += test_crc8.o +obj-$(CONFIG_REGEX) += slre.o obj-$(CONFIG_UT_LIB_CRYPT) += test_crypt.o obj-$(CONFIG_UT_TIME) += time.o obj-$(CONFIG_$(PHASE_)UT_UNICODE) += unicode.o diff --git a/test/lib/abuf.c b/test/lib/abuf.c index b38690fe1a9..97b128c01c0 100644 --- a/test/lib/abuf.c +++ b/test/lib/abuf.c @@ -419,3 +419,108 @@ static int lib_test_abuf_init(struct unit_test_state *uts) return 0; } LIB_TEST(lib_test_abuf_init, 0); + +/* Test abuf_copy() */ +static int lib_test_abuf_copy(struct unit_test_state *uts) +{ + struct abuf buf, copy; + ulong start; + + start = ut_check_free(); + + abuf_init_set(&buf, test_data, TEST_DATA_LEN); + ut_assert(abuf_copy(&buf, ©)); + ut_asserteq(buf.size, copy.size); + ut_assert(buf.data != copy.data); + ut_assert(copy.alloced); + abuf_uninit(©); + abuf_uninit(&buf); + + /* Check for memory leaks */ + ut_assertok(ut_check_delta(start)); + + return 0; +} +LIB_TEST(lib_test_abuf_copy, 0); + +/* Test abuf_init_size() */ +static int lib_test_abuf_init_size(struct unit_test_state *uts) +{ + struct abuf buf; + ulong start; + + start = ut_check_free(); + + ut_assert(abuf_init_size(&buf, TEST_DATA_LEN)); + ut_assertnonnull(buf.data); + ut_asserteq(TEST_DATA_LEN, buf.size); + ut_asserteq(true, buf.alloced); + abuf_uninit(&buf); + + /* Check for memory leaks */ + ut_assertok(ut_check_delta(start)); + + return 0; +} +LIB_TEST(lib_test_abuf_init_size, 0); + +/* Test abuf_printf() */ +static int lib_test_abuf_printf(struct unit_test_state *uts) +{ + struct abuf buf, fmt; + ulong start; + char *ptr; + + start = ut_check_free(); + + /* start with a fresh buffer */ + abuf_init(&buf); + + /* check handling of out-of-memory condition */ + malloc_enable_testing(0); + ut_asserteq(-ENOMEM, abuf_printf(&buf, "%s", "")); + malloc_enable_testing(1); + + ut_asserteq(0, abuf_printf(&buf, "%s", "")); + ut_asserteq(1, buf.size); + ut_asserteq(true, buf.alloced); + ut_asserteq_str("", buf.data); + + /* check expanding it, initially failing */ + ut_asserteq(-ENOMEM, abuf_printf(&buf, "%s", "testing")); + malloc_disable_testing(); + + ut_asserteq(7, abuf_printf(&buf, "%s", "testing")); + ut_asserteq(8, buf.size); + ut_asserteq_str("testing", buf.data); + + ut_asserteq(11, abuf_printf(&buf, "testing %d", 123)); + ut_asserteq(12, buf.size); + ut_asserteq_str("testing 123", buf.data); + + /* make it smaller; buffer should not shrink */ + ut_asserteq(9, abuf_printf(&buf, "test %d", 456)); + ut_asserteq(12, buf.size); + ut_asserteq_str("test 456", buf.data); + + /* test the maximum size */ + abuf_init(&fmt); + ut_assert(abuf_realloc(&fmt, 4100)); + memset(fmt.data, 'x', 4100); + ptr = fmt.data; + ptr[4096] = '\0'; + + /* we are allowed up to 4K including the terminator */ + ut_asserteq(-E2BIG, abuf_printf(&buf, "%s", ptr)); + ptr[4095] = '\0'; + ut_asserteq(4095, abuf_printf(&buf, "%s", ptr)); + + abuf_uninit(&fmt); + abuf_uninit(&buf); + + /* Check for memory leaks */ + ut_assertok(ut_check_delta(start)); + + return 0; +} +LIB_TEST(lib_test_abuf_printf, 0); diff --git a/test/lib/slre.c b/test/lib/slre.c new file mode 100644 index 00000000000..ff2386d614a --- /dev/null +++ b/test/lib/slre.c @@ -0,0 +1,58 @@ +// SPDX-License-Identifier: GPL-2.0 OR MIT + +#include <test/lib.h> +#include <test/ut.h> +#include <slre.h> + +struct re_test { + const char *str; + const char *re; + int match; +}; + +static const struct re_test re_test[] = { + { "123", "^\\d+$", 1}, + { "x23", "^\\d+$", 0}, + { "banana", "^([bn]a)*$", 1}, + { "panama", "^([bn]a)*$", 0}, + { "xby", "^a|b", 1}, + { "xby", "b|^a", 1}, + { "xby", "b|c$", 1}, + { "xby", "c$|b", 1}, + { "", "x*$", 1}, + { "", "^x*$", 1}, + { "yy", "x*$", 1}, + { "yy", "^x*$", 0}, + { "Gadsby", "^[^eE]*$", 1}, + { "Ernest", "^[^eE]*$", 0}, + { "6d41f0a39d6", "^[0123456789abcdef]*$", 1 }, + /* DIGIT is 17 */ + { "##\x11%%\x11", "^[#%\\d]*$", 0 }, + { "##23%%45", "^[#%\\d]*$", 1 }, + { "U-Boot", "^[B-Uo-t]*$", 0 }, + { "U-Boot", "^[A-Zm-v-]*$", 1 }, + { "U-Boot", "^[-A-Za-z]*$", 1 }, + /* The range --C covers both - and B. */ + { "U-Boot", "^[--CUot]*$", 1 }, + { "U-Boot", "^[^0-9]*$", 1 }, + { "U-Boot", "^[^0-9<->]*$", 1 }, + { "U-Boot", "^[^0-9<\\->]*$", 0 }, + {} +}; + +static int lib_slre(struct unit_test_state *uts) +{ + const struct re_test *t; + + for (t = re_test; t->str; t++) { + struct slre slre; + + ut_assert(slre_compile(&slre, t->re)); + ut_assertf(!!slre_match(&slre, t->str, strlen(t->str), NULL) == t->match, + "'%s' unexpectedly %s '%s'\n", t->str, + t->match ? "didn't match" : "matched", t->re); + } + + return 0; +} +LIB_TEST(lib_slre, 0); diff --git a/test/lib/string.c b/test/lib/string.c index 31391a387b9..f56c2e4c946 100644 --- a/test/lib/string.c +++ b/test/lib/string.c @@ -261,3 +261,40 @@ static int lib_strstr(struct unit_test_state *uts) return 0; } LIB_TEST(lib_strstr, 0); + +static int lib_strim(struct unit_test_state *uts) +{ + char buf[BUFLEN], *p; + + strcpy(buf, "abc"); + ut_asserteq_str("abc", strim(buf)); + + /* leading space */ + strcpy(buf, " abc"); + ut_asserteq_str("abc", strim(buf)); + + /* multiple leading spaces */ + strcpy(buf, " abc"); + ut_asserteq_str("abc", strim(buf)); + + /* multiple internal spaces */ + strcpy(buf, " a bc"); + ut_asserteq_str("a bc", strim(buf)); + + /* with trailing space */ + strcpy(buf, " a bc "); + ut_asserteq_str("a bc", strim(buf)); + + /* with multiple trailing spaces */ + strcpy(buf, " a bc "); + ut_asserteq_str("a bc", strim(buf)); + + /* with only spaces */ + strcpy(buf, " "); + p = strim(buf); + ut_asserteq_ptr(p, buf); + ut_asserteq_str("", p); + + return 0; +} +LIB_TEST(lib_strim, 0); diff --git a/test/py/conftest.py b/test/py/conftest.py index 6c3ac67979a..8ce680a92a0 100644 --- a/test/py/conftest.py +++ b/test/py/conftest.py @@ -514,8 +514,8 @@ def ubman(request): handle_exception(ubconfig, ubman_fix, log, err, 'Lab timeout', True) except BootFail as err: handle_exception(ubconfig, ubman_fix, log, err, 'Boot fail', True, - ubman.get_spawn_output()) - except Unexpected: + ubman_fix.get_spawn_output()) + except Unexpected as err: handle_exception(ubconfig, ubman_fix, log, err, 'Unexpected test output', False) return ubman_fix diff --git a/test/py/tests/test_tpm2.py b/test/py/tests/test_tpm2.py index 064651c3e23..9be85999d46 100644 --- a/test/py/tests/test_tpm2.py +++ b/test/py/tests/test_tpm2.py @@ -27,6 +27,16 @@ behavior. * Setup env__tpm_device_test_skip to True if tests with TPM devices should be skipped. +Parallel tests +-------------- + +These tests can be run in parallel on sandbox. In that case any action taken +by one test may be independent of another. For sandbox, care should be taken to +ensure that tests are independent. + +Unfortunately, tests cannot be made independent on real hardware, since there is +no way to reset the TPM other than restarting the board. Perhaps that would be +the best approach? """ updates = 0 @@ -50,13 +60,8 @@ def force_init(ubman, force=False): ubman.run_command('tpm2 clear TPM2_RH_PLATFORM') ubman.run_command('echo --- end of init ---') -def is_sandbox(ubman): - # Array slice removes leading/trailing quotes. - sys_arch = ubman.config.buildconfig.get('config_sys_arch', '"sandbox"')[1:-1] - return sys_arch == 'sandbox' - @pytest.mark.buildconfigspec('cmd_tpm_v2') -def test_tpm2_init(ubman): +def test_tpm2_autostart(ubman): """Init the software stack to use TPMv2 commands.""" skip_test = ubman.config.env.get('env__tpm_device_test_skip', False) if skip_test: @@ -66,56 +71,6 @@ def test_tpm2_init(ubman): assert output.endswith('0') @pytest.mark.buildconfigspec('cmd_tpm_v2') -def test_tpm2_startup(ubman): - """Execute a TPM2_Startup command. - - Initiate the TPM internal state machine. - """ - skip_test = ubman.config.env.get('env__tpm_device_test_skip', False) - if skip_test: - pytest.skip('skip TPM device test') - ubman.run_command('tpm2 startup TPM2_SU_CLEAR') - output = ubman.run_command('echo $?') - assert output.endswith('0') - -def tpm2_sandbox_init(ubman): - """Put sandbox back into a known state so we can run a test - - This allows all tests to run in parallel, since no test depends on another. - """ - ubman.restart_uboot() - ubman.run_command('tpm2 autostart') - output = ubman.run_command('echo $?') - assert output.endswith('0') - - skip_test = ubman.config.env.get('env__tpm_device_test_skip', False) - if skip_test: - pytest.skip('skip TPM device test') - -@pytest.mark.buildconfigspec('cmd_tpm_v2') -def test_tpm2_sandbox_self_test_full(ubman): - """Execute a TPM2_SelfTest (full) command. - - Ask the TPM to perform all self tests to also enable full capabilities. - """ - if is_sandbox(ubman): - ubman.restart_uboot() - ubman.run_command('tpm2 autostart') - output = ubman.run_command('echo $?') - assert output.endswith('0') - - ubman.run_command('tpm2 startup TPM2_SU_CLEAR') - output = ubman.run_command('echo $?') - assert output.endswith('0') - - skip_test = ubman.config.env.get('env__tpm_device_test_skip', False) - if skip_test: - pytest.skip('skip TPM device test') - ubman.run_command('tpm2 self_test full') - output = ubman.run_command('echo $?') - assert output.endswith('0') - -@pytest.mark.buildconfigspec('cmd_tpm_v2') def test_tpm2_continue_self_test(ubman): """Execute a TPM2_SelfTest (continued) command. @@ -126,8 +81,6 @@ def test_tpm2_continue_self_test(ubman): skip_test = ubman.config.env.get('env__tpm_device_test_skip', False) if skip_test: pytest.skip('skip TPM device test') - if is_sandbox(ubman): - tpm2_sandbox_init(ubman) ubman.run_command('tpm2 self_test continue') output = ubman.run_command('echo $?') assert output.endswith('0') @@ -144,9 +97,6 @@ def test_tpm2_clear(ubman): not have a password set, otherwise this test will fail. ENDORSEMENT and PLATFORM hierarchies are also available. """ - if is_sandbox(ubman): - tpm2_sandbox_init(ubman) - skip_test = ubman.config.env.get('env__tpm_device_test_skip', False) if skip_test: pytest.skip('skip TPM device test') @@ -167,8 +117,6 @@ def test_tpm2_change_auth(ubman): Use the LOCKOUT hierarchy for this. ENDORSEMENT and PLATFORM hierarchies are also available. """ - if is_sandbox(ubman): - tpm2_sandbox_init(ubman) force_init(ubman) ubman.run_command('tpm2 change_auth TPM2_RH_LOCKOUT unicorn') @@ -193,9 +141,6 @@ def test_tpm2_get_capability(ubman): There is no expected default values because it would depend on the chip used. We can still save them in order to check they have changed later. """ - if is_sandbox(ubman): - tpm2_sandbox_init(ubman) - force_init(ubman) ram = utils.find_ram_base(ubman) @@ -217,8 +162,6 @@ def test_tpm2_dam_parameters(ubman): the authentication, otherwise the lockout will be engaged after the first failed authentication attempt. """ - if is_sandbox(ubman): - tpm2_sandbox_init(ubman) force_init(ubman) ram = utils.find_ram_base(ubman) @@ -236,14 +179,12 @@ def test_tpm2_dam_parameters(ubman): assert 'Property 0x00000211: 0x00000000' in read_cap @pytest.mark.buildconfigspec('cmd_tpm_v2') +@pytest.mark.notbuildconfigspec('target_chromebook_coral') def test_tpm2_pcr_read(ubman): """Execute a TPM2_PCR_Read command. Perform a PCR read of the 10th PCR. Must be zero. """ - if is_sandbox(ubman): - tpm2_sandbox_init(ubman) - force_init(ubman) ram = utils.find_ram_base(ubman) @@ -261,6 +202,7 @@ def test_tpm2_pcr_read(ubman): assert '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' in read_pcr @pytest.mark.buildconfigspec('cmd_tpm_v2') +@pytest.mark.notbuildconfigspec('target_chromebook_coral') def test_tpm2_pcr_extend(ubman): """Execute a TPM2_PCR_Extend command. @@ -270,8 +212,6 @@ def test_tpm2_pcr_extend(ubman): No authentication mechanism is used here, not protecting against packet replay, yet. """ - if is_sandbox(ubman): - tpm2_sandbox_init(ubman) force_init(ubman) ram = utils.find_ram_base(ubman) |