nolog_test.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 <test/log.h>
  12. #include <test/test.h>
  13. #include <test/suites.h>
  14. #include <test/ut.h>
  15. DECLARE_GLOBAL_DATA_PTR;
  16. #define BUFFSIZE 32
  17. static int log_test_nolog_err(struct unit_test_state *uts)
  18. {
  19. char buf[BUFFSIZE];
  20. memset(buf, 0, BUFFSIZE);
  21. console_record_reset_enable();
  22. log_err("testing %s\n", "log_err");
  23. gd->flags &= ~GD_FLG_RECORD;
  24. ut_assertok(ut_check_console_line(uts, "testing log_err"));
  25. ut_assertok(ut_check_console_end(uts));
  26. return 0;
  27. }
  28. LOG_TEST(log_test_nolog_err);
  29. static int log_test_nolog_warning(struct unit_test_state *uts)
  30. {
  31. char buf[BUFFSIZE];
  32. memset(buf, 0, BUFFSIZE);
  33. console_record_reset_enable();
  34. log_warning("testing %s\n", "log_warning");
  35. gd->flags &= ~GD_FLG_RECORD;
  36. ut_assertok(ut_check_console_line(uts, "testing log_warning"));
  37. ut_assertok(ut_check_console_end(uts));
  38. return 0;
  39. }
  40. LOG_TEST(log_test_nolog_warning);
  41. static int log_test_nolog_notice(struct unit_test_state *uts)
  42. {
  43. char buf[BUFFSIZE];
  44. memset(buf, 0, BUFFSIZE);
  45. console_record_reset_enable();
  46. log_notice("testing %s\n", "log_notice");
  47. gd->flags &= ~GD_FLG_RECORD;
  48. ut_assertok(ut_check_console_line(uts, "testing log_notice"));
  49. ut_assertok(ut_check_console_end(uts));
  50. return 0;
  51. }
  52. LOG_TEST(log_test_nolog_notice);
  53. static int log_test_nolog_info(struct unit_test_state *uts)
  54. {
  55. char buf[BUFFSIZE];
  56. memset(buf, 0, BUFFSIZE);
  57. console_record_reset_enable();
  58. log_err("testing %s\n", "log_info");
  59. gd->flags &= ~GD_FLG_RECORD;
  60. ut_assertok(ut_check_console_line(uts, "testing log_info"));
  61. ut_assertok(ut_check_console_end(uts));
  62. return 0;
  63. }
  64. LOG_TEST(log_test_nolog_info);
  65. #undef _DEBUG
  66. #define _DEBUG 0
  67. static int nolog_test_nodebug(struct unit_test_state *uts)
  68. {
  69. char buf[BUFFSIZE];
  70. memset(buf, 0, BUFFSIZE);
  71. console_record_reset_enable();
  72. debug("testing %s\n", "debug");
  73. gd->flags &= ~GD_FLG_RECORD;
  74. ut_assertok(ut_check_console_end(uts));
  75. return 0;
  76. }
  77. LOG_TEST(nolog_test_nodebug);
  78. static int log_test_nolog_nodebug(struct unit_test_state *uts)
  79. {
  80. char buf[BUFFSIZE];
  81. memset(buf, 0, BUFFSIZE);
  82. console_record_reset_enable();
  83. log_debug("testing %s\n", "log_debug");
  84. gd->flags &= ~GD_FLG_RECORD;
  85. ut_assert(!strcmp(buf, ""));
  86. ut_assertok(ut_check_console_end(uts));
  87. return 0;
  88. }
  89. LOG_TEST(log_test_nolog_nodebug);
  90. #undef _DEBUG
  91. #define _DEBUG 1
  92. static int nolog_test_debug(struct unit_test_state *uts)
  93. {
  94. char buf[BUFFSIZE];
  95. memset(buf, 0, BUFFSIZE);
  96. console_record_reset_enable();
  97. debug("testing %s\n", "debug");
  98. gd->flags &= ~GD_FLG_RECORD;
  99. ut_assertok(ut_check_console_line(uts, "testing debug"));
  100. ut_assertok(ut_check_console_end(uts));
  101. return 0;
  102. }
  103. LOG_TEST(nolog_test_debug);
  104. static int log_test_nolog_debug(struct unit_test_state *uts)
  105. {
  106. char buf[BUFFSIZE];
  107. memset(buf, 0, BUFFSIZE);
  108. console_record_reset_enable();
  109. log_debug("testing %s\n", "log_debug");
  110. gd->flags &= ~GD_FLG_RECORD;
  111. ut_assertok(ut_check_console_line(uts, "testing log_debug"));
  112. ut_assertok(ut_check_console_end(uts));
  113. return 0;
  114. }
  115. LOG_TEST(log_test_nolog_debug);