@@ -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)
@@ -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;
+}
@@ -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 */
@@ -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);