syslog_test_ndebug.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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_SYSLOG=y.
  6. *
  7. * Invoke the test with: ./u-boot -d arch/sandbox/dts/test.dtb
  8. */
  9. #include <common.h>
  10. #include <dm/device.h>
  11. #include <hexdump.h>
  12. #include <test/log.h>
  13. #include <test/test.h>
  14. #include <test/suites.h>
  15. #include <test/ut.h>
  16. #include <asm/eth.h>
  17. #include "syslog_test.h"
  18. DECLARE_GLOBAL_DATA_PTR;
  19. /**
  20. * log_test_syslog_nodebug() - test logging level filter
  21. *
  22. * Verify that log_debug() does not lead to a log message if the logging level
  23. * is set to LOGL_INFO.
  24. *
  25. * @uts: unit test state
  26. * Return: 0 = success
  27. */
  28. static int log_test_syslog_nodebug(struct unit_test_state *uts)
  29. {
  30. int old_log_level = gd->default_log_level;
  31. struct sb_log_env env;
  32. ut_assertok(syslog_test_setup(uts));
  33. gd->log_fmt = LOGF_TEST;
  34. gd->default_log_level = LOGL_INFO;
  35. env_set("ethact", "eth@10002000");
  36. env_set("log_hostname", "sandbox");
  37. env.expected = "<7>sandbox uboot: log_test_syslog_nodebug() "
  38. "testing log_debug\n";
  39. env.uts = uts;
  40. sandbox_eth_set_tx_handler(0, sb_log_tx_handler);
  41. /* Used by ut_assert macros in the tx_handler */
  42. sandbox_eth_set_priv(0, &env);
  43. log_debug("testing %s\n", "log_debug");
  44. sandbox_eth_set_tx_handler(0, NULL);
  45. /* Check that the callback function was not called */
  46. ut_assertnonnull(env.expected);
  47. gd->default_log_level = old_log_level;
  48. gd->log_fmt = log_get_default_format();
  49. ut_assertok(syslog_test_finish(uts));
  50. return 0;
  51. }
  52. LOG_TEST(log_test_syslog_nodebug);