blob: 6f4e54e7f3f22c61ef7a18638cbe12f3105989cc [file] [log] [blame]
Simon Glass430e1672022-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 Glass430e1672022-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 Sankouski4f6e3482023-03-07 13:21:15 +030021 const char *name;
Simon Glass430e1672022-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 Glass430e1672022-10-06 08:36:16 -060029 ut_assertok(run_command("font list", 0));
30 ut_assert_nextline("nimbus_sans_l_regular");
Simon Glass078c6e22023-10-01 19:15:19 -060031 if (IS_ENABLED(CONFIG_CONSOLE_TRUETYPE_CANTORAONE))
32 ut_assert_nextline("cantoraone_regular");
Simon Glass430e1672022-10-06 08:36:16 -060033 ut_assertok(ut_check_console_end(uts));
34
Dzmitry Sankouski4f6e3482023-03-07 13:21:15 +030035 ut_assertok(vidconsole_get_font_size(dev, &name, &size));
36 ut_asserteq_str("nimbus_sans_l_regular", name);
Simon Glass430e1672022-10-06 08:36:16 -060037 ut_asserteq(18, size);
38
Simon Glass078c6e22023-10-01 19:15:19 -060039 if (!IS_ENABLED(CONFIG_CONSOLE_TRUETYPE_CANTORAONE))
40 return 0;
41
Simon Glass430e1672022-10-06 08:36:16 -060042 max_metrics = 1;
43 if (IS_ENABLED(CONFIG_CONSOLE_TRUETYPE))
44 max_metrics = IF_ENABLED_INT(CONFIG_CONSOLE_TRUETYPE,
45 CONFIG_CONSOLE_TRUETYPE_MAX_METRICS);
46
47 ret = run_command("font select cantoraone_regular 40", 0);
48 if (max_metrics < 2) {
49 ut_asserteq(1, ret);
50 ut_assert_nextline("Failed (error -7)");
51 ut_assertok(ut_check_console_end(uts));
52 return 0;
53 }
54
55 ut_assertok(ret);
56 ut_assertok(ut_check_console_end(uts));
57
Dzmitry Sankouski4f6e3482023-03-07 13:21:15 +030058 ut_assertok(vidconsole_get_font_size(dev, &name, &size));
59 ut_asserteq_str("cantoraone_regular", name);
Simon Glass430e1672022-10-06 08:36:16 -060060 ut_asserteq(40, size);
61
62 ut_assertok(run_command("font size 30", 0));
63 ut_assertok(ut_check_console_end(uts));
64
Dzmitry Sankouski4f6e3482023-03-07 13:21:15 +030065 ut_assertok(vidconsole_get_font_size(dev, &name, &size));
66 ut_asserteq_str("cantoraone_regular", name);
Simon Glass430e1672022-10-06 08:36:16 -060067 ut_asserteq(30, size);
68
69 return 0;
70}
Simon Glass9b997622024-08-22 07:57:50 -060071FONT_TEST(font_test_base, UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_CONSOLE |
Simon Glass725c4382024-08-22 07:57:48 -060072 UTF_DM);
Simon Glass430e1672022-10-06 08:36:16 -060073
74int do_ut_font(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
75{
76 struct unit_test *tests = UNIT_TEST_SUITE_START(font_Test);
77 const int n_ents = UNIT_TEST_SUITE_COUNT(font_test);
78
79 return cmd_ut_category("font", "font_test_", tests, n_ents, argc, argv);
80}