1 // SPDX-License-Identifier: GPL-2.0+
3 * Logging support test program
5 * Copyright (c) 2017 Google, Inc
6 * Written by Simon Glass <sjg@chromium.org>
11 /* emit some sample log records in different ways, for testing */
12 static int log_run(enum uclass_id cat, const char *file)
17 for (i = LOGL_FIRST; i < LOGL_COUNT; i++) {
18 log(cat, i, "log %d\n", i);
19 _log(log_uc_cat(cat), i, file, 100 + i, "func", "_log %d\n",
26 static int log_test(int testnum)
30 printf("test %d\n", testnum);
33 /* Check a category filter using the first category */
34 enum log_category_t cat_list[] = {
35 log_uc_cat(UCLASS_MMC), log_uc_cat(UCLASS_SPI),
39 ret = log_add_filter("console", cat_list, LOGL_MAX, NULL);
42 log_run(UCLASS_MMC, "file");
43 ret = log_remove_filter("console", ret);
49 /* Check a category filter using the second category */
50 enum log_category_t cat_list[] = {
51 log_uc_cat(UCLASS_MMC), log_uc_cat(UCLASS_SPI), LOGC_END
54 ret = log_add_filter("console", cat_list, LOGL_MAX, NULL);
57 log_run(UCLASS_SPI, "file");
58 ret = log_remove_filter("console", ret);
64 /* Check a category filter that should block log entries */
65 enum log_category_t cat_list[] = {
66 log_uc_cat(UCLASS_MMC), LOGC_NONE, LOGC_END
69 ret = log_add_filter("console", cat_list, LOGL_MAX, NULL);
72 log_run(UCLASS_SPI, "file");
73 ret = log_remove_filter("console", ret);
79 /* Check a passing file filter */
80 ret = log_add_filter("console", NULL, LOGL_MAX, "file");
83 log_run(UCLASS_SPI, "file");
84 ret = log_remove_filter("console", ret);
90 /* Check a failing file filter */
91 ret = log_add_filter("console", NULL, LOGL_MAX, "file");
94 log_run(UCLASS_SPI, "file2");
95 ret = log_remove_filter("console", ret);
101 /* Check a passing file filter (second in list) */
102 ret = log_add_filter("console", NULL, LOGL_MAX, "file,file2");
105 log_run(UCLASS_SPI, "file2");
106 ret = log_remove_filter("console", ret);
112 /* Check a passing file filter */
113 ret = log_add_filter("console", NULL, LOGL_MAX,
114 "file,file2,log/log_test.c");
117 log_run(UCLASS_SPI, "file2");
118 ret = log_remove_filter("console", ret);
124 /* Check a log level filter */
125 ret = log_add_filter("console", NULL, LOGL_WARNING, NULL);
128 log_run(UCLASS_SPI, "file");
129 ret = log_remove_filter("console", ret);
135 /* Check two filters, one of which passes everything */
138 ret = log_add_filter("console", NULL, LOGL_WARNING, NULL);
142 ret = log_add_filter("console", NULL, LOGL_MAX, NULL);
146 log_run(UCLASS_SPI, "file");
147 ret = log_remove_filter("console", filt1);
150 ret = log_remove_filter("console", filt2);
156 /* Check three filters, which together pass everything */
157 int filt1, filt2, filt3;
159 ret = log_add_filter("console", NULL, LOGL_MAX, "file)");
163 ret = log_add_filter("console", NULL, LOGL_MAX, "file2");
167 ret = log_add_filter("console", NULL, LOGL_MAX,
172 log_run(UCLASS_SPI, "file2");
173 ret = log_remove_filter("console", filt1);
176 ret = log_remove_filter("console", filt2);
179 ret = log_remove_filter("console", filt3);
189 #ifdef CONFIG_LOG_TEST
190 int do_log_test(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
196 testnum = simple_strtoul(argv[1], NULL, 10);
198 ret = log_test(testnum);
200 printf("Test failure (err=%d)\n", ret);
202 return ret ? CMD_RET_FAILURE : 0;