blob: 1fe05c1ead51b87971a92db2416d674f064a2bd8 [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
8#include <common.h>
9#include <console.h>
10#include <dm.h>
11#include <video_console.h>
12#include <test/suites.h>
13#include <test/ut.h>
14
15/* Declare a new fdt test */
16#define FONT_TEST(_name, _flags) UNIT_TEST(_name, _flags, font_test)
17
18/* Test 'fdt addr' resizing an fdt */
19static int font_test_base(struct unit_test_state *uts)
20{
21 struct udevice *dev;
Dzmitry Sankouski86c6a532023-03-07 13:21:15 +030022 const char *name;
Simon Glass9e972c32022-10-06 08:36:16 -060023 int max_metrics;
24 uint size;
25 int ret;
26
27 ut_assertok(uclass_first_device_err(UCLASS_VIDEO, &dev));
28 ut_assertok(uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev));
29
30 ut_assertok(console_record_reset_enable());
31 ut_assertok(run_command("font list", 0));
32 ut_assert_nextline("nimbus_sans_l_regular");
Simon Glass88934a72023-10-01 19:15:19 -060033 if (IS_ENABLED(CONFIG_CONSOLE_TRUETYPE_CANTORAONE))
34 ut_assert_nextline("cantoraone_regular");
Simon Glass9e972c32022-10-06 08:36:16 -060035 ut_assertok(ut_check_console_end(uts));
36
Dzmitry Sankouski86c6a532023-03-07 13:21:15 +030037 ut_assertok(vidconsole_get_font_size(dev, &name, &size));
38 ut_asserteq_str("nimbus_sans_l_regular", name);
Simon Glass9e972c32022-10-06 08:36:16 -060039 ut_asserteq(18, size);
40
Simon Glass88934a72023-10-01 19:15:19 -060041 if (!IS_ENABLED(CONFIG_CONSOLE_TRUETYPE_CANTORAONE))
42 return 0;
43
Simon Glass9e972c32022-10-06 08:36:16 -060044 max_metrics = 1;
45 if (IS_ENABLED(CONFIG_CONSOLE_TRUETYPE))
46 max_metrics = IF_ENABLED_INT(CONFIG_CONSOLE_TRUETYPE,
47 CONFIG_CONSOLE_TRUETYPE_MAX_METRICS);
48
49 ret = run_command("font select cantoraone_regular 40", 0);
50 if (max_metrics < 2) {
51 ut_asserteq(1, ret);
52 ut_assert_nextline("Failed (error -7)");
53 ut_assertok(ut_check_console_end(uts));
54 return 0;
55 }
56
57 ut_assertok(ret);
58 ut_assertok(ut_check_console_end(uts));
59
Dzmitry Sankouski86c6a532023-03-07 13:21:15 +030060 ut_assertok(vidconsole_get_font_size(dev, &name, &size));
61 ut_asserteq_str("cantoraone_regular", name);
Simon Glass9e972c32022-10-06 08:36:16 -060062 ut_asserteq(40, size);
63
64 ut_assertok(run_command("font size 30", 0));
65 ut_assertok(ut_check_console_end(uts));
66
Dzmitry Sankouski86c6a532023-03-07 13:21:15 +030067 ut_assertok(vidconsole_get_font_size(dev, &name, &size));
68 ut_asserteq_str("cantoraone_regular", name);
Simon Glass9e972c32022-10-06 08:36:16 -060069 ut_asserteq(30, size);
70
71 return 0;
72}
73FONT_TEST(font_test_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT |
74 UT_TESTF_CONSOLE_REC | UT_TESTF_DM);
75
76int do_ut_font(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
77{
78 struct unit_test *tests = UNIT_TEST_SUITE_START(font_Test);
79 const int n_ents = UNIT_TEST_SUITE_COUNT(font_test);
80
81 return cmd_ut_category("font", "font_test_", tests, n_ents, argc, argv);
82}