summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2022-10-06 17:36:16 +0300
committerAnatolij Gustschin <agust@denx.de>2022-10-30 22:01:40 +0300
commit430e1676a76bf8b7112c64e19cf64b988c281ee0 (patch)
tree97d40e3ae1f3305177622818c23d7195b3370e22 /test
parent3f425f9ca75c8d1938579044fde37a6f7d5abe16 (diff)
downloadu-boot-430e1676a76bf8b7112c64e19cf64b988c281ee0.tar.xz
video: Add commands to list and change fonts
Add a new 'font' command which allows the fonts to be listed as well as selecting a different font and size. Allow the test to run on sandbox, where multiple font/size combinations are supported, as well as sandbox_flattree, where they are not. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'test')
-rw-r--r--test/cmd/Makefile1
-rw-r--r--test/cmd/font.c77
-rw-r--r--test/cmd_ut.c6
3 files changed, 84 insertions, 0 deletions
diff --git a/test/cmd/Makefile b/test/cmd/Makefile
index f2a5f4ed80..6dd6e81875 100644
--- a/test/cmd/Makefile
+++ b/test/cmd/Makefile
@@ -11,6 +11,7 @@ endif
obj-y += mem.o
obj-$(CONFIG_CMD_ADDRMAP) += addrmap.o
obj-$(CONFIG_CMD_FDT) += fdt.o
+obj-$(CONFIG_CONSOLE_TRUETYPE) += font.o
obj-$(CONFIG_CMD_LOADM) += loadm.o
obj-$(CONFIG_CMD_MEM_SEARCH) += mem_search.o
obj-$(CONFIG_CMD_PINMUX) += pinmux.o
diff --git a/test/cmd/font.c b/test/cmd/font.c
new file mode 100644
index 0000000000..7a4156ade6
--- /dev/null
+++ b/test/cmd/font.c
@@ -0,0 +1,77 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Tests for font command
+ *
+ * Copyright 2022 Google LLC
+ */
+
+#include <common.h>
+#include <console.h>
+#include <dm.h>
+#include <video_console.h>
+#include <test/suites.h>
+#include <test/ut.h>
+
+/* Declare a new fdt test */
+#define FONT_TEST(_name, _flags) UNIT_TEST(_name, _flags, font_test)
+
+/* Test 'fdt addr' resizing an fdt */
+static int font_test_base(struct unit_test_state *uts)
+{
+ struct udevice *dev;
+ int max_metrics;
+ uint size;
+ int ret;
+
+ ut_assertok(uclass_first_device_err(UCLASS_VIDEO, &dev));
+ ut_assertok(uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev));
+
+ ut_assertok(console_record_reset_enable());
+ ut_assertok(run_command("font list", 0));
+ ut_assert_nextline("nimbus_sans_l_regular");
+ ut_assert_nextline("cantoraone_regular");
+ ut_assertok(ut_check_console_end(uts));
+
+ ut_asserteq_str("nimbus_sans_l_regular",
+ vidconsole_get_font(dev, &size));
+ ut_asserteq(18, size);
+
+ max_metrics = 1;
+ if (IS_ENABLED(CONFIG_CONSOLE_TRUETYPE))
+ max_metrics = IF_ENABLED_INT(CONFIG_CONSOLE_TRUETYPE,
+ CONFIG_CONSOLE_TRUETYPE_MAX_METRICS);
+
+ ret = run_command("font select cantoraone_regular 40", 0);
+ if (max_metrics < 2) {
+ ut_asserteq(1, ret);
+ ut_assert_nextline("Failed (error -7)");
+ ut_assertok(ut_check_console_end(uts));
+ return 0;
+ }
+
+ ut_assertok(ret);
+ ut_assertok(ut_check_console_end(uts));
+
+ ut_asserteq_str("cantoraone_regular",
+ vidconsole_get_font(dev, &size));
+ ut_asserteq(40, size);
+
+ ut_assertok(run_command("font size 30", 0));
+ ut_assertok(ut_check_console_end(uts));
+
+ ut_asserteq_str("cantoraone_regular",
+ vidconsole_get_font(dev, &size));
+ ut_asserteq(30, size);
+
+ return 0;
+}
+FONT_TEST(font_test_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT |
+ UT_TESTF_CONSOLE_REC | UT_TESTF_DM);
+
+int do_ut_font(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+{
+ struct unit_test *tests = UNIT_TEST_SUITE_START(font_Test);
+ const int n_ents = UNIT_TEST_SUITE_COUNT(font_test);
+
+ return cmd_ut_category("font", "font_test_", tests, n_ents, argc, argv);
+}
diff --git a/test/cmd_ut.c b/test/cmd_ut.c
index 99e53dddc1..dc88c5fb88 100644
--- a/test/cmd_ut.c
+++ b/test/cmd_ut.c
@@ -49,6 +49,9 @@ static struct cmd_tbl cmd_ut_sub[] = {
#ifdef CONFIG_CMD_FDT
U_BOOT_CMD_MKENT(fdt, CONFIG_SYS_MAXARGS, 1, do_ut_fdt, "", ""),
#endif
+#ifdef CONFIG_CONSOLE_TRUETYPE
+ U_BOOT_CMD_MKENT(font, CONFIG_SYS_MAXARGS, 1, do_ut_font, "", ""),
+#endif
#ifdef CONFIG_UT_OPTEE
U_BOOT_CMD_MKENT(optee, CONFIG_SYS_MAXARGS, 1, do_ut_optee, "", ""),
#endif
@@ -144,6 +147,9 @@ static char ut_help_text[] =
#ifdef CONFIG_CMD_FDT
"ut fdt [test-name] - test of the fdt command\n"
#endif
+#ifdef CONFIG_CONSOLE_TRUETYPE
+ "ut font [test-name] - test of the font command\n"
+#endif
#ifdef CONFIG_UT_LIB
"ut lib [test-name] - test library functions\n"
#endif