blob: 855353a9c40966dfad4ded9f7036e7c0bf9aeb27 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass14c8a062017-12-04 13:48:27 -07002/*
3 * Logging support test program
4 *
5 * Copyright (c) 2017 Google, Inc
6 * Written by Simon Glass <sjg@chromium.org>
Simon Glass14c8a062017-12-04 13:48:27 -07007 */
8
Simon Glassed38aef2020-05-10 11:40:03 -06009#include <command.h>
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060011#include <asm/global_data.h>
Sean Andersonc1821822020-10-27 19:55:27 -040012#include <test/log.h>
13#include <test/ut.h>
14
15DECLARE_GLOBAL_DATA_PTR;
Simon Glass14c8a062017-12-04 13:48:27 -070016
17/* emit some sample log records in different ways, for testing */
Patrick Delaunaycc034972020-11-27 11:20:53 +010018static int do_log_run(struct unit_test_state *uts, int cat, const char *file)
Simon Glass14c8a062017-12-04 13:48:27 -070019{
20 int i;
Patrick Delaunaycc034972020-11-27 11:20:53 +010021 int ret, expected_ret;
22
23 if (gd->flags & GD_FLG_LOG_READY)
24 expected_ret = 0;
25 else
26 expected_ret = -ENOSYS;
Simon Glass14c8a062017-12-04 13:48:27 -070027
Sean Andersonc1821822020-10-27 19:55:27 -040028 gd->log_fmt = LOGF_TEST;
Simon Glass14c8a062017-12-04 13:48:27 -070029 debug("debug\n");
30 for (i = LOGL_FIRST; i < LOGL_COUNT; i++) {
31 log(cat, i, "log %d\n", i);
Patrick Delaunaycc034972020-11-27 11:20:53 +010032 ret = _log(log_uc_cat(cat), i, file, 100 + i,
33 "func", "_log %d\n", i);
34 ut_asserteq(ret, expected_ret);
Simon Glass14c8a062017-12-04 13:48:27 -070035 }
Patrick Delaunay529e46f2020-11-27 11:20:51 +010036 /* test with LOGL_COUNT flag */
37 for (i = LOGL_FIRST; i < LOGL_COUNT; i++) {
Patrick Delaunaycc034972020-11-27 11:20:53 +010038 ret = _log(log_uc_cat(cat), i | LOGL_FORCE_DEBUG, file, 100 + i,
39 "func", "_log force %d\n", i);
40 ut_asserteq(ret, expected_ret);
Patrick Delaunay529e46f2020-11-27 11:20:51 +010041 }
Simon Glass14c8a062017-12-04 13:48:27 -070042
Sean Andersonc1821822020-10-27 19:55:27 -040043 gd->log_fmt = log_get_default_format();
Simon Glass14c8a062017-12-04 13:48:27 -070044 return 0;
45}
46
Patrick Delaunaycc034972020-11-27 11:20:53 +010047#define log_run_cat(cat) do_log_run(uts, cat, "file")
48#define log_run_file(file) do_log_run(uts, UCLASS_SPI, file)
49#define log_run() do_log_run(uts, UCLASS_SPI, "file")
Simon Glass14c8a062017-12-04 13:48:27 -070050
Sean Andersonc1821822020-10-27 19:55:27 -040051#define EXPECT_LOG BIT(0)
52#define EXPECT_DIRECT BIT(1)
53#define EXPECT_EXTRA BIT(2)
Patrick Delaunay529e46f2020-11-27 11:20:51 +010054#define EXPECT_FORCE BIT(3)
Patrick Delaunay293798c2020-11-27 11:20:58 +010055#define EXPECT_DEBUG BIT(4)
Simon Glass14c8a062017-12-04 13:48:27 -070056
Sean Andersonc1821822020-10-27 19:55:27 -040057static int do_check_log_entries(struct unit_test_state *uts, int flags, int min,
58 int max)
59{
60 int i;
Simon Glass14c8a062017-12-04 13:48:27 -070061
Sean Andersonc1821822020-10-27 19:55:27 -040062 for (i = min; i <= max; i++) {
63 if (flags & EXPECT_LOG)
Simon Glass81cd0402021-07-05 16:33:00 -060064 ut_assert_nextline(" do_log_run() log %d", i);
Sean Andersonc1821822020-10-27 19:55:27 -040065 if (flags & EXPECT_DIRECT)
Simon Glass81cd0402021-07-05 16:33:00 -060066 ut_assert_nextline(" func() _log %d", i);
Patrick Delaunay293798c2020-11-27 11:20:58 +010067 if (flags & EXPECT_DEBUG) {
68 ut_assert_nextline("log %d", i);
69 ut_assert_nextline("_log %d", i);
70 }
Simon Glass14c8a062017-12-04 13:48:27 -070071 }
Sean Andersonc1821822020-10-27 19:55:27 -040072 if (flags & EXPECT_EXTRA)
73 for (; i <= LOGL_MAX ; i++)
Simon Glass81cd0402021-07-05 16:33:00 -060074 ut_assert_nextline(" func() _log %d", i);
Simon Glass14c8a062017-12-04 13:48:27 -070075
Patrick Delaunay529e46f2020-11-27 11:20:51 +010076 for (i = LOGL_FIRST; i < LOGL_COUNT; i++) {
77 if (flags & EXPECT_FORCE)
Simon Glass81cd0402021-07-05 16:33:00 -060078 ut_assert_nextline(" func() _log force %d",
79 i);
Patrick Delaunay293798c2020-11-27 11:20:58 +010080 if (flags & EXPECT_DEBUG)
81 ut_assert_nextline("_log force %d", i);
Patrick Delaunay529e46f2020-11-27 11:20:51 +010082 }
83
Sean Andersonc1821822020-10-27 19:55:27 -040084 ut_assert_console_end();
85 return 0;
86}
Simon Glass14c8a062017-12-04 13:48:27 -070087
Sean Andersonc1821822020-10-27 19:55:27 -040088#define check_log_entries_flags_levels(flags, min, max) do {\
89 int ret = do_check_log_entries(uts, flags, min, max); \
90 if (ret) \
91 return ret; \
92} while (0)
Simon Glass14c8a062017-12-04 13:48:27 -070093
Sean Andersonc1821822020-10-27 19:55:27 -040094#define check_log_entries_flags(flags) \
95 check_log_entries_flags_levels(flags, LOGL_FIRST, _LOG_MAX_LEVEL)
Patrick Delaunay529e46f2020-11-27 11:20:51 +010096#define check_log_entries() check_log_entries_flags(EXPECT_LOG | EXPECT_DIRECT | EXPECT_FORCE)
Sean Andersonc1821822020-10-27 19:55:27 -040097#define check_log_entries_extra() \
Patrick Delaunay529e46f2020-11-27 11:20:51 +010098 check_log_entries_flags(EXPECT_LOG | EXPECT_DIRECT | EXPECT_EXTRA | EXPECT_FORCE)
99#define check_log_entries_none() check_log_entries_flags(EXPECT_FORCE)
Sean Andersonc1821822020-10-27 19:55:27 -0400100
101/* Check a category filter using the first category */
Sean Andersonba956672020-10-27 19:55:28 -0400102int log_test_cat_allow(struct unit_test_state *uts)
Sean Andersonc1821822020-10-27 19:55:27 -0400103{
104 enum log_category_t cat_list[] = {
105 log_uc_cat(UCLASS_MMC), log_uc_cat(UCLASS_SPI),
106 LOGC_NONE, LOGC_END
107 };
108 int filt;
109
110 filt = log_add_filter("console", cat_list, LOGL_MAX, NULL);
111 ut_assert(filt >= 0);
112
113 ut_assertok(console_record_reset_enable());
114 log_run_cat(UCLASS_MMC);
115 check_log_entries_extra();
116
117 ut_assertok(console_record_reset_enable());
118 log_run_cat(UCLASS_SPI);
119 check_log_entries_extra();
Simon Glass14c8a062017-12-04 13:48:27 -0700120
Sean Andersonc1821822020-10-27 19:55:27 -0400121 ut_assertok(log_remove_filter("console", filt));
Simon Glass14c8a062017-12-04 13:48:27 -0700122 return 0;
123}
Sean Andersonba956672020-10-27 19:55:28 -0400124LOG_TEST_FLAGS(log_test_cat_allow, UT_TESTF_CONSOLE_REC);
Simon Glass14c8a062017-12-04 13:48:27 -0700125
Sean Andersonc1821822020-10-27 19:55:27 -0400126/* Check a category filter that should block log entries */
Sean Andersonba956672020-10-27 19:55:28 -0400127int log_test_cat_deny_implicit(struct unit_test_state *uts)
Simon Glass14c8a062017-12-04 13:48:27 -0700128{
Sean Andersonc1821822020-10-27 19:55:27 -0400129 enum log_category_t cat_list[] = {
130 log_uc_cat(UCLASS_MMC), LOGC_NONE, LOGC_END
131 };
132 int filt;
133
134 filt = log_add_filter("console", cat_list, LOGL_MAX, NULL);
135 ut_assert(filt >= 0);
136
137 ut_assertok(console_record_reset_enable());
138 log_run_cat(UCLASS_SPI);
139 check_log_entries_none();
140
141 ut_assertok(log_remove_filter("console", filt));
142 return 0;
143}
Sean Andersonba956672020-10-27 19:55:28 -0400144LOG_TEST_FLAGS(log_test_cat_deny_implicit, UT_TESTF_CONSOLE_REC);
Sean Andersonc1821822020-10-27 19:55:27 -0400145
146/* Check passing and failing file filters */
Sean Andersonba956672020-10-27 19:55:28 -0400147int log_test_file(struct unit_test_state *uts)
Sean Andersonc1821822020-10-27 19:55:27 -0400148{
149 int filt;
150
151 filt = log_add_filter("console", NULL, LOGL_MAX, "file");
152 ut_assert(filt >= 0);
153
154 ut_assertok(console_record_reset_enable());
155 log_run_file("file");
Patrick Delaunay529e46f2020-11-27 11:20:51 +0100156 check_log_entries_flags(EXPECT_DIRECT | EXPECT_EXTRA | EXPECT_FORCE);
Sean Andersonc1821822020-10-27 19:55:27 -0400157
158 ut_assertok(console_record_reset_enable());
159 log_run_file("file2");
160 check_log_entries_none();
161
162 ut_assertok(log_remove_filter("console", filt));
163 return 0;
164}
Sean Andersonba956672020-10-27 19:55:28 -0400165LOG_TEST_FLAGS(log_test_file, UT_TESTF_CONSOLE_REC);
Sean Andersonc1821822020-10-27 19:55:27 -0400166
167/* Check a passing file filter (second in list) */
Sean Andersonba956672020-10-27 19:55:28 -0400168int log_test_file_second(struct unit_test_state *uts)
Sean Andersonc1821822020-10-27 19:55:27 -0400169{
170 int filt;
171
172 filt = log_add_filter("console", NULL, LOGL_MAX, "file,file2");
173 ut_assert(filt >= 0);
174
175 ut_assertok(console_record_reset_enable());
176 log_run_file("file2");
Patrick Delaunay529e46f2020-11-27 11:20:51 +0100177 check_log_entries_flags(EXPECT_DIRECT | EXPECT_EXTRA | EXPECT_FORCE);
Sean Andersonc1821822020-10-27 19:55:27 -0400178
179 ut_assertok(log_remove_filter("console", filt));
180 return 0;
181}
Sean Andersonba956672020-10-27 19:55:28 -0400182LOG_TEST_FLAGS(log_test_file_second, UT_TESTF_CONSOLE_REC);
Sean Andersonc1821822020-10-27 19:55:27 -0400183
184/* Check a passing file filter (middle of list) */
Sean Andersonba956672020-10-27 19:55:28 -0400185int log_test_file_mid(struct unit_test_state *uts)
Sean Andersonc1821822020-10-27 19:55:27 -0400186{
187 int filt;
188
189 filt = log_add_filter("console", NULL, LOGL_MAX,
190 "file,file2,log/log_test.c");
191 ut_assert(filt >= 0);
192
193 ut_assertok(console_record_reset_enable());
194 log_run_file("file2");
195 check_log_entries_extra();
196
197 ut_assertok(log_remove_filter("console", filt));
198 return 0;
199}
Sean Andersonba956672020-10-27 19:55:28 -0400200LOG_TEST_FLAGS(log_test_file_mid, UT_TESTF_CONSOLE_REC);
Sean Andersonc1821822020-10-27 19:55:27 -0400201
202/* Check a log level filter */
Sean Andersonba956672020-10-27 19:55:28 -0400203int log_test_level(struct unit_test_state *uts)
Sean Andersonc1821822020-10-27 19:55:27 -0400204{
205 int filt;
206
207 filt = log_add_filter("console", NULL, LOGL_WARNING, NULL);
208 ut_assert(filt >= 0);
209
210 ut_assertok(console_record_reset_enable());
211 log_run();
Patrick Delaunay529e46f2020-11-27 11:20:51 +0100212 check_log_entries_flags_levels(EXPECT_LOG | EXPECT_DIRECT | EXPECT_FORCE,
213 LOGL_FIRST, LOGL_WARNING);
Sean Andersonc1821822020-10-27 19:55:27 -0400214
215 ut_assertok(log_remove_filter("console", filt));
216 return 0;
217}
Sean Andersonba956672020-10-27 19:55:28 -0400218LOG_TEST_FLAGS(log_test_level, UT_TESTF_CONSOLE_REC);
Sean Andersonc1821822020-10-27 19:55:27 -0400219
220/* Check two filters, one of which passes everything */
Sean Andersonba956672020-10-27 19:55:28 -0400221int log_test_double(struct unit_test_state *uts)
Sean Andersonc1821822020-10-27 19:55:27 -0400222{
223 int filt1, filt2;
224
225 filt1 = log_add_filter("console", NULL, LOGL_WARNING, NULL);
226 ut_assert(filt1 >= 0);
227 filt2 = log_add_filter("console", NULL, LOGL_MAX, NULL);
228 ut_assert(filt2 >= 0);
229
230 ut_assertok(console_record_reset_enable());
231 log_run();
232 check_log_entries_extra();
233
234 ut_assertok(log_remove_filter("console", filt1));
235 ut_assertok(log_remove_filter("console", filt2));
236 return 0;
237}
Sean Andersonba956672020-10-27 19:55:28 -0400238LOG_TEST_FLAGS(log_test_double, UT_TESTF_CONSOLE_REC);
Sean Andersonc1821822020-10-27 19:55:27 -0400239
240/* Check three filters, which together pass everything */
Sean Andersonba956672020-10-27 19:55:28 -0400241int log_test_triple(struct unit_test_state *uts)
Sean Andersonc1821822020-10-27 19:55:27 -0400242{
243 int filt1, filt2, filt3;
244
245 filt1 = log_add_filter("console", NULL, LOGL_MAX, "file)");
246 ut_assert(filt1 >= 0);
247 filt2 = log_add_filter("console", NULL, LOGL_MAX, "file2");
248 ut_assert(filt2 >= 0);
249 filt3 = log_add_filter("console", NULL, LOGL_MAX, "log/log_test.c");
250 ut_assert(filt3 >= 0);
251
252 ut_assertok(console_record_reset_enable());
253 log_run_file("file2");
254 check_log_entries_extra();
255
256 ut_assertok(log_remove_filter("console", filt1));
257 ut_assertok(log_remove_filter("console", filt2));
258 ut_assertok(log_remove_filter("console", filt3));
259 return 0;
260}
Sean Andersonba956672020-10-27 19:55:28 -0400261LOG_TEST_FLAGS(log_test_triple, UT_TESTF_CONSOLE_REC);
Sean Andersonc1821822020-10-27 19:55:27 -0400262
Sean Andersonba956672020-10-27 19:55:28 -0400263int do_log_test_helpers(struct unit_test_state *uts)
Sean Andersonc1821822020-10-27 19:55:27 -0400264{
265 int i;
266
267 ut_assertok(console_record_reset_enable());
268 log_err("level %d\n", LOGL_EMERG);
269 log_err("level %d\n", LOGL_ALERT);
270 log_err("level %d\n", LOGL_CRIT);
271 log_err("level %d\n", LOGL_ERR);
272 log_warning("level %d\n", LOGL_WARNING);
273 log_notice("level %d\n", LOGL_NOTICE);
274 log_info("level %d\n", LOGL_INFO);
275 log_debug("level %d\n", LOGL_DEBUG);
276 log_content("level %d\n", LOGL_DEBUG_CONTENT);
277 log_io("level %d\n", LOGL_DEBUG_IO);
278
Heinrich Schuchardt3f700dc2022-07-11 08:21:30 +0200279 for (i = LOGL_EMERG; i <= gd->default_log_level; i++)
Simon Glass81cd0402021-07-05 16:33:00 -0600280 ut_assert_nextline("%*s() level %d", CONFIG_LOGF_FUNC_PAD,
281 __func__, i);
Sean Andersonc1821822020-10-27 19:55:27 -0400282 ut_assert_console_end();
283 return 0;
284}
285
Sean Andersonba956672020-10-27 19:55:28 -0400286int log_test_helpers(struct unit_test_state *uts)
Sean Andersonc1821822020-10-27 19:55:27 -0400287{
Simon Glass14c8a062017-12-04 13:48:27 -0700288 int ret;
289
Sean Andersonc1821822020-10-27 19:55:27 -0400290 gd->log_fmt = LOGF_TEST;
Sean Andersonba956672020-10-27 19:55:28 -0400291 ret = do_log_test_helpers(uts);
Sean Andersonc1821822020-10-27 19:55:27 -0400292 gd->log_fmt = log_get_default_format();
293 return ret;
294}
Sean Andersonba956672020-10-27 19:55:28 -0400295LOG_TEST_FLAGS(log_test_helpers, UT_TESTF_CONSOLE_REC);
Sean Andersonc1821822020-10-27 19:55:27 -0400296
Sean Andersonba956672020-10-27 19:55:28 -0400297int do_log_test_disable(struct unit_test_state *uts)
Sean Andersonc1821822020-10-27 19:55:27 -0400298{
299 ut_assertok(console_record_reset_enable());
300 log_err("default\n");
Simon Glass81cd0402021-07-05 16:33:00 -0600301 ut_assert_nextline("%*s() default", CONFIG_LOGF_FUNC_PAD, __func__);
Sean Andersonc1821822020-10-27 19:55:27 -0400302
303 ut_assertok(log_device_set_enable(LOG_GET_DRIVER(console), false));
304 log_err("disabled\n");
Simon Glass14c8a062017-12-04 13:48:27 -0700305
Sean Andersonc1821822020-10-27 19:55:27 -0400306 ut_assertok(log_device_set_enable(LOG_GET_DRIVER(console), true));
307 log_err("enabled\n");
Simon Glass81cd0402021-07-05 16:33:00 -0600308 ut_assert_nextline("%*s() enabled", CONFIG_LOGF_FUNC_PAD, __func__);
Sean Andersonc1821822020-10-27 19:55:27 -0400309 ut_assert_console_end();
310 return 0;
311}
312
Sean Andersonba956672020-10-27 19:55:28 -0400313int log_test_disable(struct unit_test_state *uts)
Sean Andersonc1821822020-10-27 19:55:27 -0400314{
315 int ret;
Simon Glass14c8a062017-12-04 13:48:27 -0700316
Sean Andersonc1821822020-10-27 19:55:27 -0400317 gd->log_fmt = LOGF_TEST;
Sean Andersonba956672020-10-27 19:55:28 -0400318 ret = do_log_test_disable(uts);
Sean Andersonc1821822020-10-27 19:55:27 -0400319 gd->log_fmt = log_get_default_format();
320 return ret;
Simon Glass14c8a062017-12-04 13:48:27 -0700321}
Sean Andersonba956672020-10-27 19:55:28 -0400322LOG_TEST_FLAGS(log_test_disable, UT_TESTF_CONSOLE_REC);
Sean Anderson14e99862020-10-27 19:55:29 -0400323
324/* Check denying based on category */
325int log_test_cat_deny(struct unit_test_state *uts)
326{
327 int filt1, filt2;
328 enum log_category_t cat_list[] = {
329 log_uc_cat(UCLASS_SPI), LOGC_END
330 };
331
332 filt1 = log_add_filter("console", cat_list, LOGL_MAX, NULL);
333 ut_assert(filt1 >= 0);
334 filt2 = log_add_filter_flags("console", cat_list, LOGL_MAX, NULL,
335 LOGFF_DENY);
336 ut_assert(filt2 >= 0);
337
338 ut_assertok(console_record_reset_enable());
339 log_run_cat(UCLASS_SPI);
340 check_log_entries_none();
341
342 ut_assertok(log_remove_filter("console", filt1));
343 ut_assertok(log_remove_filter("console", filt2));
344 return 0;
345}
346LOG_TEST_FLAGS(log_test_cat_deny, UT_TESTF_CONSOLE_REC);
347
348/* Check denying based on file */
349int log_test_file_deny(struct unit_test_state *uts)
350{
351 int filt1, filt2;
352
353 filt1 = log_add_filter("console", NULL, LOGL_MAX, "file");
354 ut_assert(filt1 >= 0);
355 filt2 = log_add_filter_flags("console", NULL, LOGL_MAX, "file",
356 LOGFF_DENY);
357 ut_assert(filt2 >= 0);
358
359 ut_assertok(console_record_reset_enable());
360 log_run_file("file");
361 check_log_entries_none();
362
363 ut_assertok(log_remove_filter("console", filt1));
364 ut_assertok(log_remove_filter("console", filt2));
365 return 0;
366}
367LOG_TEST_FLAGS(log_test_file_deny, UT_TESTF_CONSOLE_REC);
368
369/* Check denying based on level */
370int log_test_level_deny(struct unit_test_state *uts)
371{
372 int filt1, filt2;
373
374 filt1 = log_add_filter("console", NULL, LOGL_INFO, NULL);
375 ut_assert(filt1 >= 0);
376 filt2 = log_add_filter_flags("console", NULL, LOGL_WARNING, NULL,
377 LOGFF_DENY);
378 ut_assert(filt2 >= 0);
379
380 ut_assertok(console_record_reset_enable());
381 log_run();
Patrick Delaunay529e46f2020-11-27 11:20:51 +0100382 check_log_entries_flags_levels(EXPECT_LOG | EXPECT_DIRECT | EXPECT_FORCE,
Heinrich Schuchardt3f700dc2022-07-11 08:21:30 +0200383 LOGL_WARNING + 1,
384 min(gd->default_log_level, LOGL_INFO));
Sean Anderson14e99862020-10-27 19:55:29 -0400385
386 ut_assertok(log_remove_filter("console", filt1));
387 ut_assertok(log_remove_filter("console", filt2));
388 return 0;
389}
390LOG_TEST_FLAGS(log_test_level_deny, UT_TESTF_CONSOLE_REC);
Sean Anderson41473172020-10-27 19:55:31 -0400391
392/* Check matching based on minimum level */
393int log_test_min(struct unit_test_state *uts)
394{
395 int filt1, filt2;
396
397 filt1 = log_add_filter_flags("console", NULL, LOGL_WARNING, NULL,
398 LOGFF_LEVEL_MIN);
399 ut_assert(filt1 >= 0);
400 filt2 = log_add_filter_flags("console", NULL, LOGL_INFO, NULL,
401 LOGFF_DENY | LOGFF_LEVEL_MIN);
402 ut_assert(filt2 >= 0);
403
404 ut_assertok(console_record_reset_enable());
405 log_run();
Patrick Delaunay529e46f2020-11-27 11:20:51 +0100406 check_log_entries_flags_levels(EXPECT_LOG | EXPECT_DIRECT | EXPECT_FORCE,
Sean Anderson41473172020-10-27 19:55:31 -0400407 LOGL_WARNING, LOGL_INFO - 1);
408
409 ut_assertok(log_remove_filter("console", filt1));
410 ut_assertok(log_remove_filter("console", filt2));
411 return 0;
412}
413LOG_TEST_FLAGS(log_test_min, UT_TESTF_CONSOLE_REC);
Patrick Delaunaycc034972020-11-27 11:20:53 +0100414
415/* Check dropped traces */
416int log_test_dropped(struct unit_test_state *uts)
417{
418 /* force LOG not ready */
419 gd->flags &= ~(GD_FLG_LOG_READY);
420 gd->log_drop_count = 0;
421
422 ut_assertok(console_record_reset_enable());
Patrick Delaunaycc034972020-11-27 11:20:53 +0100423
Heinrich Schuchardt3f700dc2022-07-11 08:21:30 +0200424 log_run();
425 ut_asserteq(2 * (LOGL_COUNT - LOGL_FIRST) +
426 _LOG_MAX_LEVEL - LOGL_FIRST + 1,
427 gd->log_drop_count);
Patrick Delaunay293798c2020-11-27 11:20:58 +0100428 check_log_entries_flags_levels(EXPECT_DEBUG, LOGL_FIRST, CONFIG_LOG_DEFAULT_LEVEL);
Patrick Delaunaycc034972020-11-27 11:20:53 +0100429
430 gd->flags |= GD_FLG_LOG_READY;
431 gd->log_drop_count = 0;
432
433 return 0;
434}
435LOG_TEST_FLAGS(log_test_dropped, UT_TESTF_CONSOLE_REC);
Simon Glass7fb97592021-05-08 07:00:06 -0600436
437/* Check log_buffer() */
438int log_test_buffer(struct unit_test_state *uts)
439{
440 u8 *buf;
441 int i;
442
443 buf = malloc(0x20);
444 ut_assertnonnull(buf);
445 memset(buf, '\0', 0x20);
446 for (i = 0; i < 0x11; i++)
447 buf[i] = i * 0x11;
448
449 ut_assertok(console_record_reset_enable());
450 log_buffer(LOGC_BOOT, LOGL_INFO, 0, buf, 1, 0x12, 0);
451
452 /* This one should product no output due to the debug level */
453 log_buffer(LOGC_BOOT, LOGL_DEBUG, 0, buf, 1, 0x12, 0);
454
455 ut_assert_nextline("00000000: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff ..\"3DUfw........");
456 ut_assert_nextline("00000010: 10 00 ..");
457 ut_assert_console_end();
458 free(buf);
459
460 return 0;
461}
462LOG_TEST_FLAGS(log_test_buffer, UT_TESTF_CONSOLE_REC);