Simon Glass | 9e972c3 | 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 | 9e972c3 | 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 | 86c6a53 | 2023-03-07 13:21:15 +0300 | [diff] [blame] | 21 | const char *name; |
Simon Glass | 9e972c3 | 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 | |
| 29 | ut_assertok(console_record_reset_enable()); |
| 30 | ut_assertok(run_command("font list", 0)); |
| 31 | ut_assert_nextline("nimbus_sans_l_regular"); |
Simon Glass | 88934a7 | 2023-10-01 19:15:19 -0600 | [diff] [blame] | 32 | if (IS_ENABLED(CONFIG_CONSOLE_TRUETYPE_CANTORAONE)) |
| 33 | ut_assert_nextline("cantoraone_regular"); |
Simon Glass | 9e972c3 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 34 | ut_assertok(ut_check_console_end(uts)); |
| 35 | |
Dzmitry Sankouski | 86c6a53 | 2023-03-07 13:21:15 +0300 | [diff] [blame] | 36 | ut_assertok(vidconsole_get_font_size(dev, &name, &size)); |
| 37 | ut_asserteq_str("nimbus_sans_l_regular", name); |
Simon Glass | 9e972c3 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 38 | ut_asserteq(18, size); |
| 39 | |
Simon Glass | 88934a7 | 2023-10-01 19:15:19 -0600 | [diff] [blame] | 40 | if (!IS_ENABLED(CONFIG_CONSOLE_TRUETYPE_CANTORAONE)) |
| 41 | return 0; |
| 42 | |
Simon Glass | 9e972c3 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 43 | 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 Sankouski | 86c6a53 | 2023-03-07 13:21:15 +0300 | [diff] [blame] | 59 | ut_assertok(vidconsole_get_font_size(dev, &name, &size)); |
| 60 | ut_asserteq_str("cantoraone_regular", name); |
Simon Glass | 9e972c3 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 61 | ut_asserteq(40, size); |
| 62 | |
| 63 | ut_assertok(run_command("font size 30", 0)); |
| 64 | ut_assertok(ut_check_console_end(uts)); |
| 65 | |
Dzmitry Sankouski | 86c6a53 | 2023-03-07 13:21:15 +0300 | [diff] [blame] | 66 | ut_assertok(vidconsole_get_font_size(dev, &name, &size)); |
| 67 | ut_asserteq_str("cantoraone_regular", name); |
Simon Glass | 9e972c3 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 68 | ut_asserteq(30, size); |
| 69 | |
| 70 | return 0; |
| 71 | } |
| 72 | FONT_TEST(font_test_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT | |
| 73 | UT_TESTF_CONSOLE_REC | UT_TESTF_DM); |
| 74 | |
| 75 | int 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 | } |