blob: 1c89df4ef188284410cfa6795be47d8a4125d0b1 [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
Sean Andersonc1821822020-10-27 19:55:27 -0400113 log_run_cat(UCLASS_MMC);
114 check_log_entries_extra();
115
Sean Andersonc1821822020-10-27 19:55:27 -0400116 log_run_cat(UCLASS_SPI);
117 check_log_entries_extra();
Simon Glass14c8a062017-12-04 13:48:27 -0700118
Sean Andersonc1821822020-10-27 19:55:27 -0400119 ut_assertok(log_remove_filter("console", filt));
Simon Glass14c8a062017-12-04 13:48:27 -0700120 return 0;
121}
Simon Glass11fcfa32024-08-22 07:57:50 -0600122LOG_TEST_FLAGS(log_test_cat_allow, UTF_CONSOLE);
Simon Glass14c8a062017-12-04 13:48:27 -0700123
Sean Andersonc1821822020-10-27 19:55:27 -0400124/* Check a category filter that should block log entries */
Sean Andersonba956672020-10-27 19:55:28 -0400125int log_test_cat_deny_implicit(struct unit_test_state *uts)
Simon Glass14c8a062017-12-04 13:48:27 -0700126{
Sean Andersonc1821822020-10-27 19:55:27 -0400127 enum log_category_t cat_list[] = {
128 log_uc_cat(UCLASS_MMC), LOGC_NONE, LOGC_END
129 };
130 int filt;
131
132 filt = log_add_filter("console", cat_list, LOGL_MAX, NULL);
133 ut_assert(filt >= 0);
134
Sean Andersonc1821822020-10-27 19:55:27 -0400135 log_run_cat(UCLASS_SPI);
136 check_log_entries_none();
137
138 ut_assertok(log_remove_filter("console", filt));
139 return 0;
140}
Simon Glass11fcfa32024-08-22 07:57:50 -0600141LOG_TEST_FLAGS(log_test_cat_deny_implicit, UTF_CONSOLE);
Sean Andersonc1821822020-10-27 19:55:27 -0400142
143/* Check passing and failing file filters */
Sean Andersonba956672020-10-27 19:55:28 -0400144int log_test_file(struct unit_test_state *uts)
Sean Andersonc1821822020-10-27 19:55:27 -0400145{
146 int filt;
147
148 filt = log_add_filter("console", NULL, LOGL_MAX, "file");
149 ut_assert(filt >= 0);
150
Sean Andersonc1821822020-10-27 19:55:27 -0400151 log_run_file("file");
Patrick Delaunay529e46f2020-11-27 11:20:51 +0100152 check_log_entries_flags(EXPECT_DIRECT | EXPECT_EXTRA | EXPECT_FORCE);
Sean Andersonc1821822020-10-27 19:55:27 -0400153
Sean Andersonc1821822020-10-27 19:55:27 -0400154 log_run_file("file2");
155 check_log_entries_none();
156
157 ut_assertok(log_remove_filter("console", filt));
158 return 0;
159}
Simon Glass11fcfa32024-08-22 07:57:50 -0600160LOG_TEST_FLAGS(log_test_file, UTF_CONSOLE);
Sean Andersonc1821822020-10-27 19:55:27 -0400161
162/* Check a passing file filter (second in list) */
Sean Andersonba956672020-10-27 19:55:28 -0400163int log_test_file_second(struct unit_test_state *uts)
Sean Andersonc1821822020-10-27 19:55:27 -0400164{
165 int filt;
166
167 filt = log_add_filter("console", NULL, LOGL_MAX, "file,file2");
168 ut_assert(filt >= 0);
169
Sean Andersonc1821822020-10-27 19:55:27 -0400170 log_run_file("file2");
Patrick Delaunay529e46f2020-11-27 11:20:51 +0100171 check_log_entries_flags(EXPECT_DIRECT | EXPECT_EXTRA | EXPECT_FORCE);
Sean Andersonc1821822020-10-27 19:55:27 -0400172
173 ut_assertok(log_remove_filter("console", filt));
174 return 0;
175}
Simon Glass11fcfa32024-08-22 07:57:50 -0600176LOG_TEST_FLAGS(log_test_file_second, UTF_CONSOLE);
Sean Andersonc1821822020-10-27 19:55:27 -0400177
178/* Check a passing file filter (middle of list) */
Sean Andersonba956672020-10-27 19:55:28 -0400179int log_test_file_mid(struct unit_test_state *uts)
Sean Andersonc1821822020-10-27 19:55:27 -0400180{
181 int filt;
182
183 filt = log_add_filter("console", NULL, LOGL_MAX,
184 "file,file2,log/log_test.c");
185 ut_assert(filt >= 0);
186
Sean Andersonc1821822020-10-27 19:55:27 -0400187 log_run_file("file2");
188 check_log_entries_extra();
189
190 ut_assertok(log_remove_filter("console", filt));
191 return 0;
192}
Simon Glass11fcfa32024-08-22 07:57:50 -0600193LOG_TEST_FLAGS(log_test_file_mid, UTF_CONSOLE);
Sean Andersonc1821822020-10-27 19:55:27 -0400194
195/* Check a log level filter */
Sean Andersonba956672020-10-27 19:55:28 -0400196int log_test_level(struct unit_test_state *uts)
Sean Andersonc1821822020-10-27 19:55:27 -0400197{
198 int filt;
199
200 filt = log_add_filter("console", NULL, LOGL_WARNING, NULL);
201 ut_assert(filt >= 0);
202
Sean Andersonc1821822020-10-27 19:55:27 -0400203 log_run();
Patrick Delaunay529e46f2020-11-27 11:20:51 +0100204 check_log_entries_flags_levels(EXPECT_LOG | EXPECT_DIRECT | EXPECT_FORCE,
205 LOGL_FIRST, LOGL_WARNING);
Sean Andersonc1821822020-10-27 19:55:27 -0400206
207 ut_assertok(log_remove_filter("console", filt));
208 return 0;
209}
Simon Glass11fcfa32024-08-22 07:57:50 -0600210LOG_TEST_FLAGS(log_test_level, UTF_CONSOLE);
Sean Andersonc1821822020-10-27 19:55:27 -0400211
212/* Check two filters, one of which passes everything */
Sean Andersonba956672020-10-27 19:55:28 -0400213int log_test_double(struct unit_test_state *uts)
Sean Andersonc1821822020-10-27 19:55:27 -0400214{
215 int filt1, filt2;
216
217 filt1 = log_add_filter("console", NULL, LOGL_WARNING, NULL);
218 ut_assert(filt1 >= 0);
219 filt2 = log_add_filter("console", NULL, LOGL_MAX, NULL);
220 ut_assert(filt2 >= 0);
221
Sean Andersonc1821822020-10-27 19:55:27 -0400222 log_run();
223 check_log_entries_extra();
224
225 ut_assertok(log_remove_filter("console", filt1));
226 ut_assertok(log_remove_filter("console", filt2));
227 return 0;
228}
Simon Glass11fcfa32024-08-22 07:57:50 -0600229LOG_TEST_FLAGS(log_test_double, UTF_CONSOLE);
Sean Andersonc1821822020-10-27 19:55:27 -0400230
231/* Check three filters, which together pass everything */
Sean Andersonba956672020-10-27 19:55:28 -0400232int log_test_triple(struct unit_test_state *uts)
Sean Andersonc1821822020-10-27 19:55:27 -0400233{
234 int filt1, filt2, filt3;
235
236 filt1 = log_add_filter("console", NULL, LOGL_MAX, "file)");
237 ut_assert(filt1 >= 0);
238 filt2 = log_add_filter("console", NULL, LOGL_MAX, "file2");
239 ut_assert(filt2 >= 0);
240 filt3 = log_add_filter("console", NULL, LOGL_MAX, "log/log_test.c");
241 ut_assert(filt3 >= 0);
242
Sean Andersonc1821822020-10-27 19:55:27 -0400243 log_run_file("file2");
244 check_log_entries_extra();
245
246 ut_assertok(log_remove_filter("console", filt1));
247 ut_assertok(log_remove_filter("console", filt2));
248 ut_assertok(log_remove_filter("console", filt3));
249 return 0;
250}
Simon Glass11fcfa32024-08-22 07:57:50 -0600251LOG_TEST_FLAGS(log_test_triple, UTF_CONSOLE);
Sean Andersonc1821822020-10-27 19:55:27 -0400252
Sean Andersonba956672020-10-27 19:55:28 -0400253int do_log_test_helpers(struct unit_test_state *uts)
Sean Andersonc1821822020-10-27 19:55:27 -0400254{
255 int i;
256
Sean Andersonc1821822020-10-27 19:55:27 -0400257 log_err("level %d\n", LOGL_EMERG);
258 log_err("level %d\n", LOGL_ALERT);
259 log_err("level %d\n", LOGL_CRIT);
260 log_err("level %d\n", LOGL_ERR);
261 log_warning("level %d\n", LOGL_WARNING);
262 log_notice("level %d\n", LOGL_NOTICE);
263 log_info("level %d\n", LOGL_INFO);
264 log_debug("level %d\n", LOGL_DEBUG);
265 log_content("level %d\n", LOGL_DEBUG_CONTENT);
266 log_io("level %d\n", LOGL_DEBUG_IO);
267
Heinrich Schuchardt3f700dc2022-07-11 08:21:30 +0200268 for (i = LOGL_EMERG; i <= gd->default_log_level; i++)
Simon Glass81cd0402021-07-05 16:33:00 -0600269 ut_assert_nextline("%*s() level %d", CONFIG_LOGF_FUNC_PAD,
270 __func__, i);
Sean Andersonc1821822020-10-27 19:55:27 -0400271 ut_assert_console_end();
272 return 0;
273}
274
Sean Andersonba956672020-10-27 19:55:28 -0400275int log_test_helpers(struct unit_test_state *uts)
Sean Andersonc1821822020-10-27 19:55:27 -0400276{
Simon Glass14c8a062017-12-04 13:48:27 -0700277 int ret;
278
Sean Andersonc1821822020-10-27 19:55:27 -0400279 gd->log_fmt = LOGF_TEST;
Sean Andersonba956672020-10-27 19:55:28 -0400280 ret = do_log_test_helpers(uts);
Sean Andersonc1821822020-10-27 19:55:27 -0400281 gd->log_fmt = log_get_default_format();
282 return ret;
283}
Simon Glass11fcfa32024-08-22 07:57:50 -0600284LOG_TEST_FLAGS(log_test_helpers, UTF_CONSOLE);
Sean Andersonc1821822020-10-27 19:55:27 -0400285
Sean Andersonba956672020-10-27 19:55:28 -0400286int do_log_test_disable(struct unit_test_state *uts)
Sean Andersonc1821822020-10-27 19:55:27 -0400287{
Sean Andersonc1821822020-10-27 19:55:27 -0400288 log_err("default\n");
Simon Glass81cd0402021-07-05 16:33:00 -0600289 ut_assert_nextline("%*s() default", CONFIG_LOGF_FUNC_PAD, __func__);
Sean Andersonc1821822020-10-27 19:55:27 -0400290
291 ut_assertok(log_device_set_enable(LOG_GET_DRIVER(console), false));
292 log_err("disabled\n");
Simon Glass14c8a062017-12-04 13:48:27 -0700293
Sean Andersonc1821822020-10-27 19:55:27 -0400294 ut_assertok(log_device_set_enable(LOG_GET_DRIVER(console), true));
295 log_err("enabled\n");
Simon Glass81cd0402021-07-05 16:33:00 -0600296 ut_assert_nextline("%*s() enabled", CONFIG_LOGF_FUNC_PAD, __func__);
Sean Andersonc1821822020-10-27 19:55:27 -0400297 ut_assert_console_end();
298 return 0;
299}
300
Sean Andersonba956672020-10-27 19:55:28 -0400301int log_test_disable(struct unit_test_state *uts)
Sean Andersonc1821822020-10-27 19:55:27 -0400302{
303 int ret;
Simon Glass14c8a062017-12-04 13:48:27 -0700304
Sean Andersonc1821822020-10-27 19:55:27 -0400305 gd->log_fmt = LOGF_TEST;
Sean Andersonba956672020-10-27 19:55:28 -0400306 ret = do_log_test_disable(uts);
Sean Andersonc1821822020-10-27 19:55:27 -0400307 gd->log_fmt = log_get_default_format();
308 return ret;
Simon Glass14c8a062017-12-04 13:48:27 -0700309}
Simon Glass11fcfa32024-08-22 07:57:50 -0600310LOG_TEST_FLAGS(log_test_disable, UTF_CONSOLE);
Sean Anderson14e99862020-10-27 19:55:29 -0400311
312/* Check denying based on category */
313int log_test_cat_deny(struct unit_test_state *uts)
314{
315 int filt1, filt2;
316 enum log_category_t cat_list[] = {
317 log_uc_cat(UCLASS_SPI), LOGC_END
318 };
319
320 filt1 = log_add_filter("console", cat_list, LOGL_MAX, NULL);
321 ut_assert(filt1 >= 0);
322 filt2 = log_add_filter_flags("console", cat_list, LOGL_MAX, NULL,
323 LOGFF_DENY);
324 ut_assert(filt2 >= 0);
325
Sean Anderson14e99862020-10-27 19:55:29 -0400326 log_run_cat(UCLASS_SPI);
327 check_log_entries_none();
328
329 ut_assertok(log_remove_filter("console", filt1));
330 ut_assertok(log_remove_filter("console", filt2));
331 return 0;
332}
Simon Glass11fcfa32024-08-22 07:57:50 -0600333LOG_TEST_FLAGS(log_test_cat_deny, UTF_CONSOLE);
Sean Anderson14e99862020-10-27 19:55:29 -0400334
335/* Check denying based on file */
336int log_test_file_deny(struct unit_test_state *uts)
337{
338 int filt1, filt2;
339
340 filt1 = log_add_filter("console", NULL, LOGL_MAX, "file");
341 ut_assert(filt1 >= 0);
342 filt2 = log_add_filter_flags("console", NULL, LOGL_MAX, "file",
343 LOGFF_DENY);
344 ut_assert(filt2 >= 0);
345
Sean Anderson14e99862020-10-27 19:55:29 -0400346 log_run_file("file");
347 check_log_entries_none();
348
349 ut_assertok(log_remove_filter("console", filt1));
350 ut_assertok(log_remove_filter("console", filt2));
351 return 0;
352}
Simon Glass11fcfa32024-08-22 07:57:50 -0600353LOG_TEST_FLAGS(log_test_file_deny, UTF_CONSOLE);
Sean Anderson14e99862020-10-27 19:55:29 -0400354
355/* Check denying based on level */
356int log_test_level_deny(struct unit_test_state *uts)
357{
358 int filt1, filt2;
359
360 filt1 = log_add_filter("console", NULL, LOGL_INFO, NULL);
361 ut_assert(filt1 >= 0);
362 filt2 = log_add_filter_flags("console", NULL, LOGL_WARNING, NULL,
363 LOGFF_DENY);
364 ut_assert(filt2 >= 0);
365
Sean Anderson14e99862020-10-27 19:55:29 -0400366 log_run();
Simon Glass9113dd32024-08-21 10:19:17 -0600367 check_log_entries_flags_levels(
368 EXPECT_LOG | EXPECT_DIRECT | EXPECT_FORCE,
369 LOGL_WARNING + 1, min((int)gd->default_log_level, LOGL_INFO));
Sean Anderson14e99862020-10-27 19:55:29 -0400370
371 ut_assertok(log_remove_filter("console", filt1));
372 ut_assertok(log_remove_filter("console", filt2));
373 return 0;
374}
Simon Glass11fcfa32024-08-22 07:57:50 -0600375LOG_TEST_FLAGS(log_test_level_deny, UTF_CONSOLE);
Sean Anderson41473172020-10-27 19:55:31 -0400376
377/* Check matching based on minimum level */
378int log_test_min(struct unit_test_state *uts)
379{
380 int filt1, filt2;
381
382 filt1 = log_add_filter_flags("console", NULL, LOGL_WARNING, NULL,
383 LOGFF_LEVEL_MIN);
384 ut_assert(filt1 >= 0);
385 filt2 = log_add_filter_flags("console", NULL, LOGL_INFO, NULL,
386 LOGFF_DENY | LOGFF_LEVEL_MIN);
387 ut_assert(filt2 >= 0);
388
Sean Anderson41473172020-10-27 19:55:31 -0400389 log_run();
Patrick Delaunay529e46f2020-11-27 11:20:51 +0100390 check_log_entries_flags_levels(EXPECT_LOG | EXPECT_DIRECT | EXPECT_FORCE,
Sean Anderson41473172020-10-27 19:55:31 -0400391 LOGL_WARNING, LOGL_INFO - 1);
392
393 ut_assertok(log_remove_filter("console", filt1));
394 ut_assertok(log_remove_filter("console", filt2));
395 return 0;
396}
Simon Glass11fcfa32024-08-22 07:57:50 -0600397LOG_TEST_FLAGS(log_test_min, UTF_CONSOLE);
Patrick Delaunaycc034972020-11-27 11:20:53 +0100398
399/* Check dropped traces */
400int log_test_dropped(struct unit_test_state *uts)
401{
402 /* force LOG not ready */
403 gd->flags &= ~(GD_FLG_LOG_READY);
404 gd->log_drop_count = 0;
405
Heinrich Schuchardt3f700dc2022-07-11 08:21:30 +0200406 log_run();
407 ut_asserteq(2 * (LOGL_COUNT - LOGL_FIRST) +
408 _LOG_MAX_LEVEL - LOGL_FIRST + 1,
409 gd->log_drop_count);
Patrick Delaunay293798c2020-11-27 11:20:58 +0100410 check_log_entries_flags_levels(EXPECT_DEBUG, LOGL_FIRST, CONFIG_LOG_DEFAULT_LEVEL);
Patrick Delaunaycc034972020-11-27 11:20:53 +0100411
412 gd->flags |= GD_FLG_LOG_READY;
413 gd->log_drop_count = 0;
414
415 return 0;
416}
Simon Glass11fcfa32024-08-22 07:57:50 -0600417LOG_TEST_FLAGS(log_test_dropped, UTF_CONSOLE);
Simon Glass7fb97592021-05-08 07:00:06 -0600418
419/* Check log_buffer() */
420int log_test_buffer(struct unit_test_state *uts)
421{
422 u8 *buf;
423 int i;
424
425 buf = malloc(0x20);
426 ut_assertnonnull(buf);
427 memset(buf, '\0', 0x20);
428 for (i = 0; i < 0x11; i++)
429 buf[i] = i * 0x11;
430
Simon Glass7fb97592021-05-08 07:00:06 -0600431 log_buffer(LOGC_BOOT, LOGL_INFO, 0, buf, 1, 0x12, 0);
432
433 /* This one should product no output due to the debug level */
434 log_buffer(LOGC_BOOT, LOGL_DEBUG, 0, buf, 1, 0x12, 0);
435
Simon Glassfa55f422024-08-22 07:54:56 -0600436 ut_assert_nextline(
437 " log_test_buffer() 00000000: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff ..\"3DUfw........");
438 ut_assert_nextline(
439 " log_test_buffer() 00000010: 10 00 ..");
Simon Glass7fb97592021-05-08 07:00:06 -0600440 ut_assert_console_end();
441 free(buf);
442
443 return 0;
444}
Simon Glass11fcfa32024-08-22 07:57:50 -0600445LOG_TEST_FLAGS(log_test_buffer, UTF_CONSOLE);