blob: 174c31a3852eaf731d287d023e88a6af476a2371 [file] [log] [blame]
Samuel Dionne-Rieldc0d17c2022-08-18 15:44:04 -04001// 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-Rieldc0d17c2022-08-18 15:44:04 -04008#include <asm/global_data.h>
9#include <test/lib.h>
10#include <test/ut.h>
11
12DECLARE_GLOBAL_DATA_PTR;
13
14static int lib_test_hush_pause(struct unit_test_state *uts)
15{
16 /* Test default message */
Samuel Dionne-Rieldc0d17c2022-08-18 15:44:04 -040017 /* 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 Glasse6f498e2024-08-22 07:58:03 -060022 ut_assert_console_end();
Samuel Dionne-Rieldc0d17c2022-08-18 15:44:04 -040023
24 /* Test provided message */
Samuel Dionne-Rieldc0d17c2022-08-18 15:44:04 -040025 /* 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 Glasse6f498e2024-08-22 07:58:03 -060030 ut_assert_console_end();
Samuel Dionne-Rieldc0d17c2022-08-18 15:44:04 -040031
32 /* Test providing more than one params */
Samuel Dionne-Rieldc0d17c2022-08-18 15:44:04 -040033 /* 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 Glass0af38d12024-08-22 07:57:58 -060041LIB_TEST(lib_test_hush_pause, UTF_CONSOLE);