All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bin Meng <bmeng.cn@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 09/13] log: Add a test command
Date: Mon, 18 Sep 2017 11:47:27 +0800	[thread overview]
Message-ID: <CAEUhbmWPMaa02j4+oSQ3-hbh0nAYN+YeXs16PQ3JDVyaKcDFoQ@mail.gmail.com> (raw)
In-Reply-To: <20170916212331.170463-10-sjg@chromium.org>

Hi Simon,

On Sun, Sep 17, 2017 at 5:23 AM, Simon Glass <sjg@chromium.org> wrote:
> Add a command which exercises the logging system.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  cmd/Kconfig         |   3 +-
>  cmd/log.c           |   6 ++
>  common/Kconfig      |  10 +++
>  include/log.h       |   3 +
>  test/Makefile       |   1 +
>  test/log/Makefile   |   7 ++
>  test/log/log_test.c | 204 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  7 files changed, 233 insertions(+), 1 deletion(-)
>  create mode 100644 test/log/Makefile
>  create mode 100644 test/log/log_test.c
>
> diff --git a/cmd/Kconfig b/cmd/Kconfig
> index 702d4f251f..9d52e4fecc 100644
> --- a/cmd/Kconfig
> +++ b/cmd/Kconfig
> @@ -1483,7 +1483,8 @@ config CMD_LOG
>         help
>           This provides access to logging features. It allows the output of
>           log data to be controlled to a limited extent (setting up the default
> -         maximum log level for emitting of records).
> +         maximum log level for emitting of records). It also provides access
> +         to a command used for testing the log system.
>
>  config CMD_TRACE
>         bool "trace - Support tracing of function calls and timing"
> diff --git a/cmd/log.c b/cmd/log.c
> index 44e04ab16a..1fc49c4cf2 100644
> --- a/cmd/log.c
> +++ b/cmd/log.c
> @@ -23,6 +23,9 @@ static int do_log_level(cmd_tbl_t *cmdtp, int flag, int argc,
>
>  static cmd_tbl_t log_sub[] = {
>         U_BOOT_CMD_MKENT(level, CONFIG_SYS_MAXARGS, 1, do_log_level, "", ""),
> +#ifdef CONFIG_LOG_TEST
> +       U_BOOT_CMD_MKENT(test, 2, 1, do_log_level, "", ""),

It should be "do_log_test".

> +#endif
>  };
>
>  static int do_log(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
> @@ -46,6 +49,9 @@ static int do_log(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
>  #ifdef CONFIG_SYS_LONGHELP
>  static char log_help_text[] =
>         "level - get/set log level\n"
> +#ifdef CONFIG_LOG_TEST
> +       "test - run log tests\n"

It should be "log test", as U-Boot's command line won't append the
main command name except the first one.

> +#endif
>         ;
>  #endif
>
> diff --git a/common/Kconfig b/common/Kconfig
> index ba4578e870..57ce2cbe9a 100644
> --- a/common/Kconfig
> +++ b/common/Kconfig
> @@ -458,6 +458,16 @@ config LOG_SPL_CONSOLE
>           log message is shown - other details like level, category, file and
>           line number are omitted.
>
> +config LOG_TEST
> +       bool "Provide a test for logging"
> +       depends on LOG
> +       default y if SANDBOX
> +       help
> +         This enables a 'log test' command to test logging. It is normally
> +         executed from a pytest and simply outputs logging information
> +         in various different ways to test that the logging system works
> +         correctly with varoius settings.
> +
>  endmenu
>
>  config DTB_RESELECT
> diff --git a/include/log.h b/include/log.h
> index fb6a196202..f03ed94128 100644
> --- a/include/log.h
> +++ b/include/log.h
> @@ -263,6 +263,9 @@ struct log_filter {
>  #define LOG_DRIVER(_name) \
>         ll_entry_declare(struct log_driver, _name, log_driver)
>
> +/* Handle the 'log test' command */
> +int do_log_test(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]);
> +
>  /**
>   * log_add_filter() - Add a new filter to a log device
>   *
> diff --git a/test/Makefile b/test/Makefile
> index 6305afb211..40f2244b79 100644
> --- a/test/Makefile
> +++ b/test/Makefile
> @@ -10,3 +10,4 @@ obj-$(CONFIG_SANDBOX) += command_ut.o
>  obj-$(CONFIG_SANDBOX) += compression.o
>  obj-$(CONFIG_SANDBOX) += print_ut.o
>  obj-$(CONFIG_UT_TIME) += time_ut.o
> +obj-$(CONFIG_$(SPL_)LOG) += log/
> diff --git a/test/log/Makefile b/test/log/Makefile
> new file mode 100644
> index 0000000000..b0da8dee28
> --- /dev/null
> +++ b/test/log/Makefile
> @@ -0,0 +1,7 @@
> +#
> +# Copyright (c) 2017 Google, Inc
> +#
> +# SPDX-License-Identifier:     GPL-2.0+
> +#
> +
> +obj-$(CONFIG_LOG_TEST) += log_test.o
> diff --git a/test/log/log_test.c b/test/log/log_test.c
> new file mode 100644
> index 0000000000..c3d076491f
> --- /dev/null
> +++ b/test/log/log_test.c
> @@ -0,0 +1,204 @@
> +/*
> + * Logging support test program
> + *
> + * Copyright (c) 2017 Google, Inc
> + * Written by Simon Glass <sjg@chromium.org>
> + *
> + * SPDX-License-Identifier:    GPL-2.0+
> + */
> +
> +#include <common.h>
> +
> +/* emit some sample log records in different ways, for testing */
> +static int log_run(enum log_category_t cat, const char *file)
> +{
> +       int i;
> +
> +       debug("debug\n");
> +       error("error\n");
> +       for (i = LOGL_FIRST; i < LOGL_COUNT; i++) {
> +               log(cat, i, "log %d\n", i);
> +               _log(cat, i, file, 100 + i, "func", "_log %d\n", i);
> +       }
> +
> +       return 0;
> +}
> +
> +static int log_test(int testnum)
> +{
> +       int ret;
> +
> +       printf("test %d\n", testnum);
> +       switch (testnum) {
> +       case 0: {
> +               /* Check a category filter using the first category */
> +               enum log_category_t cat_list[] = {
> +                       UCLASS_MMC, 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[] = {
> +                       UCLASS_MMC, 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[] = {
> +                       UCLASS_MMC,  LOGC_NONE, 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 3: {
> +               /* Check a passing file filter */
> +               ret = log_add_filter("console", NULL, LOGL_MAX, "file");
> +               if (ret < 0)
> +                       return ret;
> +               log_run(UCLASS_SPI, "file");
> +               ret = log_remove_filter("console", ret);
> +               if (ret < 0)
> +                       return ret;
> +               break;
> +       }
> +       case 4: {
> +               /* Check a failing file filter */
> +               ret = log_add_filter("console", NULL, LOGL_MAX, "file");
> +               if (ret < 0)
> +                       return ret;
> +               log_run(UCLASS_SPI, "file2");
> +               ret = log_remove_filter("console", ret);
> +               if (ret < 0)
> +                       return ret;
> +               break;
> +       }
> +       case 5: {
> +               /* Check a passing file filter (second in list) */
> +               ret = log_add_filter("console", NULL, LOGL_MAX, "file,file2");
> +               if (ret < 0)
> +                       return ret;
> +               log_run(UCLASS_SPI, "file2");
> +               ret = log_remove_filter("console", ret);
> +               if (ret < 0)
> +                       return ret;
> +               break;
> +       }
> +       case 6: {
> +               /* Check a passing file filter (also passing error()) */
> +               ret = log_add_filter("console", NULL, LOGL_MAX,
> +                                    "file,file2,log/log_test.c");
> +               if (ret < 0)
> +                       return ret;
> +               log_run(UCLASS_SPI, "file2");
> +               ret = log_remove_filter("console", ret);
> +               if (ret < 0)
> +                       return ret;
> +               break;
> +       }
> +       case 7: {
> +               /* Check a log level filter */
> +               ret = log_add_filter("console", NULL, LOGL_WARN, NULL);
> +               if (ret < 0)
> +                       return ret;
> +               log_run(UCLASS_SPI, "file");
> +               ret = log_remove_filter("console", ret);
> +               if (ret < 0)
> +                       return ret;
> +               break;
> +       }
> +       case 8: {
> +               /* Check two filters, one of which passes everything */
> +               int filt1, filt2;
> +
> +               ret = log_add_filter("console", NULL, LOGL_WARN, NULL);
> +               if (ret < 0)
> +                       return ret;
> +               filt1 = ret;
> +               ret = log_add_filter("console", NULL, LOGL_MAX, NULL);
> +               if (ret < 0)
> +                       return ret;
> +               filt2 = ret;
> +               log_run(UCLASS_SPI, "file");
> +               ret = log_remove_filter("console", filt1);
> +               if (ret < 0)
> +                       return ret;
> +               ret = log_remove_filter("console", filt2);
> +               if (ret < 0)
> +                       return ret;
> +               break;
> +       }
> +       case 9: {
> +               /* Check three filters, which together pass everything */
> +               int filt1, filt2, filt3;
> +
> +               ret = log_add_filter("console", NULL, LOGL_MAX, "file)");
> +               if (ret < 0)
> +                       return ret;
> +               filt1 = ret;
> +               ret = log_add_filter("console", NULL, LOGL_MAX, "file2");
> +               if (ret < 0)
> +                       return ret;
> +               filt2 = ret;
> +               ret = log_add_filter("console", NULL, LOGL_MAX,
> +                                    "log/log_test.c");
> +               if (ret < 0)
> +                       return ret;
> +               filt3 = ret;
> +               log_run(UCLASS_SPI, "file2");
> +               ret = log_remove_filter("console", filt1);
> +               if (ret < 0)
> +                       return ret;
> +               ret = log_remove_filter("console", filt2);
> +               if (ret < 0)
> +                       return ret;
> +               ret = log_remove_filter("console", filt3);
> +               if (ret < 0)
> +                       return ret;
> +               break;
> +       }
> +       }
> +
> +       return 0;
> +}
> +
> +#ifdef CONFIG_LOG_TEST
> +int do_log_test(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
> +{
> +       int testnum = 0;
> +       int ret;
> +
> +       if (argc > 1)
> +               testnum = simple_strtoul(argv[1], NULL, 10);
> +
> +       ret = log_test(testnum);
> +       if (ret)
> +               printf("Test failure (err=%d)\n", ret);
> +
> +       return ret ? CMD_RET_FAILURE : 0;
> +}
> +#endif
> --

Regards,
Bin

  reply	other threads:[~2017-09-18  3:47 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-16 21:23 [U-Boot] [PATCH 00/13] log: Add a new logging feature Simon Glass
2017-09-16 21:23 ` [U-Boot] [PATCH 01/13] Revert "sandbox: remove os_putc() and os_puts()" Simon Glass
2017-09-17 12:48   ` Bin Meng
2017-09-17 17:55     ` Simon Glass
2017-09-16 21:23 ` [U-Boot] [PATCH 02/13] Revert "sandbox: Drop special case console code for sandbox" Simon Glass
2017-09-17 12:50   ` Bin Meng
2017-09-17 17:55     ` Simon Glass
2017-09-16 21:23 ` [U-Boot] [PATCH 03/13] Move debug and logging support to a separate header Simon Glass
2017-09-17 12:52   ` Bin Meng
2017-09-16 21:23 ` [U-Boot] [PATCH 04/13] mtdparts: Correct use of debug() Simon Glass
2017-09-17 12:54   ` Bin Meng
2017-09-16 21:23 ` [U-Boot] [PATCH 05/13] Drop the log buffer Simon Glass
2017-09-17 12:58   ` Bin Meng
2017-09-16 21:23 ` [U-Boot] [PATCH 06/13] log: Add an implemention of logging Simon Glass
2017-09-18  3:45   ` Bin Meng
2017-09-20 13:50     ` Simon Glass
2017-09-20 14:41       ` Bin Meng
2017-09-20 14:51         ` Dr. Philipp Tomsich
2017-09-21  4:58         ` Simon Glass
2017-09-22 13:37           ` Bin Meng
2017-09-25  2:14             ` Simon Glass
2017-09-20  2:51   ` Masahiro Yamada
2017-09-20 13:49     ` Simon Glass
2017-09-20 14:37       ` Dr. Philipp Tomsich
2017-09-20 17:34         ` Masahiro Yamada
2017-09-20 17:51           ` Dr. Philipp Tomsich
2017-09-27 16:19             ` Masahiro Yamada
2017-09-20 17:19       ` Masahiro Yamada
2017-09-26 19:10         ` Simon Glass
2017-09-27 17:11           ` Masahiro Yamada
2017-09-28 12:39             ` Simon Glass
2017-09-16 21:23 ` [U-Boot] [PATCH 07/13] log: Add a console driver Simon Glass
2017-09-18  3:45   ` Bin Meng
2017-09-26 19:10     ` Simon Glass
2017-09-16 21:23 ` [U-Boot] [PATCH 08/13] log: Add a 'log level' command Simon Glass
2017-09-18  3:46   ` Bin Meng
2017-09-16 21:23 ` [U-Boot] [PATCH 09/13] log: Add a test command Simon Glass
2017-09-18  3:47   ` Bin Meng [this message]
2017-09-16 21:23 ` [U-Boot] [PATCH 10/13] log: Plumb logging into the init sequence Simon Glass
2017-09-18  3:47   ` Bin Meng
2017-09-16 21:23 ` [U-Boot] [PATCH 11/13] log: sandbox: Enable logging Simon Glass
2017-09-18  3:47   ` Bin Meng
2017-09-16 21:23 ` [U-Boot] [PATCH 12/13] log: test: Add a pytest for logging Simon Glass
2017-09-16 21:23 ` [U-Boot] [PATCH 13/13] log: Add documentation Simon Glass
2017-09-18  3:47   ` Bin Meng
2017-09-20  3:04   ` Masahiro Yamada
2017-09-20 13:49     ` Simon Glass
2017-09-20  2:32 ` [U-Boot] [PATCH 00/13] log: Add a new logging feature Masahiro Yamada
2017-09-20 20:20   ` Heinrich Schuchardt
2017-09-21  4:58     ` Simon Glass
2017-09-20 19:55 ` Wolfgang Denk
2017-09-21  4:58   ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAEUhbmWPMaa02j4+oSQ3-hbh0nAYN+YeXs16PQ3JDVyaKcDFoQ@mail.gmail.com \
    --to=bmeng.cn@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.