[{"id":1769850,"web_url":"http://patchwork.ozlabs.org/comment/1769850/","msgid":"<CAEUhbmWPMaa02j4+oSQ3-hbh0nAYN+YeXs16PQ3JDVyaKcDFoQ@mail.gmail.com>","list_archive_url":null,"date":"2017-09-18T03:47:27","subject":"Re: [U-Boot] [PATCH 09/13] log: Add a test command","submitter":{"id":64981,"url":"http://patchwork.ozlabs.org/api/people/64981/","name":"Bin Meng","email":"bmeng.cn@gmail.com"},"content":"Hi Simon,\n\nOn Sun, Sep 17, 2017 at 5:23 AM, Simon Glass <sjg@chromium.org> wrote:\n> Add a command which exercises the logging system.\n>\n> Signed-off-by: Simon Glass <sjg@chromium.org>\n> ---\n>\n>  cmd/Kconfig         |   3 +-\n>  cmd/log.c           |   6 ++\n>  common/Kconfig      |  10 +++\n>  include/log.h       |   3 +\n>  test/Makefile       |   1 +\n>  test/log/Makefile   |   7 ++\n>  test/log/log_test.c | 204 ++++++++++++++++++++++++++++++++++++++++++++++++++++\n>  7 files changed, 233 insertions(+), 1 deletion(-)\n>  create mode 100644 test/log/Makefile\n>  create mode 100644 test/log/log_test.c\n>\n> diff --git a/cmd/Kconfig b/cmd/Kconfig\n> index 702d4f251f..9d52e4fecc 100644\n> --- a/cmd/Kconfig\n> +++ b/cmd/Kconfig\n> @@ -1483,7 +1483,8 @@ config CMD_LOG\n>         help\n>           This provides access to logging features. It allows the output of\n>           log data to be controlled to a limited extent (setting up the default\n> -         maximum log level for emitting of records).\n> +         maximum log level for emitting of records). It also provides access\n> +         to a command used for testing the log system.\n>\n>  config CMD_TRACE\n>         bool \"trace - Support tracing of function calls and timing\"\n> diff --git a/cmd/log.c b/cmd/log.c\n> index 44e04ab16a..1fc49c4cf2 100644\n> --- a/cmd/log.c\n> +++ b/cmd/log.c\n> @@ -23,6 +23,9 @@ static int do_log_level(cmd_tbl_t *cmdtp, int flag, int argc,\n>\n>  static cmd_tbl_t log_sub[] = {\n>         U_BOOT_CMD_MKENT(level, CONFIG_SYS_MAXARGS, 1, do_log_level, \"\", \"\"),\n> +#ifdef CONFIG_LOG_TEST\n> +       U_BOOT_CMD_MKENT(test, 2, 1, do_log_level, \"\", \"\"),\n\nIt should be \"do_log_test\".\n\n> +#endif\n>  };\n>\n>  static int do_log(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])\n> @@ -46,6 +49,9 @@ static int do_log(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])\n>  #ifdef CONFIG_SYS_LONGHELP\n>  static char log_help_text[] =\n>         \"level - get/set log level\\n\"\n> +#ifdef CONFIG_LOG_TEST\n> +       \"test - run log tests\\n\"\n\nIt should be \"log test\", as U-Boot's command line won't append the\nmain command name except the first one.\n\n> +#endif\n>         ;\n>  #endif\n>\n> diff --git a/common/Kconfig b/common/Kconfig\n> index ba4578e870..57ce2cbe9a 100644\n> --- a/common/Kconfig\n> +++ b/common/Kconfig\n> @@ -458,6 +458,16 @@ config LOG_SPL_CONSOLE\n>           log message is shown - other details like level, category, file and\n>           line number are omitted.\n>\n> +config LOG_TEST\n> +       bool \"Provide a test for logging\"\n> +       depends on LOG\n> +       default y if SANDBOX\n> +       help\n> +         This enables a 'log test' command to test logging. It is normally\n> +         executed from a pytest and simply outputs logging information\n> +         in various different ways to test that the logging system works\n> +         correctly with varoius settings.\n> +\n>  endmenu\n>\n>  config DTB_RESELECT\n> diff --git a/include/log.h b/include/log.h\n> index fb6a196202..f03ed94128 100644\n> --- a/include/log.h\n> +++ b/include/log.h\n> @@ -263,6 +263,9 @@ struct log_filter {\n>  #define LOG_DRIVER(_name) \\\n>         ll_entry_declare(struct log_driver, _name, log_driver)\n>\n> +/* Handle the 'log test' command */\n> +int do_log_test(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]);\n> +\n>  /**\n>   * log_add_filter() - Add a new filter to a log device\n>   *\n> diff --git a/test/Makefile b/test/Makefile\n> index 6305afb211..40f2244b79 100644\n> --- a/test/Makefile\n> +++ b/test/Makefile\n> @@ -10,3 +10,4 @@ obj-$(CONFIG_SANDBOX) += command_ut.o\n>  obj-$(CONFIG_SANDBOX) += compression.o\n>  obj-$(CONFIG_SANDBOX) += print_ut.o\n>  obj-$(CONFIG_UT_TIME) += time_ut.o\n> +obj-$(CONFIG_$(SPL_)LOG) += log/\n> diff --git a/test/log/Makefile b/test/log/Makefile\n> new file mode 100644\n> index 0000000000..b0da8dee28\n> --- /dev/null\n> +++ b/test/log/Makefile\n> @@ -0,0 +1,7 @@\n> +#\n> +# Copyright (c) 2017 Google, Inc\n> +#\n> +# SPDX-License-Identifier:     GPL-2.0+\n> +#\n> +\n> +obj-$(CONFIG_LOG_TEST) += log_test.o\n> diff --git a/test/log/log_test.c b/test/log/log_test.c\n> new file mode 100644\n> index 0000000000..c3d076491f\n> --- /dev/null\n> +++ b/test/log/log_test.c\n> @@ -0,0 +1,204 @@\n> +/*\n> + * Logging support test program\n> + *\n> + * Copyright (c) 2017 Google, Inc\n> + * Written by Simon Glass <sjg@chromium.org>\n> + *\n> + * SPDX-License-Identifier:    GPL-2.0+\n> + */\n> +\n> +#include <common.h>\n> +\n> +/* emit some sample log records in different ways, for testing */\n> +static int log_run(enum log_category_t cat, const char *file)\n> +{\n> +       int i;\n> +\n> +       debug(\"debug\\n\");\n> +       error(\"error\\n\");\n> +       for (i = LOGL_FIRST; i < LOGL_COUNT; i++) {\n> +               log(cat, i, \"log %d\\n\", i);\n> +               _log(cat, i, file, 100 + i, \"func\", \"_log %d\\n\", i);\n> +       }\n> +\n> +       return 0;\n> +}\n> +\n> +static int log_test(int testnum)\n> +{\n> +       int ret;\n> +\n> +       printf(\"test %d\\n\", testnum);\n> +       switch (testnum) {\n> +       case 0: {\n> +               /* Check a category filter using the first category */\n> +               enum log_category_t cat_list[] = {\n> +                       UCLASS_MMC, UCLASS_SPI, LOGC_NONE, LOGC_END\n> +               };\n> +\n> +               ret = log_add_filter(\"console\", cat_list, LOGL_MAX, NULL);\n> +               if (ret < 0)\n> +                       return ret;\n> +               log_run(UCLASS_MMC, \"file\");\n> +               ret = log_remove_filter(\"console\", ret);\n> +               if (ret < 0)\n> +                       return ret;\n> +               break;\n> +       }\n> +       case 1: {\n> +               /* Check a category filter using the second category */\n> +               enum log_category_t cat_list[] = {\n> +                       UCLASS_MMC, UCLASS_SPI, LOGC_END\n> +               };\n> +\n> +               ret = log_add_filter(\"console\", cat_list, LOGL_MAX, NULL);\n> +               if (ret < 0)\n> +                       return ret;\n> +               log_run(UCLASS_SPI, \"file\");\n> +               ret = log_remove_filter(\"console\", ret);\n> +               if (ret < 0)\n> +                       return ret;\n> +               break;\n> +       }\n> +       case 2: {\n> +               /* Check a category filter that should block log entries */\n> +               enum log_category_t cat_list[] = {\n> +                       UCLASS_MMC,  LOGC_NONE, LOGC_END\n> +               };\n> +\n> +               ret = log_add_filter(\"console\", cat_list, LOGL_MAX, NULL);\n> +               if (ret < 0)\n> +                       return ret;\n> +               log_run(UCLASS_SPI, \"file\");\n> +               ret = log_remove_filter(\"console\", ret);\n> +               if (ret < 0)\n> +                       return ret;\n> +               break;\n> +       }\n> +       case 3: {\n> +               /* Check a passing file filter */\n> +               ret = log_add_filter(\"console\", NULL, LOGL_MAX, \"file\");\n> +               if (ret < 0)\n> +                       return ret;\n> +               log_run(UCLASS_SPI, \"file\");\n> +               ret = log_remove_filter(\"console\", ret);\n> +               if (ret < 0)\n> +                       return ret;\n> +               break;\n> +       }\n> +       case 4: {\n> +               /* Check a failing file filter */\n> +               ret = log_add_filter(\"console\", NULL, LOGL_MAX, \"file\");\n> +               if (ret < 0)\n> +                       return ret;\n> +               log_run(UCLASS_SPI, \"file2\");\n> +               ret = log_remove_filter(\"console\", ret);\n> +               if (ret < 0)\n> +                       return ret;\n> +               break;\n> +       }\n> +       case 5: {\n> +               /* Check a passing file filter (second in list) */\n> +               ret = log_add_filter(\"console\", NULL, LOGL_MAX, \"file,file2\");\n> +               if (ret < 0)\n> +                       return ret;\n> +               log_run(UCLASS_SPI, \"file2\");\n> +               ret = log_remove_filter(\"console\", ret);\n> +               if (ret < 0)\n> +                       return ret;\n> +               break;\n> +       }\n> +       case 6: {\n> +               /* Check a passing file filter (also passing error()) */\n> +               ret = log_add_filter(\"console\", NULL, LOGL_MAX,\n> +                                    \"file,file2,log/log_test.c\");\n> +               if (ret < 0)\n> +                       return ret;\n> +               log_run(UCLASS_SPI, \"file2\");\n> +               ret = log_remove_filter(\"console\", ret);\n> +               if (ret < 0)\n> +                       return ret;\n> +               break;\n> +       }\n> +       case 7: {\n> +               /* Check a log level filter */\n> +               ret = log_add_filter(\"console\", NULL, LOGL_WARN, NULL);\n> +               if (ret < 0)\n> +                       return ret;\n> +               log_run(UCLASS_SPI, \"file\");\n> +               ret = log_remove_filter(\"console\", ret);\n> +               if (ret < 0)\n> +                       return ret;\n> +               break;\n> +       }\n> +       case 8: {\n> +               /* Check two filters, one of which passes everything */\n> +               int filt1, filt2;\n> +\n> +               ret = log_add_filter(\"console\", NULL, LOGL_WARN, NULL);\n> +               if (ret < 0)\n> +                       return ret;\n> +               filt1 = ret;\n> +               ret = log_add_filter(\"console\", NULL, LOGL_MAX, NULL);\n> +               if (ret < 0)\n> +                       return ret;\n> +               filt2 = ret;\n> +               log_run(UCLASS_SPI, \"file\");\n> +               ret = log_remove_filter(\"console\", filt1);\n> +               if (ret < 0)\n> +                       return ret;\n> +               ret = log_remove_filter(\"console\", filt2);\n> +               if (ret < 0)\n> +                       return ret;\n> +               break;\n> +       }\n> +       case 9: {\n> +               /* Check three filters, which together pass everything */\n> +               int filt1, filt2, filt3;\n> +\n> +               ret = log_add_filter(\"console\", NULL, LOGL_MAX, \"file)\");\n> +               if (ret < 0)\n> +                       return ret;\n> +               filt1 = ret;\n> +               ret = log_add_filter(\"console\", NULL, LOGL_MAX, \"file2\");\n> +               if (ret < 0)\n> +                       return ret;\n> +               filt2 = ret;\n> +               ret = log_add_filter(\"console\", NULL, LOGL_MAX,\n> +                                    \"log/log_test.c\");\n> +               if (ret < 0)\n> +                       return ret;\n> +               filt3 = ret;\n> +               log_run(UCLASS_SPI, \"file2\");\n> +               ret = log_remove_filter(\"console\", filt1);\n> +               if (ret < 0)\n> +                       return ret;\n> +               ret = log_remove_filter(\"console\", filt2);\n> +               if (ret < 0)\n> +                       return ret;\n> +               ret = log_remove_filter(\"console\", filt3);\n> +               if (ret < 0)\n> +                       return ret;\n> +               break;\n> +       }\n> +       }\n> +\n> +       return 0;\n> +}\n> +\n> +#ifdef CONFIG_LOG_TEST\n> +int do_log_test(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])\n> +{\n> +       int testnum = 0;\n> +       int ret;\n> +\n> +       if (argc > 1)\n> +               testnum = simple_strtoul(argv[1], NULL, 10);\n> +\n> +       ret = log_test(testnum);\n> +       if (ret)\n> +               printf(\"Test failure (err=%d)\\n\", ret);\n> +\n> +       return ret ? CMD_RET_FAILURE : 0;\n> +}\n> +#endif\n> --\n\nRegards,\nBin","headers":{"Return-Path":"<u-boot-bounces@lists.denx.de>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=lists.denx.de\n\t(client-ip=81.169.180.215; helo=lists.denx.de;\n\tenvelope-from=u-boot-bounces@lists.denx.de;\n\treceiver=<UNKNOWN>)","ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"nNJVNW8F\"; dkim-atps=neutral"],"Received":["from lists.denx.de (dione.denx.de [81.169.180.215])\n\tby ozlabs.org (Postfix) with ESMTP id 3xwX5P089yz9rxj\n\tfor <incoming@patchwork.ozlabs.org>;\n\tMon, 18 Sep 2017 13:47:36 +1000 (AEST)","by lists.denx.de (Postfix, from userid 105)\n\tid A676EC21EE5; Mon, 18 Sep 2017 03:47:33 +0000 (UTC)","from lists.denx.de (localhost [IPv6:::1])\n\tby lists.denx.de (Postfix) with ESMTP id C2F60C21D80;\n\tMon, 18 Sep 2017 03:47:29 +0000 (UTC)","by lists.denx.de (Postfix, from userid 105)\n\tid A17AFC21D80; Mon, 18 Sep 2017 03:47:28 +0000 (UTC)","from mail-wm0-f52.google.com (mail-wm0-f52.google.com\n\t[74.125.82.52])\n\tby lists.denx.de (Postfix) with ESMTPS id 39BF9C21D57\n\tfor <u-boot@lists.denx.de>; Mon, 18 Sep 2017 03:47:28 +0000 (UTC)","by mail-wm0-f52.google.com with SMTP id 189so11118799wmh.1\n\tfor <u-boot@lists.denx.de>; Sun, 17 Sep 2017 20:47:28 -0700 (PDT)","by 10.223.145.3 with HTTP; Sun, 17 Sep 2017 20:47:27 -0700 (PDT)"],"X-Spam-Checker-Version":"SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de","X-Spam-Level":"","X-Spam-Status":"No, score=-0.0 required=5.0 tests=FREEMAIL_FROM,\n\tRCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,\n\tT_DKIM_INVALID\n\tautolearn=unavailable autolearn_force=no version=3.4.0","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;\n\th=mime-version:in-reply-to:references:from:date:message-id:subject:to\n\t:cc; bh=HSTXvlTPtZDyiUkhwNVfBRVrZ18V+ZE4PMy72DXpbrE=;\n\tb=nNJVNW8Fr54poA+0fRA1DdLgc1xofvfkMJaU8FR2gqpwOTJCm+QJLynzUWBPOAWMCD\n\tKTnuXa6ll356WQ5z18ILmLD0yRvISCjnT0UJseH8cDL1Nr96Q+1pDx0cm/g0vscyKzDC\n\tL4AJ4Qp6LvQeA0DD50HFRQX4seS9s0jGRlWd1aSSvbGrYEeIAWxUKAHrdhw2ne1eGtbs\n\tEe5ATbt17MBkQubZpwoTn2aPJB0luQVZzLMsHjS1En0qs1ahsRqOHBCJ4i6BpHTCxMVN\n\tekQXrVsAUzjQ01TNeXshStQr8iOXzfitLlInRA8HQJuBWgwqRLJnj2op4KW8Xo2VMxR4\n\tOZnQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:mime-version:in-reply-to:references:from:date\n\t:message-id:subject:to:cc;\n\tbh=HSTXvlTPtZDyiUkhwNVfBRVrZ18V+ZE4PMy72DXpbrE=;\n\tb=LvVFoHaQKJef3F+mTlmxqjFqvshNarIPxh9p/0I4oGDXmA6IDEQQiCtTImi0aE8vvZ\n\t7qoDCxbKYch9gP23JRGSmtA1cA6dx8/J6FQ1eFcG+alnsxwolt1zoppW5XnjFXJJ6Amh\n\t2CS2FguY+imzE5Lnwt80B3SgVEIGt1Kkt2EpxQsVeaFa6kBwBlXKyMa87pBv8sD1vQsP\n\tKbL7re/30+684QvlRx9NteDl39uRXHWwY1QLo9XkNLgKkwPKH1SKOmED8TQH9NXh0fWM\n\td6RXK6RKMTM1D74jAd5e1wrxRWztiecEUqVFnAjbWkhvzP4R1BxygO5/DRSxHiL7vcOO\n\tl+cw==","X-Gm-Message-State":"AHPjjUiEEhExVLmJnliIrASmopellA7OoB6/XwYHFMF0bZGBXdV8cRmj\n\t7Kz6/CnNdAkR6HH4ctjGmI9lRZDvrARF28STQBA=","X-Google-Smtp-Source":"AOwi7QBP61Jsmr+GIxy0Wp5fRzdlxrB4xtxWMqcHAH+T4bCBH4Q+dY9vbclDzvIWl4Lvv8HuF45ORfvCLRE+YKmRrS0=","X-Received":"by 10.28.64.6 with SMTP id n6mr8308667wma.61.1505706447838; Sun,\n\t17 Sep 2017 20:47:27 -0700 (PDT)","MIME-Version":"1.0","In-Reply-To":"<20170916212331.170463-10-sjg@chromium.org>","References":"<20170916212331.170463-1-sjg@chromium.org>\n\t<20170916212331.170463-10-sjg@chromium.org>","From":"Bin Meng <bmeng.cn@gmail.com>","Date":"Mon, 18 Sep 2017 11:47:27 +0800","Message-ID":"<CAEUhbmWPMaa02j4+oSQ3-hbh0nAYN+YeXs16PQ3JDVyaKcDFoQ@mail.gmail.com>","To":"Simon Glass <sjg@chromium.org>","Cc":"Tom Rini <trini@konsulko.com>, U-Boot Mailing List <u-boot@lists.denx.de>,\n\tMaxime Ripard <maxime.ripard@free-electrons.com>,\n\tJagan Teki <jagan@openedev.com>","Subject":"Re: [U-Boot] [PATCH 09/13] log: Add a test command","X-BeenThere":"u-boot@lists.denx.de","X-Mailman-Version":"2.1.18","Precedence":"list","List-Id":"U-Boot discussion <u-boot.lists.denx.de>","List-Unsubscribe":"<https://lists.denx.de/options/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=unsubscribe>","List-Archive":"<http://lists.denx.de/pipermail/u-boot/>","List-Post":"<mailto:u-boot@lists.denx.de>","List-Help":"<mailto:u-boot-request@lists.denx.de?subject=help>","List-Subscribe":"<https://lists.denx.de/listinfo/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=subscribe>","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"u-boot-bounces@lists.denx.de","Sender":"\"U-Boot\" <u-boot-bounces@lists.denx.de>"}}]