blob: de7b7f064cd597cfcbb74ca35f496e27d695f5f2 [file] [log] [blame]
Heinrich Schuchardt92015762020-10-17 14:31:59 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (c) 2020, Heinrich Schuchardt <xypron.glpk@gmx.de>
4 *
5 * Test continuation of log messages.
6 */
7
8#include <common.h>
9#include <console.h>
Simon Glass401d1c42020-10-30 21:38:53 -060010#include <asm/global_data.h>
Heinrich Schuchardt92015762020-10-17 14:31:59 +020011#include <test/log.h>
12#include <test/test.h>
13#include <test/suites.h>
14#include <test/ut.h>
15
16DECLARE_GLOBAL_DATA_PTR;
17
Heinrich Schuchardt92015762020-10-17 14:31:59 +020018static int log_test_cont(struct unit_test_state *uts)
19{
20 int log_fmt;
21 int log_level;
22
23 log_fmt = gd->log_fmt;
24 log_level = gd->default_log_level;
25
26 /* Write two messages, the second continuing the first */
27 gd->log_fmt = (1 << LOGF_CAT) | (1 << LOGF_LEVEL) | (1 << LOGF_MSG);
28 gd->default_log_level = LOGL_INFO;
29 console_record_reset_enable();
Simon Glass9ad7a6c2021-01-20 20:10:53 -070030 log(LOGC_ARCH, LOGL_ERR, "ea%d\n", 1);
Heinrich Schuchardt92015762020-10-17 14:31:59 +020031 log(LOGC_CONT, LOGL_CONT, "cc%d\n", 2);
32 gd->default_log_level = log_level;
33 gd->log_fmt = log_fmt;
34 gd->flags &= ~GD_FLG_RECORD;
Simon Glass9ad7a6c2021-01-20 20:10:53 -070035 ut_assertok(ut_check_console_line(uts, "ERR.arch, ea1"));
36 ut_assertok(ut_check_console_line(uts, "ERR.arch, cc2"));
Heinrich Schuchardt92015762020-10-17 14:31:59 +020037 ut_assertok(ut_check_console_end(uts));
38
39 /* Write a third message which is not a continuation */
40 gd->log_fmt = (1 << LOGF_CAT) | (1 << LOGF_LEVEL) | (1 << LOGF_MSG);
41 gd->default_log_level = LOGL_INFO;
42 console_record_reset_enable();
43 log(LOGC_EFI, LOGL_INFO, "ie%d\n", 3);
44 gd->default_log_level = log_level;
45 gd->log_fmt = log_fmt;
46 gd->flags &= ~GD_FLG_RECORD;
47 ut_assertok(ut_check_console_line(uts, "INFO.efi, ie3"));
48 ut_assertok(ut_check_console_end(uts));
49
Simon Glass9ad7a6c2021-01-20 20:10:53 -070050 /* Write two messages without a newline between them */
51 gd->log_fmt = (1 << LOGF_CAT) | (1 << LOGF_LEVEL) | (1 << LOGF_MSG);
52 gd->default_log_level = LOGL_INFO;
53 console_record_reset_enable();
54 log(LOGC_ARCH, LOGL_ERR, "ea%d ", 1);
55 log(LOGC_CONT, LOGL_CONT, "cc%d\n", 2);
56 gd->default_log_level = log_level;
57 gd->log_fmt = log_fmt;
58 gd->flags &= ~GD_FLG_RECORD;
59 ut_assertok(ut_check_console_line(uts, "ERR.arch, ea1 cc2"));
60 ut_assertok(ut_check_console_end(uts));
61
Heinrich Schuchardt92015762020-10-17 14:31:59 +020062 return 0;
63}
64LOG_TEST(log_test_cont);