From patchwork Sat Oct 10 19:43:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1380098 X-Patchwork-Delegate: trini@ti.com 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; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=TqExA37h; 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 4C7wP83m8sz9sSn for ; Sun, 11 Oct 2020 06:44:11 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EFA28823C2; Sat, 10 Oct 2020 21:43:59 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="TqExA37h"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0D954823AE; Sat, 10 Oct 2020 21:43:57 +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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qv1-xf43.google.com (mail-qv1-xf43.google.com [IPv6:2607:f8b0:4864:20::f43]) (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 A013682351 for ; Sat, 10 Oct 2020 21:43:54 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qv1-xf43.google.com with SMTP id t6so2388969qvz.4 for ; Sat, 10 Oct 2020 12:43:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=l/7OjjWAm0p9ajYv2E28XSve0GvY0wsSwgfQk8AC0fQ=; b=TqExA37hU1aWHwkfgPcx4V+zDMT1igJhnn3ZWRjMeKidPghmnEC1pakrk8zv03sara 23HtLLnuPW4hQOH+GL/R7wllcvqxDldRIOIW/3+fOrb/hxnPWdNbUFf+v18kvmQ1fSOq vS+eHKA2tLYR6rkhJDwGKp9jUBepGqHE1eY+Z0OqsPnLxLa4LTx+oZa9FTzD+EvfXVN8 SfECL1h6hpQPbqyJvBf9ts9Rts3fst/e0lUP6RBiUOl0tS3cEXhz/EKRZ1s/JHakW1VM CpFgMPJQd/i39ch9mPnpNkFcYh72rn3nStH7puKtVbmfm99BzOlx6ZtRVWf1Q9czQw4r BOUw== 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=l/7OjjWAm0p9ajYv2E28XSve0GvY0wsSwgfQk8AC0fQ=; b=t1VNEQwPnqWGOEbJbneAYNujmCmUk1gIxPP/VZifHkO6b8dn7/8QIW6u0TZic1fCxi VDc46RbSGEdE7Wt7yQbS2ZLYY1vrvziiPyr+E6UQIxB3euB2Zor0iNPEBAU6oyRe8Q9G NNPSuLrqcjkaCg46Rq9gQu6+bt+MRaf/8Y1/o1k3q4IAhrD67LFdtRIvCD/UAAndACwk Q8t/WFQ+3ywlfjXkcMHn6Htaa4wkAJAKIWEaEBAWkOJHM7/KXQkRuSTXB15HDG7Z3vEM SRA78knlcA2h04hJIz02hdzsPNsNiRBvkD4lvMCI+KO3Y7q+Ebt14xTMts38BJZUslvu FedQ== X-Gm-Message-State: AOAM532l8xMx3d1SDqcvGvPmO24FhlyISIsG8pgTH9V+aKUGvGFMfWs9 QvO/8Z5p9rICf6nAStO8mmm26N3uSQL/HA== X-Google-Smtp-Source: ABdhPJwBqgSu7KhxEw+cmWvtKnxfT/3HLOlWkAMLYm/mh8+wEQMXjxar9WiqR+HfHhEVcWLoaTJzBQ== X-Received: by 2002:a0c:f1cd:: with SMTP id u13mr5917632qvl.46.1602359033134; Sat, 10 Oct 2020 12:43:53 -0700 (PDT) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id h2sm5588376qkn.89.2020.10.10.12.43.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Oct 2020 12:43:52 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v2 01/22] log: Fix missing negation of ENOMEM Date: Sat, 10 Oct 2020 15:43:26 -0400 Message-Id: <20201010194347.90096-2-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201010194347.90096-1-seanga2@gmail.com> References: <20201010194347.90096-1-seanga2@gmail.com> 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.3 at phobos.denx.de X-Virus-Status: Clean Errors returned should be negative. Fixes: 45fac9fc18 ("log: Correct missing free() on error in log_add_filter()") Signed-off-by: Sean Anderson Reviewed-by: Heinrich Schuchardt --- (no changes since v1) common/log.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/log.c b/common/log.c index 9a5f100da3..3f6f4bdc2a 100644 --- a/common/log.c +++ b/common/log.c @@ -268,7 +268,7 @@ int log_add_filter(const char *drv_name, enum log_category_t cat_list[], if (file_list) { filt->file_list = strdup(file_list); if (!filt->file_list) { - ret = ENOMEM; + ret = -ENOMEM; goto err; } } From patchwork Sat Oct 10 19:43:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1380100 X-Patchwork-Delegate: trini@ti.com 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; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=JRl2aqTx; 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 4C7wPN0xPzz9sSn for ; Sun, 11 Oct 2020 06:44:24 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6FC8D823BF; Sat, 10 Oct 2020 21:44:01 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="JRl2aqTx"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2B677823C2; Sat, 10 Oct 2020 21:43:58 +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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) (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 98D7A82396 for ; Sat, 10 Oct 2020 21:43:55 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qk1-x743.google.com with SMTP id w12so14153127qki.6 for ; Sat, 10 Oct 2020 12:43:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yD/uvT79UQEYEit2CwLuXNFFYlUVWaCLWfYUMmxBO6A=; b=JRl2aqTxWFd9ktLCbkOeTa1QGrF8lVVEUIJX4wP1KGF16wu6VchJLSY77fVR30AvA2 0aHAx2W8HPTj+4F+hcATmcN2OBuu8XJm4VgVL97WBmm97xSOGyyp1s3YT1krGvZFjPId f1g7Np5tE4qUSSUzQ1Cd46kJ14YMIod8a9iM7+aX5iRuKAdKaNLOuKX6H2e1x/b814JJ qj6rST/L5Ckp8PmAOQrDfOl2iUWIm/EVz6IXvWa9SQu+7n8bniuDcD41nNbiY4GmXA/Q ORcKH5aPShSX8+l1lEQQ7CcVpV+33sxFJDfZClVBH9lin4ywMYIDOYN+EZj0rfcqyIT4 Oo5w== 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=yD/uvT79UQEYEit2CwLuXNFFYlUVWaCLWfYUMmxBO6A=; b=oH6nXXUpt9NZsrp7eLLqU4VRpu7qmsbt4v3efJH2OCykKnFidSvEkse0TitwWxqtFI xfNzMmlKOE2znMTOQD36eXtztT4kvKipZrBlQQfiKFtC8QjUKtV6oByC0Zn0N4e9w9kP cE6RJE7QdmRsG1zsi7DSE58u2zKfxy+o3UXOKWHfSY2mGGfBeDucZlsTo+e/sdkugukH 16+L4EQ/ir3HRmCMrws5AJwR0wKUPjmWBOcLpnObBKv2QKE4iijc1xKOwmU7hobQjFKB E63IP/1PYphH3TVDWGLlD6TUF9HJsqk0QfeplPEfXFP7OaCLcPGx4opDUU2PWVueZwOn thrA== X-Gm-Message-State: AOAM5312yUtBbpzG6TeGEo2fZQNxKxrcMb8+aMY9MgX0G81jhXS16w1J YMFS1/zBXdpqacAkGTxBrN8k1D9/moX3Vg== X-Google-Smtp-Source: ABdhPJxG2p58wmNmqfEOtq+/B7niQAQ2qnNNcqguaE7y7pz2RB0cIA4r2JdhbuPtdqSiklUCkXBcWA== X-Received: by 2002:a05:620a:4d:: with SMTP id t13mr3511838qkt.289.1602359034359; Sat, 10 Oct 2020 12:43:54 -0700 (PDT) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id h2sm5588376qkn.89.2020.10.10.12.43.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Oct 2020 12:43:53 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v2 02/22] log: Fix incorrect documentation of log_filter.cat_list Date: Sat, 10 Oct 2020 15:43:27 -0400 Message-Id: <20201010194347.90096-3-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201010194347.90096-1-seanga2@gmail.com> References: <20201010194347.90096-1-seanga2@gmail.com> 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.3 at phobos.denx.de X-Virus-Status: Clean Logging category lists are terminated by LOGC_END, not LOGC_NONE. Fixes: e9c8d49d54 ("log: Add an implementation of logging") Signed-off-by: Sean Anderson Reviewed-by: Heinrich Schuchardt --- Changes in v2: - Also fix misdocumentation of for log_add_filter() include/log.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/log.h b/include/log.h index 2859ce1f2e..1e29c94fd3 100644 --- a/include/log.h +++ b/include/log.h @@ -349,7 +349,7 @@ enum log_filter_flags { * new filter, and must be provided when removing a previously added * filter. * @flags: Flags for this filter (LOGFF_...) - * @cat_list: List of categories to allow (terminated by LOGC_none). If empty + * @cat_list: List of categories to allow (terminated by %LOGC_END). If empty * then all categories are permitted. Up to LOGF_MAX_CATEGORIES entries * can be provided * @max_level: Maximum log level to allow @@ -423,7 +423,7 @@ int do_log_test(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); * * @drv_name: Driver name to add the filter to (since each driver only has a * single device) - * @cat_list: List of categories to allow (terminated by LOGC_none). If empty + * @cat_list: List of categories to allow (terminated by %LOGC_END). If empty * then all categories are permitted. Up to LOGF_MAX_CATEGORIES entries * can be provided * @max_level: Maximum log level to allow From patchwork Sat Oct 10 19:43:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1380101 X-Patchwork-Delegate: trini@ti.com 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; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=OLfJ+DZJ; 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 4C7wPb5WY3z9sSn for ; Sun, 11 Oct 2020 06:44:35 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 36A78823EA; Sat, 10 Oct 2020 21:44:03 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="OLfJ+DZJ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0CC69823C2; Sat, 10 Oct 2020 21:43:59 +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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qv1-xf44.google.com (mail-qv1-xf44.google.com [IPv6:2607:f8b0:4864:20::f44]) (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 928F58233D for ; Sat, 10 Oct 2020 21:43:56 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qv1-xf44.google.com with SMTP id b19so6501989qvm.6 for ; Sat, 10 Oct 2020 12:43:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TVbYs0yptuKHD8mGD/RXxpLs+pjxlpZe25FvPkua2jA=; b=OLfJ+DZJ6Ae27HaanNM7lhagjhUcEUabo6gojMrWTAq439YBdilh3gxftfUhtaTSwZ M92CSivqshL0Bq4L0eBI8O9J3gEVz6pM/ybwr/dQq+EZW77mMR2e9vuTBh8DeLQpzRr+ kawZfLdYH0GtwVG8yaSYTpEeNyAUZDqb3Y9dgiFbNVELQ4z3Z/kjHL0jHsds1cJz880b 9hZFykT3KZ4h28c6UDQ9PUDOVeY7Jer325ay5IC15n5lAM3QR43maLskgzO3IzxTe4rF zqCmcAOF64W3uE3inA3y/+rJnssEZ+cwzNiw0wIsJF/sGxPSls5/t7AVzmdFSMEaIWxP FxEQ== 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=TVbYs0yptuKHD8mGD/RXxpLs+pjxlpZe25FvPkua2jA=; b=kyOFvruZE9g91cCBhtUGtvqqEMS/gKseS9MwFr0P/eYbMDAsZAPoAhxWJJciFupke6 vH/ldifdtOKTaTfvx/PXmz4Uj9zvaBi/AuFy+SeS+rx9Mpwl1q3DHUy7Ncv+1OTMOeFz o8lutmpOykPMK1suEZHT+q6FlxjDbOKfTKeh4pUiLDmUpbPJ/9qD/7SsnlZhq5SJ9H5G QPetmWhWBk+BzEDkSZ1Tis0JRYuRwQhVzvYkfzGaZSv7elChjR0/5xLZi+7DVAbDIxwy CbkSBkL4Lnc2W0BNLW2Rr7TnmDT/HtTUD08v/YMHncoqI170itUhU103GJoXP4e3Pa6X +BFw== X-Gm-Message-State: AOAM532cDKS1CacN22O1x+Aj7GES65F9zOL0oB0uUh7Um7Zq3Ey4+gf9 QnqRfIQgsqzJHSHHhDrtNcMQIVZD3f9ZjA== X-Google-Smtp-Source: ABdhPJyNVQv8x4RLa79dnz+UCDvuIeGuZCIzHUDbJOyohtjEclJp44Nw2wEqNfP9v9c3UILuMSB9/g== X-Received: by 2002:a0c:e78d:: with SMTP id x13mr18756100qvn.20.1602359035326; Sat, 10 Oct 2020 12:43:55 -0700 (PDT) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id h2sm5588376qkn.89.2020.10.10.12.43.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Oct 2020 12:43:54 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v2 03/22] log: Add additional const qualifier to arrays Date: Sat, 10 Oct 2020 15:43:28 -0400 Message-Id: <20201010194347.90096-4-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201010194347.90096-1-seanga2@gmail.com> References: <20201010194347.90096-1-seanga2@gmail.com> 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.3 at phobos.denx.de X-Virus-Status: Clean Both these arrays and their members are const. Fixes checkpatch complaint. Signed-off-by: Sean Anderson Reviewed-by: Simon Glass --- Changes in v2: - New common/log.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/log.c b/common/log.c index 3f6f4bdc2a..bda5139b69 100644 --- a/common/log.c +++ b/common/log.c @@ -13,7 +13,7 @@ DECLARE_GLOBAL_DATA_PTR; -static const char *log_cat_name[LOGC_COUNT - LOGC_NONE] = { +static const char *const log_cat_name[LOGC_COUNT - LOGC_NONE] = { "none", "arch", "board", @@ -23,7 +23,7 @@ static const char *log_cat_name[LOGC_COUNT - LOGC_NONE] = { "efi", }; -static const char *log_level_name[LOGL_COUNT] = { +static const char *const log_level_name[LOGL_COUNT] = { "EMERG", "ALERT", "CRIT", From patchwork Sat Oct 10 19:43:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1380102 X-Patchwork-Delegate: trini@ti.com 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; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=K/n5tG7P; 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 4C7wPr4Vp4z9sSn for ; Sun, 11 Oct 2020 06:44:48 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A5B52823E1; Sat, 10 Oct 2020 21:44:04 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="K/n5tG7P"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6F601823CF; Sat, 10 Oct 2020 21:44:00 +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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qt1-x841.google.com (mail-qt1-x841.google.com [IPv6:2607:f8b0:4864:20::841]) (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 CF474823BE for ; Sat, 10 Oct 2020 21:43:57 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qt1-x841.google.com with SMTP id c5so10758422qtw.3 for ; Sat, 10 Oct 2020 12:43:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rH6c4k4QrdfhciRefAKXwuts2RMqxv+Q86CVkO6gyT8=; b=K/n5tG7PgAy+EYI/NfmMrm9pKPmN9S0pkLozmFIffW4igDhgCoksyjAoKCnsBvOE69 XqJqeFFayZYVKdVQfU+jsONj74xJ4zb3boYlf4i0KovS8uoUJKZIaMSJqs1jO1tVjtEA O4MBXZ84wyHWWSZt9cayvgskR4Aa3OjAt/Hqy3DbKSeNbYzy3DdzK0EyU3BtUBIaT/UH 7UORXBVPFJsmT7l2QpqR2hDUpBZWd2Fh93DqF13N2z1R6MH3Nz1a5i0O5jZNdcS1BbV4 ES80BFQ8gx+vLQoTap0sU2DVHZ6Q97bLFu/qdAaMor9pSFCt5HOMnrOnG1rc6siSBXmu Zehw== 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=rH6c4k4QrdfhciRefAKXwuts2RMqxv+Q86CVkO6gyT8=; b=OIzaWRhtDmdCci2Bbg6gkuSRDWKwoimwGND9arAUadcrcAj5u1usZWLPIy2MDUbNMO gzqb77QJaNquZJDphFgEPyuV/+xU3qxFyfrFPJ7wZxgwNN+98hjQqi4N/zIGGkYap+H0 Wt/BHiwqJXTxKTgaAasKf5Dl7TcLsuIjvDJ71QEIQW0OxgjYwq8OEpyMIXGp1TocF5lO latlo+SmTQmbWopak7If83/pVWs6qovtNmAPJr09gZvIguzmjog6s5IAoevUDDOeZvvy qJgczGAl4guxqFUsX2xye8+F+5rnnRFgDfVFxuepNQJM52b/Ke6eLUuE0oRCeOTqwg3f aSQA== X-Gm-Message-State: AOAM530hMflJU68Gpdljn/XJvNp/OWreWBrIsffvksoGUuYuexA59LQw lC2z9n3sp+C0kqcKG20TqDM6yCxeMUAlHA== X-Google-Smtp-Source: ABdhPJyrgko9uLTPQqQdjUKInnVWpttgDvpP4PAGc5Pbyf4rblkVhbsMYHjToP/iXDcVLArUZ6tcBw== X-Received: by 2002:ac8:1a30:: with SMTP id v45mr3739095qtj.345.1602359036467; Sat, 10 Oct 2020 12:43:56 -0700 (PDT) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id h2sm5588376qkn.89.2020.10.10.12.43.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Oct 2020 12:43:55 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v2 04/22] log: Add new category names to log_cat_name Date: Sat, 10 Oct 2020 15:43:29 -0400 Message-Id: <20201010194347.90096-5-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201010194347.90096-1-seanga2@gmail.com> References: <20201010194347.90096-1-seanga2@gmail.com> 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.3 at phobos.denx.de X-Virus-Status: Clean Without every category between LOGC_NONE and LOGC_COUNT present in log_cat_name, log_get_cat_by_name will dereference NULL pointers if it doesn't find a name early enough. Fixes: c3aed5db59 ("sandbox: spi: Add more logging") Fixes: a5c13b68e7 ("sandbox: log: Add a category for sandbox") Fixes: 9f407d4ef0 ("Add core support for a bloblist to convey data from SPL") Fixes: cce61fc428 ("dm: devres: Convert to use logging") Fixes: 7ca2850cbc ("dm: core: Add basic ACPI support") Signed-off-by: Sean Anderson Reviewed-by: Simon Glass --- Changes in v2: - Add compiletime assert on size of log_cat_name common/log.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/common/log.c b/common/log.c index bda5139b69..11f488d71d 100644 --- a/common/log.c +++ b/common/log.c @@ -13,7 +13,7 @@ DECLARE_GLOBAL_DATA_PTR; -static const char *const log_cat_name[LOGC_COUNT - LOGC_NONE] = { +static const char *const log_cat_name[] = { "none", "arch", "board", @@ -21,6 +21,11 @@ static const char *const log_cat_name[LOGC_COUNT - LOGC_NONE] = { "driver-model", "device-tree", "efi", + "alloc", + "sandbox", + "bloblist", + "devres", + "acpi", }; static const char *const log_level_name[LOGL_COUNT] = { @@ -40,6 +45,9 @@ const char *log_get_cat_name(enum log_category_t cat) { const char *name; + compiletime_assert(ARRAY_SIZE(log_cat_name) == LOGC_COUNT - LOGC_NONE, + "missing logging category name"); + if (cat < 0 || cat >= LOGC_COUNT) return ""; if (cat >= LOGC_NONE) From patchwork Sat Oct 10 19:43:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1380103 X-Patchwork-Delegate: trini@ti.com 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; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=uOckqg9k; 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 4C7wQ31t7Qz9sSn for ; Sun, 11 Oct 2020 06:44:59 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 20686823F9; Sat, 10 Oct 2020 21:44:06 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="uOckqg9k"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5E738823D9; Sat, 10 Oct 2020 21:44:01 +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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [IPv6:2607:f8b0:4864:20::82b]) (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 C05F5823BF for ; Sat, 10 Oct 2020 21:43:58 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qt1-x82b.google.com with SMTP id h19so694988qtq.4 for ; Sat, 10 Oct 2020 12:43:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UBWvWdyz3wr47KWupFbiMKeT1hZF+wIAbMcXsDBQ0eI=; b=uOckqg9kxJhOM5aHg445vlnimbIVzQ6ohYimieEYjeCU/xuhkLxPhTK4ToErDW2ISA aEA1DW43YzWsCydS3wtbnM84adU2nLloLD9vgOSyBlX11oh/3uz3N7BC8Vn6kPog5wDo P7YB2kBrK/zZNjCH+hhDmvxxPbj2dbMjEz+q+IeYgYQdCVCMLcJl14CLOefVhqHo9drp ygGmxR3j9xZdeJTl6wzYiPF4UVUR8QYdxVdqLkwL380gmcqCsqN9p7ITKE+V2es9poF4 vTC83WrBvnt2jCHoPn1LrhcYlkd8xlj7yNMLaQtDzdun6O88uEUfAZ4rTkd7th5YXt7H UW3w== 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=UBWvWdyz3wr47KWupFbiMKeT1hZF+wIAbMcXsDBQ0eI=; b=AHDErpr0AYt0LGI2Ew8X9dlP9dwrzcOZxmK0zezW2WmHxwWjb6vxUwcJSc2FBmqTg9 kIgQRMXH9qABxGv0P/i1cXtacLe5crcpyFVczZ4/J8Ittc6URcMUbEIrssFbh5BYc0fz y3JxQS0jyFwr3zuVpg8xw6P9f8Sd0UKxbYL/y8ptKiorOQ8RB03ohZM6Hx5KbYCN+Vv/ ObmjRbL4+6cIeyRfdSbaMOP+6utWXF8KU7w/HEgsPjIkkcu18i5SZDg1VSpDU9UOIzT/ Fz0/FVt/8sRd8WpN1O+SLcxsYYb8YFliCVlCWB2+9eAB4KbC10XK/LvDlmbZyLk6v4bl jU6w== X-Gm-Message-State: AOAM5312caO1+vV2xhI9ikbUmjRrtOBo1Pa8jQxp2yHy+16dS5fGZk56 V271RqFm33PYOTuNb1EMZegOe9veEXk7Hw== X-Google-Smtp-Source: ABdhPJyvK5ooVTE9NHFgdJxa66iUWEEcjELybh2MghySNqy84+YpW/nQzvmDNT5aYagoi5Yme6btiQ== X-Received: by 2002:ac8:f6d:: with SMTP id l42mr3859188qtk.367.1602359037537; Sat, 10 Oct 2020 12:43:57 -0700 (PDT) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id h2sm5588376qkn.89.2020.10.10.12.43.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Oct 2020 12:43:57 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v2 05/22] log: Use CONFIG_IS_ENABLED() for LOG_TEST Date: Sat, 10 Oct 2020 15:43:30 -0400 Message-Id: <20201010194347.90096-6-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201010194347.90096-1-seanga2@gmail.com> References: <20201010194347.90096-1-seanga2@gmail.com> 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.3 at phobos.denx.de X-Virus-Status: Clean Checkpatch complains about using #ifdef for CONFIG variables. Signed-off-by: Sean Anderson --- (no changes since v1) cmd/log.c | 4 ++-- test/log/log_test.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/log.c b/cmd/log.c index 6afe6ead25..16a6ef7539 100644 --- a/cmd/log.c +++ b/cmd/log.c @@ -105,7 +105,7 @@ 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, "", ""), -#ifdef CONFIG_LOG_TEST +#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, "", ""), @@ -133,7 +133,7 @@ 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" -#ifdef CONFIG_LOG_TEST +#if CONFIG_IS_ENABLED(LOG_TEST) "log test - run log tests\n" #endif "log format - set log output format. is a string where\n" diff --git a/test/log/log_test.c b/test/log/log_test.c index 4245372d65..787f680971 100644 --- a/test/log/log_test.c +++ b/test/log/log_test.c @@ -201,7 +201,7 @@ static int log_test(int testnum) return 0; } -#ifdef CONFIG_LOG_TEST +#if CONFIG_IS_ENABLED(LOG_TEST) int do_log_test(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { int testnum = 0; From patchwork Sat Oct 10 19:43:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1380104 X-Patchwork-Delegate: trini@ti.com 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; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=EK0vEtLr; 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 4C7wQH1hlRz9sSn for ; Sun, 11 Oct 2020 06:45:11 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8CCC0823E5; Sat, 10 Oct 2020 21:44:07 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="EK0vEtLr"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A70AC823F9; Sat, 10 Oct 2020 21:44:04 +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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [IPv6:2607:f8b0:4864:20::82b]) (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 BC90C8233D for ; Sat, 10 Oct 2020 21:43:59 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qt1-x82b.google.com with SMTP id c5so10758464qtw.3 for ; Sat, 10 Oct 2020 12:43:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Qshg58UUbihXPkpKT3zsvifxBW/XgOaUU5i9xUv08cI=; b=EK0vEtLrGW+09Ypk2Ln/jwFYZBp/qmTKY76B1RcvqYQ6/BZgwgRCCuAmaEdAFZ8vWe 21kzUbv92btMT91vsVbwY6rTDdmXIdxGUS5xDwkNdVFoRjfYjNoBNMt3XOAbDWgBqIqa 7XV4dRopnUNrYRTfwNpv5+0POKIl8RKHAvUKtdIaY2tNTWtYFUwMZ8DQ0KkREPCAU2IW 3EPnp0Zov6rfuGPIxEVxpkfbIYhEFmIl6S+8mZYXIOGX9Phb4PJpN5oCTK0bsTw+PSI6 8o3/BTKYdmD4MY/zjdXcwuZpKaKdPJni552548Kvv4w9RYMjzYv5BP8e/EXi+LA47i9p s3PQ== 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=Qshg58UUbihXPkpKT3zsvifxBW/XgOaUU5i9xUv08cI=; b=iRffzefuJBBUZo/bVZfd0c6WIUk23oqO4P3IE8a2J8yuqQhfQLqmKozxjSDeNWITLZ 7lmviYAdLzRCmD6qbos9kl/xVJbLxpuYEHjxzr/3wYiJ/MGcc4jsEj23Y50nUKNFpCxb O5m7/JO3ZyXJ0KBRprUS63rrw/MwFWSYZxfoogU3kx2gSBL5sllbcTpQlyCVh7Y4rHd8 9jVUU7+J+kpvAFUinODJ6LRLa54hpkdvyotRpCL/lOxfnl0hfZl/6yU2InPQbHEyl5Rk HrRL0gqvax2Sg0tgGNTJ6OlMAi8EnccSvMDd8nsqW1HLMH7hYkkB7XyBC8EDWJSTMGWz 5mIQ== X-Gm-Message-State: AOAM530MNiOrvQ9c6bJy7Vqtf80EKfDey8GCRXN3MbLs9XhjjhBQC7wH WEwclrx3EtrPbpkDsgdpnw8bsxGxjny1LA== X-Google-Smtp-Source: ABdhPJxrXiIrM3lspQSU/4lQAVdppYvDaz6d1YMSf+9Aim4suXGjbriISGWlLERgOyz4jqys3/naLg== X-Received: by 2002:ac8:59d4:: with SMTP id f20mr3669876qtf.327.1602359038515; Sat, 10 Oct 2020 12:43:58 -0700 (PDT) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id h2sm5588376qkn.89.2020.10.10.12.43.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Oct 2020 12:43:58 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v2 06/22] log: Expose some helper functions Date: Sat, 10 Oct 2020 15:43:31 -0400 Message-Id: <20201010194347.90096-7-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201010194347.90096-1-seanga2@gmail.com> References: <20201010194347.90096-1-seanga2@gmail.com> 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.3 at phobos.denx.de X-Virus-Status: Clean These functions are required by "cmd: log: Add commands to manipulate filters" and "test: Add a test for log filter-*". Signed-off-by: Sean Anderson Reviewed-by: Simon Glass --- Changes in v2: - Expose log_has_cat and log_has_file for filter tests common/log.c | 23 +++-------------------- include/log.h | 31 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/common/log.c b/common/log.c index 11f488d71d..5e9ce3184f 100644 --- a/common/log.c +++ b/common/log.c @@ -96,7 +96,7 @@ enum log_level_t log_get_level_by_name(const char *name) return LOGL_NONE; } -static struct log_device *log_device_find_by_name(const char *drv_name) +struct log_device *log_device_find_by_name(const char *drv_name) { struct log_device *ldev; @@ -108,15 +108,7 @@ static struct log_device *log_device_find_by_name(const char *drv_name) return NULL; } -/** - * log_has_cat() - check if a log category exists within a list - * - * @cat_list: List of categories to check, at most LOGF_MAX_CATEGORIES entries - * long, terminated by LC_END if fewer - * @cat: Category to search for - * @return true if @cat is in @cat_list, else false - */ -static bool log_has_cat(enum log_category_t cat_list[], enum log_category_t cat) +bool log_has_cat(enum log_category_t cat_list[], enum log_category_t cat) { int i; @@ -128,16 +120,7 @@ static bool log_has_cat(enum log_category_t cat_list[], enum log_category_t cat) return false; } -/** - * log_has_file() - check if a file is with a list - * - * @file_list: List of files to check, separated by comma - * @file: File to check for. This string is matched against the end of each - * file in the list, i.e. ignoring any preceding path. The list is - * intended to consist of relative pathnames, e.g. common/main.c,cmd/log.c - * @return true if @file is in @file_list, else false - */ -static bool log_has_file(const char *file_list, const char *file) +bool log_has_file(const char *file_list, const char *file) { int file_len = strlen(file); const char *s, *p; diff --git a/include/log.h b/include/log.h index 1e29c94fd3..d84514a898 100644 --- a/include/log.h +++ b/include/log.h @@ -402,6 +402,37 @@ const char *log_get_level_name(enum log_level_t level); */ enum log_level_t log_get_level_by_name(const char *name); +/** + * log_device_find_by_name() - Look up a log device by its driver's name + * + * @drv_name: Name of the driver + * @return the log device, or NULL if not found + */ +struct log_device *log_device_find_by_name(const char *drv_name); + +/** + * log_has_cat() - check if a log category exists within a list + * + * @cat_list: List of categories to check, at most %LOGF_MAX_CATEGORIES entries + * long, terminated by %LC_END if fewer + * @cat: Category to search for + * + * Return: ``true`` if @cat is in @cat_list, else ``false`` + */ +bool log_has_cat(enum log_category_t cat_list[], enum log_category_t cat); + +/** + * log_has_file() - check if a file is with a list + * + * @file_list: List of files to check, separated by comma + * @file: File to check for. This string is matched against the end of each + * file in the list, i.e. ignoring any preceding path. The list is + * intended to consist of relative pathnames, e.g. common/main.c,cmd/log.c + * + * Return: ``true`` if @file is in @file_list, else ``false`` + */ +bool log_has_file(const char *file_list, const char *file); + /* Log format flags (bit numbers) for gd->log_fmt. See log_fmt_chars */ enum log_fmt { LOGF_CAT = 0, From patchwork Sat Oct 10 19:43:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1380105 X-Patchwork-Delegate: trini@ti.com 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; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=WOYyQoZJ; 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 4C7wQW6tvmz9sSn for ; Sun, 11 Oct 2020 06:45:23 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B3FC582410; Sat, 10 Oct 2020 21:44:08 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="WOYyQoZJ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BCE8F823D4; Sat, 10 Oct 2020 21:44:04 +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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) (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 DBA55823D6 for ; Sat, 10 Oct 2020 21:44:00 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qt1-x843.google.com with SMTP id o21so10762426qtp.2 for ; Sat, 10 Oct 2020 12:44:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=H7JlyRXgxVSCkT4PACNHuaqM7pQJyVxBC+tRyUiRW2Y=; b=WOYyQoZJs7dB3yUvTCQevSPyJMqNba4a+Sq2VMOzxlpfKzvRffJgamrd//m67l+kJz hTlAUP9j2hAzRPq0rFnCGdbaZHce9S17iLO+FzLDwastHcIpRs4r9DE1OXZUMM3LfJ27 9KHmhUqxSe5g/Ah9VvbtiK6x4/AE70ojfdlPrm6HIli5TCsRWUBytPWjExB5pAQ0Ir0o XtsensCf/nsr/poeKNGnps3rHx22BpCLRqvPhPgPnZHglLSVvPZy/y671BUOZYLNa6wb SyiZilyZ6BZXaDNzXKblxBietSSrQ6KO6INffK+rC0Am7EW6Fnnz/kCJAcpB0XK4L+0K OIBA== 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=H7JlyRXgxVSCkT4PACNHuaqM7pQJyVxBC+tRyUiRW2Y=; b=ooyXp9SYEkA9KbbRUolgnRG5ijxAc3ak7o0Mu4KWrWkSgM2g0wfsXhGN0AlB9+z7n7 ygt130g1Isc6EPaO5yvD+E5sXgZbPxNYqDdeesXUGGqWpgqhPxqmpGnyMN3IP7eC8r51 qkAnyObuN4PIaEpBJQBK9B0xJeZ3kOp3jsos5gtLj8dr1p/Mh7qvtGM+AO6jjjc0iTld VQizpRaQVFbRX5wXXSGCAjBN9TIBQmSaCd5BNtpMxh5WtECjAxBHB1XdNQ4Dh13bT2G/ 8n8710zWGwdQc6YrHSiV0dumWix+uO5ZsRq6hwTefFZpC4K2w9RazjCVXX+uZKIAiHjl Xs0Q== X-Gm-Message-State: AOAM533R/kJsC4JNQwZkK3+LzQPMh1IfgD/+r8gz1Q4MOEpgQ6CYUJT+ hu57VbA9uKmYl+5jV6naepvv+kMisvUXCw== X-Google-Smtp-Source: ABdhPJz/hZNe6EOGpXcgb5BdMPb4BTufNex0SjF6VxtbAtTAd/YoXDZytQD/lxzUSsxq1z9r5lgLLw== X-Received: by 2002:ac8:7591:: with SMTP id s17mr3757387qtq.138.1602359039505; Sat, 10 Oct 2020 12:43:59 -0700 (PDT) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id h2sm5588376qkn.89.2020.10.10.12.43.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Oct 2020 12:43:59 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v2 07/22] log: Add function to create a filter with flags Date: Sat, 10 Oct 2020 15:43:32 -0400 Message-Id: <20201010194347.90096-8-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201010194347.90096-1-seanga2@gmail.com> References: <20201010194347.90096-1-seanga2@gmail.com> 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.3 at phobos.denx.de X-Virus-Status: Clean This function exposes a way to specify flags when creating a filter. Signed-off-by: Sean Anderson Reviewed-by: Simon Glass --- (no changes since v1) common/log.c | 6 ++++-- include/log.h | 29 +++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/common/log.c b/common/log.c index 5e9ce3184f..1066ead9e5 100644 --- a/common/log.c +++ b/common/log.c @@ -228,8 +228,9 @@ int _log(enum log_category_t cat, enum log_level_t level, const char *file, return 0; } -int log_add_filter(const char *drv_name, enum log_category_t cat_list[], - enum log_level_t max_level, const char *file_list) +int log_add_filter_flags(const char *drv_name, enum log_category_t cat_list[], + enum log_level_t max_level, const char *file_list, + int flags) { struct log_filter *filt; struct log_device *ldev; @@ -243,6 +244,7 @@ int log_add_filter(const char *drv_name, enum log_category_t cat_list[], if (!filt) return -ENOMEM; + filt->flags = flags; if (cat_list) { filt->flags |= LOGFF_HAS_CAT; for (i = 0; ; i++) { diff --git a/include/log.h b/include/log.h index d84514a898..43935a1e34 100644 --- a/include/log.h +++ b/include/log.h @@ -449,6 +449,25 @@ enum log_fmt { /* Handle the 'log test' command */ int do_log_test(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); +/** + * log_add_filter_flags() - Add a new filter to a log device, specifying flags + * + * @drv_name: Driver name to add the filter to (since each driver only has a + * single device) + * @flags: Flags for this filter (LOGFF_...) + * @cat_list: List of categories to allow (terminated by %LOGC_END). If empty + * then all categories are permitted. Up to LOGF_MAX_CATEGORIES entries + * can be provided + * @max_level: Maximum log level to allow + * @file_list: List of files to allow, separated by comma. If NULL then all + * files are permitted + * @return the sequence number of the new filter (>=0) if the filter was added, + * or a -ve value on error + */ +int log_add_filter_flags(const char *drv_name, enum log_category_t cat_list[], + enum log_level_t max_level, const char *file_list, + int flags); + /** * log_add_filter() - Add a new filter to a log device * @@ -463,8 +482,14 @@ int do_log_test(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); * @return the sequence number of the new filter (>=0) if the filter was added, * or a -ve value on error */ -int log_add_filter(const char *drv_name, enum log_category_t cat_list[], - enum log_level_t max_level, const char *file_list); +static inline int log_add_filter(const char *drv_name, + enum log_category_t cat_list[], + enum log_level_t max_level, + const char *file_list) +{ + return log_add_filter_flags(drv_name, cat_list, max_level, file_list, + 0); +} /** * log_remove_filter() - Remove a filter from a log device From patchwork Sat Oct 10 19:43:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1380106 X-Patchwork-Delegate: trini@ti.com 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; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=VL7DdcNZ; 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 4C7wQn0lRdz9sSn for ; Sun, 11 Oct 2020 06:45:37 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C216C823DE; Sat, 10 Oct 2020 21:44:10 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="VL7DdcNZ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CBA9D8240D; Sat, 10 Oct 2020 21:44:06 +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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) (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 E3FB6823DE for ; Sat, 10 Oct 2020 21:44:01 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qk1-x741.google.com with SMTP id w12so14153268qki.6 for ; Sat, 10 Oct 2020 12:44:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9cqwUqP/leKe7znkaLeiVWgHHBTq9tNlD+u4mRyqx2s=; b=VL7DdcNZSo2omUVVwsK7hxzotgMUf+6CKso0XwDT7q0ncmF5owgxKpA6ePu6NwTQ7s ZTD2GHBINfei+rt9dr/56zFUhavaOn8b8tdeSW+z/8uPGF5Rxx3hfL4+jAd/UdwOdn1T nK9mwu4Y7M7QFpVGlBPK6pHQ2R3Mf7f7pIgazhdfDu1nGtu7W0CcbbEXcG7ldbuueyzz mfibVcp98CjnlvRTD9GmpAO+FOBHV80mSsPDiZTM01zKHcDryosQawMrbGOPq4NQy7QW cuMuQM9rk8RTlBvg4SaeDBSDEfZ3+wfz0PxpW4ISamtz61b+zXkCQSA4O4hzFgvkJ0/r cPvA== 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=9cqwUqP/leKe7znkaLeiVWgHHBTq9tNlD+u4mRyqx2s=; b=cEhsFAxV/CNytnJLQRc/C5wLevNyv+wSraIcnWc8b29cIYKRAyCd+YII00PWYoUIZ0 2HccRV7FkkQvLkRvGywu2GM+FeFfITfwM5Furo/FdAEe+/RrmD7UrKzOVYRsxec3ryuS egQAzAKDPqlkm1PypSIFC8++QFtxT24B8coPcvnuJP0/MLkxwet1sbqtMQsH1gEI/yaO 8Kt5iNjZEBYNKsSV0/eqJKmyQDJ2s8pwOuUCttK1tXuwRbvavKDKQCuMSaBZJJtzywgM d5TWEv6Vwj7rR73UCj8AL6dda7ZmrHiaisLIKI/aNE830DWeXNxuxda0OZmV9SdxPQqJ hdjg== X-Gm-Message-State: AOAM533/as6Yf/wwLFBNpflbZ24vm67hRsLcwm6PRerDBiXDoZpQ/xLj PGhUtUUGRPHiA5Li82K56vM11VFlp1WTkw== X-Google-Smtp-Source: ABdhPJxg4toLC4f0e4ADH6IH7RMMp8HhDyNw5lWE0ovjcS5ZBh8hEBj7+YEqzRcSkEi8Ks9olSHahQ== X-Received: by 2002:a05:620a:16cb:: with SMTP id a11mr3708037qkn.474.1602359040591; Sat, 10 Oct 2020 12:44:00 -0700 (PDT) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id h2sm5588376qkn.89.2020.10.10.12.43.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Oct 2020 12:44:00 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v2 08/22] log: Add filter flag to deny on match Date: Sat, 10 Oct 2020 15:43:33 -0400 Message-Id: <20201010194347.90096-9-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201010194347.90096-1-seanga2@gmail.com> References: <20201010194347.90096-1-seanga2@gmail.com> 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.3 at phobos.denx.de X-Virus-Status: Clean Without this flag, log filters can only explicitly accept messages. Allowing denial makes it easier to filter certain subsystems. Unlike allow-ing filters, deny-ing filters are added to the beginning of the filter list. This should do the Right Thing most of the time, but it's less-universal than allowing filters to be inserted anywhere. If this becomes a problem, then perhaps log_filter_add* should take a filter number to insert before/after. Signed-off-by: Sean Anderson Reviewed-by: Simon Glass --- (no changes since v1) common/log.c | 12 ++++++++++-- include/log.h | 11 ++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/common/log.c b/common/log.c index 1066ead9e5..910dc6b672 100644 --- a/common/log.c +++ b/common/log.c @@ -164,7 +164,11 @@ static bool log_passes_filters(struct log_device *ldev, struct log_rec *rec) if (filt->file_list && !log_has_file(filt->file_list, rec->file)) continue; - return true; + + if (filt->flags & LOGFF_DENY) + return false; + else + return true; } return false; @@ -266,7 +270,11 @@ int log_add_filter_flags(const char *drv_name, enum log_category_t cat_list[], } } filt->filter_num = ldev->next_filter_num++; - list_add_tail(&filt->sibling_node, &ldev->filter_head); + /* Add deny filters to the beginning of the list */ + if (flags & LOGFF_DENY) + list_add(&filt->sibling_node, &ldev->filter_head); + else + list_add_tail(&filt->sibling_node, &ldev->filter_head); return filt->filter_num; diff --git a/include/log.h b/include/log.h index 43935a1e34..9f09d3a486 100644 --- a/include/log.h +++ b/include/log.h @@ -338,13 +338,22 @@ enum { LOGF_MAX_CATEGORIES = 5, /* maximum categories per filter */ }; +/** + * enum log_filter_flags - Flags which modify a filter + */ enum log_filter_flags { - LOGFF_HAS_CAT = 1 << 0, /* Filter has a category list */ + /** @LOGFF_HAS_CAT: Filter has a category list */ + LOGFF_HAS_CAT = 1 << 0, + /** @LOGFF_DENY: Filter denies matching messages */ + LOGFF_DENY = 1 << 1, }; /** * struct log_filter - criterial to filter out log messages * + * If a message matches all criteria, then it is allowed. If LOGFF_DENY is set, + * then it is denied instead. + * * @filter_num: Sequence number of this filter. This is returned when adding a * new filter, and must be provided when removing a previously added * filter. From patchwork Sat Oct 10 19:43:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1380107 X-Patchwork-Delegate: trini@ti.com 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; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=oD+x+JcC; 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 4C7wR15CHnz9sSn for ; Sun, 11 Oct 2020 06:45:49 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C689582421; Sat, 10 Oct 2020 21:44:11 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="oD+x+JcC"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0D61A8240F; Sat, 10 Oct 2020 21:44:07 +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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qt1-x842.google.com (mail-qt1-x842.google.com [IPv6:2607:f8b0:4864:20::842]) (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 EE648823E5 for ; Sat, 10 Oct 2020 21:44:02 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qt1-x842.google.com with SMTP id t9so9945313qtp.9 for ; Sat, 10 Oct 2020 12:44:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tdVmTmoN9K+w3ijjOttrv5AffPaU7xzHim7izkF6BJ4=; b=oD+x+JcChZXAMeujRkkLaHx/zl3Z5E7JxLFBZvBVrYG0hyKmPz7JEPa2LqfhttWVxV kSc1D+uT7Sk/QYFbf3F/NzkQVWzaeK/Ll3WiwWXKXu7k4Gxgmf+1rhXnCahe25+7ZTsk PS2Cm7TJ0TUH6o4wIOUDoh93vzxVPf9D2Mec7Pc2Bl3hb3h5CcnqQR99/m73zvGO7VFe uw+NV3t/w8H+bcTv2NAhz8oF9E3FqD2rG6WvT3L978n1b6HSnfHMxyAUhuUf3uvuhVis 6GAkLLV84A9ylyBMEXN79iZnQ0PNiwbyHNZSHliOwSJ9CEittg+MZfeSrzWcsb/AmVvV TAsA== 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=tdVmTmoN9K+w3ijjOttrv5AffPaU7xzHim7izkF6BJ4=; b=l4DOjLuMpHuISDuHRZsDrlv8DNFpIIPHGIE/KLvcYguDB6lNEAezxwVUMZISwe+499 psrCV690rWRwd6l8mBN7DD1siHazm8u9kacymJdDYMabIE1bqpq5nYGEybvUggQnXTMj Hlhb3Q3QeACX5fOMoDPnhTL96uSG1zWHkUTppbvvLPFonG5CQOtsShCYwDfANaxoMFSP 0yVV6d+SwuaZLe5HEOYAJg7fRw/KrsNYHbPvymvDEQtNrpOMfNSr0MDjCsPi59lUhiI4 83atSbu7ap6mM9iu+bT8aZQBdnbbGyXAuAxY8ZbWOvPpXasKPaolf6jndcoBhqCGWwii VwHw== X-Gm-Message-State: AOAM530RBtqPfn5Q8EBkFDXCBUhQGfhdbrv6uq55o+qXO0VPtkiYUPAh WTBXDeVdRp8Eta7nIAUX4Vow6yhPL1XoJQ== X-Google-Smtp-Source: ABdhPJzF+TacK72fkByvQOBSWkpHy/Iy7nwWK+OZSIvh4Ed0RRYjJTOBhovau/gWolUxDy/P0yKrng== X-Received: by 2002:aed:2338:: with SMTP id h53mr3871035qtc.127.1602359041697; Sat, 10 Oct 2020 12:44:01 -0700 (PDT) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id h2sm5588376qkn.89.2020.10.10.12.44.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Oct 2020 12:44:01 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v2 09/22] test: Add tests for LOGFF_DENY Date: Sat, 10 Oct 2020 15:43:34 -0400 Message-Id: <20201010194347.90096-10-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201010194347.90096-1-seanga2@gmail.com> References: <20201010194347.90096-1-seanga2@gmail.com> 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.3 at phobos.denx.de X-Virus-Status: Clean This adds some tests for log filters which deny if they match. Signed-off-by: Sean Anderson Reviewed-by: Simon Glass --- (no changes since v1) test/log/log_test.c | 69 +++++++++++++++++++++++++++++++++++++++ test/py/tests/test_log.py | 21 ++++++++++-- 2 files changed, 88 insertions(+), 2 deletions(-) diff --git a/test/log/log_test.c b/test/log/log_test.c index 787f680971..6a71d3db7d 100644 --- a/test/log/log_test.c +++ b/test/log/log_test.c @@ -196,6 +196,75 @@ static int log_test(int testnum) log_io("level %d\n", LOGL_DEBUG_IO); break; } + case 11: { + /* Check denying based on category */ + int filt1, filt2; + enum log_category_t cat_list[] = { + log_uc_cat(UCLASS_SPI), LOGC_END + }; + + ret = log_add_filter("console", cat_list, LOGL_MAX, NULL); + if (ret < 0) + return ret; + filt1 = ret; + ret = log_add_filter_flags("console", cat_list, LOGL_MAX, NULL, + LOGFF_DENY); + 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 12: { + /* Check denying based on file */ + int filt1, filt2; + + ret = log_add_filter("console", NULL, LOGL_MAX, "file"); + if (ret < 0) + return ret; + filt1 = ret; + ret = log_add_filter_flags("console", NULL, LOGL_MAX, "file", + LOGFF_DENY); + 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 13: { + /* Check denying based on level */ + int filt1, filt2; + + ret = log_add_filter("console", NULL, LOGL_INFO, NULL); + if (ret < 0) + return ret; + filt1 = ret; + ret = log_add_filter_flags("console", NULL, LOGL_WARNING, NULL, + LOGFF_DENY); + 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; + } } return 0; diff --git a/test/py/tests/test_log.py b/test/py/tests/test_log.py index ddc28f19ee..fabf3001cb 100644 --- a/test/py/tests/test_log.py +++ b/test/py/tests/test_log.py @@ -15,7 +15,8 @@ LOGL_FIRST, LOGL_WARNING, LOGL_INFO = (0, 4, 6) @pytest.mark.buildconfigspec('cmd_log') def test_log(u_boot_console): """Test that U-Boot logging works correctly.""" - def check_log_entries(lines, mask, max_level=LOGL_INFO): + def check_log_entries(lines, mask, max_level=LOGL_INFO, + min_level=LOGL_FIRST): """Check that the expected log records appear in the output Args: @@ -24,8 +25,9 @@ def test_log(u_boot_console): bit 0: standard log line bit 1: _log line max_level: maximum log level to expect in the output + min_level: minimum log level to expect in the output """ - for i in range(max_level): + for i in range(min_level, max_level + 1): if mask & 1: assert 'log_run() log %d' % i == next(lines) if mask & 3: @@ -92,6 +94,18 @@ def test_log(u_boot_console): for i in range(7): assert 'log_test() level %d' % i == next(lines) + def test11(): + lines = run_test(11) + assert next(lines, None) == None + + def test12(): + lines = run_test(12) + assert next(lines, None) == None + + def test13(): + lines = run_test(13) + check_log_entries(lines, 1, LOGL_INFO, LOGL_WARNING + 1) + # TODO(sjg@chromium.org): Consider structuring this as separate tests cons = u_boot_console test0() @@ -105,6 +119,9 @@ def test_log(u_boot_console): test8() test9() test10() + test11() + test12() + test13() @pytest.mark.buildconfigspec('cmd_log') def test_log_format(u_boot_console): From patchwork Sat Oct 10 19:43:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1380108 X-Patchwork-Delegate: trini@ti.com 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; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=idcdXEJG; 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 4C7wRF6DgTz9sSn for ; Sun, 11 Oct 2020 06:46:01 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 41A9B8242C; Sat, 10 Oct 2020 21:44:13 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="idcdXEJG"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 35200823E5; Sat, 10 Oct 2020 21:44:07 +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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) (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 E1BDE823F3 for ; Sat, 10 Oct 2020 21:44:03 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qk1-x743.google.com with SMTP id w12so14153317qki.6 for ; Sat, 10 Oct 2020 12:44:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JhcsIPTZhAyMyf0yfoxfQ/tuNQKXEmVlZz9ZmVvDZ1A=; b=idcdXEJGREvkg7HDkgGbZ0fxtEr1pmNnpn8bR/W/+X0llrQcmmGVSYxtDosFAHs8uz lfWk/USgpPiCc4LkdIc5sNtJJ5cw3g2pJZmF7WRGmgEpjb/EDw9z7NB+x3pkzTO5XwVB AMrY2MUKe0UMlmcUEJGN0OfTKpueO6WEqhcTMDyb4qGH4CGHFGlZqRwpxd2dUFn0S1Gw 3hy6jUNpoBIRA6G/HsRhngL4fVxIIc8oIW/XzPY4ke5uiijplSyy5rFxUn69xBb7kXQC z5q9WdR4udT8yA5RvKarQ5w0nHXacYxa6mLhnfWcD8HV6Yt12DF/GrmDZLGWBGmcPuIJ 4JQA== 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=JhcsIPTZhAyMyf0yfoxfQ/tuNQKXEmVlZz9ZmVvDZ1A=; b=nCOFAyrt5dRPDcXoWa419ajHwbnSd+/USE6CgQaYNSuIYoTMwPojSgqNAz6IWV81Yf 8X8KgtRP+CR/retKYI4JRHSphLBt03P2/4USdfSjMn6z3yVf9BDKf0AZggdbASrHaaeL mI+C+91hlewthb5jDcc+aF2kaHvr59lUB9tAtk01HBHQx6FOt+2pJOicKPf2Layp06QH Rc/15RvReRtu5ybTw+X6YyRJ1jRY8DXiNppxvR3KxCeF98T5bLrxMysWpEpU58GX8YIA ziMcvq1ZZ7ztEOcLbT0WS1KgW+iaJ9u8iqtpOUDYA/hU5JB0yyS70kxMvbgxDwOBJbL6 sm3w== X-Gm-Message-State: AOAM531lDTXEXdvwR3Zz+Os+MveOoVTjx6lNkho8M0/2fCjWUbMzlGS3 LwwYXAtexpKcqlSBBBkwZQTgfs23ad7LrQ== X-Google-Smtp-Source: ABdhPJyYIMxcK/jBNvDy2+AEiWEOXWsIcbqdhzMDMZcPiD/A3fG3a+yjGpSpNz6Ak/kbBt5iZOoQrg== X-Received: by 2002:a37:e213:: with SMTP id g19mr3633644qki.147.1602359042679; Sat, 10 Oct 2020 12:44:02 -0700 (PDT) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id h2sm5588376qkn.89.2020.10.10.12.44.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Oct 2020 12:44:02 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v2 10/22] log: Add filter flag to match greater than a log level Date: Sat, 10 Oct 2020 15:43:35 -0400 Message-Id: <20201010194347.90096-11-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201010194347.90096-1-seanga2@gmail.com> References: <20201010194347.90096-1-seanga2@gmail.com> 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.3 at phobos.denx.de X-Virus-Status: Clean This is the compliment of the existing behavior to match only messages with a log level less than a threshold. This is primarily useful in conjunction with LOGFF_DENY. Signed-off-by: Sean Anderson Reviewed-by: Simon Glass --- (no changes since v1) common/log.c | 12 +++++++++--- include/log.h | 10 ++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/common/log.c b/common/log.c index 910dc6b672..7a9906a9b0 100644 --- a/common/log.c +++ b/common/log.c @@ -156,11 +156,17 @@ static bool log_passes_filters(struct log_device *ldev, struct log_rec *rec) } list_for_each_entry(filt, &ldev->filter_head, sibling_node) { - if (rec->level > filt->max_level) + if (filt->flags & LOGFF_LEVEL_MIN) { + if (rec->level < filt->level) + continue; + } else if (rec->level > filt->level) { continue; + } + if ((filt->flags & LOGFF_HAS_CAT) && !log_has_cat(filt->cat_list, rec->cat)) continue; + if (filt->file_list && !log_has_file(filt->file_list, rec->file)) continue; @@ -233,7 +239,7 @@ int _log(enum log_category_t cat, enum log_level_t level, const char *file, } int log_add_filter_flags(const char *drv_name, enum log_category_t cat_list[], - enum log_level_t max_level, const char *file_list, + enum log_level_t level, const char *file_list, int flags) { struct log_filter *filt; @@ -261,7 +267,7 @@ int log_add_filter_flags(const char *drv_name, enum log_category_t cat_list[], break; } } - filt->max_level = max_level; + filt->level = level; if (file_list) { filt->file_list = strdup(file_list); if (!filt->file_list) { diff --git a/include/log.h b/include/log.h index 9f09d3a486..9dd4484095 100644 --- a/include/log.h +++ b/include/log.h @@ -346,6 +346,8 @@ enum log_filter_flags { LOGFF_HAS_CAT = 1 << 0, /** @LOGFF_DENY: Filter denies matching messages */ LOGFF_DENY = 1 << 1, + /** @LOGFF_LEVEL_MIN: Filter's level is a minimum, not a maximum */ + LOGFF_LEVEL_MIN = 1 << 2, }; /** @@ -361,7 +363,7 @@ enum log_filter_flags { * @cat_list: List of categories to allow (terminated by %LOGC_END). If empty * then all categories are permitted. Up to LOGF_MAX_CATEGORIES entries * can be provided - * @max_level: Maximum log level to allow + * @level: Maximum (or minimum, if LOGFF_MIN_LEVEL) log level to allow * @file_list: List of files to allow, separated by comma. If NULL then all * files are permitted * @sibling_node: Next filter in the list of filters for this log device @@ -370,7 +372,7 @@ struct log_filter { int filter_num; int flags; enum log_category_t cat_list[LOGF_MAX_CATEGORIES]; - enum log_level_t max_level; + enum log_level_t level; const char *file_list; struct list_head sibling_node; }; @@ -467,14 +469,14 @@ int do_log_test(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); * @cat_list: List of categories to allow (terminated by %LOGC_END). If empty * then all categories are permitted. Up to LOGF_MAX_CATEGORIES entries * can be provided - * @max_level: Maximum log level to allow + * @level: Maximum (or minimum, if LOGFF_LEVEL_MIN) log level to allow * @file_list: List of files to allow, separated by comma. If NULL then all * files are permitted * @return the sequence number of the new filter (>=0) if the filter was added, * or a -ve value on error */ int log_add_filter_flags(const char *drv_name, enum log_category_t cat_list[], - enum log_level_t max_level, const char *file_list, + enum log_level_t level, const char *file_list, int flags); /** From patchwork Sat Oct 10 19:43:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1380110 X-Patchwork-Delegate: trini@ti.com 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; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=lABrfSB4; 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 4C7wRh1Pr2z9sSn for ; Sun, 11 Oct 2020 06:46:24 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A176E82427; Sat, 10 Oct 2020 21:44:15 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="lABrfSB4"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 09FB98241C; Sat, 10 Oct 2020 21:44:09 +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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) (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 EA7D4823CF for ; Sat, 10 Oct 2020 21:44:04 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qt1-x843.google.com with SMTP id t9so9945351qtp.9 for ; Sat, 10 Oct 2020 12:44:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CHUayW+vviaEPvFcZerhGh932eE1tLqaqYayta+QwAM=; b=lABrfSB4//voilE5Jye7HaUxr+Ojc4TzaPBubidWazDenB7zlSQH701khUrK7ME4ca 4mRK3l6Ri+8xQSG20SHdauJtz6+hk7S5enk9N9VMnCsJaZcl5N6RjtQhCt2XT8AR4FuW V99GC/rRyyTjjGhhp2B2wXRtUaBFwjEj781DqRO9rgaG79EsQoPknHBsBD6Ok2yn+M+Q YYJjWVXujQtArh8cBnlup0VrG6hAjJEFx6sH8hwIAS5aZSglXWSG3AFOZF6U4CPhOszo SfcNGczU9/NHtOqo4HVtGqApOe0z1MIVdEx+v1S49H/C/GDXWPVlfP7six69zBWfwH33 B6dA== 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=CHUayW+vviaEPvFcZerhGh932eE1tLqaqYayta+QwAM=; b=JBG5w9g4l+PhQJjyCL2erQeJBYRzSioT4HE/J+5bTty6kz81TU8Tgt7XcMqRDbumwI BYkqiUjcq0gmk6jVfsM7Iz3quyx0i/WcD8rUN4vb28DTpz7AMQnWdJ8w0dShySrO7+K4 jKG00TnLWE41Ww4nQ0abHfnGw4Ycw13SF0qMwg9cpGoNrb5fuLgpY3INjvKQTJ43YR9O 1w3rKez4Tk8/x3OCAAw8hotclznj0TAl13SZ4UygRo04eFOmJaQtGKF082yqTbvm8nhD iQ5buiitUkETeia6eyH1dOW7ECjoozrkgOfVCh//CT43c3auBCWEk1DGVDGx7lsqd6ha m1GQ== X-Gm-Message-State: AOAM532MDIHhVPAHnCmog3Y6FA7OFbxQwvjcrVPueIhWhpFW4BM3Qgqd 4hzVrko+wO5NY8W9avxK8oVIkJAa/tMnJA== X-Google-Smtp-Source: ABdhPJw39XcFslHqXd3P0htqsohiBrkAUhtkRApwzzQBH3cO0nbl28D5kKFgQ3p4dkT4P5TO7EME/Q== X-Received: by 2002:ac8:45c6:: with SMTP id e6mr2746767qto.322.1602359043761; Sat, 10 Oct 2020 12:44:03 -0700 (PDT) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id h2sm5588376qkn.89.2020.10.10.12.44.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Oct 2020 12:44:03 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v2 11/22] test: Add test for LOGFF_MIN Date: Sat, 10 Oct 2020 15:43:36 -0400 Message-Id: <20201010194347.90096-12-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201010194347.90096-1-seanga2@gmail.com> References: <20201010194347.90096-1-seanga2@gmail.com> 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.3 at phobos.denx.de X-Virus-Status: Clean This tests log filters matching on a minimum level. Signed-off-by: Sean Anderson Reviewed-by: Simon Glass --- (no changes since v1) test/log/log_test.c | 23 +++++++++++++++++++++++ test/py/tests/test_log.py | 5 +++++ 2 files changed, 28 insertions(+) diff --git a/test/log/log_test.c b/test/log/log_test.c index 6a71d3db7d..da433e332b 100644 --- a/test/log/log_test.c +++ b/test/log/log_test.c @@ -265,6 +265,29 @@ static int log_test(int testnum) return ret; break; } + case 14: { + /* Check matching based on minimum level */ + int filt1, filt2; + + ret = log_add_filter_flags("console", NULL, LOGL_WARNING, NULL, + LOGFF_LEVEL_MIN); + if (ret < 0) + return ret; + filt1 = ret; + ret = log_add_filter_flags("console", NULL, LOGL_INFO, NULL, + LOGFF_DENY | LOGFF_LEVEL_MIN); + 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; + } } return 0; diff --git a/test/py/tests/test_log.py b/test/py/tests/test_log.py index fabf3001cb..f191c84c02 100644 --- a/test/py/tests/test_log.py +++ b/test/py/tests/test_log.py @@ -106,6 +106,10 @@ def test_log(u_boot_console): lines = run_test(13) check_log_entries(lines, 1, LOGL_INFO, LOGL_WARNING + 1) + def test14(): + lines = run_test(14) + check_log_entries(lines, 1, LOGL_INFO - 1, LOGL_WARNING) + # TODO(sjg@chromium.org): Consider structuring this as separate tests cons = u_boot_console test0() @@ -122,6 +126,7 @@ def test_log(u_boot_console): test11() test12() test13() + test14() @pytest.mark.buildconfigspec('cmd_log') def test_log_format(u_boot_console): From patchwork Sat Oct 10 19:43:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1380109 X-Patchwork-Delegate: trini@ti.com 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; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=ndWK2exr; 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 4C7wRT2SGWz9sSn for ; Sun, 11 Oct 2020 06:46:13 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 42AF882437; Sat, 10 Oct 2020 21:44:14 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ndWK2exr"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6BB4482413; Sat, 10 Oct 2020 21:44:08 +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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) (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 E2EB4823F4 for ; Sat, 10 Oct 2020 21:44:05 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qt1-x843.google.com with SMTP id m9so10714176qth.7 for ; Sat, 10 Oct 2020 12:44:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DU+glGa76FLB6dAohcXNihNrb92NBhS4kVR+JndUrVk=; b=ndWK2exrbzq7QzHuCwiMr5UYRqGHW+kyBhiuOkkyPCSmKohGuGf1BXA4aqK2sROE6b 76HKwjZNtUC7AdIHy4FhqFkaMVHl2B1PqBjk3R77I9wJ+vo/uu33hz7R50uQCRrLZp9S i3j2ykJfDfHXXvJDgYnQ5rp33zro3z8s++zi9CAu7GLTix0DheMLdjyGBy9FqB5BOc+t WQxZvnZ9+S3O0es1VrSG0HU4ohttQc25YZdNOTcgO2tHSHHSXPZpE6fgr3261NQsXkoe YVVlAHOFKfmBIsAAJeE4wMhvZPb055fJ7jL1gVr1QAJgpl3Yft9v+BpfPHMziD5zLXf8 cL9g== 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=DU+glGa76FLB6dAohcXNihNrb92NBhS4kVR+JndUrVk=; b=OSzKETx0Z7Hx6aOw78l20Q+23ilt2QwMGbF1U1FCuEp8xW0x6qS8j4wkH/5D803n10 XVuEqqDh0ZZBYSPKl3skJfRFpRpi2pLmucxur8pjftHEGfgvQYwcFNuzu5/0T3rgveg2 F6+dZVYeJbPYknQon1RXQN6TfGGR66bnv8E5Bi0oM7xwle9BkoQ2rjG+KYqXC/vfl9hZ v4CIgtFVoqv16psBsAr9PC2CaweknK3E3T/1sR+dwfX47A7p3IakAyYsfvkIwXA3OboW YQl8BH1oUy5fuInzaJcm6Y/xtM6/nQn3cLst8JPb0XhmMcdMDU03r/yCPJUwvUahGEff 2OUg== X-Gm-Message-State: AOAM530J+nmWOUZPegOqE4TPkfieZ9ujLUgv8f4M/DLlReadFBWIzjDR 3uscCOwom21LM+7E4qdB1eLcATcXoQYRQg== X-Google-Smtp-Source: ABdhPJwetgfic+z4CqasEvQgzTi/peJupaBlPGMWXz0vzfgd38YhoykchrkB7K7HZVJC4qZ6kJPYOA== X-Received: by 2002:ac8:a87:: with SMTP id d7mr3876315qti.336.1602359044735; Sat, 10 Oct 2020 12:44:04 -0700 (PDT) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id h2sm5588376qkn.89.2020.10.10.12.44.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Oct 2020 12:44:04 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v2 12/22] cmd: log: Use sub-commands for log Date: Sat, 10 Oct 2020 15:43:37 -0400 Message-Id: <20201010194347.90096-13-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201010194347.90096-1-seanga2@gmail.com> References: <20201010194347.90096-1-seanga2@gmail.com> 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.3 at phobos.denx.de X-Virus-Status: Clean This reduces duplicate code, and makes adding new sub-commands easier. Signed-off-by: Sean Anderson Reviewed-by: Simon Glass --- (no changes since v1) cmd/log.c | 37 +++++++------------------------------ 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/cmd/log.c b/cmd/log.c index 16a6ef7539..e55ace9e14 100644 --- a/cmd/log.c +++ b/cmd/log.c @@ -103,33 +103,6 @@ static int do_log_rec(struct cmd_tbl *cmdtp, int flag, int argc, return 0; } -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, "", ""), -}; - -static int do_log(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) -{ - struct cmd_tbl *cp; - - if (argc < 2) - return CMD_RET_USAGE; - - /* drop initial "log" arg */ - argc--; - argv++; - - cp = find_cmd_tbl(argv[0], log_sub, ARRAY_SIZE(log_sub)); - if (cp) - return cp->cmd(cmdtp, flag, argc, argv); - - return CMD_RET_USAGE; -} - #ifdef CONFIG_SYS_LONGHELP static char log_help_text[] = "level - get/set log level\n" @@ -145,7 +118,11 @@ static char log_help_text[] = ; #endif -U_BOOT_CMD( - log, CONFIG_SYS_MAXARGS, 1, do_log, - "log system", log_help_text +U_BOOT_CMD_WITH_SUBCMDS(log, "log system", log_help_text, + U_BOOT_SUBCMD_MKENT(level, 2, 1, do_log_level), +#if CONFIG_IS_ENABLED(LOG_TEST) + U_BOOT_SUBCMD_MKENT(test, 2, 1, do_log_test), +#endif + U_BOOT_SUBCMD_MKENT(format, 2, 1, do_log_format), + U_BOOT_SUBCMD_MKENT(rec, 7, 1, do_log_rec), ); From patchwork Sat Oct 10 19:43:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1380113 X-Patchwork-Delegate: trini@ti.com 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; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=iyUaDpcQ; 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 4C7wS52Yq7z9sSn for ; Sun, 11 Oct 2020 06:46:45 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A771182434; Sat, 10 Oct 2020 21:44:17 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="iyUaDpcQ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 822F48240F; Sat, 10 Oct 2020 21:44:10 +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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) (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 E484A823DE for ; Sat, 10 Oct 2020 21:44:06 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qt1-x843.google.com with SMTP id d1so10750508qtr.6 for ; Sat, 10 Oct 2020 12:44:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IxFPDLgS+1/OLIzVRwbTIgm2mm1MjAPvoUJMvLZoX4U=; b=iyUaDpcQgPUeR2gs2SgN68Lfx6UCAgTb2zK0VN6wK9U5k4n6KNsqeGmvZzvjdtc1Fb mbLXnMrZnrgs5OrEbzUf5NDKO1tvj4sHMVdsoUk3qzSEiHtj4JzHuKIClmpRhqPeu0nA gRXoMpMHEbt7mkU3tyou5J00tNIlvjp+7ZFkqRgKkdcXmOFvP37Zyo5A3qSHlZ2kKLs4 uzd9e4x1tULKZWkZ6cRTPN66ez/8UdEJc4LjBKZyAw5vKp4rM/pKLWxGL4lrJWERKm+l pPAtRXcg2cLZI9IgAl58DENdE7C0hqBjt9uSQNV7bHBoWQ15q5ttL9Zfl1fYRGujJb0V Jy1w== 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=IxFPDLgS+1/OLIzVRwbTIgm2mm1MjAPvoUJMvLZoX4U=; b=qCzY3Tj07H9GGvCJKlfGdO7TXVa+ejOTda0mAfNkkoA+JPUnjRe7I/9inuLHvI9YvH kl6L8u0EVfvpur+SOg0AjudKndIqfpdsXYfZztc0tLOmyvui4/pNx44LqiRRBtDguTeY apQGYVlY3mauAz/wZV1E7l27xcem/4SmKMQXd7xmW7hLeqzXi7Lb0mrqP55gLn8lUyh6 oy5aUbOOBOUKZyFT7i3cRRR4jd9RazZ+mmQJ8HVM4kb1SRn3IHKC4pytoieV0LRauIfw 7tmEftOYiYd+vSi00LiYoPu2ckTpyA19taibjLh+Q2oIe7i5NemSfOlEKUXC3UThtnih WCZg== X-Gm-Message-State: AOAM530TFWFm6qHAavbXTxrFFHl8QrMttd6ND3Bw7pGUaWP1AmRulXKM +YcpweviTrORaJBqUXUohvN/I19uDUW1kA== X-Google-Smtp-Source: ABdhPJzSipPIglHOcsLKYGPFAw4CLYgcaIcWfCz0GdydhxaNhMwwriHXmi4HZV6aS2U0noxc3u5r/A== X-Received: by 2002:ac8:2612:: with SMTP id u18mr3947111qtu.363.1602359045717; Sat, 10 Oct 2020 12:44:05 -0700 (PDT) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id h2sm5588376qkn.89.2020.10.10.12.44.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Oct 2020 12:44:05 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v2 13/22] cmd: log: Split off log level parsing Date: Sat, 10 Oct 2020 15:43:38 -0400 Message-Id: <20201010194347.90096-14-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201010194347.90096-1-seanga2@gmail.com> References: <20201010194347.90096-1-seanga2@gmail.com> 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.3 at phobos.denx.de X-Virus-Status: Clean Move parsing of log level into its own function so it can be re-used. This also adds support for using log level names instead of just the integer equivalent. Signed-off-by: Sean Anderson Reviewed-by: Simon Glass --- Changes in v2: - Print an error message if the log level is invalid. cmd/log.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/cmd/log.c b/cmd/log.c index e55ace9e14..5387aab551 100644 --- a/cmd/log.c +++ b/cmd/log.c @@ -11,23 +11,40 @@ static char log_fmt_chars[LOGF_COUNT] = "clFLfm"; +static enum log_level_t parse_log_level(char *const arg) +{ + enum log_level_t ret; + ulong level; + + if (!strict_strtoul(arg, 10, &level)) { + if (level > _LOG_MAX_LEVEL) { + printf("Only log levels <= %d are supported\n", + _LOG_MAX_LEVEL); + return LOGL_NONE; + } + return level; + } + + ret = log_get_level_by_name(arg); + if (ret == LOGL_NONE) + printf("Unknown log level \"%s\"\n", arg); + return ret; +} + static int do_log_level(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { if (argc > 1) { - long log_level = simple_strtol(argv[1], NULL, 10); + enum log_level_t log_level = parse_log_level(argv[1]); - if (log_level < 0 || log_level > _LOG_MAX_LEVEL) { - printf("Only log levels <= %d are supported\n", - _LOG_MAX_LEVEL); + if (log_level == LOGL_NONE) return CMD_RET_FAILURE; - } gd->default_log_level = log_level; } else { printf("Default log level: %d\n", gd->default_log_level); } - return 0; + return CMD_RET_SUCCESS; } static int do_log_format(struct cmd_tbl *cmdtp, int flag, int argc, From patchwork Sat Oct 10 19:43:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1380111 X-Patchwork-Delegate: trini@ti.com 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; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=R9Xh5csd; 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 4C7wRv2cGpz9sSn for ; Sun, 11 Oct 2020 06:46:35 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C659C82443; Sat, 10 Oct 2020 21:44:16 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="R9Xh5csd"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 627448241E; Sat, 10 Oct 2020 21:44:10 +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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) (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 DD0078240F for ; Sat, 10 Oct 2020 21:44:07 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qk1-x742.google.com with SMTP id q63so14165680qkf.3 for ; Sat, 10 Oct 2020 12:44:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0OUQL9Ks/z5qVDXT8aurJ+cGsgfFdjwnTMh2GQKBwtQ=; b=R9Xh5csdbHYx2e6gNMssUqBag6g/FGRVszcgrcSFzPeq7Kew9r7RtyQ4giuKkODDO9 XP+Tl1lWg917AM/MpTLC8eFPI9u+yE1qaKHK0m9vZbiIXdXq6CYR+Ze9rDf6IOFSmqk+ gXLbaTc2MOX6rpRPLQRWJEvqBqAVTsdH6YFBONJob0j7tU164RuECTBDFrg6seILS//j MPYG9eBp3+NngFh/EdVp+Usc0lWmE/PGL0AQ9FM5UWiCRmxMw1k/x9ro/0IS6KXBnLeG TJOxjCz0vfCn2dmjIMtHN9Lfs3taFG7e/K6YfGsKArd0cgnrvREu5Fhv3sNxyHPS+YQR y+4A== 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=0OUQL9Ks/z5qVDXT8aurJ+cGsgfFdjwnTMh2GQKBwtQ=; b=OVMD8ad/2Tf25NgH46bxyZJebshjroemRa3JjlnGeshNUdKqh9RtPO+dE3dPVhg8+V Pmo5Inhb14dbm2gcMBS8F5Xouh2FjAOm5Dd/KM05lSwOezvlaypl5wEJOGER7/kvNeOP 2MTvq7sIRruRxV4G3rnvj1Ljx+uwoK3FYikGRW6WBHTS7kq+8yDFmTXZfQfG4+UqZf34 h7bxQp1qLm0kM6Obfm39VKkfSfs7iOk8qK+epQnCNkBRks+blKZYkcPKSPu8bH479asG j5ysmc02i9sVmgyt8Jh6ZMkxxjyM3jb91iWSxXTuQP4WweedyflNX69wn6Te/I8Ik1eS gSLA== X-Gm-Message-State: AOAM532MjC4KhqcQrrQxyPeGCX0z4vAgDylungJtflXX9aBvebz7Y2CV NQnOY1Sw4xqJJnuktKk0E8I3jb4CDr9ovQ== X-Google-Smtp-Source: ABdhPJwDRPPpQBq3OUBhIiVqezKd5ELdqzV1T/+1IJ9675YJpPaCqN8YlsFF3GiPgecANKWKkTvSrQ== X-Received: by 2002:a05:620a:844:: with SMTP id u4mr3701541qku.32.1602359046658; Sat, 10 Oct 2020 12:44:06 -0700 (PDT) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id h2sm5588376qkn.89.2020.10.10.12.44.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Oct 2020 12:44:06 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v2 14/22] cmd: log: Move log test to end of help string Date: Sat, 10 Oct 2020 15:43:39 -0400 Message-Id: <20201010194347.90096-15-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201010194347.90096-1-seanga2@gmail.com> References: <20201010194347.90096-1-seanga2@gmail.com> 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.3 at phobos.denx.de X-Virus-Status: Clean This is probably what a typical user is least interested in. Move it to the end of the description. Signed-off-by: Sean Anderson Reviewed-by: Simon Glass --- (no changes since v1) cmd/log.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/log.c b/cmd/log.c index 5387aab551..9076e220f0 100644 --- a/cmd/log.c +++ b/cmd/log.c @@ -123,23 +123,23 @@ static int do_log_rec(struct cmd_tbl *cmdtp, int flag, int argc, #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" "\tor 'default', or 'all' for all\n" "log rec - " "output a log record" +#if CONFIG_IS_ENABLED(LOG_TEST) + "\nlog test - run log tests" +#endif ; #endif U_BOOT_CMD_WITH_SUBCMDS(log, "log system", log_help_text, U_BOOT_SUBCMD_MKENT(level, 2, 1, do_log_level), + U_BOOT_SUBCMD_MKENT(format, 2, 1, do_log_format), + U_BOOT_SUBCMD_MKENT(rec, 7, 1, do_log_rec), #if CONFIG_IS_ENABLED(LOG_TEST) U_BOOT_SUBCMD_MKENT(test, 2, 1, do_log_test), #endif - U_BOOT_SUBCMD_MKENT(format, 2, 1, do_log_format), - U_BOOT_SUBCMD_MKENT(rec, 7, 1, do_log_rec), ); From patchwork Sat Oct 10 19:43:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1380114 X-Patchwork-Delegate: trini@ti.com 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; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=ViKGToqm; 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 4C7wSG5jsvz9sSn for ; Sun, 11 Oct 2020 06:46:54 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4114C8244A; Sat, 10 Oct 2020 21:44:19 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ViKGToqm"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5D79582421; Sat, 10 Oct 2020 21:44:11 +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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) (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 D6F3D8241A for ; Sat, 10 Oct 2020 21:44:08 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qk1-x741.google.com with SMTP id z6so14174246qkz.4 for ; Sat, 10 Oct 2020 12:44:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9EGh854PStW6hrnGCH1E9WAiel104yAhaVZPjim+rJA=; b=ViKGToqmX7XiAg8F6t/y2EoFZOnrQoBQvjaeqyrliwn4XKAX04XyF4CL7PfBn2nue6 jnLdVLzUwnVYjPp4dQ68EcgHnN3aG80VMCLHP5Eaq2jrX4Lf6UaPubesx2Z9bgXUdnfe +dtmmMrYAe5C3XOF/JsC2KJwcazFwtTXS0PQLysw90IekwWbuHrkPWB9fTAjo96Zw0Fe n+hurK4E4OEBh8CGrkGBP7UOvfYVwRZ21exYoo6jqlOhkxOuhj6Ep8nQLtfo4KME4j86 1gaxg5LmzsOYq1e2O/btVO42U2YVdAVaGut0j/hZA+p4yIfdYUptjId14eL3J24xlHvR 8XzA== 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=9EGh854PStW6hrnGCH1E9WAiel104yAhaVZPjim+rJA=; b=d+KAmmEvbvtrQrXqGn5FbG7BKISzj8pej2J+5h7Fh5xAB4RAirOf6U119lGjYrK/cW Aw6eke7qHGbs9ocijZD+EQAS4PN0XDVk4I5ZA492tWMGEg2bSFC4we8sKwBLW9RDNNa/ KVtagZySoddA+xAaDGpULqLujGhAsNmDw97n0NFQB3JutlZsanjpgOtuDEQLLMZ+zNV0 H+rNxQR1gxS79IkMitdKpwnBI1V0CcqS+52gjTvEm/tn8/V3KkHlJlfntwFuhbvePG5c iu7tEXN4Ow3Q4fc7AG13ah1hyFzZDEzCH9EBw/KPW9HFVIWkW7fgkym7v9ApaDCSxM0z Xovg== X-Gm-Message-State: AOAM532EFExgXvcnmRPVOPlMGdwput7i6RbNwfRmoWqwqXpTS8dxPvdK rV+xHvTg7GuXiP6KAouim6IvinEsZDLSaw== X-Google-Smtp-Source: ABdhPJyU2+AsJdq63IMLU1mQZb943gibWd9PyQMrcMnanS1J5M2FrAwTuakEUc94cYqr5Dq6tRgltQ== X-Received: by 2002:a37:478c:: with SMTP id u134mr3818577qka.206.1602359047614; Sat, 10 Oct 2020 12:44:07 -0700 (PDT) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id h2sm5588376qkn.89.2020.10.10.12.44.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Oct 2020 12:44:07 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v2 15/22] cmd: log: Add commands to list categories and drivers Date: Sat, 10 Oct 2020 15:43:40 -0400 Message-Id: <20201010194347.90096-16-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201010194347.90096-1-seanga2@gmail.com> References: <20201010194347.90096-1-seanga2@gmail.com> 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.3 at phobos.denx.de X-Virus-Status: Clean This allows users to query which categories and drivers are available on their system. This allows them to construct filter-add commands without (e.g.) adjusting the log format to show categories and drivers. Signed-off-by: Sean Anderson Reviewed-by: Simon Glass --- Changes in v2: - New cmd/log.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/cmd/log.c b/cmd/log.c index 9076e220f0..ea458f36f4 100644 --- a/cmd/log.c +++ b/cmd/log.c @@ -47,6 +47,38 @@ static int do_log_level(struct cmd_tbl *cmdtp, int flag, int argc, return CMD_RET_SUCCESS; } +static int do_log_categories(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + enum log_category_t cat; + const char *name; + + for (cat = LOGC_FIRST; cat < LOGC_COUNT; cat++) { + name = log_get_cat_name(cat); + /* + * Invalid category names (e.g. or ) begin + * with '<'. TODO: perhaps change the interface of + * log_get_cat_name to return an error code? + */ + if (name[0] == '<') + continue; + printf("%s\n", name); + } + + return CMD_RET_SUCCESS; +} + +static int do_log_drivers(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + struct log_device *ldev; + + list_for_each_entry(ldev, &gd->log_head, sibling_node) + printf("%s\n", ldev->drv->name); + + return CMD_RET_SUCCESS; +} + static int do_log_format(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { @@ -123,6 +155,8 @@ static int do_log_rec(struct cmd_tbl *cmdtp, int flag, int argc, #ifdef CONFIG_SYS_LONGHELP static char log_help_text[] = "level - get/set log level\n" + "categories - list log categories\n" + "drivers - list log drivers\n" "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" @@ -137,6 +171,8 @@ static char log_help_text[] = U_BOOT_CMD_WITH_SUBCMDS(log, "log system", log_help_text, U_BOOT_SUBCMD_MKENT(level, 2, 1, do_log_level), + U_BOOT_SUBCMD_MKENT(categories, 1, 1, do_log_categories), + U_BOOT_SUBCMD_MKENT(drivers, 1, 1, do_log_drivers), U_BOOT_SUBCMD_MKENT(format, 2, 1, do_log_format), U_BOOT_SUBCMD_MKENT(rec, 7, 1, do_log_rec), #if CONFIG_IS_ENABLED(LOG_TEST) From patchwork Sat Oct 10 19:43:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1380115 X-Patchwork-Delegate: trini@ti.com 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; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=YjOGzs/T; 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 4C7wSS1LPhz9sSn for ; Sun, 11 Oct 2020 06:47:04 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4099182452; Sat, 10 Oct 2020 21:44:20 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="YjOGzs/T"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 830E582428; Sat, 10 Oct 2020 21:44:12 +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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) (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 E72B88241C for ; Sat, 10 Oct 2020 21:44:09 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qk1-x742.google.com with SMTP id z6so14174271qkz.4 for ; Sat, 10 Oct 2020 12:44:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PuTokuOhDh8IhCU1SP4ufZXPzCB7xL8pz5VqAiwqudo=; b=YjOGzs/TSkiMxy0RT+JxQxR2ZKe4VBUqMmmEJrD3/efjYCDKQFeYdj6qJEnOb9mZZd UMfIUz8P6wd3z2v0DIAkKGSmrncpL1/dzQgdh5kOrh4k66y5Pq/CBOumng0pMUwAIb7s hv6LXvokPsGYJx7uu7lQ9p3dXiCNpcOixLpKYAqfTbwbcqk/L1JXM7nzPBdOP8vETw6N 135KPgolwI1uOUSadmKXK6JmMrvMErfgF0dUEdNmEvHM0EuuZso+42qv9xgEbW0mR2b+ kk0Q9awXCRXDiOTmPPSLGPnQMFjzbIy94LgOJ29WamrHIsc/SdWyvgMGDuO97B69vF3I lGvQ== 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=PuTokuOhDh8IhCU1SP4ufZXPzCB7xL8pz5VqAiwqudo=; b=td05Rgm4hOhAqZBDfL0iJQ2JZKDfY+U3zP6cPQhjms3dqdwREUseqArzjqolfpFhJy v4NZ66KBsFKlYihTkBvupzUl4msBMut9x2yBa4Rww6UoA4Rkj14RbVS58lrm7pzMs5va bCD7Ob5PctaBfyMl0lpRNY6Avz/c68XsJf5HTyTukkYZtpoRBtjm9e0O/J95Uhym+4Q5 cnKpr9sHL6/9Z34ZmOcoY5W+EqwzxTtBLJI8snwnRqDZ9vNKLW6TimRm9oWOA6c2SqHi yWJh7/c+CUnnROHdmLdQ0Al6iHq5FzfOJuBAEOAjAfe7PMAJdkefU9n+xEdmZFA8aqSl 59XQ== X-Gm-Message-State: AOAM5328+jCLvp8na1DJ3PTZS1rmDpxq45ik7SbdJrDFAdETNcP4n1Ny oSCA45Sh2F4arIC0FjZmmLwP//Zhc9xTOw== X-Google-Smtp-Source: ABdhPJzCOCFQea8fIKfaRupRT2GojSYPOY7PQaOLFRQ9sudKvjcFQEFj9S7trvWjdkTcmeMODBKJpA== X-Received: by 2002:a37:4d95:: with SMTP id a143mr3660605qkb.248.1602359048646; Sat, 10 Oct 2020 12:44:08 -0700 (PDT) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id h2sm5588376qkn.89.2020.10.10.12.44.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Oct 2020 12:44:08 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v2 16/22] cmd: log: Make "log level" print all log levels Date: Sat, 10 Oct 2020 15:43:41 -0400 Message-Id: <20201010194347.90096-17-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201010194347.90096-1-seanga2@gmail.com> References: <20201010194347.90096-1-seanga2@gmail.com> 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.3 at phobos.denx.de X-Virus-Status: Clean This makes the log level command print all valid log levels. The default log level is annotated. This provides an easy way to see which log levels are compiled-in. Signed-off-by: Sean Anderson Reviewed-by: Simon Glass --- Changes in v2: - New cmd/log.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cmd/log.c b/cmd/log.c index ea458f36f4..f3a265798c 100644 --- a/cmd/log.c +++ b/cmd/log.c @@ -34,14 +34,20 @@ static enum log_level_t parse_log_level(char *const arg) static int do_log_level(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { + enum log_level_t log_level; + if (argc > 1) { - enum log_level_t log_level = parse_log_level(argv[1]); + log_level = parse_log_level(argv[1]); if (log_level == LOGL_NONE) return CMD_RET_FAILURE; gd->default_log_level = log_level; } else { - printf("Default log level: %d\n", gd->default_log_level); + for (log_level = LOGL_FIRST; log_level <= _LOG_MAX_LEVEL; + log_level++) + printf("%s%s\n", log_get_level_name(log_level), + log_level == gd->default_log_level ? + " (default)" : ""); } return CMD_RET_SUCCESS; @@ -154,7 +160,7 @@ static int do_log_rec(struct cmd_tbl *cmdtp, int flag, int argc, #ifdef CONFIG_SYS_LONGHELP static char log_help_text[] = - "level - get/set log level\n" + "level [] - get/set log level\n" "categories - list log categories\n" "drivers - list log drivers\n" "log format - set log output format. is a string where\n" From patchwork Sat Oct 10 19:43:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1380117 X-Patchwork-Delegate: trini@ti.com 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; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=eQvuOmTZ; 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 4C7wSn4RRdz9sSn for ; Sun, 11 Oct 2020 06:47:21 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 88DAB82465; Sat, 10 Oct 2020 21:44:22 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="eQvuOmTZ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 185A28243E; Sat, 10 Oct 2020 21:44:15 +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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) (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 581B58241E for ; Sat, 10 Oct 2020 21:44:11 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qk1-x741.google.com with SMTP id c2so14116606qkf.10 for ; Sat, 10 Oct 2020 12:44:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6gndZCqEKsRzG52snHSyjznpQ39DMwzLt43zWkOknZs=; b=eQvuOmTZ23WheXkN3yw5cEtovpK9M80ihkfGUiobIv8wOAhIPIY1cuaNil65cyWA73 unEKgWVjN7Kk20kIhy1sY/VgyuP0bNiH/ITt3HcvtdD+BRyEDMQ3l+z2FY6Ixd6Qu9YZ mKglH9SisrDLqqgFTmz4YIIbbUjE14pklOWjpLQ5v0QG01sKhrt6JZlqnebm/fZvThKM zbFTOkumNi2iAr2gxt+9+Jodh1Koh4pIXo6lMlhigU73CY9D6DVLENlXcbOKqQxRz/fH IFSRYqWv8HAgFzsnyAePrD9MpKwPzgyHm+vu1/8G3Y/bLsapLdn2ZFB/+PJ35ZYwA9Nq QOVQ== 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=6gndZCqEKsRzG52snHSyjznpQ39DMwzLt43zWkOknZs=; b=mfzg9yeo8wfG9GVAtXFMCgBsTIUcizLQpv5F4EoUwQKzZlnrdTxlBOyBCnzIRHOgac OC0GhnXW+mFBV96l6Rc1LjPvhWOCbq3gf2eLy4DWmYHvaZSFH11gsmFDluawNwlpeYQW I1i8ZHdYLRxauhGQ1Q7AdzChhtACDRhR+g3nRhsSt8PAF11SvxyjWbZbBfh613wXMGFL WoqAacTF4WchWbme3+mxBeXkvfMKV/mhxI7Xq594l2Zn3aRpHQ/JjS8Q4UcZwa4Ckwr+ QIVgYPJa37PiJmSTjKVIEdTDDCQn5+8Gs3h6gcw9qi1X97WEidjLOA171SYUEwrWKBAP Dv5A== X-Gm-Message-State: AOAM532/NdWytXzU+Ow5h6TYfK8gTMR/Sg5NxAdjShdSWpvdqSdHG6wA ThnPuZVD/PHSUEFfTKr1SIZaTY1W0OuctA== X-Google-Smtp-Source: ABdhPJyhemKTWGWGOPVhQ/xS2ZnawVa69QXlhXnnxrng7dcnoxhR7rxeoxtSN/Ilfz5Mdbmm0gE39g== X-Received: by 2002:a37:9e8e:: with SMTP id h136mr3771954qke.205.1602359049655; Sat, 10 Oct 2020 12:44:09 -0700 (PDT) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id h2sm5588376qkn.89.2020.10.10.12.44.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Oct 2020 12:44:09 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v2 17/22] lib: Add getopt Date: Sat, 10 Oct 2020 15:43:42 -0400 Message-Id: <20201010194347.90096-18-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201010194347.90096-1-seanga2@gmail.com> References: <20201010194347.90096-1-seanga2@gmail.com> 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.3 at phobos.denx.de X-Virus-Status: Clean Some commands can get very unweildy if they have too many positional arguments. Adding options makes them easier to read, remember, and understand. This implementation of getopt has been taken from barebox, which has had option support for quite a while. I have made a few modifications to their version, such as the removal of opterr in favor of a separate getopt_silent function. In addition, I have moved all global variables into struct getopt_context. The getopt from barebox also re-orders the arguments passed to it so that non-options are placed last. This allows users to specify options anywhere. For example, `ls -l foo/ -R` would be re-ordered to `ls -l -R foo/` as getopt parsed the options. However, this feature conflicts with the const argv in cmd_tbl->cmd. This was originally added in 54841ab50c ("Make sure that argv[] argument pointers are not modified."). The reason stated in that commit is that hush requires argv to stay unmodified. Has this situation changed? Barebox also uses hush, and does not have this problem. Perhaps we could use their fix? I have assigned maintenance of getopt to Simon Glass, as it is currently only used by the log command. I would also be fine maintaining it. Signed-off-by: Sean Anderson --- Changes in v2: - Expand documentation of getopt() to include examples - Remove opt prefix from getopt_state members MAINTAINERS | 1 + doc/api/getopt.rst | 8 +++ doc/api/index.rst | 1 + include/getopt.h | 130 +++++++++++++++++++++++++++++++++++++++++++++ lib/Kconfig | 5 ++ lib/Makefile | 1 + lib/getopt.c | 125 +++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 271 insertions(+) create mode 100644 doc/api/getopt.rst create mode 100644 include/getopt.h create mode 100644 lib/getopt.c diff --git a/MAINTAINERS b/MAINTAINERS index fb9ba37984..0f8e1f6d4c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -747,6 +747,7 @@ T: git https://gitlab.denx.de/u-boot/u-boot.git F: common/log* F: cmd/log.c F: doc/develop/logging.rst +F: lib/getopt.c F: test/log/ F: test/py/tests/test_log.py diff --git a/doc/api/getopt.rst b/doc/api/getopt.rst new file mode 100644 index 0000000000..773f79aeb6 --- /dev/null +++ b/doc/api/getopt.rst @@ -0,0 +1,8 @@ +.. SPDX-License-Identifier: GPL-2.0+ +.. Copyright (C) 2020 Sean Anderson + +Option Parsing +============== + +.. kernel-doc:: include/getopt.h + :internal: diff --git a/doc/api/index.rst b/doc/api/index.rst index 1c261bcb73..d90e70e16a 100644 --- a/doc/api/index.rst +++ b/doc/api/index.rst @@ -8,6 +8,7 @@ U-Boot API documentation dfu efi + getopt linker_lists pinctrl rng diff --git a/include/getopt.h b/include/getopt.h new file mode 100644 index 0000000000..6f5811e64b --- /dev/null +++ b/include/getopt.h @@ -0,0 +1,130 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * getopt.h - a simple getopt(3) implementation. + * + * Copyright (C) 2020 Sean Anderson + * Copyright (c) 2007 Sascha Hauer , Pengutronix + */ + +#ifndef __GETOPT_H +#define __GETOPT_H + +/** + * struct getopt_state - Saved state across getopt() calls + */ +struct getopt_state { + /** + * @index: Index of the next unparsed argument of @argv. If getopt() has + * parsed all of @argv, then @index will equal @argc. + */ + int index; + /* private: */ + /** @arg_index: Index within the current argument */ + int arg_index; + union { + /* public: */ + /** + * @opt: Option being parsed when an error occurs. @opt is only + * valid when getopt() returns ``?`` or ``:``. + */ + int opt; + /** + * @arg: The argument to an option, NULL if there is none. @arg + * is only valid when getopt() returns an option character. + */ + char *arg; + /* private: */ + }; +}; + +/** + * getopt_init_state() - Initialize a &struct getopt_state + * @gs: The state to initialize + * + * This must be called before using @gs with getopt(). + */ +void getopt_init_state(struct getopt_state *gs); + +int __getopt(struct getopt_state *gs, int argc, char *const argv[], + const char *optstring, bool silent); + +/** + * getopt() - Parse short command-line options + * @gs: Internal state and out-of-band return arguments. This must be + * initialized with getopt_init_context() beforehand. + * @argc: Number of arguments, not including the %NULL terminator + * @argv: Argument list, terminated by %NULL + * @optstring: Option specification, as described below + * + * getopt() parses short options. Short options are single characters. They may + * be followed by a required argument or an optional argument. Arguments to + * options may occur in the same argument as an option (like ``-larg``), or + * in the following argument (like ``-l arg``). An argument containing + * options begins with a ``-``. If an option expects no arguments, then it may + * be immediately followed by another option (like ``ls -alR``). + * + * @optstring is a list of accepted options. If an option is followed by ``:`` + * in @optstring, then it expects a mandatory argument. If an option is followed + * by ``::`` in @optstring, it expects an optional argument. @gs.arg points + * to the argument, if one is parsed. + * + * getopt() stops parsing options when it encounters the first non-option + * argument, when it encounters the argument ``--``, or when it runs out of + * arguments. For example, in ``ls -l foo -R``, option parsing will stop when + * getopt() encounters ``foo``, if ``l`` does not expect an argument. However, + * the whole list of arguments would be parsed if ``l`` expects an argument. + * + * An example invocation of getopt() might look like:: + * + * char *argv[] = { "program", "-cbx", "-a", "foo", "bar", 0 }; + * int opt, argc = ARRAY_SIZE(argv) - 1; + * struct getopt_state gs; + * + * getopt_init_state(&gs); + * while ((opt = getopt(&gs, argc, argv, "a::b:c")) != -1) + * printf("opt = %c, index = %d, arg = \"%s\"\n", opt, gs.index, gs.arg); + * printf("%d argument(s) left\n", argc - gs.index); + * + * and would produce an output of:: + * + * opt = c, index = 1, arg = "" + * opt = b, index = 2, arg = "x" + * opt = a, index = 4, arg = "foo" + * 1 argument(s) left + * + * For further information, refer to the getopt(3) man page. + * + * Return: + * * An option character if an option is found. @gs.arg is set to the + * argument if there is one, otherwise it is set to ``NULL``. + * * ``-1`` if there are no more options, if a non-option argument is + * encountered, or if an ``--`` argument is encountered. + * * ``'?'`` if we encounter an option not in @optstring. @gs.opt is set to + * the unknown option. + * * ``':'`` if an argument is required, but no argument follows the + * option. @gs.opt is set to the option missing its argument. + * + * @gs.index is always set to the index of the next unparsed argument in @argv. + */ +static inline int getopt(struct getopt_state *gs, int argc, + char *const argv[], const char *optstring) +{ + return __getopt(gs, argc, argv, optstring, false); +} + +/** + * getopt_silent() - Parse short command-line options silently + * @gs: State + * @argc: Argument count + * @argv: Argument list + * @optstring: Option specification + * + * Same as getopt(), except no error messages are printed. + */ +static inline int getopt_silent(struct getopt_state *gs, int argc, + char *const argv[], const char *optstring) +{ + return __getopt(gs, argc, argv, optstring, true); +} + +#endif /* __GETOPT_H */ diff --git a/lib/Kconfig b/lib/Kconfig index 8efb154f73..a3346eee04 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -542,6 +542,11 @@ config HEXDUMP help This enables functions for printing dumps of binary data. +config GETOPT + bool "Enable getopt" + help + This enables functions for parsing command-line options. + config OF_LIBFDT bool "Enable the FDT library" default y if OF_CONTROL diff --git a/lib/Makefile b/lib/Makefile index 0cd7bea282..7c7fb9aae7 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -106,6 +106,7 @@ obj-y += string.o obj-y += tables_csum.o obj-y += time.o obj-y += hexdump.o +obj-$(CONFIG_GETOPT) += getopt.o obj-$(CONFIG_TRACE) += trace.o obj-$(CONFIG_LIB_UUID) += uuid.o obj-$(CONFIG_LIB_RAND) += rand.o diff --git a/lib/getopt.c b/lib/getopt.c new file mode 100644 index 0000000000..8b4515dc19 --- /dev/null +++ b/lib/getopt.c @@ -0,0 +1,125 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * getopt.c - a simple getopt(3) implementation. See getopt.h for explanation. + * + * Copyright (C) 2020 Sean Anderson + * Copyright (c) 2007 Sascha Hauer , Pengutronix + */ + +#define LOG_CATEGORY LOGC_CORE + +#include +#include +#include + +void getopt_init_state(struct getopt_state *gs) +{ + gs->index = 1; + gs->arg_index = 1; +} + +int __getopt(struct getopt_state *gs, int argc, char *const argv[], + const char *optstring, bool silent) +{ + char curopt; /* current option character */ + const char *curoptp; /* pointer to the current option in optstring */ + + while (1) { + log_debug("arg_index: %d index: %d\n", gs->arg_index, + gs->index); + + /* `--` indicates the end of options */ + if (gs->arg_index == 1 && argv[gs->index] && + !strcmp(argv[gs->index], "--")) { + gs->index++; + return -1; + } + + /* Out of arguments */ + if (gs->index >= argc) + return -1; + + /* Can't parse non-options */ + if (*argv[gs->index] != '-') + return -1; + + /* We have found an option */ + curopt = argv[gs->index][gs->arg_index]; + if (curopt) + break; + /* + * no more options in current argv[] element; try the next one + */ + gs->index++; + gs->arg_index = 1; + } + + /* look up current option in optstring */ + curoptp = strchr(optstring, curopt); + + if (!curoptp) { + if (!silent) + printf("%s: invalid option -- %c\n", argv[0], curopt); + gs->opt = curopt; + gs->arg_index++; + return '?'; + } + + if (*(curoptp + 1) != ':') { + /* option with no argument. Just return it */ + gs->arg = NULL; + gs->arg_index++; + return curopt; + } + + if (*(curoptp + 1) && *(curoptp + 2) == ':') { + /* optional argument */ + if (argv[gs->index][gs->arg_index + 1]) { + /* optional argument with directly following arg */ + gs->arg = argv[gs->index++] + gs->arg_index + 1; + gs->arg_index = 1; + return curopt; + } + if (gs->index + 1 == argc) { + /* We are at the last argv[] element */ + gs->arg = NULL; + gs->index++; + return curopt; + } + if (*argv[gs->index + 1] != '-') { + /* + * optional argument with arg in next argv[] element + */ + gs->index++; + gs->arg = argv[gs->index++]; + gs->arg_index = 1; + return curopt; + } + + /* no optional argument found */ + gs->arg = NULL; + gs->arg_index = 1; + gs->index++; + return curopt; + } + + if (argv[gs->index][gs->arg_index + 1]) { + /* required argument with directly following arg */ + gs->arg = argv[gs->index++] + gs->arg_index + 1; + gs->arg_index = 1; + return curopt; + } + + gs->index++; + gs->arg_index = 1; + + if (gs->index >= argc || argv[gs->index][0] == '-') { + if (!silent) + printf("option requires an argument -- %c\n", curopt); + gs->opt = curopt; + return ':'; + } + + gs->arg = argv[gs->index++]; + return curopt; +} From patchwork Sat Oct 10 19:43:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1380116 X-Patchwork-Delegate: trini@ti.com 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; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=Az+YHUg9; 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 4C7wSc6zzyz9sSn for ; Sun, 11 Oct 2020 06:47:12 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7C2368245A; Sat, 10 Oct 2020 21:44:21 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Az+YHUg9"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CC9088243F; Sat, 10 Oct 2020 21:44:14 +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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) (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 E2AF282423 for ; Sat, 10 Oct 2020 21:44:11 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qk1-x730.google.com with SMTP id a23so14093585qkg.13 for ; Sat, 10 Oct 2020 12:44:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xOS2vESCniYX2G4wcTWexTfBwCQfHQybCIJc07nSaEQ=; b=Az+YHUg9LMdb35z5dhgAKHNhXySIL1yekYgfNrFJbt5lROw7EMcCBXPXH/WZDWEhpC qvMRExGv3MkcPqkTrTJhc3AniXnukz+q0f/IRxMxSz/580jolQ3Fb4xLGErsQOtSmsz9 EDjMVYe+aEFWkWdz7ConPSVtjeXZmxXyhQvvXa9SqhrOW1anSpIuhv91pwtnuq5NJuvI 62ktsQy2yIuTEI5gYiGVLwZ2vm23hWCc9DQz4xGaYxNofD+dEzpndtBHNahNTXlSJgKL iBf5ipJJvHaSSHxQZTW1cKOERFmBm9DzoeI9cO8nSSUgDwxGYXpK7IgYlx8Z61ISl3bY EeTQ== 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=xOS2vESCniYX2G4wcTWexTfBwCQfHQybCIJc07nSaEQ=; b=kIz+FS0ymToiSj+iFWRmGwK1XPKaY6+McyabdvbUCUn6JueMOEPadZ/8YAjVDTt1Wj FqxRX9P+F9jDqJCYl0Ol4Km3pECIThTWjRmiIO7HIkhPanJ73fj/ASBmz4YiHTq78O0G /n744Cuw8jSex18QgA7PaxxbavfQ7UQtj2sMOYCSk0yTYj/Xco5wmtl40ttuMmWAP4mz Xt3olm3XzSrAXV2Z6OC7Qbsz2+wj8cPFAVSyxyRc9PvNFTsXRSM0QQ39uFu2tpgxN4Qw cXHH5jcEg1cfQ7MiypzMU4UuKlF2lKPAMEP0gO7IWs/MQLkrohOhDQtBWueg2oZzmhev TELA== X-Gm-Message-State: AOAM530BUqYXrb/H8Xp7eXyTOsVdpLs/exivgfBM0AK3sGogJUbdPTM+ uamJ4oVA97shH9u2F6tbQovBtCiw5U4cZA== X-Google-Smtp-Source: ABdhPJy3wOwZybJr9fRaTl2FK9v+UedvFB5sXHwttSx1qat/o7sX7Rf5nqjSrxVv9cmEq5kK5gdTvA== X-Received: by 2002:a37:a74e:: with SMTP id q75mr3643665qke.277.1602359050627; Sat, 10 Oct 2020 12:44:10 -0700 (PDT) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id h2sm5588376qkn.89.2020.10.10.12.44.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Oct 2020 12:44:10 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v2 18/22] test: Add a test for getopt Date: Sat, 10 Oct 2020 15:43:43 -0400 Message-Id: <20201010194347.90096-19-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201010194347.90096-1-seanga2@gmail.com> References: <20201010194347.90096-1-seanga2@gmail.com> 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.3 at phobos.denx.de X-Virus-Status: Clean A few of these tests were inspired by those in glibc. The syntax for invoking test_getopt is a bit funky, but it's necessary so that the CPP can parse the arguments correctly. Signed-off-by: Sean Anderson --- (no changes since v1) test/lib/Makefile | 1 + test/lib/getopt.c | 123 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 test/lib/getopt.c diff --git a/test/lib/Makefile b/test/lib/Makefile index 22236f8587..3140c2dad7 100644 --- a/test/lib/Makefile +++ b/test/lib/Makefile @@ -13,3 +13,4 @@ obj-$(CONFIG_ERRNO_STR) += test_errno_str.o obj-$(CONFIG_UT_LIB_ASN1) += asn1.o obj-$(CONFIG_UT_LIB_RSA) += rsa.o obj-$(CONFIG_AES) += test_aes.o +obj-$(CONFIG_GETOPT) += getopt.o diff --git a/test/lib/getopt.c b/test/lib/getopt.c new file mode 100644 index 0000000000..3c68b93c8a --- /dev/null +++ b/test/lib/getopt.c @@ -0,0 +1,123 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2020 Sean Anderson + * + * Portions of these tests were inspired by glibc's posix/bug-getopt1.c and + * posix/tst-getopt-cancel.c + */ + +#include +#include +#include +#include +#include + +static int do_test_getopt(struct unit_test_state *uts, int line, + struct getopt_state *gs, const char *optstring, + int args, char *argv[], int expected_count, + int expected[]) +{ + int opt; + + getopt_init_state(gs); + for (int i = 0; i < expected_count; i++) { + opt = getopt_silent(gs, args, argv, optstring); + if (expected[i] != opt) { + /* + * Fudge the line number so we can tell which test + * failed + */ + ut_failf(uts, __FILE__, line, __func__, + "expected[i] == getopt()", + "Expected '%c' (%d) with i=%d, got '%c' (%d)", + expected[i], expected[i], i, opt, opt); + return CMD_RET_FAILURE; + } + } + + opt = getopt_silent(gs, args, argv, optstring); + if (opt != -1) { + ut_failf(uts, __FILE__, line, __func__, + "getopt() != -1", + "Expected -1, got '%c' (%d)", opt, opt); + return CMD_RET_FAILURE; + } + + return 0; +} + +#define test_getopt(optstring, argv, expected) do { \ + int ret = do_test_getopt(uts, __LINE__, &gs, optstring, \ + ARRAY_SIZE(argv) - 1, argv, \ + ARRAY_SIZE(expected), expected); \ + if (ret) \ + return ret; \ +} while (0) + +static int lib_test_getopt(struct unit_test_state *uts) +{ + struct getopt_state gs; + + /* Happy path */ + test_getopt("ab:c", + ((char *[]){ "program", "-cb", "x", "-a", "foo", 0 }), + ((int []){ 'c', 'b', 'a' })); + ut_asserteq(4, gs.index); + + /* Make sure we pick up the optional argument */ + test_getopt("a::b:c", + ((char *[]){ "program", "-cbx", "-a", "foo", 0 }), + ((int []){ 'c', 'b', 'a' })); + ut_asserteq(4, gs.index); + + /* Test required arguments */ + test_getopt("a:b", ((char *[]){ "program", "-a", 0 }), + ((int []){ ':' })); + ut_asserteq('a', gs.opt); + test_getopt("a:b", ((char *[]){ "program", "-b", "-a", 0 }), + ((int []){ 'b', ':' })); + ut_asserteq('a', gs.opt); + + /* Test invalid arguments */ + test_getopt("ab:c", ((char *[]){ "program", "-d", 0 }), + ((int []){ '?' })); + ut_asserteq('d', gs.opt); + + /* Test arg */ + test_getopt("a::b:c", + ((char *[]){ "program", "-a", 0 }), + ((int []){ 'a' })); + ut_asserteq(2, gs.index); + ut_assertnull(gs.arg); + + test_getopt("a::b:c", + ((char *[]){ "program", "-afoo", 0 }), + ((int []){ 'a' })); + ut_asserteq(2, gs.index); + ut_assertnonnull(gs.arg); + ut_asserteq_str("foo", gs.arg); + + test_getopt("a::b:c", + ((char *[]){ "program", "-a", "foo", 0 }), + ((int []){ 'a' })); + ut_asserteq(3, gs.index); + ut_assertnonnull(gs.arg); + ut_asserteq_str("foo", gs.arg); + + test_getopt("a::b:c", + ((char *[]){ "program", "-bfoo", 0 }), + ((int []){ 'b' })); + ut_asserteq(2, gs.index); + ut_assertnonnull(gs.arg); + ut_asserteq_str("foo", gs.arg); + + test_getopt("a::b:c", + ((char *[]){ "program", "-b", "foo", 0 }), + ((int []){ 'b' })); + ut_asserteq(3, gs.index); + ut_assertnonnull(gs.arg); + ut_asserteq_str("foo", gs.arg); + + return 0; +} +LIB_TEST(lib_test_getopt, 0); From patchwork Sat Oct 10 19:43:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1380118 X-Patchwork-Delegate: trini@ti.com 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; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=nMbKlKwe; 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 4C7wSy666xz9sSn for ; Sun, 11 Oct 2020 06:47:30 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6D7B18246F; Sat, 10 Oct 2020 21:44:23 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="nMbKlKwe"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1A5F58243E; Sat, 10 Oct 2020 21:44:16 +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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qv1-xf31.google.com (mail-qv1-xf31.google.com [IPv6:2607:f8b0:4864:20::f31]) (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 171DF8241C for ; Sat, 10 Oct 2020 21:44:13 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qv1-xf31.google.com with SMTP id ev17so6505407qvb.3 for ; Sat, 10 Oct 2020 12:44:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=I8qe6IF1P0oW9aOgrCkaoh3Glh79rbsi2QWVlqHrXZQ=; b=nMbKlKwecehQL0wiGJH2CZ0/E6+eybweIYi1RAclqZdmQQSQ7xfWvhhea9xC+M2jI2 MDfdOSEpAFId0STGUeoZ0a1wcFWyP80OkNffrfaw89OfAxyHNgPMqvceZY3Og1aejhiF obaeeY6xLrNVI58GpRgUlmSyjGfuLGwpvCUiLas1DL4oeciARoJbF84sfpBnCAC6/rpF O35oJGYZKG3FxSjeINFSF3LeX2FZp6U+ThskujCI0uEG8Vkmfjy50+gOI8o//n4iO0OY jM58a6GJwSPlZwgtKUIdGSuFAsnNqZ/lsnceop2zcSv2WjMwvouL7den3yptS/Vj5q8o aZfA== 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=I8qe6IF1P0oW9aOgrCkaoh3Glh79rbsi2QWVlqHrXZQ=; b=j++ZVGmqyb9xPKduWRh+0OjhYIkfzWBLrYd8OS905hkqy6ei6cSBUU9CxLO4BhlJWF ppYrT7xwnw+NugaHGcuXJm3A825AGZJQ3Yt8NdRAIw1wQoOnvHGhZjb2VTOENChYqn+k ojIy+AZLYvSrID84i4+CFD4N4Trq9bA9Xm08oNVBSKWqjhmaYjUDr2HOrvlw9poL6ezX KPBv1ZH/BVv5EPg1ZY84lutgGmXqvi7upSHWfsWD42b+UrVaZnz0RYW1Nu2nj7N7afaw xnvx/ytDNkLmn+IVgPgUmBbSjta+BgpWRzJ104F4nlLRkxOHRtlvTglaVzVshp63Wawm vGSg== X-Gm-Message-State: AOAM533xOL+sF7fnO+UhyIhm8Jwy2LHVIexyln0Mx0ZSXs6z5kjje0hj bzuuEyXnAqAH+W3j1mg7rkbrOJLg0KmBsQ== X-Google-Smtp-Source: ABdhPJwDYn6Caz7ekkZELmRQfW1LEovyzpcxV0mYL66NhQQD7wzOg8Ap0KKx4gGFtFwWg4LSvMoxbw== X-Received: by 2002:ad4:472c:: with SMTP id l12mr18757865qvz.42.1602359051619; Sat, 10 Oct 2020 12:44:11 -0700 (PDT) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id h2sm5588376qkn.89.2020.10.10.12.44.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Oct 2020 12:44:11 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v2 19/22] cmd: log: Add commands to manipulate filters Date: Sat, 10 Oct 2020 15:43:44 -0400 Message-Id: <20201010194347.90096-20-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201010194347.90096-1-seanga2@gmail.com> References: <20201010194347.90096-1-seanga2@gmail.com> 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.3 at phobos.denx.de X-Virus-Status: Clean This adds several commands to add, list, and remove log filters. Due to the complexity of adding a filter, `log filter-list` uses options instead of positional arguments. These commands have been added as subcommands to log by using a dash to join the subcommand and subsubcommand. This is stylistic, and they could be converted to proper subsubcommands if it is wished. Signed-off-by: Sean Anderson Reviewed-by: Simon Glass --- Changes in v2: - Add option to remove all filters to filter-remove - Clarify filter-* help text cmd/Kconfig | 1 + cmd/log.c | 240 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 241 insertions(+) diff --git a/cmd/Kconfig b/cmd/Kconfig index 4cb171790b..e7e5d88bdb 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -2147,6 +2147,7 @@ config CMD_KGDB config CMD_LOG bool "log - Generation, control and access to logging" select LOG + select GETOPT 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 diff --git a/cmd/log.c b/cmd/log.c index f3a265798c..3c27b35025 100644 --- a/cmd/log.c +++ b/cmd/log.c @@ -7,7 +7,9 @@ #include #include #include +#include #include +#include static char log_fmt_chars[LOGF_COUNT] = "clFLfm"; @@ -85,6 +87,220 @@ static int do_log_drivers(struct cmd_tbl *cmdtp, int flag, int argc, return CMD_RET_SUCCESS; } +static int do_log_filter_list(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + int opt; + const char *drv_name = "console"; + struct getopt_state gs; + struct log_filter *filt; + struct log_device *ldev; + + getopt_init_state(&gs); + while ((opt = getopt(&gs, argc, argv, "d:")) > 0) { + switch (opt) { + case 'd': + drv_name = gs.arg; + break; + default: + return CMD_RET_USAGE; + } + } + + if (gs.index != argc) + return CMD_RET_USAGE; + + ldev = log_device_find_by_name(drv_name); + if (!ldev) { + printf("Could not find log device for \"%s\"\n", drv_name); + return CMD_RET_FAILURE; + } + + printf("num policy level categories files\n"); + list_for_each_entry(filt, &ldev->filter_head, sibling_node) { + printf("%3d %6.6s %s%-7.7s ", filt->filter_num, + filt->flags & LOGFF_DENY ? "deny" : "allow", + filt->flags & LOGFF_LEVEL_MIN ? ">=" : "<=", + log_get_level_name(filt->level)); + + if (filt->flags & LOGFF_HAS_CAT) { + int i; + + if (filt->cat_list[0] != LOGC_END) + printf("%16.16s %s\n", + log_get_cat_name(filt->cat_list[0]), + filt->file_list ? filt->file_list : ""); + + for (i = 1; i < LOGF_MAX_CATEGORIES && + filt->cat_list[i] != LOGC_END; i++) + printf("%20c %16.16s\n", ' ', + log_get_cat_name(filt->cat_list[i])); + } else { + printf("%16c %s\n", ' ', + filt->file_list ? filt->file_list : ""); + } + } + + return CMD_RET_SUCCESS; +} + +static int do_log_filter_add(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + bool level_set = false; + bool print_num = false; + bool type_set = false; + char *file_list = NULL; + const char *drv_name = "console"; + int opt, err; + int cat_count = 0; + int flags = 0; + enum log_category_t cat_list[LOGF_MAX_CATEGORIES + 1]; + enum log_level_t level = LOGL_MAX; + struct getopt_state gs; + + getopt_init_state(&gs); + while ((opt = getopt(&gs, argc, argv, "Ac:d:Df:l:L:p")) > 0) { + switch (opt) { + case 'A': +#define do_type() do { \ + if (type_set) { \ + printf("Allow or deny set twice\n"); \ + return CMD_RET_USAGE; \ + } \ + type_set = true; \ +} while (0) + do_type(); + break; + case 'c': { + enum log_category_t cat; + + if (cat_count >= LOGF_MAX_CATEGORIES) { + printf("Too many categories\n"); + return CMD_RET_FAILURE; + } + + cat = log_get_cat_by_name(gs.arg); + if (cat == LOGC_NONE) { + printf("Unknown category \"%s\"\n", gs.arg); + return CMD_RET_FAILURE; + } + + cat_list[cat_count++] = cat; + break; + } + case 'd': + drv_name = gs.arg; + break; + case 'D': + do_type(); + flags |= LOGFF_DENY; + break; + case 'f': + file_list = gs.arg; + break; + case 'l': +#define do_level() do { \ + if (level_set) { \ + printf("Log level set twice\n"); \ + return CMD_RET_USAGE; \ + } \ + level = parse_log_level(gs.arg); \ + if (level == LOGL_NONE) \ + return CMD_RET_FAILURE; \ + level_set = true; \ +} while (0) + do_level(); + break; + case 'L': + do_level(); + flags |= LOGFF_LEVEL_MIN; + break; + case 'p': + print_num = true; + break; + default: + return CMD_RET_USAGE; + } + } + + if (gs.index != argc) + return CMD_RET_USAGE; + + cat_list[cat_count] = LOGC_END; + err = log_add_filter_flags(drv_name, cat_count ? cat_list : NULL, level, + file_list, flags); + if (err < 0) { + printf("Could not add filter (err = %d)\n", err); + return CMD_RET_FAILURE; + } else if (print_num) { + printf("%d\n", err); + } + + return CMD_RET_SUCCESS; +} + +static int do_log_filter_remove(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + bool all = false; + int opt, err; + ulong filter_num; + const char *drv_name = "console"; + struct getopt_state gs; + + getopt_init_state(&gs); + while ((opt = getopt(&gs, argc, argv, "ad:")) > 0) { + switch (opt) { + case 'a': + all = true; + break; + case 'd': + drv_name = gs.arg; + break; + default: + return CMD_RET_USAGE; + } + } + + if (all) { + struct log_filter *filt, *tmp_filt; + struct log_device *ldev; + + if (gs.index != argc) + return CMD_RET_USAGE; + + ldev = log_device_find_by_name(drv_name); + if (!ldev) { + printf("Could not find log device for \"%s\"\n", + drv_name); + return CMD_RET_FAILURE; + } + + list_for_each_entry_safe(filt, tmp_filt, &ldev->filter_head, + sibling_node) { + list_del(&filt->sibling_node); + free(filt); + } + } else { + if (gs.index + 1 != argc) + return CMD_RET_USAGE; + + if (strict_strtoul(argv[gs.index], 10, &filter_num)) { + printf("Invalid filter number \"%s\"\n", argv[gs.index]); + return CMD_RET_FAILURE; + } + + err = log_remove_filter(drv_name, filter_num); + if (err) { + printf("Could not remove filter (err = %d)\n", err); + return CMD_RET_FAILURE; + } + } + + return CMD_RET_SUCCESS; +} + static int do_log_format(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { @@ -163,6 +379,26 @@ static char log_help_text[] = "level [] - get/set log level\n" "categories - list log categories\n" "drivers - list log drivers\n" + "log filter-list [OPTIONS] - list all filters for a log driver\n" + "\t-d - Specify the log driver to list filters from; defaults\n" + "\t to console\n" + "log filter-add [OPTIONS] - add a new filter to a driver\n" + "\t-A - Allow messages matching this filter; mutually exclusive with -D\n" + "\t This is the default.\n" + "\t-c - Category to match; may be specified multiple times\n" + "\t-d - Specify the log driver to add the filter to; defaults\n" + "\t to console\n" + "\t-D - Deny messages matching this filter; mutually exclusive with -A\n" + "\t-f - A comma-separated list of files to match\n" + "\t-l - Match log levels less than or equal to ;\n" + "\t mutually-exclusive with -L\n" + "\t-L - Match log levels greather than or equal to ;\n" + "\t mutually-exclusive with -l\n" + "\t-p - Print the filter number on success\n" + "log filter-remove [OPTIONS] [] - Remove filter number \n" + "\t-a - Remove ALL filters\n" + "\t-d - Specify the log driver to remove the filter from;\n" + "\t defaults to console\n" "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" @@ -179,6 +415,10 @@ U_BOOT_CMD_WITH_SUBCMDS(log, "log system", log_help_text, U_BOOT_SUBCMD_MKENT(level, 2, 1, do_log_level), U_BOOT_SUBCMD_MKENT(categories, 1, 1, do_log_categories), U_BOOT_SUBCMD_MKENT(drivers, 1, 1, do_log_drivers), + U_BOOT_SUBCMD_MKENT(filter-list, 3, 1, do_log_filter_list), + U_BOOT_SUBCMD_MKENT(filter-add, CONFIG_SYS_MAXARGS, 1, + do_log_filter_add), + U_BOOT_SUBCMD_MKENT(filter-remove, 4, 1, do_log_filter_remove), U_BOOT_SUBCMD_MKENT(format, 2, 1, do_log_format), U_BOOT_SUBCMD_MKENT(rec, 7, 1, do_log_rec), #if CONFIG_IS_ENABLED(LOG_TEST) From patchwork Sat Oct 10 19:43:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1380119 X-Patchwork-Delegate: trini@ti.com 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; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=J/GN8UZs; 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 4C7wT80CTpz9sSn for ; Sun, 11 Oct 2020 06:47:39 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5AAF682479; Sat, 10 Oct 2020 21:44:24 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="J/GN8UZs"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8D31982444; Sat, 10 Oct 2020 21:44:17 +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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) (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 EEE2582434 for ; Sat, 10 Oct 2020 21:44:13 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qk1-x743.google.com with SMTP id x20so7134982qkn.1 for ; Sat, 10 Oct 2020 12:44:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=boHMZLInkqaEyslPtp8al15mZffZ48hB7citzaf+cLU=; b=J/GN8UZsyVNCmwR6rHS813amhyqB6qnK4nWjMwQhVipuCgiZe/jp9eNbdsf52CwORt ogT3yWVwNC0xfajMw8nJeC4pUoUvcY5iXnIkWODG9sKZsYOsPa3UAloruqMw0LE+czpJ NEte9VUVFs0qJHGs1GaSHlR9BlKPp3nbqGturRdkMgL3YRLrbzkTo/txT3T9vbPbGF7W sZdHSQsLTFtZGfbyOU+hz7eri575k8oFPkIZTmtupdSybtks4fznP5buaaf9OxNVUZgm xyZRiWyCwoRIg8cUxgtIDlAbEFebrdYxKCHYjbQpipxj3An6HhjcGNSifSyF6ER8PsCo pSlA== 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=boHMZLInkqaEyslPtp8al15mZffZ48hB7citzaf+cLU=; b=X/Ag6K2W3rmI9WyAwwzM/OwKIm9Ya2AyyyyUX97hwyPmoJDiFspUsK+vK/cZoD4P8R yDn0DgH/TYFv2SO74kCvuBmcy2xk0R/T1KwUXFJl342+3KfEldea7W3wn9rsu5Xobv52 8yuv/q6LB6YTDm5gz32sP35V/zR0O9AEv2iNALZ/8bRCqt7T9OEDhA8jtp0PakSNzUMG b/Xy4YwldhcMG/NXG0zQ2m8pnILamgIhOZIS5lk6kn0xQTbP5+Zc5YpbLvDxhPBRQ03D WmuC5nz6zuB+rDOQL8l8i0Lpgcnoqc2gJ2g5rkRvgZG4tHKl9s+YXQh5FUkCR+eabzo6 CwDA== X-Gm-Message-State: AOAM533u7bWXwNGRK2kRn5VqNDi1hg9Y6qa9QqcMcbIBmqgb3uI2Xwmz m06JbOhNXSneMdP3ck+bx+B5eLMaFJJWoA== X-Google-Smtp-Source: ABdhPJxjEUqYICLu222ALWIv0Mxp4rb/vHXo0oRNa+CeLExMPe9SkLaVeYmq7j/PtmXwSqkLn/R/mQ== X-Received: by 2002:a37:e103:: with SMTP id c3mr3478448qkm.360.1602359052660; Sat, 10 Oct 2020 12:44:12 -0700 (PDT) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id h2sm5588376qkn.89.2020.10.10.12.44.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Oct 2020 12:44:12 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v2 20/22] test: Add a test for log filter-* Date: Sat, 10 Oct 2020 15:43:45 -0400 Message-Id: <20201010194347.90096-21-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201010194347.90096-1-seanga2@gmail.com> References: <20201010194347.90096-1-seanga2@gmail.com> 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.3 at phobos.denx.de X-Virus-Status: Clean This exercises a few success and failure modes of the log filter-* commands. log filter-list is not tested because it's purely informational. I don't think there's a good way to test it except by testing if the output of the command exactly matches a sample run. Signed-off-by: Sean Anderson Reviewed-by: Simon Glass --- Changes in v2: - Converted log filter-* tests to C from python include/test/log.h | 1 + test/log/Makefile | 1 + test/log/log_filter.c | 111 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 test/log/log_filter.c diff --git a/include/test/log.h b/include/test/log.h index c661cde75a..99988d65ea 100644 --- a/include/test/log.h +++ b/include/test/log.h @@ -12,5 +12,6 @@ /* Declare a new logging test */ #define LOG_TEST(_name) UNIT_TEST(_name, 0, log_test) +#define LOG_TEST_FLAGS(_name, _flags) UNIT_TEST(_name, _flags, log_test) #endif /* __TEST_LOG_H__ */ diff --git a/test/log/Makefile b/test/log/Makefile index 4c92550f6e..6cb0f81a91 100644 --- a/test/log/Makefile +++ b/test/log/Makefile @@ -3,6 +3,7 @@ # Copyright (c) 2017 Google, Inc obj-$(CONFIG_LOG_TEST) += log_test.o +obj-$(CONFIG_CMD_LOG) += log_filter.o ifdef CONFIG_UT_LOG diff --git a/test/log/log_filter.c b/test/log/log_filter.c new file mode 100644 index 0000000000..4ae4d95308 --- /dev/null +++ b/test/log/log_filter.c @@ -0,0 +1,111 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Tests for memory commands + * + * Copyright 2020 Google LLC + * Written by Simon Glass + */ + +#include +#include +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +/* Test invalid options */ +static int log_test_filter_invalid(struct unit_test_state *uts) +{ + ut_asserteq(1, run_command("log filter-add -AD", 0)); + ut_asserteq(1, run_command("log filter-add -l1 -L1", 0)); + ut_asserteq(1, run_command("log filter-add -l1 -L1", 0)); + ut_asserteq(1, run_command("log filter-add -lfoo", 0)); + ut_asserteq(1, run_command("log filter-add -cfoo", 0)); + ut_asserteq(1, run_command("log filter-add -ccore -ccore -ccore -ccore " + "-ccore -ccore", 0)); + + return 0; +} +LOG_TEST_FLAGS(log_test_filter_invalid, UT_TESTF_CONSOLE_REC); + +/* Test adding and removing filters */ +static int log_test_filter(struct unit_test_state *uts) +{ + bool any_found = false; + bool filt1_found = false; + bool filt2_found = false; + char cmd[32]; + struct log_filter *filt; + struct log_device *ldev; + ulong filt1, filt2; + +#define create_filter(args, filter_num) do {\ + ut_assertok(console_record_reset_enable()); \ + ut_assertok(run_command("log filter-add -p " args, 0)); \ + ut_assert_skipline(); \ + ut_assertok(strict_strtoul(uts->actual_str, 10, &(filter_num))); \ + ut_assert_console_end(); \ +} while (0) + + create_filter("", filt1); + create_filter("-DL warning -cmmc -cspi -ffile", filt2); + + ldev = log_device_find_by_name("console"); + ut_assertnonnull(ldev); + list_for_each_entry(filt, &ldev->filter_head, sibling_node) { + if (filt->filter_num == filt1) { + filt1_found = true; + ut_asserteq(0, filt->flags); + ut_asserteq(LOGL_MAX, filt->level); + ut_assertnull(filt->file_list); + } else if (filt->filter_num == filt2) { + filt2_found = true; + ut_asserteq(LOGFF_HAS_CAT | LOGFF_DENY | + LOGFF_LEVEL_MIN, filt->flags); + ut_asserteq(true, log_has_cat(filt->cat_list, + UCLASS_MMC)); + ut_asserteq(true, log_has_cat(filt->cat_list, + UCLASS_SPI)); + ut_asserteq(LOGL_WARNING, filt->level); + ut_asserteq_str("file", filt->file_list); + } + } + ut_asserteq(true, filt1_found); + ut_asserteq(true, filt2_found); + +#define remove_filter(filter_num) do { \ + ut_assertok(console_record_reset_enable()); \ + snprintf(cmd, sizeof(cmd), "log filter-remove %lu", filter_num); \ + ut_assertok(run_command(cmd, 0)); \ + ut_assert_console_end(); \ +} while (0) + + remove_filter(filt1); + remove_filter(filt2); + + filt1_found = false; + filt2_found = false; + list_for_each_entry(filt, &ldev->filter_head, sibling_node) { + if (filt->filter_num == filt1) + filt1_found = true; + else if (filt->filter_num == filt2) + filt2_found = true; + } + ut_asserteq(false, filt1_found); + ut_asserteq(false, filt2_found); + + create_filter("", filt1); + create_filter("", filt2); + + ut_assertok(console_record_reset_enable()); + ut_assertok(run_command("log filter-remove -a", 0)); + ut_assert_console_end(); + + list_for_each_entry(filt, &ldev->filter_head, sibling_node) + any_found = true; + ut_asserteq(false, any_found); + + return 0; +} +LOG_TEST_FLAGS(log_test_filter, UT_TESTF_CONSOLE_REC); From patchwork Sat Oct 10 19:43:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1380120 X-Patchwork-Delegate: trini@ti.com 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; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=lQfLSugM; 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 4C7wTJ6d7Wz9sSn for ; Sun, 11 Oct 2020 06:47:48 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7FA7B8247E; Sat, 10 Oct 2020 21:44:25 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="lQfLSugM"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CC7198244A; Sat, 10 Oct 2020 21:44:18 +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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qv1-xf36.google.com (mail-qv1-xf36.google.com [IPv6:2607:f8b0:4864:20::f36]) (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 74535823B6 for ; Sat, 10 Oct 2020 21:44:15 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qv1-xf36.google.com with SMTP id bl9so6492013qvb.10 for ; Sat, 10 Oct 2020 12:44:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=04XFxSHelvigO5InnuYdCdhB34y6WdfgiDT6cRwzaqU=; b=lQfLSugMaCWo4px9C3Cj3YvZnrgDkpm2/HZCpZTk2FFvu8GXc1qBkBNgeiPmna77Jk B384grTEYyoJJv2hNhlGEzlyEQS8Cb2kLcB+QwA1T4uQrFovrz+cNeKBjnQiW/z5FwbT 30OVDvwt/UWV458NEdyC78IcbENwfkOANXqzj0W1/vliR1X1ocIoeKCED2qwHSap+q9P BnAs7XDfH1FbJtrYtcp7rdihGiPpq63Gr3DFzPcrHeGQqtzEskoQ/3vBDBFc+o8JYw5s Y7w5mjkaSCmCty05DbEgeEf+qWl5ECKBUW5RFsUqg7wMSFSmqSoCwJAH+0tGkp17cSoF calg== 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=04XFxSHelvigO5InnuYdCdhB34y6WdfgiDT6cRwzaqU=; b=clr9e3gFXJ/qfMAWI14HyAIfO9PpYbhQ3vnaBpwXZJm/PIvJGHPPWkQs/MSWiDoPjm 2nKxUes78ZOZlB0tYp7fHdtrniO6xduOv6nSNlp/eOI1e6R8pjX3A6ojlKr7Ys8zrQRD +njaGHj7hRCxF7bzaUjySUpxFP5oLiHE7yS/DcB5/xvA7/w+8dLmC6gHPUw1c8ZyurJ5 0id98ghMBXWFsdq4VTaokErxIqbEVj3TECkfoRRHb9ZbpYa3d7Xh4E8zyczz8PiTEvXx Dx/GZIzIXGOiQiaF6EB8eeHp1g+HVY70NQmy6F4FnBFMJkcnCDpLEfQ7JIqvhHUp0J13 W9PQ== X-Gm-Message-State: AOAM5312ny+12/FBve1AxvnooJyx4wp1RqNKZSkEOUH0IRCBqZzMyZmC WJJ7sFUKwgaRFxqdJCabTCYm/DI0KIJmQQ== X-Google-Smtp-Source: ABdhPJzcyGH/o61CzKv0tUECjU3p0bXtV3ccHnrbS6WD5nNXXFafTq+90/vLLSPw0WMpR2yTRiOAkQ== X-Received: by 2002:a05:6214:594:: with SMTP id bx20mr7803725qvb.2.1602359053761; Sat, 10 Oct 2020 12:44:13 -0700 (PDT) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id h2sm5588376qkn.89.2020.10.10.12.44.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Oct 2020 12:44:13 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v2 21/22] doc: Add log kerneldocs to documentation Date: Sat, 10 Oct 2020 15:43:46 -0400 Message-Id: <20201010194347.90096-22-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201010194347.90096-1-seanga2@gmail.com> References: <20201010194347.90096-1-seanga2@gmail.com> 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.3 at phobos.denx.de X-Virus-Status: Clean The functions in log.h are already mostly documented, so add them to the generated documentation. Signed-off-by: Sean Anderson Reviewed-by: Simon Glass --- Changes in v2: - Add % before constants in kerneldocs - Document log_level_t and log_category_t members doc/develop/logging.rst | 5 ++ include/log.h | 138 +++++++++++++++++++++++++--------------- 2 files changed, 92 insertions(+), 51 deletions(-) diff --git a/doc/develop/logging.rst b/doc/develop/logging.rst index 7ce8482ab6..6a22062073 100644 --- a/doc/develop/logging.rst +++ b/doc/develop/logging.rst @@ -288,3 +288,8 @@ information Add a command to add new log records and delete existing records. Provide additional log() functions - e.g. logc() to specify the category + +Logging API +----------- +.. kernel-doc:: include/log.h + :internal: diff --git a/include/log.h b/include/log.h index 9dd4484095..1aae3e3ef1 100644 --- a/include/log.h +++ b/include/log.h @@ -17,49 +17,81 @@ struct cmd_tbl; -/** Log levels supported, ranging from most to least important */ +/** + * enum log_level_t - Log levels supported, ranging from most to least important + */ enum log_level_t { - LOGL_EMERG = 0, /* U-Boot is unstable */ - LOGL_ALERT, /* Action must be taken immediately */ - LOGL_CRIT, /* Critical conditions */ - LOGL_ERR, /* Error that prevents something from working */ - LOGL_WARNING, /* Warning may prevent optimial operation */ - LOGL_NOTICE, /* Normal but significant condition, printf() */ - LOGL_INFO, /* General information message */ - LOGL_DEBUG, /* Basic debug-level message */ - LOGL_DEBUG_CONTENT, /* Debug message showing full message content */ - LOGL_DEBUG_IO, /* Debug message showing hardware I/O access */ + /** @LOGL_EMERG: U-Boot is unstable */ + LOGL_EMERG = 0, + /** @LOGL_ALERT: Action must be taken immediately */ + LOGL_ALERT, + /** @LOGL_CRIT: Critical conditions */ + LOGL_CRIT, + /** @LOGL_ERR: Error that prevents something from working */ + LOGL_ERR, + /** @LOGL_WARNING: Warning may prevent optimial operation */ + LOGL_WARNING, + /** @LOGL_NOTICE: Normal but significant condition, printf() */ + LOGL_NOTICE, + /** @LOGL_INFO: General information message */ + LOGL_INFO, + /** @LOGL_DEBUG: Basic debug-level message */ + LOGL_DEBUG, + /** @LOGL_DEBUG_CONTENT: Debug message showing full message content */ + LOGL_DEBUG_CONTENT, + /** @LOGL_DEBUG_IO: Debug message showing hardware I/O access */ + LOGL_DEBUG_IO, + /** @LOGL_COUNT: Total number of valid log levels */ LOGL_COUNT, + /** @LOGL_NONE: Used to indicate that there is no valid log level */ LOGL_NONE, + /** @LOGL_FIRST: The first, most-important log level */ LOGL_FIRST = LOGL_EMERG, + /** @LOGL_MAX: The last, least-important log level */ LOGL_MAX = LOGL_DEBUG_IO, }; /** - * Log categories supported. Most of these correspond to uclasses (i.e. - * enum uclass_id) but there are also some more generic categories + * enum log_category_t - Log categories supported. + * + * Log categories between %LOGC_FIRST and %LOGC_NONE correspond to uclasses + * (i.e. &enum uclass_id), but there are also some more generic categories. */ enum log_category_t { + /** @LOGC_FIRST: First log category */ LOGC_FIRST = 0, /* First part mirrors UCLASS_... */ + /** @LOGC_NONE: Default log category */ LOGC_NONE = UCLASS_COUNT, /* First number is after all uclasses */ - LOGC_ARCH, /* Related to arch-specific code */ - LOGC_BOARD, /* Related to board-specific code */ - LOGC_CORE, /* Related to core features (non-driver-model) */ - LOGC_DM, /* Core driver-model */ - LOGC_DT, /* Device-tree */ - LOGC_EFI, /* EFI implementation */ - LOGC_ALLOC, /* Memory allocation */ - LOGC_SANDBOX, /* Related to the sandbox board */ - LOGC_BLOBLIST, /* Bloblist */ - LOGC_DEVRES, /* Device resources (devres_... functions) */ - /* Advanced Configuration and Power Interface (ACPI) */ + /** @LOGC_ARCH: Related to arch-specific code */ + LOGC_ARCH, + /** @LOGC_BOARD: Related to board-specific code */ + LOGC_BOARD, + /** @LOGC_CORE: Related to core features (non-driver-model) */ + LOGC_CORE, + /** @LOGC_DM: Core driver-model */ + LOGC_DM, + /** @LOGC_DT: Device-tree */ + LOGC_DT, + /** @LOGC_EFI: EFI implementation */ + LOGC_EFI, + /** @LOGC_ALLOC: Memory allocation */ + LOGC_ALLOC, + /** @LOGC_SANDBOX: Related to the sandbox board */ + LOGC_SANDBOX, + /** @LOGC_BLOBLIST: Bloblist */ + LOGC_BLOBLIST, + /** @LOGC_DEVRES: Device resources (``devres_...`` functions) */ + LOGC_DEVRES, + /** @LOGC_ACPI: Advanced Configuration and Power Interface (ACPI) */ LOGC_ACPI, - LOGC_COUNT, /* Number of log categories */ - LOGC_END, /* Sentinel value for a list of log categories */ + /** @LOGC_COUNT: Number of log categories */ + LOGC_COUNT, + /** @LOGC_END: Sentinel value for lists of log categories */ + LOGC_END, }; /* Helper to cast a uclass ID to a log category */ @@ -78,7 +110,7 @@ static inline int log_uc_cat(enum uclass_id id) * @func: Function where log record was generated * @fmt: printf() format string for log record * @...: Optional parameters, according to the format string @fmt - * @return 0 if log record was emitted, -ve on error + * Return: 0 if log record was emitted, -ve on error */ int _log(enum log_category_t cat, enum log_level_t level, const char *file, int line, const char *func, const char *fmt, ...) @@ -231,7 +263,7 @@ void __assert_fail(const char *assertion, const char *file, unsigned int line, * full pathname as it may be huge. Only use this when the user should be * warning, similar to BUG_ON() in linux. * - * @return true if assertion succeeded (condition is true), else false + * Return: true if assertion succeeded (condition is true), else false */ #define assert_noisy(x) \ ({ bool _val = (x); \ @@ -304,8 +336,9 @@ struct log_device; */ struct log_driver { const char *name; + /** - * emit() - emit a log record + * @emit: emit a log record * * Called by the log system to pass a log record to a particular driver * for processing. The filter is checked before calling this function. @@ -359,11 +392,11 @@ enum log_filter_flags { * @filter_num: Sequence number of this filter. This is returned when adding a * new filter, and must be provided when removing a previously added * filter. - * @flags: Flags for this filter (LOGFF_...) + * @flags: Flags for this filter (``LOGFF_...``) * @cat_list: List of categories to allow (terminated by %LOGC_END). If empty - * then all categories are permitted. Up to LOGF_MAX_CATEGORIES entries + * then all categories are permitted. Up to %LOGF_MAX_CATEGORIES entries * can be provided - * @level: Maximum (or minimum, if LOGFF_MIN_LEVEL) log level to allow + * @level: Maximum (or minimum, if %LOGFF_MIN_LEVEL) log level to allow * @file_list: List of files to allow, separated by comma. If NULL then all * files are permitted * @sibling_node: Next filter in the list of filters for this log device @@ -384,8 +417,8 @@ struct log_filter { * log_get_cat_name() - Get the name of a category * * @cat: Category to look up - * @return category name (which may be a uclass driver name) if found, or - * "" if invalid, or "" if not found + * Return: category name (which may be a uclass driver name) if found, or + * "" if invalid, or "" if not found */ const char *log_get_cat_name(enum log_category_t cat); @@ -393,7 +426,7 @@ const char *log_get_cat_name(enum log_category_t cat); * log_get_cat_by_name() - Look up a category by name * * @name: Name to look up - * @return category ID, or LOGC_NONE if not found + * Return: Category, or %LOGC_NONE if not found */ enum log_category_t log_get_cat_by_name(const char *name); @@ -401,7 +434,7 @@ enum log_category_t log_get_cat_by_name(const char *name); * log_get_level_name() - Get the name of a log level * * @level: Log level to look up - * @return log level name (in ALL CAPS) + * Return: Log level name (in ALL CAPS) */ const char *log_get_level_name(enum log_level_t level); @@ -409,7 +442,7 @@ const char *log_get_level_name(enum log_level_t level); * log_get_level_by_name() - Look up a log level by name * * @name: Name to look up - * @return log level ID, or LOGL_NONE if not found + * Return: Log level, or %LOGL_NONE if not found */ enum log_level_t log_get_level_by_name(const char *name); @@ -417,7 +450,7 @@ enum log_level_t log_get_level_by_name(const char *name); * log_device_find_by_name() - Look up a log device by its driver's name * * @drv_name: Name of the driver - * @return the log device, or NULL if not found + * Return: the log device, or %NULL if not found */ struct log_device *log_device_find_by_name(const char *drv_name); @@ -465,15 +498,16 @@ int do_log_test(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); * * @drv_name: Driver name to add the filter to (since each driver only has a * single device) - * @flags: Flags for this filter (LOGFF_...) + * @flags: Flags for this filter (``LOGFF_...``) * @cat_list: List of categories to allow (terminated by %LOGC_END). If empty - * then all categories are permitted. Up to LOGF_MAX_CATEGORIES entries + * then all categories are permitted. Up to %LOGF_MAX_CATEGORIES entries * can be provided - * @level: Maximum (or minimum, if LOGFF_LEVEL_MIN) log level to allow + * @level: Maximum (or minimum, if %LOGFF_LEVEL_MIN) log level to allow * @file_list: List of files to allow, separated by comma. If NULL then all * files are permitted - * @return the sequence number of the new filter (>=0) if the filter was added, - * or a -ve value on error + * Return: + * the sequence number of the new filter (>=0) if the filter was added, or a + * -ve value on error */ int log_add_filter_flags(const char *drv_name, enum log_category_t cat_list[], enum log_level_t level, const char *file_list, @@ -485,13 +519,14 @@ int log_add_filter_flags(const char *drv_name, enum log_category_t cat_list[], * @drv_name: Driver name to add the filter to (since each driver only has a * single device) * @cat_list: List of categories to allow (terminated by %LOGC_END). If empty - * then all categories are permitted. Up to LOGF_MAX_CATEGORIES entries + * then all categories are permitted. Up to %LOGF_MAX_CATEGORIES entries * can be provided * @max_level: Maximum log level to allow - * @file_list: List of files to allow, separated by comma. If NULL then all + * @file_list: List of files to allow, separated by comma. If %NULL then all * files are permitted - * @return the sequence number of the new filter (>=0) if the filter was added, - * or a -ve value on error + * Return: + * the sequence number of the new filter (>=0) if the filter was added, or a + * -ve value on error */ static inline int log_add_filter(const char *drv_name, enum log_category_t cat_list[], @@ -508,8 +543,9 @@ static inline int log_add_filter(const char *drv_name, * @drv_name: Driver name to remove the filter from (since each driver only has * a single device) * @filter_num: Filter number to remove (as returned by log_add_filter()) - * @return 0 if the filter was removed, -ENOENT if either the driver or the - * filter number was not found + * Return: + * 0 if the filter was removed, -%ENOENT if either the driver or the filter + * number was not found */ int log_remove_filter(const char *drv_name, int filter_num); @@ -517,7 +553,7 @@ int log_remove_filter(const char *drv_name, int filter_num); /** * log_init() - Set up the log system ready for use * - * @return 0 if OK, -ENOMEM if out of memory + * Return: 0 if OK, -%ENOMEM if out of memory */ int log_init(void); #else @@ -531,7 +567,7 @@ static inline int log_init(void) * log_get_default_format() - get default log format * * The default log format is configurable via - * CONFIG_LOGF_FILE, CONFIG_LOGF_LINE, CONFIG_LOGF_FUNC. + * %CONFIG_LOGF_FILE, %CONFIG_LOGF_LINE, and %CONFIG_LOGF_FUNC. * * Return: default log format */ From patchwork Sat Oct 10 19:43:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1380121 X-Patchwork-Delegate: trini@ti.com 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; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=sJEI6ykx; 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 4C7wTV27MWz9sSn for ; Sun, 11 Oct 2020 06:47:58 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C2A9382473; Sat, 10 Oct 2020 21:44:26 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="sJEI6ykx"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 913A68244E; Sat, 10 Oct 2020 21:44:19 +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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [IPv6:2607:f8b0:4864:20::735]) (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 87A738241E for ; Sat, 10 Oct 2020 21:44:16 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qk1-x735.google.com with SMTP id f21so1294675qko.5 for ; Sat, 10 Oct 2020 12:44:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GCXrW28UdWB+XmQhJqqCU4xh0S4BZNvV6RuLw6p0aSk=; b=sJEI6ykxESznDS2h+CO8u8wL4qtRwBU3w1Jsk+O05lRDQAqI7ICXqD9CIlwVmM2AZ1 iZN6cvNS1gaNn01NoprP8MJiaaKqlrEPWrMezzPYgsfxoXKKVYOvM9v5JfXH8UpMydUP fEJM43krfeVQibvOrHgTf0Gg/czvaZdEjbqvVgUkPELab5WgBfAmdRx4aLwxrSBjsbKJ wQKpirz+AHBR6zptUhVuaPVRB1ApGzQRwPr/xisfSoWf6gYCdotZbwWk/nvKW6mjbRwg eFnwE7rzywBWTa9jPuFxkPWDztDprzrQwXdpESUGK5uW0wE9Ruf7GAKYpiKbo7BfcjYs Q0sQ== 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=GCXrW28UdWB+XmQhJqqCU4xh0S4BZNvV6RuLw6p0aSk=; b=XCb40W5+H6wzZe75gXMa6Y4yM8n4gn4/C2m5+c1V2A4jb2TrWIIwRx/FnitZqRyAv7 Jd8IRF7jNNZxv70wpatsa/78BXOZz94HkPDSIENgZIgLd0RSwcXiiwochag//X7Kcpov 6FbUIP6rkDf44bMVHCRC3kjQF1SdvI8anBK/oZoEqFbduGrjzUw+XcgLwjM2YwFXfWqu V2vWaVCVuEydqIx9DQnTkK/k/HPjcl/FJ9PDdG95LNnxtIN62LAMsJnOw/LX5490bWxY umMdjR+D/ULyHuoFA8LvoI91YfjACSnK7k9vgIzI+ILxQ9xzGyoDbWUZvuBnW+afWtfM KRyg== X-Gm-Message-State: AOAM532Ok2iQ6SWipXNmy9tL+X2MnVCsfY+ET/WNLJLMMd2C7YeCcMz5 NbybG6Q01wYAl70RGAdzm82Yo0WLjKbNag== X-Google-Smtp-Source: ABdhPJzpUL6p4kRu3L77U+sPiVi+G4URrOspKxQtAydSSgnGbEhLjMLoBv58Y2WwoCp2tt12OuBzXw== X-Received: by 2002:a37:ac12:: with SMTP id e18mr3475598qkm.306.1602359054763; Sat, 10 Oct 2020 12:44:14 -0700 (PDT) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id h2sm5588376qkn.89.2020.10.10.12.44.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Oct 2020 12:44:14 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v2 22/22] doc: Update logging documentation Date: Sat, 10 Oct 2020 15:43:47 -0400 Message-Id: <20201010194347.90096-23-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201010194347.90096-1-seanga2@gmail.com> References: <20201010194347.90096-1-seanga2@gmail.com> 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.3 at phobos.denx.de X-Virus-Status: Clean This updates logging documentation with some examples of the new commands added in the previous commits. It also removes some items from the to-do list which have been implemented. Signed-off-by: Sean Anderson Reviewed-by: Simon Glass --- Changes in v2: - Clarify wording of filter documentation - Include enum definitions instead of re-documenting them - Reorganize log documentation; related sections should now be more proximate doc/develop/logging.rst | 233 ++++++++++++++++++++-------------------- 1 file changed, 114 insertions(+), 119 deletions(-) diff --git a/doc/develop/logging.rst b/doc/develop/logging.rst index 6a22062073..e2ac643c36 100644 --- a/doc/develop/logging.rst +++ b/doc/develop/logging.rst @@ -21,23 +21,13 @@ is visible from the basic console output. U-Boot's logging feature aims to satisfy this goal for both users and developers. - Logging levels -------------- -There are a number logging levels available, in increasing order of verbosity: - -* LOGL_EMERG - Printed before U-Boot halts -* LOGL_ALERT - Indicates action must be taken immediate or U-Boot will crash -* LOGL_CRIT - Indicates a critical error that will cause boot failure -* LOGL_ERR - Indicates an error that may cause boot failure -* LOGL_WARNING - Warning about an unexpected condition -* LOGL_NOTE - Important information about progress -* LOGL_INFO - Information about normal boot progress -* LOGL_DEBUG - Debug information (useful for debugging a driver or subsystem) -* LOGL_DEBUG_CONTENT - Debug message showing full message content -* LOGL_DEBUG_IO - Debug message showing hardware I/O access +There are a number logging levels available. +.. kernel-doc:: include/log.h + :identifiers: log_level_t Logging category ---------------- @@ -46,16 +36,8 @@ Logging can come from a wide variety of places within U-Boot. Each log message has a category which is intended to allow messages to be filtered according to their source. -The following main categories are defined: - -* LOGC_NONE - Unknown category (e.g. a debug() statement) -* UCLASS\_... - Related to a particular uclass (e.g. UCLASS_USB) -* LOGC_ARCH - Related to architecture-specific code -* LOGC_BOARD - Related to board-specific code -* LOGC_CORE - Related to core driver-model support -* LOGC_DT - Related to device tree control -* LOGC_EFI - Related to EFI implementation - +.. kernel-doc:: include/log.h + :identifiers: log_category_t Enabling logging ---------------- @@ -72,7 +54,6 @@ 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. - Temporary logging within a single file -------------------------------------- @@ -86,46 +67,8 @@ to enable building in of all logging statements in a single file. Put it at the top of the file, before any #includes. To actually get U-Boot to output this you need to also set the default logging -level - e.g. set CONFIG_LOG_DEFAULT_LEVEL to 7 (LOGL_DEBUG) or more. Otherwise -debug output is suppressed and will not be generated. - - -Convenience functions ---------------------- - -A number of convenience functions are available to shorten the code needed -for logging: - -* log_err(_fmt...) -* log_warning(_fmt...) -* log_notice(_fmt...) -* log_info(_fmt...) -* log_debug(_fmt...) -* log_content(_fmt...) -* log_io(_fmt...) - -With these the log level is implicit in the name. The category is set by -LOG_CATEGORY, which you can only define once per file, above all #includes, e.g. - -.. code-block:: c - - #define LOG_CATEGORY LOGC_ALLOC - -Remember that all uclasses IDs are log categories too. - - -Log command ------------ - -The 'log' command provides access to several features: - -* level - access the default log level -* format - access the console log format -* rec - output a log record -* test - run tests - -Type 'help log' for details. - +level - e.g. set CONFIG_LOG_DEFAULT_LEVEL to 7 (:c:type:`LOGL_DEBUG`) or more. +Otherwise debug output is suppressed and will not be generated. Using DEBUG ----------- @@ -142,51 +85,6 @@ at the top of a file, then it takes precedence. This means that debug() statements will result in output to the console and this output will not be logged. - -Logging destinations --------------------- - -If logging information goes nowhere then it serves no purpose. U-Boot provides -several possible determinations for logging information, all of which can be -enabled or disabled independently: - -* console - goes to stdout -* syslog - broadcast RFC 3164 messages to syslog servers on UDP port 514 - -The syslog driver sends the value of environmental variable 'log_hostname' as -HOSTNAME if available. - - -Log format ----------- - -You can control the log format using the 'log format' command. The basic -format is:: - - LEVEL.category,file.c:123-func() message - -In the above, file.c:123 is the filename where the log record was generated and -func() is the function name. By default ('log format default') only the -function name and message are displayed on the console. You can control which -fields are present, but not the field order. - - -Filters -------- - -Filters are attached to log drivers to control what those drivers emit. Only -records that pass through the filter make it to the driver. - -Filters can be based on several criteria: - -* maximum log level -* in a set of categories -* in a set of files - -If no filters are attached to a driver then a default filter is used, which -limits output to records with a level less than CONFIG_MAX_LOG_LEVEL. - - Logging statements ------------------ @@ -210,6 +108,113 @@ can be used whenever your function returns an error value: This will write a log record when an error code is detected (a value < 0). This can make it easier to trace errors that are generated deep in the call stack. +Convenience functions +~~~~~~~~~~~~~~~~~~~~~ + +A number of convenience functions are available to shorten the code needed +for logging: + +* log_err(_fmt...) +* log_warning(_fmt...) +* log_notice(_fmt...) +* log_info(_fmt...) +* log_debug(_fmt...) +* log_content(_fmt...) +* log_io(_fmt...) + +With these the log level is implicit in the name. The category is set by +LOG_CATEGORY, which you can only define once per file, above all #includes, e.g. + +.. code-block:: c + + #define LOG_CATEGORY LOGC_ALLOC + +Remember that all uclasses IDs are log categories too. + +Logging destinations +-------------------- + +If logging information goes nowhere then it serves no purpose. U-Boot provides +several possible determinations for logging information, all of which can be +enabled or disabled independently: + +* console - goes to stdout +* syslog - broadcast RFC 3164 messages to syslog servers on UDP port 514 + +The syslog driver sends the value of environmental variable 'log_hostname' as +HOSTNAME if available. + +Filters +~~~~~~~ + +Filters are attached to log drivers to control what those drivers emit. FIlters +can either allow or deny a log message when they match it. Only records which +are allowed by a filter make it to the driver. + +Filters can be based on several criteria: + +* minimum or maximum log level +* in a set of categories +* in a set of files + +If no filters are attached to a driver then a default filter is used, which +limits output to records with a level less than CONFIG_MAX_LOG_LEVEL. + +Log command +----------- + +The 'log' command provides access to several features: + +* level - get/set the log level +* categories - list log categories +* drivers - list log drivers +* filter-list - list filters +* filter-add - add a new filter +* filter-remove - remove filters +* format - access the console log format +* rec - output a log record +* test - run tests + +Type 'help log' for details. + +Log format +~~~~~~~~~~ + +You can control the log format using the 'log format' command. The basic +format is:: + + LEVEL.category,file.c:123-func() message + +In the above, file.c:123 is the filename where the log record was generated and +func() is the function name. By default ('log format default') only the message +is displayed on the console. You can control which fields are present, but not +the field order. + +Adding Filters +~~~~~~~~~~~~~~ + +To add new filters at runtime, use the 'log filter-add' command. For example, to +suppress messages from the SPI subsystem, run:: + + log filter-add -D -c spi + +You will also need to add another filter to allow other messages (because the +default filter no longer applies):: + + log filter-add -A -l debug + +To view active filters, use the 'log filter-list' command. Some example output +is:: + + => log filter-list + num policy level categories files + 0 deny <=IO spi + 1 allow <=DEBUG + +Note that filters are processed in-order from top to bottom, not in the order of +their filter number. Filters are added to the top of the list if they deny when +they match, and to the bottom if they allow when they match. For more +information, consult the usage of the 'log' command, by running 'help log'. Code size --------- @@ -226,7 +231,6 @@ The last option turns every debug() statement into a logging call, which bloats the code hugely. The advantage is that it is then possible to enable all logging within U-Boot. - To Do ----- @@ -259,8 +263,6 @@ Add a way to browse log records Add a way to record log records for browsing using an external tool -Add commands to add and remove filters - Add commands to add and remove log devices Allow sharing of printf format strings in log records to reduce storage size @@ -268,10 +270,6 @@ for large numbers of log records Add a command-line option to sandbox to set the default logging level -Convert core driver model code to use logging - -Convert uclasses to use logging with the correct category - Consider making log() calls emit an automatic newline, perhaps with a logn() function to avoid that @@ -282,9 +280,6 @@ number dropped due to them being generated before the log system was ready. Add a printf() format string pragma so that log statements are checked properly -Enhance the log console driver to show level / category / file / line -information - Add a command to add new log records and delete existing records. Provide additional log() functions - e.g. logc() to specify the category