From 430e1676a76bf8b7112c64e19cf64b988c281ee0 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 6 Oct 2022 08:36:16 -0600 Subject: 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 --- test/cmd/Makefile | 1 + test/cmd/font.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/cmd_ut.c | 6 +++++ 3 files changed, 84 insertions(+) create mode 100644 test/cmd/font.c (limited to 'test') diff --git a/test/cmd/Makefile b/test/cmd/Makefile index f2a5f4ed808..6dd6e818757 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 00000000000..7a4156ade62 --- /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 +#include +#include +#include +#include +#include + +/* 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 99e53dddc15..dc88c5fb88c 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 -- cgit v1.2.3