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