Samuel Dionne-Riel | dc0d17c | 2022-08-18 15:44:04 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Tests for pause command |
| 4 | * |
| 5 | * Copyright 2022, Samuel Dionne-Riel <samuel@dionne-riel.com> |
| 6 | */ |
| 7 | |
Samuel Dionne-Riel | dc0d17c | 2022-08-18 15:44:04 -0400 | [diff] [blame] | 8 | #include <asm/global_data.h> |
| 9 | #include <test/lib.h> |
| 10 | #include <test/ut.h> |
| 11 | |
| 12 | DECLARE_GLOBAL_DATA_PTR; |
| 13 | |
| 14 | static int lib_test_hush_pause(struct unit_test_state *uts) |
| 15 | { |
| 16 | /* Test default message */ |
Samuel Dionne-Riel | dc0d17c | 2022-08-18 15:44:04 -0400 | [diff] [blame] | 17 | /* Cook a newline when the command is expected to pause */ |
| 18 | console_in_puts("\n"); |
| 19 | ut_assertok(run_command("pause", 0)); |
| 20 | console_record_readline(uts->actual_str, sizeof(uts->actual_str)); |
| 21 | ut_asserteq_str("Press any key to continue...", uts->actual_str); |
Simon Glass | e6f498e | 2024-08-22 07:58:03 -0600 | [diff] [blame] | 22 | ut_assert_console_end(); |
Samuel Dionne-Riel | dc0d17c | 2022-08-18 15:44:04 -0400 | [diff] [blame] | 23 | |
| 24 | /* Test provided message */ |
Samuel Dionne-Riel | dc0d17c | 2022-08-18 15:44:04 -0400 | [diff] [blame] | 25 | /* Cook a newline when the command is expected to pause */ |
| 26 | console_in_puts("\n"); |
| 27 | ut_assertok(run_command("pause 'Prompt for pause...'", 0)); |
| 28 | console_record_readline(uts->actual_str, sizeof(uts->actual_str)); |
| 29 | ut_asserteq_str("Prompt for pause...", uts->actual_str); |
Simon Glass | e6f498e | 2024-08-22 07:58:03 -0600 | [diff] [blame] | 30 | ut_assert_console_end(); |
Samuel Dionne-Riel | dc0d17c | 2022-08-18 15:44:04 -0400 | [diff] [blame] | 31 | |
| 32 | /* Test providing more than one params */ |
Samuel Dionne-Riel | dc0d17c | 2022-08-18 15:44:04 -0400 | [diff] [blame] | 33 | /* No newline cooked here since the command is expected to fail */ |
| 34 | ut_asserteq(1, run_command("pause a b", 0)); |
| 35 | console_record_readline(uts->actual_str, sizeof(uts->actual_str)); |
| 36 | ut_asserteq_str("pause - delay until user input", uts->actual_str); |
| 37 | ut_asserteq(1, ut_check_console_end(uts)); |
| 38 | |
| 39 | return 0; |
| 40 | } |
Simon Glass | 0af38d1 | 2024-08-22 07:57:58 -0600 | [diff] [blame] | 41 | LIB_TEST(lib_test_hush_pause, UTF_CONSOLE); |