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