cont_test.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2020, Heinrich Schuchardt <xypron.glpk@gmx.de>
  4. *
  5. * Test continuation of log messages.
  6. */
  7. #include <common.h>
  8. #include <console.h>
  9. #include <asm/global_data.h>
  10. #include <test/log.h>
  11. #include <test/test.h>
  12. #include <test/suites.h>
  13. #include <test/ut.h>
  14. DECLARE_GLOBAL_DATA_PTR;
  15. static int log_test_cont(struct unit_test_state *uts)
  16. {
  17. int log_fmt;
  18. int log_level;
  19. log_fmt = gd->log_fmt;
  20. log_level = gd->default_log_level;
  21. /* Write two messages, the second continuing the first */
  22. gd->log_fmt = (1 << LOGF_CAT) | (1 << LOGF_LEVEL) | (1 << LOGF_MSG);
  23. gd->default_log_level = LOGL_INFO;
  24. console_record_reset_enable();
  25. log(LOGC_ARCH, LOGL_ERR, "ea%d\n", 1);
  26. log(LOGC_CONT, LOGL_CONT, "cc%d\n", 2);
  27. gd->default_log_level = log_level;
  28. gd->log_fmt = log_fmt;
  29. gd->flags &= ~GD_FLG_RECORD;
  30. ut_assertok(ut_check_console_line(uts, "ERR.arch, ea1"));
  31. ut_assertok(ut_check_console_line(uts, "ERR.arch, cc2"));
  32. ut_assertok(ut_check_console_end(uts));
  33. /* Write a third message which is not a continuation */
  34. gd->log_fmt = (1 << LOGF_CAT) | (1 << LOGF_LEVEL) | (1 << LOGF_MSG);
  35. gd->default_log_level = LOGL_INFO;
  36. console_record_reset_enable();
  37. log(LOGC_EFI, LOGL_INFO, "ie%d\n", 3);
  38. gd->default_log_level = log_level;
  39. gd->log_fmt = log_fmt;
  40. gd->flags &= ~GD_FLG_RECORD;
  41. ut_assertok(ut_check_console_line(uts, "INFO.efi, ie3"));
  42. ut_assertok(ut_check_console_end(uts));
  43. /* Write two messages without a newline between them */
  44. gd->log_fmt = (1 << LOGF_CAT) | (1 << LOGF_LEVEL) | (1 << LOGF_MSG);
  45. gd->default_log_level = LOGL_INFO;
  46. console_record_reset_enable();
  47. log(LOGC_ARCH, LOGL_ERR, "ea%d ", 1);
  48. log(LOGC_CONT, LOGL_CONT, "cc%d\n", 2);
  49. gd->default_log_level = log_level;
  50. gd->log_fmt = log_fmt;
  51. gd->flags &= ~GD_FLG_RECORD;
  52. ut_assertok(ut_check_console_line(uts, "ERR.arch, ea1 cc2"));
  53. ut_assertok(ut_check_console_end(uts));
  54. return 0;
  55. }
  56. LOG_TEST(log_test_cont);