Heinrich Schuchardt | 9201576 | 2020-10-17 14:31:59 +0200 | [diff] [blame] | 1 | // 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 Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 10 | #include <asm/global_data.h> |
Heinrich Schuchardt | 9201576 | 2020-10-17 14:31:59 +0200 | [diff] [blame] | 11 | #include <test/log.h> |
| 12 | #include <test/test.h> |
| 13 | #include <test/suites.h> |
| 14 | #include <test/ut.h> |
| 15 | |
| 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | |
Heinrich Schuchardt | 9201576 | 2020-10-17 14:31:59 +0200 | [diff] [blame] | 18 | static 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 Glass | 9ad7a6c | 2021-01-20 20:10:53 -0700 | [diff] [blame] | 30 | log(LOGC_ARCH, LOGL_ERR, "ea%d\n", 1); |
Heinrich Schuchardt | 9201576 | 2020-10-17 14:31:59 +0200 | [diff] [blame] | 31 | 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 Glass | 9ad7a6c | 2021-01-20 20:10:53 -0700 | [diff] [blame] | 35 | ut_assertok(ut_check_console_line(uts, "ERR.arch, ea1")); |
| 36 | ut_assertok(ut_check_console_line(uts, "ERR.arch, cc2")); |
Heinrich Schuchardt | 9201576 | 2020-10-17 14:31:59 +0200 | [diff] [blame] | 37 | 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 Glass | 9ad7a6c | 2021-01-20 20:10:53 -0700 | [diff] [blame] | 50 | /* 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 Schuchardt | 9201576 | 2020-10-17 14:31:59 +0200 | [diff] [blame] | 62 | return 0; |
| 63 | } |
| 64 | LOG_TEST(log_test_cont); |