When testing menu items it is easier to check that the correct preview
is shown if the preview images are different. Make a copy of the image
and modify the palette for the second menu item, so this is obvious.

Signed-off-by: Simon Glass <s...@chromium.org>
---

 boot/bootflow_menu.c         |  2 +-
 drivers/video/video-uclass.c |  6 +++++-
 include/video.h              |  3 ++-
 test/boot/expo.c             | 29 ++++++++++++++++++++++-------
 4 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/boot/bootflow_menu.c b/boot/bootflow_menu.c
index 4a442e16850..5d77a0eaea8 100644
--- a/boot/bootflow_menu.c
+++ b/boot/bootflow_menu.c
@@ -67,7 +67,7 @@ int bootflow_menu_new(struct expo **expp)
                                  SCENEOB_DISPLAY_MAX, 30);
        ret |= scene_obj_set_halign(scn, OBJ_MENU_TITLE, SCENEOA_CENTRE);
 
-       logo = video_get_u_boot_logo();
+       logo = video_get_u_boot_logo(NULL);
        if (logo) {
                ret |= scene_img(scn, "ulogo", OBJ_U_BOOT_LOGO, logo, NULL);
                ret |= scene_obj_set_pos(scn, OBJ_U_BOOT_LOGO, 1165, 100);
diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c
index 780b2bc6125..c02fd9bb958 100644
--- a/drivers/video/video-uclass.c
+++ b/drivers/video/video-uclass.c
@@ -582,11 +582,15 @@ int video_get_ysize(struct udevice *dev)
        extern u8 __splash_ ## _name ## _end[]
 
 #define SPLASH_START(_name)    __splash_ ## _name ## _begin
+#define SPLASH_END(_name)      __splash_ ## _name ## _end
 
 SPLASH_DECL(u_boot_logo);
 
-void *video_get_u_boot_logo(void)
+void *video_get_u_boot_logo(int *sizep)
 {
+       if (sizep)
+               *sizep = SPLASH_END(u_boot_logo) - SPLASH_START(u_boot_logo);
+
        return SPLASH_START(u_boot_logo);
 }
 
diff --git a/include/video.h b/include/video.h
index 9ea6b676463..2fbf8a9598a 100644
--- a/include/video.h
+++ b/include/video.h
@@ -418,9 +418,10 @@ bool video_is_active(void);
 /**
  * video_get_u_boot_logo() - Get a pointer to the U-Boot logo
  *
+ * @sizep: If non-null, returns the size of the logic in bytes
  * Returns: Pointer to logo
  */
-void *video_get_u_boot_logo(void);
+void *video_get_u_boot_logo(int *sizep);
 
 /*
  * bmp_display() - Display BMP (bitmap) data located in memory
diff --git a/test/boot/expo.c b/test/boot/expo.c
index ddfb739f9cf..64b6c154b15 100644
--- a/test/boot/expo.c
+++ b/test/boot/expo.c
@@ -463,13 +463,15 @@ BOOTSTD_TEST(expo_object_menu, UTF_DM | UTF_SCAN_FDT);
 static int expo_render_image(struct unit_test_state *uts)
 {
        struct scene_obj_menu *menu;
+       struct abuf buf, logo_copy;
        struct scene *scn, *scn2;
        struct abuf orig, *text;
        struct expo_action act;
        struct scene_obj *obj;
        struct udevice *dev;
        struct expo *exp;
-       int id;
+       int id, size;
+       void *logo;
 
        ut_assertok(uclass_first_device_err(UCLASS_VIDEO, &dev));
 
@@ -478,7 +480,8 @@ static int expo_render_image(struct unit_test_state *uts)
        ut_assert(id > 0);
        ut_assertok(expo_set_display(exp, dev));
 
-       id = scene_img(scn, "logo", OBJ_LOGO, video_get_u_boot_logo(), NULL);
+       id = scene_img(scn, "logo", OBJ_LOGO, video_get_u_boot_logo(NULL),
+                      NULL);
        ut_assert(id > 0);
        ut_assertok(scene_obj_set_pos(scn, OBJ_LOGO, 50, 20));
 
@@ -526,8 +529,18 @@ static int expo_render_image(struct unit_test_state *uts)
        id = scene_txt_str(scn, "item1-key", ITEM1_KEY, STR_ITEM1_KEY, "1",
                           NULL);
        ut_assert(id > 0);
-       id = scene_img(scn, "item1-preview", ITEM1_PREVIEW,
-                      video_get_u_boot_logo(), NULL);
+
+       /*
+        * hack the logo to change the palette and use that for item2 so we can
+        * tell them apart
+        */
+       logo = video_get_u_boot_logo(&size);
+       abuf_init_const(&buf, logo, size);
+       ut_assert(abuf_copy(&buf, &logo_copy));
+       memset(logo_copy.data + 0x70, '\x45', 0x20);
+
+       id = scene_img(scn, "item1-preview", ITEM1_PREVIEW, logo_copy.data,
+                      NULL);
        id = scene_menuitem(scn, OBJ_MENU, "item1", ITEM1, ITEM1_KEY,
                            ITEM1_LABEL, ITEM1_DESC, ITEM1_PREVIEW, 0, NULL);
        ut_assert(id > 0);
@@ -542,7 +555,7 @@ static int expo_render_image(struct unit_test_state *uts)
                           NULL);
        ut_assert(id > 0);
        id = scene_img(scn, "item2-preview", ITEM2_PREVIEW,
-                      video_get_u_boot_logo(), NULL);
+                      video_get_u_boot_logo(NULL), NULL);
        ut_assert(id > 0);
 
        id = scene_menuitem(scn, OBJ_MENU, "item2", ITEM2, ITEM2_KEY,
@@ -670,8 +683,7 @@ static int expo_render_image(struct unit_test_state *uts)
        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));
+       ut_asserteq(20433, video_compress_fb(uts, dev, false));
 
        /* move down */
        ut_assertok(expo_send_key(exp, BKEY_DOWN));
@@ -762,6 +774,9 @@ static int expo_render_image(struct unit_test_state *uts)
 
        ut_assert_console_end();
 
+       abuf_uninit(&buf);
+       abuf_uninit(&logo_copy);
+
        expo_destroy(exp);
 
        return 0;
-- 
2.43.0

Reply via email to