blob: 25d365dedd2ab50da50c28f5c0e935ea77258ce3 [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));
30 ut_assert_nextline("nimbus_sans_l_regular");
Simon Glass88934a72023-10-01 19:15:19 -060031 if (IS_ENABLED(CONFIG_CONSOLE_TRUETYPE_CANTORAONE))
32 ut_assert_nextline("cantoraone_regular");
Simon Glassc579bd42024-08-22 07:58:03 -060033 ut_assert_console_end();
Simon Glass9e972c32022-10-06 08:36:16 -060034
Dzmitry Sankouski86c6a532023-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 Glass9e972c32022-10-06 08:36:16 -060037 ut_asserteq(18, size);
38
Simon Glass88934a72023-10-01 19:15:19 -060039 if (!IS_ENABLED(CONFIG_CONSOLE_TRUETYPE_CANTORAONE))
40 return 0;
41
Simon Glass9e972c32022-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)");
Simon Glassc579bd42024-08-22 07:58:03 -060051 ut_assert_console_end();
Simon Glass9e972c32022-10-06 08:36:16 -060052 return 0;
53 }
54
55 ut_assertok(ret);
Simon Glassc579bd42024-08-22 07:58:03 -060056 ut_assert_console_end();
Simon Glass9e972c32022-10-06 08:36:16 -060057
Dzmitry Sankouski86c6a532023-03-07 13:21:15 +030058 ut_assertok(vidconsole_get_font_size(dev, &name, &size));
59 ut_asserteq_str("cantoraone_regular", name);
Simon Glass9e972c32022-10-06 08:36:16 -060060 ut_asserteq(40, size);
61
62 ut_assertok(run_command("font size 30", 0));
Simon Glassc579bd42024-08-22 07:58:03 -060063 ut_assert_console_end();
Simon Glass9e972c32022-10-06 08:36:16 -060064
Dzmitry Sankouski86c6a532023-03-07 13:21:15 +030065 ut_assertok(vidconsole_get_font_size(dev, &name, &size));
66 ut_asserteq_str("cantoraone_regular", name);
Simon Glass9e972c32022-10-06 08:36:16 -060067 ut_asserteq(30, size);
68
69 return 0;
70}
Simon Glass11fcfa32024-08-22 07:57:50 -060071FONT_TEST(font_test_base, UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_CONSOLE |
Simon Glass1a92f832024-08-22 07:57:48 -060072 UTF_DM);
Simon Glass9e972c32022-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}