test_pause.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. #include <common.h>
  8. #include <asm/global_data.h>
  9. #include <test/lib.h>
  10. #include <test/ut.h>
  11. DECLARE_GLOBAL_DATA_PTR;
  12. static int lib_test_hush_pause(struct unit_test_state *uts)
  13. {
  14. /* Test default message */
  15. console_record_reset_enable();
  16. /* Cook a newline when the command is expected to pause */
  17. console_in_puts("\n");
  18. ut_assertok(run_command("pause", 0));
  19. console_record_readline(uts->actual_str, sizeof(uts->actual_str));
  20. ut_asserteq_str("Press any key to continue...", uts->actual_str);
  21. ut_assertok(ut_check_console_end(uts));
  22. /* Test provided message */
  23. console_record_reset_enable();
  24. /* Cook a newline when the command is expected to pause */
  25. console_in_puts("\n");
  26. ut_assertok(run_command("pause 'Prompt for pause...'", 0));
  27. console_record_readline(uts->actual_str, sizeof(uts->actual_str));
  28. ut_asserteq_str("Prompt for pause...", uts->actual_str);
  29. ut_assertok(ut_check_console_end(uts));
  30. /* Test providing more than one params */
  31. console_record_reset_enable();
  32. /* No newline cooked here since the command is expected to fail */
  33. ut_asserteq(1, run_command("pause a b", 0));
  34. console_record_readline(uts->actual_str, sizeof(uts->actual_str));
  35. ut_asserteq_str("pause - delay until user input", uts->actual_str);
  36. ut_asserteq(1, ut_check_console_end(uts));
  37. return 0;
  38. }
  39. LIB_TEST(lib_test_hush_pause, 0);