nolog_test.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2020, Heinrich Schuchardt <xypron.glpk@gmx.de>
  4. *
  5. * Logging function tests for CONFIG_LOG=n.
  6. */
  7. /* Needed for testing log_debug() */
  8. #define DEBUG 1
  9. #include <common.h>
  10. #include <console.h>
  11. #include <log.h>
  12. #include <asm/global_data.h>
  13. #include <test/log.h>
  14. #include <test/test.h>
  15. #include <test/suites.h>
  16. #include <test/ut.h>
  17. DECLARE_GLOBAL_DATA_PTR;
  18. #define BUFFSIZE 32
  19. static int log_test_nolog_err(struct unit_test_state *uts)
  20. {
  21. char buf[BUFFSIZE];
  22. memset(buf, 0, BUFFSIZE);
  23. console_record_reset_enable();
  24. log_err("testing %s\n", "log_err");
  25. gd->flags &= ~GD_FLG_RECORD;
  26. ut_assertok(ut_check_console_line(uts, "testing log_err"));
  27. ut_assertok(ut_check_console_end(uts));
  28. return 0;
  29. }
  30. LOG_TEST(log_test_nolog_err);
  31. static int log_test_nolog_warning(struct unit_test_state *uts)
  32. {
  33. char buf[BUFFSIZE];
  34. memset(buf, 0, BUFFSIZE);
  35. console_record_reset_enable();
  36. log_warning("testing %s\n", "log_warning");
  37. gd->flags &= ~GD_FLG_RECORD;
  38. ut_assertok(ut_check_console_line(uts, "testing log_warning"));
  39. ut_assertok(ut_check_console_end(uts));
  40. return 0;
  41. }
  42. LOG_TEST(log_test_nolog_warning);
  43. static int log_test_nolog_notice(struct unit_test_state *uts)
  44. {
  45. char buf[BUFFSIZE];
  46. memset(buf, 0, BUFFSIZE);
  47. console_record_reset_enable();
  48. log_notice("testing %s\n", "log_notice");
  49. gd->flags &= ~GD_FLG_RECORD;
  50. ut_assertok(ut_check_console_line(uts, "testing log_notice"));
  51. ut_assertok(ut_check_console_end(uts));
  52. return 0;
  53. }
  54. LOG_TEST(log_test_nolog_notice);
  55. static int log_test_nolog_info(struct unit_test_state *uts)
  56. {
  57. char buf[BUFFSIZE];
  58. memset(buf, 0, BUFFSIZE);
  59. console_record_reset_enable();
  60. log_err("testing %s\n", "log_info");
  61. gd->flags &= ~GD_FLG_RECORD;
  62. ut_assertok(ut_check_console_line(uts, "testing log_info"));
  63. ut_assertok(ut_check_console_end(uts));
  64. return 0;
  65. }
  66. LOG_TEST(log_test_nolog_info);
  67. #undef _DEBUG
  68. #define _DEBUG 0
  69. static int nolog_test_nodebug(struct unit_test_state *uts)
  70. {
  71. char buf[BUFFSIZE];
  72. memset(buf, 0, BUFFSIZE);
  73. console_record_reset_enable();
  74. debug("testing %s\n", "debug");
  75. gd->flags &= ~GD_FLG_RECORD;
  76. ut_assertok(ut_check_console_end(uts));
  77. return 0;
  78. }
  79. LOG_TEST(nolog_test_nodebug);
  80. static int log_test_nolog_nodebug(struct unit_test_state *uts)
  81. {
  82. char buf[BUFFSIZE];
  83. memset(buf, 0, BUFFSIZE);
  84. console_record_reset_enable();
  85. log_debug("testing %s\n", "log_debug");
  86. gd->flags &= ~GD_FLG_RECORD;
  87. ut_assert(!strcmp(buf, ""));
  88. ut_assertok(ut_check_console_end(uts));
  89. return 0;
  90. }
  91. LOG_TEST(log_test_nolog_nodebug);
  92. #undef _DEBUG
  93. #define _DEBUG 1
  94. static int nolog_test_debug(struct unit_test_state *uts)
  95. {
  96. char buf[BUFFSIZE];
  97. memset(buf, 0, BUFFSIZE);
  98. console_record_reset_enable();
  99. debug("testing %s\n", "debug");
  100. gd->flags &= ~GD_FLG_RECORD;
  101. ut_assertok(ut_check_console_line(uts, "testing debug"));
  102. ut_assertok(ut_check_console_end(uts));
  103. return 0;
  104. }
  105. LOG_TEST(nolog_test_debug);
  106. static int log_test_nolog_debug(struct unit_test_state *uts)
  107. {
  108. char buf[BUFFSIZE];
  109. memset(buf, 0, BUFFSIZE);
  110. console_record_reset_enable();
  111. log_debug("testing %s\n", "log_debug");
  112. log(LOGC_NONE, LOGL_DEBUG, "more %s\n", "log_debug");
  113. gd->flags &= ~GD_FLG_RECORD;
  114. ut_assertok(ut_check_console_line(uts, "testing log_debug"));
  115. ut_assertok(ut_check_console_line(uts, "more log_debug"));
  116. ut_assertok(ut_check_console_end(uts));
  117. return 0;
  118. }
  119. LOG_TEST(log_test_nolog_debug);