blob: a8905ce617e828945ea61947fe55c4ae9f790ada [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
29 ut_assertok(console_record_reset_enable());
30 ut_assertok(run_command("font list", 0));
31 ut_assert_nextline("nimbus_sans_l_regular");
Simon Glass88934a72023-10-01 19:15:19 -060032 if (IS_ENABLED(CONFIG_CONSOLE_TRUETYPE_CANTORAONE))
33 ut_assert_nextline("cantoraone_regular");
Simon Glass9e972c32022-10-06 08:36:16 -060034 ut_assertok(ut_check_console_end(uts));
35
Dzmitry Sankouski86c6a532023-03-07 13:21:15 +030036 ut_assertok(vidconsole_get_font_size(dev, &name, &size));
37 ut_asserteq_str("nimbus_sans_l_regular", name);
Simon Glass9e972c32022-10-06 08:36:16 -060038 ut_asserteq(18, size);
39
Simon Glass88934a72023-10-01 19:15:19 -060040 if (!IS_ENABLED(CONFIG_CONSOLE_TRUETYPE_CANTORAONE))
41 return 0;
42
Simon Glass9e972c32022-10-06 08:36:16 -060043 max_metrics = 1;
44 if (IS_ENABLED(CONFIG_CONSOLE_TRUETYPE))
45 max_metrics = IF_ENABLED_INT(CONFIG_CONSOLE_TRUETYPE,
46 CONFIG_CONSOLE_TRUETYPE_MAX_METRICS);
47
48 ret = run_command("font select cantoraone_regular 40", 0);
49 if (max_metrics < 2) {
50 ut_asserteq(1, ret);
51 ut_assert_nextline("Failed (error -7)");
52 ut_assertok(ut_check_console_end(uts));
53 return 0;
54 }
55
56 ut_assertok(ret);
57 ut_assertok(ut_check_console_end(uts));
58
Dzmitry Sankouski86c6a532023-03-07 13:21:15 +030059 ut_assertok(vidconsole_get_font_size(dev, &name, &size));
60 ut_asserteq_str("cantoraone_regular", name);
Simon Glass9e972c32022-10-06 08:36:16 -060061 ut_asserteq(40, size);
62
63 ut_assertok(run_command("font size 30", 0));
64 ut_assertok(ut_check_console_end(uts));
65
Dzmitry Sankouski86c6a532023-03-07 13:21:15 +030066 ut_assertok(vidconsole_get_font_size(dev, &name, &size));
67 ut_asserteq_str("cantoraone_regular", name);
Simon Glass9e972c32022-10-06 08:36:16 -060068 ut_asserteq(30, size);
69
70 return 0;
71}
72FONT_TEST(font_test_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT |
73 UT_TESTF_CONSOLE_REC | UT_TESTF_DM);
74
75int do_ut_font(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
76{
77 struct unit_test *tests = UNIT_TEST_SUITE_START(font_Test);
78 const int n_ents = UNIT_TEST_SUITE_COUNT(font_test);
79
80 return cmd_ut_category("font", "font_test_", tests, n_ents, argc, argv);
81}