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 | |
| 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 */ |
| 19 | static int font_test_base(struct unit_test_state *uts) |
| 20 | { |
| 21 | struct udevice *dev; |
Dzmitry Sankouski | 4f6e348 | 2023-03-07 13:21:15 +0300 | [diff] [blame^] | 22 | const char *name; |
Simon Glass | 430e167 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 23 | int max_metrics; |
| 24 | uint size; |
| 25 | int ret; |
| 26 | |
| 27 | ut_assertok(uclass_first_device_err(UCLASS_VIDEO, &dev)); |
| 28 | ut_assertok(uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev)); |
| 29 | |
| 30 | ut_assertok(console_record_reset_enable()); |
| 31 | ut_assertok(run_command("font list", 0)); |
| 32 | ut_assert_nextline("nimbus_sans_l_regular"); |
| 33 | ut_assert_nextline("cantoraone_regular"); |
| 34 | ut_assertok(ut_check_console_end(uts)); |
| 35 | |
Dzmitry Sankouski | 4f6e348 | 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 | 430e167 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 38 | ut_asserteq(18, size); |
| 39 | |
| 40 | max_metrics = 1; |
| 41 | if (IS_ENABLED(CONFIG_CONSOLE_TRUETYPE)) |
| 42 | max_metrics = IF_ENABLED_INT(CONFIG_CONSOLE_TRUETYPE, |
| 43 | CONFIG_CONSOLE_TRUETYPE_MAX_METRICS); |
| 44 | |
| 45 | ret = run_command("font select cantoraone_regular 40", 0); |
| 46 | if (max_metrics < 2) { |
| 47 | ut_asserteq(1, ret); |
| 48 | ut_assert_nextline("Failed (error -7)"); |
| 49 | ut_assertok(ut_check_console_end(uts)); |
| 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | ut_assertok(ret); |
| 54 | ut_assertok(ut_check_console_end(uts)); |
| 55 | |
Dzmitry Sankouski | 4f6e348 | 2023-03-07 13:21:15 +0300 | [diff] [blame^] | 56 | ut_assertok(vidconsole_get_font_size(dev, &name, &size)); |
| 57 | ut_asserteq_str("cantoraone_regular", name); |
Simon Glass | 430e167 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 58 | ut_asserteq(40, size); |
| 59 | |
| 60 | ut_assertok(run_command("font size 30", 0)); |
| 61 | ut_assertok(ut_check_console_end(uts)); |
| 62 | |
Dzmitry Sankouski | 4f6e348 | 2023-03-07 13:21:15 +0300 | [diff] [blame^] | 63 | ut_assertok(vidconsole_get_font_size(dev, &name, &size)); |
| 64 | ut_asserteq_str("cantoraone_regular", name); |
Simon Glass | 430e167 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 65 | ut_asserteq(30, size); |
| 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | FONT_TEST(font_test_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT | |
| 70 | UT_TESTF_CONSOLE_REC | UT_TESTF_DM); |
| 71 | |
| 72 | int do_ut_font(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
| 73 | { |
| 74 | struct unit_test *tests = UNIT_TEST_SUITE_START(font_Test); |
| 75 | const int n_ents = UNIT_TEST_SUITE_COUNT(font_test); |
| 76 | |
| 77 | return cmd_ut_category("font", "font_test_", tests, n_ents, argc, argv); |
| 78 | } |