Re: [PATCH v4 08/22] test: log: Convert log_test from python to C

2020-10-30 Thread Tom Rini
On Tue, Oct 27, 2020 at 07:55:27PM -0400, Sean Anderson wrote:

> When rebasing this series I had to renumber all my log tests because
> someone made another log test in the meantime. This involved updaing a
> number in several places (C and python), and it wasn't checked by the
> compiler. So I though "how hard could it be to just rewrite in C?" And
> though it wasn't hard, it *was* tedious. Tests are numbered the same as
> before to allow for easier review.
> 
> A note that if a test fails, everything after it will probably also fail.
> This is because that test won't clean up its filters.  There's no easy way
> to do the cleanup, except perhaps removing all filters in a wrapper
> function.
> 
> Signed-off-by: Sean Anderson 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


[PATCH v4 08/22] test: log: Convert log_test from python to C

2020-10-27 Thread Sean Anderson
When rebasing this series I had to renumber all my log tests because
someone made another log test in the meantime. This involved updaing a
number in several places (C and python), and it wasn't checked by the
compiler. So I though "how hard could it be to just rewrite in C?" And
though it wasn't hard, it *was* tedious. Tests are numbered the same as
before to allow for easier review.

A note that if a test fails, everything after it will probably also fail.
This is because that test won't clean up its filters.  There's no easy way
to do the cleanup, except perhaps removing all filters in a wrapper
function.

Signed-off-by: Sean Anderson 
---

(no changes since v3)

Changes in v3:
- New

 cmd/log.c |   6 -
 include/test/log.h|   2 +
 test/log/log_test.c   | 446 ++
 test/log/syslog_test.h|   2 -
 test/py/tests/test_log.py | 104 -
 5 files changed, 260 insertions(+), 300 deletions(-)

diff --git a/cmd/log.c b/cmd/log.c
index 16a6ef7539..d20bfdf744 100644
--- a/cmd/log.c
+++ b/cmd/log.c
@@ -105,9 +105,6 @@ static int do_log_rec(struct cmd_tbl *cmdtp, int flag, int 
argc,
 
 static struct cmd_tbl log_sub[] = {
U_BOOT_CMD_MKENT(level, CONFIG_SYS_MAXARGS, 1, do_log_level, "", ""),
-#if CONFIG_IS_ENABLED(LOG_TEST)
-   U_BOOT_CMD_MKENT(test, 2, 1, do_log_test, "", ""),
-#endif
U_BOOT_CMD_MKENT(format, CONFIG_SYS_MAXARGS, 1, do_log_format, "", ""),
U_BOOT_CMD_MKENT(rec, CONFIG_SYS_MAXARGS, 1, do_log_rec, "", ""),
 };
@@ -133,9 +130,6 @@ static int do_log(struct cmd_tbl *cmdtp, int flag, int 
argc, char *const argv[])
 #ifdef CONFIG_SYS_LONGHELP
 static char log_help_text[] =
"level - get/set log level\n"
-#if CONFIG_IS_ENABLED(LOG_TEST)
-   "log test - run log tests\n"
-#endif
"log format  - set log output format.  is a string where\n"
"\teach letter indicates something that should be displayed:\n"
"\tc=category, l=level, F=file, L=line number, f=function, m=msg\n"
diff --git a/include/test/log.h b/include/test/log.h
index c661cde75a..772e197806 100644
--- a/include/test/log.h
+++ b/include/test/log.h
@@ -10,6 +10,8 @@
 
 #include 
 
+#define LOGF_TEST (BIT(LOGF_FUNC) | BIT(LOGF_MSG))
+
 /* Declare a new logging test */
 #define LOG_TEST(_name) UNIT_TEST(_name, 0, log_test)
 
diff --git a/test/log/log_test.c b/test/log/log_test.c
index 6a60ff6be3..c5ca6dcb7a 100644
--- a/test/log/log_test.c
+++ b/test/log/log_test.c
@@ -9,12 +9,17 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+
+DECLARE_GLOBAL_DATA_PTR;
 
 /* emit some sample log records in different ways, for testing */
-static int log_run(enum uclass_id cat, const char *file)
+static int do_log_run(int cat, const char *file)
 {
int i;
 
+   gd->log_fmt = LOGF_TEST;
debug("debug\n");
for (i = LOGL_FIRST; i < LOGL_COUNT; i++) {
log(cat, i, "log %d\n", i);
@@ -22,203 +27,268 @@ static int log_run(enum uclass_id cat, const char *file)
 i);
}
 
+   gd->log_fmt = log_get_default_format();
return 0;
 }
 
-static int log_test(int testnum)
+#define log_run_cat(cat) do_log_run(cat, "file")
+#define log_run_file(file) do_log_run(UCLASS_SPI, file)
+#define log_run() do_log_run(UCLASS_SPI, "file")
+
+#define EXPECT_LOG BIT(0)
+#define EXPECT_DIRECT BIT(1)
+#define EXPECT_EXTRA BIT(2)
+
+static int do_check_log_entries(struct unit_test_state *uts, int flags, int 
min,
+   int max)
 {
-   int ret;
+   int i;
 
-   printf("test %d\n", testnum);
-   switch (testnum) {
-   case 0: {
-   /* Check a category filter using the first category */
-   enum log_category_t cat_list[] = {
-   log_uc_cat(UCLASS_MMC), log_uc_cat(UCLASS_SPI),
-   LOGC_NONE, LOGC_END
-   };
-
-   ret = log_add_filter("console", cat_list, LOGL_MAX, NULL);
-   if (ret < 0)
-   return ret;
-   log_run(UCLASS_MMC, "file");
-   ret = log_remove_filter("console", ret);
-   if (ret < 0)
-   return ret;
-   break;
-   }
-   case 1: {
-   /* Check a category filter using the second category */
-   enum log_category_t cat_list[] = {
-   log_uc_cat(UCLASS_MMC), log_uc_cat(UCLASS_SPI), LOGC_END
-   };
-
-   ret = log_add_filter("console", cat_list, LOGL_MAX, NULL);
-   if (ret < 0)
-   return ret;
-   log_run(UCLASS_SPI, "file");
-   ret = log_remove_filter("console", ret);
-   if (ret < 0)
-   return ret;
-   break;
-   }
-   case 2: {
-   /* Check a category filter that should block log entries */
-   enum log_category_t cat_list[] = {
-