blob: 3335dd65bea8f21f4a6c26e7afba0649b137459e [file] [log] [blame]
Simon Glass9e972c32022-10-06 08:36:16 -06001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Tests for font command
4 *
5 * Copyright 2022 Google LLC
6 */
7
Simon Glass9e972c32022-10-06 08:36:16 -06008#include <console.h>
9#include <dm.h>
10#include <video_console.h>
11#include <test/suites.h>
12#include <test/ut.h>
13
14/* Declare a new fdt test */
15#define FONT_TEST(_name, _flags) UNIT_TEST(_name, _flags, font_test)
16
17/* Test 'fdt addr' resizing an fdt */
18static int font_test_base(struct unit_test_state *uts)
19{
20 struct udevice *dev;
Dzmitry Sankouski86c6a532023-03-07 13:21:15 +030021 const char *name;
Simon Glass9e972c32022-10-06 08:36:16 -060022 int max_metrics;
23 uint size;
24 int ret;
25
26 ut_assertok(uclass_first_device_err(UCLASS_VIDEO, &dev));
27 ut_assertok(uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev));
28
Simon Glass9e972c32022-10-06 08:36:16 -060029 ut_assertok(run_command("font list", 0));
Simon Glass2fc5d8c2024-01-07 17:14:55 -070030 if (IS_ENABLED(CONFIG_CONSOLE_TRUETYPE_NIMBUS))
31 ut_assert_nextline("nimbus_sans_l_regular");
32 if (IS_ENABLED(CONFIG_CONSOLE_TRUETYPE_ANKACODER))
33 ut_assert_nextline("ankacoder_c75_r");
Simon Glass88934a72023-10-01 19:15:19 -060034 if (IS_ENABLED(CONFIG_CONSOLE_TRUETYPE_CANTORAONE))
35 ut_assert_nextline("cantoraone_regular");
Simon Glassc579bd42024-08-22 07:58:03 -060036 ut_assert_console_end();
Simon Glass9e972c32022-10-06 08:36:16 -060037
Dzmitry Sankouski86c6a532023-03-07 13:21:15 +030038 ut_assertok(vidconsole_get_font_size(dev, &name, &size));
Simon Glass2fc5d8c2024-01-07 17:14:55 -070039 if (IS_ENABLED(CONFIG_CONSOLE_TRUETYPE_ANKACODER))
40 ut_asserteq_str("ankacoder_c75_r", name);
41 else
42 ut_asserteq_str("nimbus_sans_l_regular", name);
43 ut_asserteq(CONFIG_CONSOLE_TRUETYPE_SIZE, size);
Simon Glass9e972c32022-10-06 08:36:16 -060044
Simon Glass88934a72023-10-01 19:15:19 -060045 if (!IS_ENABLED(CONFIG_CONSOLE_TRUETYPE_CANTORAONE))
46 return 0;
47
Simon Glass9e972c32022-10-06 08:36:16 -060048 max_metrics = 1;
49 if (IS_ENABLED(CONFIG_CONSOLE_TRUETYPE))
50 max_metrics = IF_ENABLED_INT(CONFIG_CONSOLE_TRUETYPE,
51 CONFIG_CONSOLE_TRUETYPE_MAX_METRICS);
52
53 ret = run_command("font select cantoraone_regular 40", 0);
54 if (max_metrics < 2) {
55 ut_asserteq(1, ret);
56 ut_assert_nextline("Failed (error -7)");
Simon Glassc579bd42024-08-22 07:58:03 -060057 ut_assert_console_end();
Simon Glass9e972c32022-10-06 08:36:16 -060058 return 0;
59 }
60
61 ut_assertok(ret);
Simon Glassc579bd42024-08-22 07:58:03 -060062 ut_assert_console_end();
Simon Glass9e972c32022-10-06 08:36:16 -060063
Dzmitry Sankouski86c6a532023-03-07 13:21:15 +030064 ut_assertok(vidconsole_get_font_size(dev, &name, &size));
65 ut_asserteq_str("cantoraone_regular", name);
Simon Glass9e972c32022-10-06 08:36:16 -060066 ut_asserteq(40, size);
Simon Glass4f0336d2024-01-07 17:14:54 -070067 ut_assertok(ut_check_console_end(uts));
68
69 ut_assertok(run_command("font size", 0));
70 ut_assert_nextline("40");
71 ut_assertok(ut_check_console_end(uts));
Simon Glass9e972c32022-10-06 08:36:16 -060072
73 ut_assertok(run_command("font size 30", 0));
Simon Glassc579bd42024-08-22 07:58:03 -060074 ut_assert_console_end();
Simon Glass9e972c32022-10-06 08:36:16 -060075
Simon Glass4f0336d2024-01-07 17:14:54 -070076 ut_assertok(run_command("font size", 0));
77 ut_assert_nextline("30");
78 ut_assertok(ut_check_console_end(uts));
79
Dzmitry Sankouski86c6a532023-03-07 13:21:15 +030080 ut_assertok(vidconsole_get_font_size(dev, &name, &size));
81 ut_asserteq_str("cantoraone_regular", name);
Simon Glass9e972c32022-10-06 08:36:16 -060082 ut_asserteq(30, size);
83
84 return 0;
85}
Simon Glass11fcfa32024-08-22 07:57:50 -060086FONT_TEST(font_test_base, UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_CONSOLE |
Simon Glass1a92f832024-08-22 07:57:48 -060087 UTF_DM);
Simon Glass9e972c32022-10-06 08:36:16 -060088
89int do_ut_font(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
90{
91 struct unit_test *tests = UNIT_TEST_SUITE_START(font_Test);
92 const int n_ents = UNIT_TEST_SUITE_COUNT(font_test);
93
94 return cmd_ut_category("font", "font_test_", tests, n_ents, argc, argv);
95}