Simon Glass | 430e167 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Tests for font command |
| 4 | * |
| 5 | * Copyright 2022 Google LLC |
| 6 | */ |
| 7 | |
Simon Glass | 430e167 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 8 | #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 */ |
| 18 | static int font_test_base(struct unit_test_state *uts) |
| 19 | { |
| 20 | struct udevice *dev; |
Dzmitry Sankouski | 4f6e348 | 2023-03-07 13:21:15 +0300 | [diff] [blame] | 21 | const char *name; |
Simon Glass | 430e167 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 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 | |
Simon Glass | 430e167 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 29 | ut_assertok(run_command("font list", 0)); |
| 30 | ut_assert_nextline("nimbus_sans_l_regular"); |
Simon Glass | 078c6e2 | 2023-10-01 19:15:19 -0600 | [diff] [blame] | 31 | if (IS_ENABLED(CONFIG_CONSOLE_TRUETYPE_CANTORAONE)) |
| 32 | ut_assert_nextline("cantoraone_regular"); |
Simon Glass | 430e167 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 33 | ut_assertok(ut_check_console_end(uts)); |
| 34 | |
Dzmitry Sankouski | 4f6e348 | 2023-03-07 13:21:15 +0300 | [diff] [blame] | 35 | ut_assertok(vidconsole_get_font_size(dev, &name, &size)); |
| 36 | ut_asserteq_str("nimbus_sans_l_regular", name); |
Simon Glass | 430e167 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 37 | ut_asserteq(18, size); |
| 38 | |
Simon Glass | 078c6e2 | 2023-10-01 19:15:19 -0600 | [diff] [blame] | 39 | if (!IS_ENABLED(CONFIG_CONSOLE_TRUETYPE_CANTORAONE)) |
| 40 | return 0; |
| 41 | |
Simon Glass | 430e167 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 42 | 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 Sankouski | 4f6e348 | 2023-03-07 13:21:15 +0300 | [diff] [blame] | 58 | ut_assertok(vidconsole_get_font_size(dev, &name, &size)); |
| 59 | ut_asserteq_str("cantoraone_regular", name); |
Simon Glass | 430e167 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 60 | ut_asserteq(40, size); |
| 61 | |
| 62 | ut_assertok(run_command("font size 30", 0)); |
| 63 | ut_assertok(ut_check_console_end(uts)); |
| 64 | |
Dzmitry Sankouski | 4f6e348 | 2023-03-07 13:21:15 +0300 | [diff] [blame] | 65 | ut_assertok(vidconsole_get_font_size(dev, &name, &size)); |
| 66 | ut_asserteq_str("cantoraone_regular", name); |
Simon Glass | 430e167 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 67 | ut_asserteq(30, size); |
| 68 | |
| 69 | return 0; |
| 70 | } |
Simon Glass | 9b99762 | 2024-08-22 07:57:50 -0600 | [diff] [blame] | 71 | FONT_TEST(font_test_base, UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_CONSOLE | |
Simon Glass | 725c438 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 72 | UTF_DM); |
Simon Glass | 430e167 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 73 | |
| 74 | int 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 | } |