syslog_test_ndebug.c 1.6 KB

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