From patchwork Sat May 8 15:30:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1475892 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=gTnnj/iV; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FcrrB1bS6z9vFY for ; Sun, 9 May 2021 01:31:06 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CF66782E7A; Sat, 8 May 2021 17:30:54 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="gTnnj/iV"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8171C82D58; Sat, 8 May 2021 17:30:53 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x12e.google.com (mail-il1-x12e.google.com [IPv6:2607:f8b0:4864:20::12e]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 6782A82D58 for ; Sat, 8 May 2021 17:30:50 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x12e.google.com with SMTP id m7so950535ilg.9 for ; Sat, 08 May 2021 08:30:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0bKoUDV/mwGsRk27mWPKSdtPkHi4EBMs10LjnM+Jig0=; b=gTnnj/iV037PBe23XlDRXR88FUtz8tWKbDcwWrUYxO5dOLb++WEIBeZxuSghK5OIxf wOhGkIkzM0nMOKwXBVv4iwjpIG6DAXbA4Yk65UWIILQwQYYIV7NGCVOw2zsCB+569Ho4 SLD1+ape23sl7emlUtWfU59vulyOCvISC9Jp4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0bKoUDV/mwGsRk27mWPKSdtPkHi4EBMs10LjnM+Jig0=; b=aavJOV777QMQzGC4h4Q+kf07QX82C9EsiNQWeLO7IrGc88bI5Vd6viFxrX+GzWqzej prrdHPnNRxM7HZgErqWv8dgUyX3TzvEZLDb+CP+8AWby5NvmPPxR4fnBE939HBMEwhkv IoZsa/XkLO4F7oArii0NDacKYYXjPbHKQNlairOxsEZa2tsMN61qfX1x/Z0xyjFTBoIS RGUwedM5CMWw8FPPbZiI1jE/GzFnwedyOitFPnq6eJfz4xGkvtnqcLCgisj6lwj3yo3C cHrZoPvknn/MAIQSOAWZN5wDLomz+UOnw8xRHo0xWjIHbDf9eGAWvu+oJBAU1ZrkKWFC BrVg== X-Gm-Message-State: AOAM530LnwVLkmDdDfVG+bweuOq5yGdiyR2LQX+B4SAxu79LOmNJHgXG F0gd2jm6n+fSE5rf77pg348KGhZePFDf5IU8 X-Google-Smtp-Source: ABdhPJxxJxoMLJoxySLCrSlf77n5edf3SrJI6emUWkVHIUVycXk7t/ylMnIwx6EMeiNZcp+MWJoYiA== X-Received: by 2002:a05:6e02:e82:: with SMTP id t2mr4730934ilj.18.1620487848850; Sat, 08 May 2021 08:30:48 -0700 (PDT) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id t8sm1947496ilj.56.2021.05.08.08.30.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 May 2021 08:30:48 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Heinrich Schuchardt , Simon Glass Subject: [PATCH v3 1/2] sandbox: log: Avoid build error with !CONFIG_LOG Date: Sat, 8 May 2021 09:30:42 -0600 Message-Id: <20210508153043.1728019-2-sjg@chromium.org> X-Mailer: git-send-email 2.31.1.607.g51e8a6a459-goog In-Reply-To: <20210508153043.1728019-1-sjg@chromium.org> References: <20210508153043.1728019-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.4 at phobos.denx.de X-Virus-Status: Clean The pr_cont_test.c test requires CONFIG_LOG since it directly accesses fields in global_data that require it. Move the test into the CONFIG_LOG condition to avoid build errors. Enable CONFIG_LOG on sandbox (not sandbox_spl, etc.) so that we still run this test. This requires resyncing of the configs. Signed-off-by: Simon Glass --- (no changes since v1) configs/sandbox_defconfig | 1 + test/log/Makefile | 1 + 2 files changed, 2 insertions(+) diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index bdbf714e2bd..60cdad10848 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -21,6 +21,7 @@ CONFIG_BOOTSTAGE_STASH_SIZE=0x4096 CONFIG_CONSOLE_RECORD=y CONFIG_CONSOLE_RECORD_OUT_SIZE=0x1000 CONFIG_PRE_CONSOLE_BUFFER=y +CONFIG_LOG=y CONFIG_DISPLAY_BOARDINFO_LATE=y CONFIG_MISC_INIT_F=y CONFIG_STACKPROTECTOR=y diff --git a/test/log/Makefile b/test/log/Makefile index a3dedace043..09f8689d070 100644 --- a/test/log/Makefile +++ b/test/log/Makefile @@ -17,6 +17,7 @@ endif ifdef CONFIG_LOG obj-y += pr_cont_test.o obj-$(CONFIG_CONSOLE_RECORD) += cont_test.o +obj-y += pr_cont_test.o else obj-$(CONFIG_CONSOLE_RECORD) += nolog_test.o endif From patchwork Sat May 8 15:30:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1475893 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=VjT/i0rd; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FcrrL3cnXz9vFc for ; Sun, 9 May 2021 01:31:14 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 24F3D82E7D; Sat, 8 May 2021 17:30:58 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="VjT/i0rd"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 41A6382E7E; Sat, 8 May 2021 17:30:56 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3388782CDB for ; Sat, 8 May 2021 17:30:52 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd2b.google.com with SMTP id n10so10756671ion.8 for ; Sat, 08 May 2021 08:30:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/sCf6iQelZzBAZDNdVig5/BAu8+mCZ7BGn5xxhQcKXE=; b=VjT/i0rdMR5TOaF5Wk46+/l5eq2FTZbRlp6+nQBl+TrZg4iJjaG5xe1DZh0iKQ+sZr Ou2VSyEudcbcoFr3jUwr4+gZDVNwSklfW1cBGQLd2A3Asuv6z9jvZxetZmh8e95L5c8S tT1qMh4PgYHOemU0pM0fQWMk+27bFU8NldXSU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/sCf6iQelZzBAZDNdVig5/BAu8+mCZ7BGn5xxhQcKXE=; b=K9FZHSH9mqWxZOzEF21c2O61LuLOwqtGZ4Ykc0gbAnRcx6YW4CFykC6ueNInaytwEz +3LNVTx+XSIJ2khMleTVrbjgcBW16K2q2GvlVKfK+02QUsBa6mxo3VkS9khg5rXEX4YI aAZdxtd7wwLbbu3RmOP2hrvGrtDRbPCwwZlY4yTSYUUbKUY2pJ3nsNxGoIFuz4qpFqEu NCDG6G1TgsVh8KsUEe7E6Ufs8tUIqsyDdOUJmrTF7AQuyaGwftAW9m3mYk5QGXfRovlZ JN9i4c2WvrfpvKBLwetVpuvgxqcgKq2OlKUjoKzcWQy+HhgZ7TiB0XxXWSc8lVyR+ZZj LzJg== X-Gm-Message-State: AOAM530lXGNHA+oSOAx1FSiFwptub7at+oUEvdEoONeck3gNi6bo9dFK ku3bpJmg8oWc4abyxpyZpaa6ZS2wg86pB78Z X-Google-Smtp-Source: ABdhPJzEPfmXX/Aww9PfIS8YkYSSWBzCUO/24/N6O/oeuUBY/GG7kKRbluN2s/UQPMraMWrN9Bk4hQ== X-Received: by 2002:a02:854a:: with SMTP id g68mr13668858jai.56.1620487850725; Sat, 08 May 2021 08:30:50 -0700 (PDT) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id t8sm1947496ilj.56.2021.05.08.08.30.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 May 2021 08:30:50 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Heinrich Schuchardt , Simon Glass Subject: [PATCH v3 2/2] log: Convert log values to printf() if not enabled Date: Sat, 8 May 2021 09:30:43 -0600 Message-Id: <20210508093040.v3.2.I798add6e0dde4cf424464017d453ea635f06e198@changeid> X-Mailer: git-send-email 2.31.1.607.g51e8a6a459-goog In-Reply-To: <20210508153043.1728019-1-sjg@chromium.org> References: <20210508153043.1728019-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.4 at phobos.denx.de X-Virus-Status: Clean At present if logging not enabled, log_info() becomes a nop. But we want log output at the 'info' level to be akin to printf(). Update the macro to pass the output straight to printf() in this case. This mimics the behaviour for the log_...() macros like log_debug() and log_info(), so we can drop the special case for these. Add new tests to cover this case. Signed-off-by: Simon Glass --- Changes in v3: - Rebase on hexdump series http://patchwork.ozlabs.org/project/uboot/list/?series=242818 Changes in v2: - Update commit message and cover letter to mention log_...() macros - Add a test for !CONFIG_LOG - Update log() to (effectively) call debug() for log_level == LOGL_DEBUG doc/develop/logging.rst | 6 ++++-- include/log.h | 34 +++++++++++++++------------------- test/log/Makefile | 1 + test/log/nolog_ndebug.c | 38 ++++++++++++++++++++++++++++++++++++++ test/log/nolog_test.c | 3 +++ 5 files changed, 61 insertions(+), 21 deletions(-) create mode 100644 test/log/nolog_ndebug.c diff --git a/doc/develop/logging.rst b/doc/develop/logging.rst index f4e925048e8..51095b05ba9 100644 --- a/doc/develop/logging.rst +++ b/doc/develop/logging.rst @@ -52,6 +52,10 @@ If CONFIG_LOG is not set, then no logging will be available. The above have SPL and TPL versions also, e.g. CONFIG_SPL_LOG_MAX_LEVEL and CONFIG_TPL_LOG_MAX_LEVEL. +If logging is disabled, the default behaviour is to output any message at +level LOGL_INFO and below. If logging is disabled and DEBUG is defined (at +the very top of a C file) then any message at LOGL_DEBUG will be written. + Temporary logging within a single file -------------------------------------- @@ -291,8 +295,6 @@ More logging destinations: Convert debug() statements in the code to log() statements -Support making printf() emit log statements at L_INFO level - Convert error() statements in the code to log() statements Figure out what to do with BUG(), BUG_ON() and warn_non_spl() diff --git a/include/log.h b/include/log.h index feb0204855a..e0e12ce1944 100644 --- a/include/log.h +++ b/include/log.h @@ -174,6 +174,10 @@ int _log_buffer(enum log_category_t cat, enum log_level_t level, */ #if CONFIG_IS_ENABLED(LOG) #define _LOG_MAX_LEVEL CONFIG_VAL(LOG_MAX_LEVEL) +#else +#define _LOG_MAX_LEVEL LOGL_INFO +#endif + #define log_emer(_fmt...) log(LOG_CATEGORY, LOGL_EMERG, ##_fmt) #define log_alert(_fmt...) log(LOG_CATEGORY, LOGL_ALERT, ##_fmt) #define log_crit(_fmt...) log(LOG_CATEGORY, LOGL_CRIT, ##_fmt) @@ -185,34 +189,19 @@ int _log_buffer(enum log_category_t cat, enum log_level_t level, #define log_content(_fmt...) log(LOG_CATEGORY, LOGL_DEBUG_CONTENT, ##_fmt) #define log_io(_fmt...) log(LOG_CATEGORY, LOGL_DEBUG_IO, ##_fmt) #define log_cont(_fmt...) log(LOGC_CONT, LOGL_CONT, ##_fmt) -#else -#define _LOG_MAX_LEVEL LOGL_INFO -#define log_emerg(_fmt, ...) printf(_fmt, ##__VA_ARGS__) -#define log_alert(_fmt, ...) printf(_fmt, ##__VA_ARGS__) -#define log_crit(_fmt, ...) printf(_fmt, ##__VA_ARGS__) -#define log_err(_fmt, ...) printf(_fmt, ##__VA_ARGS__) -#define log_warning(_fmt, ...) printf(_fmt, ##__VA_ARGS__) -#define log_notice(_fmt, ...) printf(_fmt, ##__VA_ARGS__) -#define log_info(_fmt, ...) printf(_fmt, ##__VA_ARGS__) -#define log_cont(_fmt, ...) printf(_fmt, ##__VA_ARGS__) -#define log_debug(_fmt, ...) debug(_fmt, ##__VA_ARGS__) -#define log_content(_fmt...) log_nop(LOG_CATEGORY, \ - LOGL_DEBUG_CONTENT, ##_fmt) -#define log_io(_fmt...) log_nop(LOG_CATEGORY, LOGL_DEBUG_IO, ##_fmt) -#endif -#if CONFIG_IS_ENABLED(LOG) #ifdef LOG_DEBUG #define _LOG_DEBUG LOGL_FORCE_DEBUG #else #define _LOG_DEBUG 0 #endif +#if CONFIG_IS_ENABLED(LOG) + /* Emit a log record if the level is less that the maximum */ #define log(_cat, _level, _fmt, _args...) ({ \ int _l = _level; \ - if (CONFIG_IS_ENABLED(LOG) && \ - (_LOG_DEBUG != 0 || _l <= _LOG_MAX_LEVEL)) \ + if (_LOG_DEBUG != 0 || _l <= _LOG_MAX_LEVEL) \ _log((enum log_category_t)(_cat), \ (enum log_level_t)(_l | _LOG_DEBUG), __FILE__, \ __LINE__, __func__, \ @@ -229,7 +218,14 @@ int _log_buffer(enum log_category_t cat, enum log_level_t level, _width, _count, _linelen); \ }) #else -#define log(_cat, _level, _fmt, _args...) + +/* Note: _LOG_DEBUG != 0 avoids a warning with clang */ +#define log(_cat, _level, _fmt, _args...) ({ \ + int _l = _level; \ + if (_LOG_DEBUG != 0 || _l <= LOGL_INFO || \ + (_DEBUG && _l == LOGL_DEBUG)) \ + printf(_fmt, ##_args); \ + }) #define log_buffer(_cat, _level, _addr, _data, _width, _count, _linelen) ({ \ int _l = _level; \ diff --git a/test/log/Makefile b/test/log/Makefile index 09f8689d070..08eea70e344 100644 --- a/test/log/Makefile +++ b/test/log/Makefile @@ -20,6 +20,7 @@ obj-$(CONFIG_CONSOLE_RECORD) += cont_test.o obj-y += pr_cont_test.o else obj-$(CONFIG_CONSOLE_RECORD) += nolog_test.o +obj-$(CONFIG_CONSOLE_RECORD) += nolog_ndebug.o endif endif # CONFIG_UT_LOG diff --git a/test/log/nolog_ndebug.c b/test/log/nolog_ndebug.c new file mode 100644 index 00000000000..5df353781d9 --- /dev/null +++ b/test/log/nolog_ndebug.c @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2021 Google LLC + * + * Logging function tests for CONFIG_LOG=n without #define DEBUG + */ + +#include +#include +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +#define BUFFSIZE 32 + +static int log_test_log_disabled_ndebug(struct unit_test_state *uts) +{ + char buf[BUFFSIZE]; + int i; + + memset(buf, 0, BUFFSIZE); + console_record_reset_enable(); + + /* Output a log record at every level */ + for (i = LOGL_EMERG; i < LOGL_COUNT; i++) + log(LOGC_NONE, i, "testing level %i\n", i); + gd->flags &= ~GD_FLG_RECORD; + + /* Since DEBUG is not defined, we expect to not get debug output */ + for (i = LOGL_EMERG; i < LOGL_DEBUG; i++) + ut_assertok(ut_check_console_line(uts, "testing level %d", i)); + ut_assertok(ut_check_console_end(uts)); + + return 0; +} +LOG_TEST(log_test_log_disabled_ndebug); diff --git a/test/log/nolog_test.c b/test/log/nolog_test.c index cb4fb3db9a2..4e52e5bed82 100644 --- a/test/log/nolog_test.c +++ b/test/log/nolog_test.c @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -128,8 +129,10 @@ static int log_test_nolog_debug(struct unit_test_state *uts) memset(buf, 0, BUFFSIZE); console_record_reset_enable(); log_debug("testing %s\n", "log_debug"); + log(LOGC_NONE, LOGL_DEBUG, "more %s\n", "log_debug"); gd->flags &= ~GD_FLG_RECORD; ut_assertok(ut_check_console_line(uts, "testing log_debug")); + ut_assertok(ut_check_console_line(uts, "more log_debug")); ut_assertok(ut_check_console_end(uts)); return 0; }