blob: adb353965a7f88e63f39a45b3def52e33fc5963f [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;
22 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");
32 ut_assert_nextline("cantoraone_regular");
33 ut_assertok(ut_check_console_end(uts));
34
35 ut_asserteq_str("nimbus_sans_l_regular",
Simon Glass3b175ba2023-01-06 08:52:32 -060036 vidconsole_get_font_size(dev, &size));
Simon Glass9e972c32022-10-06 08:36:16 -060037 ut_asserteq(18, size);
38
39 max_metrics = 1;
40 if (IS_ENABLED(CONFIG_CONSOLE_TRUETYPE))
41 max_metrics = IF_ENABLED_INT(CONFIG_CONSOLE_TRUETYPE,
42 CONFIG_CONSOLE_TRUETYPE_MAX_METRICS);
43
44 ret = run_command("font select cantoraone_regular 40", 0);
45 if (max_metrics < 2) {
46 ut_asserteq(1, ret);
47 ut_assert_nextline("Failed (error -7)");
48 ut_assertok(ut_check_console_end(uts));
49 return 0;
50 }
51
52 ut_assertok(ret);
53 ut_assertok(ut_check_console_end(uts));
54
55 ut_asserteq_str("cantoraone_regular",
Simon Glass3b175ba2023-01-06 08:52:32 -060056 vidconsole_get_font_size(dev, &size));
Simon Glass9e972c32022-10-06 08:36:16 -060057 ut_asserteq(40, size);
58
59 ut_assertok(run_command("font size 30", 0));
60 ut_assertok(ut_check_console_end(uts));
61
62 ut_asserteq_str("cantoraone_regular",
Simon Glass3b175ba2023-01-06 08:52:32 -060063 vidconsole_get_font_size(dev, &size));
Simon Glass9e972c32022-10-06 08:36:16 -060064 ut_asserteq(30, size);
65
66 return 0;
67}
68FONT_TEST(font_test_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT |
69 UT_TESTF_CONSOLE_REC | UT_TESTF_DM);
70
71int do_ut_font(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
72{
73 struct unit_test *tests = UNIT_TEST_SUITE_START(font_Test);
74 const int n_ents = UNIT_TEST_SUITE_COUNT(font_test);
75
76 return cmd_ut_category("font", "font_test_", tests, n_ents, argc, argv);
77}