From: Simon Glass <sjg@chromium.org> When expo-test is enabled, show the frame count in the top right of the display. This allows an easy visual check that expo is working correctly, and provides an indication of performance. Add a test for this also. Co-developed-by: Claude <noreply@anthropic.com> Signed-off-by: Simon Glass <sjg@chromium.org> --- boot/expo.c | 7 +++++ boot/expo_test.c | 47 +++++++++++++++++++++++++++++--- include/expo_test.h | 27 +++++++++++++++++++ test/boot/expo.c | 66 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 143 insertions(+), 4 deletions(-) diff --git a/boot/expo.c b/boot/expo.c index e7c4ab8d7db..2a75eed2c39 100644 --- a/boot/expo.c +++ b/boot/expo.c @@ -346,6 +346,11 @@ static int expo_render_(struct expo *exp, bool dirty_only) if (ret) return log_msg_ret("mou", ret); + /* Render test-mode info if enabled */ + ret = expo_test_render(exp); + if (ret) + return log_msg_ret("tst", ret); + video_sync(dev, true); return scn ? 0 : -ECHILD; @@ -558,6 +563,8 @@ void expo_enter_mode(struct expo *exp) video_manual_sync(exp->display, true); if (IS_ENABLED(CONFIG_MOUSE) && exp->mouse_enabled) mouse_set_ptr_visible(exp->mouse, false); + + expo_test_checkenv(exp); } void expo_exit_mode(struct expo *exp) diff --git a/boot/expo_test.c b/boot/expo_test.c index 269052a61cb..0ac2d0551a1 100644 --- a/boot/expo_test.c +++ b/boot/expo_test.c @@ -8,12 +8,15 @@ #define LOG_CATEGORY LOGC_EXPO +#include <dm.h> #include <env.h> #include <errno.h> #include <expo.h> #include <expo_test.h> #include <log.h> #include <malloc.h> +#include <video.h> +#include <video_console.h> int expo_test_init(struct expo *exp) { @@ -23,8 +26,8 @@ int expo_test_init(struct expo *exp) if (!test) return log_msg_ret("test", -ENOMEM); - test->enabled = env_get_yesno("expotest") == 1; exp->test = test; + expo_test_checkenv(exp); return 0; } @@ -35,12 +38,48 @@ void expo_test_uninit(struct expo *exp) exp->test = NULL; } -void expo_test_update(struct expo *exp) +void expo_test_checkenv(struct expo *exp) { struct expo_test_mode *test = exp->test; - if (!test) - return; + test->enabled = env_get_yesno("expotest") == 1; + test->render_count = 0; +} + +void expo_test_update(struct expo *exp) +{ + struct expo_test_mode *test = exp->test; test->render_count++; } + +int expo_test_render(struct expo *exp) +{ + struct expo_test_mode *test = exp->test; + struct vidconsole_priv *cons_priv; + struct udevice *dev = exp->display; + struct video_priv *vid_priv; + char buf[30]; + int x, y; + int ret; + + if (!test->enabled) + return 0; + + /* Select 8x16 font for test display */ + ret = vidconsole_select_font(exp->cons, "8x16", 0); + if (ret && ret != -ENOSYS) + return log_msg_ret("font", ret); + + vid_priv = dev_get_uclass_priv(dev); + cons_priv = dev_get_uclass_priv(exp->cons); + + /* Display frame count */ + snprintf(buf, sizeof(buf), "frame %6d", test->render_count); + x = vid_priv->xsize - 18 * cons_priv->x_charsize; + y = 10; + vidconsole_set_cursor_pos(exp->cons, x, y); + vidconsole_put_string(exp->cons, buf); + + return 0; +} diff --git a/include/expo_test.h b/include/expo_test.h index ee4ae4611f7..88cec4a2a96 100644 --- a/include/expo_test.h +++ b/include/expo_test.h @@ -37,6 +37,16 @@ int expo_test_init(struct expo *exp); */ void expo_test_uninit(struct expo *exp); +/** + * expo_test_checkenv() - Check environment and reset test mode + * + * @exp: Expo to update test mode for + * + * Checks the expotest environment variable and updates the enabled flag + * accordingly. Also resets the render count to 0. + */ +void expo_test_checkenv(struct expo *exp); + /** * expo_test_update() - Update test mode counters * @@ -44,6 +54,14 @@ void expo_test_uninit(struct expo *exp); */ void expo_test_update(struct expo *exp); +/** + * expo_test_render() - Render test mode information + * + * @exp: Expo to render test info for + * Return: 0 if OK, -ve on error + */ +int expo_test_render(struct expo *exp); + #else static inline int expo_test_init(struct expo *exp) @@ -55,10 +73,19 @@ static inline void expo_test_uninit(struct expo *exp) { } +static inline void expo_test_checkenv(struct expo *exp) +{ +} + static inline void expo_test_update(struct expo *exp) { } +static inline int expo_test_render(struct expo *exp) +{ + return 0; +} + #endif /* EXPO_TEST */ #endif /* __EXPO_TEST_H */ diff --git a/test/boot/expo.c b/test/boot/expo.c index 7723a301c9f..a1aa543ab71 100644 --- a/test/boot/expo.c +++ b/test/boot/expo.c @@ -7,6 +7,7 @@ #include <command.h> #include <dm.h> #include <expo.h> +#include <expo_test.h> #include <menu.h> #include <video.h> #include <linux/input.h> @@ -1097,3 +1098,68 @@ static int expo_mouse_click(struct unit_test_state *uts) return 0; } BOOTSTD_TEST(expo_mouse_click, UTF_DM | UTF_SCAN_FDT); + +static int expo_test_mode(struct unit_test_state *uts) +{ + struct scene_obj_menu *menu; + struct abuf buf, logo_copy; + struct udevice *dev; + struct scene *scn; + struct expo *exp; + + ut_assertok(create_test_expo(uts, &exp, &scn, &menu, &buf, &logo_copy)); + dev = exp->display; + + /* Check test mode is initially off */ + ut_asserteq(false, exp->test->enabled); + + /* Entering expo mode without expotest env var keeps it off */ + expo_enter_mode(exp); + ut_asserteq(false, exp->test->enabled); + expo_exit_mode(exp); + + /* Enable test mode */ + ut_assertok(env_set("expotest", "1")); + expo_enter_mode(exp); + ut_asserteq(true, exp->test->enabled); + + /* Check initial render count */ + ut_asserteq(0, exp->test->render_count); + + /* Render and check count increments */ + ut_assertok(expo_set_scene_id(exp, scn->id)); + ut_assertok(scene_arrange(scn)); + ut_assertok(expo_render(exp)); + ut_asserteq(1, exp->test->render_count); + + ut_assertok(expo_render(exp)); + ut_asserteq(2, exp->test->render_count); + + /* Test that expo_enter_mode() resets the counter */ + expo_exit_mode(exp); + expo_enter_mode(exp); + ut_asserteq(0, exp->test->render_count); + ut_assertok(expo_render(exp)); + ut_asserteq(1, exp->test->render_count); + expo_exit_mode(exp); + + /* Disable test mode */ + ut_assertok(env_set("expotest", "0")); + expo_enter_mode(exp); + ut_asserteq(false, exp->test->enabled); + expo_exit_mode(exp); + + /* Check test mode is off when env var is unset */ + ut_assertok(env_set("expotest", NULL)); + expo_enter_mode(exp); + ut_asserteq(false, exp->test->enabled); + expo_exit_mode(exp); + + ut_assertok(env_set("expotest", NULL)); + abuf_uninit(&buf); + abuf_uninit(&logo_copy); + expo_destroy(exp); + + return 0; +} +BOOTSTD_TEST(expo_test_mode, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE); -- 2.43.0