From patchwork Tue Oct 27 23:55:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1389049 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=pN7fY+88; 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 4CLTBF5X0Xz9sV1 for ; Wed, 28 Oct 2020 10:56:21 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 17DBF82496; Wed, 28 Oct 2020 00:56:05 +0100 (CET) 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="pN7fY+88"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BD383823DD; Wed, 28 Oct 2020 00:56:00 +0100 (CET) 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 31840823DD for ; Wed, 28 Oct 2020 00:55:58 +0100 (CET) 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 j129so3037139qke.5 for ; Tue, 27 Oct 2020 16:55: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=VplDn/Z3eLTaG0994elbCvKnWDlOsipC6/e0cfSXQ2w=; b=pN7fY+88lxTnljgqaBnaTtHK71MhLGWqKrN5rflP4ltLuMwc/6OnBXEkxnwverDYwN 1a4UkfYYwkU+K1RzlPo4oDWZ/OE0SsgKENpTCNVOY9NpODnJwt4/THrjS8QygNiZIF1n wTJHBUNhZDSsnjMtO/t8YFvbA/5NbPxG5Dx7YfSLx2rwFNowj8tfHhSursJhgD18bqDL 6nW7oXyrdC1W4aT/htr7bIsVhhEi3dzFfqtMhnczQxh09oS/vJPPUnin2ZNbdTde0cz9 YJ7scGtZAexoBhJ9zj65pjUHpMFfr9ez4kwleUoCFzqymMJ7l7POamMo8gTlm6qiIhhk NAng== 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=VplDn/Z3eLTaG0994elbCvKnWDlOsipC6/e0cfSXQ2w=; b=hvOrvevEaMj5x7dJtMdHk7ynonLMinMeem4MErrnkVy5XSg1qw7oCypcbvsYGhgfze Qf83Oj31a2Xr6rrGFzrUxZD05q5G3ZOvEdvwS9MGcWTR5Dk3eSFFe+VVm1K9EDDIL41Q Ixc8MGZuR7+J9DvwkSfb7Rs33KYwAPpZvutsMXqaQL7GCvtl9j5R49X1cl8lPnq7OpM0 klhoJUSvigmWumCaJvzQ0OcOtSNmbSHm9InQTbvyuUUqvk8YJgtFtK4V18q2KD+oUs5P jWQsXF9hd/rIDQtaUWJnjE7rb2PtzRvSR/tgjRfBa70mq1gwjBqNa268/poAxk9NfrQ5 cQEQ== X-Gm-Message-State: AOAM53297zVnn6cDIOstUCYiI+uUycCkNxHvxfJHbvhG/K3fYEG5jeZU /cvJGz8n3D7odHYpmVUT9CQqfB0f/qB6PQ== X-Google-Smtp-Source: ABdhPJyOqRxbvAGENtlVLXHynOClZU5ssidA/peww4uxcnPbKQxqsTooYoMMxruJ3CH+Nq8uQQMxVw== X-Received: by 2002:a05:620a:10b7:: with SMTP id h23mr4662115qkk.132.1603842956797; Tue, 27 Oct 2020 16:55: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 69sm1907543qko.48.2020.10.27.16.55.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2020 16:55:56 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v4 01/22] log: Fix missing negation of ENOMEM Date: Tue, 27 Oct 2020 19:55:20 -0400 Message-Id: <20201027235541.706077-2-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201027235541.706077-1-seanga2@gmail.com> References: <20201027235541.706077-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 b7a6ebe298..6aab189a46 100644 --- a/common/log.c +++ b/common/log.c @@ -278,7 +278,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 Tue Oct 27 23:55:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1389051 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=hB+mkbnz; 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 4CLTBh1tyyz9sV7 for ; Wed, 28 Oct 2020 10:56:44 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 65EA1824E1; Wed, 28 Oct 2020 00:56:12 +0100 (CET) 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="hB+mkbnz"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 45ADE824A8; Wed, 28 Oct 2020 00:56:03 +0100 (CET) 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-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) (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 157AA823F3 for ; Wed, 28 Oct 2020 00:55:59 +0100 (CET) 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-x744.google.com with SMTP id h140so3029262qke.7 for ; Tue, 27 Oct 2020 16:55: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=HcMs2N+247wTJeYrZ/7cVwK5xynMDCEMbm4Y+OFbeV0=; b=hB+mkbnzTgEG/PnMv/JJJD3LtFicSQt4Ov/LPIJuKXkaWWprVDJ6IaSJg0cp6LpbLE HjojraHpTNwtUMf//se8j7Z+G9NBZXu5zru15zun31/CKCBEzBEKZqEVOnxlHSTUktxp Y/XbvMkBhWERICuHY1iCJXL/3BJ0CXmmEtJjL8bM9+x+0pcj+5k0FJfa2k/Vv5WhZSsh yshxGhXSOsTmAxXNeu5c4cBaTLixT7Ggr5/MUF/CrAZwc01yTqcruhTZriIb6/5UUDKw 2T97jVYDg+eutchcz1qYq5j3HNrbQmKAv0abBTVllURpTlZWor7Jzk7JQJ6JfYYd+tTZ 61Dw== 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=HcMs2N+247wTJeYrZ/7cVwK5xynMDCEMbm4Y+OFbeV0=; b=brczTOidUmV1yJsSaUN+CQeGXvfu7RLuj8lzzTeF5L7D3eL0YMHh+R3zbk3AIM36+7 nC/zi9SBr64YREvgPnWEJ54F+kBU2zVRL3BgbCNee2ldQQvDc1dPrP+DGGJLTdaXXUAF NA+jStpgaN6RCOYHUTloWd/J2Kfp30dsy9DQXQUWDK6U9oVWynNFuB7NgM08jVVfFEUA dmPGNe5GRzJSP8xwKJDpTzDfDrLMHXJyVp9brdZ6rvAEVloo0n6c5S2/ib0bC5AD/c4z aThnImIeXqf1dVBZECwJ16DW732Q7Hc9sBAdd390IBgphernCJewSyU+OBpEqFVnraDR sHow== X-Gm-Message-State: AOAM532J3HBzPnq7xNl2OTFLS92VEPqd+M6niG7zArisyWxzzM3vcJo+ 31J6OmU5rtaj3ZVBqNuBPLCVsJf6fCDlAg== X-Google-Smtp-Source: ABdhPJyV0l6EHAMKDgVPa9cQvZfzidw2dZwVo3cbVbDf2UaSui02uQpHZHvjexInaaS+lFbGZptVSQ== X-Received: by 2002:a05:620a:a90:: with SMTP id v16mr4555645qkg.377.1603842957843; Tue, 27 Oct 2020 16:55: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 69sm1907543qko.48.2020.10.27.16.55.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2020 16:55:57 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v4 02/22] log: Fix incorrect documentation of log_filter.cat_list Date: Tue, 27 Oct 2020 19:55:21 -0400 Message-Id: <20201027235541.706077-3-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201027235541.706077-1-seanga2@gmail.com> References: <20201027235541.706077-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 --- (no changes since v2) 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 6de5e611c7..5fde401bd9 100644 --- a/include/log.h +++ b/include/log.h @@ -370,7 +370,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 @@ -448,7 +448,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 Tue Oct 27 23:55:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1389050 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=AvN1W+Ih; dkim-atps=neutral Received: from phobos.denx.de (unknown [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) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CLTBh1M9Yz9sV1 for ; Wed, 28 Oct 2020 10:56:43 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C85E6824C4; Wed, 28 Oct 2020 00:56:10 +0100 (CET) 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="AvN1W+Ih"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 64E0682430; Wed, 28 Oct 2020 00:56:03 +0100 (CET) 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-x844.google.com (mail-qt1-x844.google.com [IPv6:2607:f8b0:4864:20::844]) (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 4253A8243D for ; Wed, 28 Oct 2020 00:56:00 +0100 (CET) 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-x844.google.com with SMTP id c5so2417965qtw.3 for ; Tue, 27 Oct 2020 16:56: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=HbBcDoltU9OhLqzRAxaDr5W9lxw3mmHUK90TldIcKck=; b=AvN1W+IhZLrurRQ943OrqXPyDnPzM6WeGiWMHNKF5s+i4a065EutfB4EFZe3XL2erH dpLi/Q2g/9m6ZFox7KwMxk9wylzDfn5sdSxJJKDopSefET37UjxmMzKblw5KkICDGQ8M FozSPNNAw+0JFaba2woXGozkgKWY7h4ut93qiIXvgIBRRF6MiDkH2ucr3NPRoWBfb1PK Zz320LjQvmepf3lwLvOVSG9tMO3hA1ZDjyTJRxWnjPx+KWpC4+KPbtl8pxx3AxkHTxdX YcUCtl/PKERUNxfqEQNqGohgVI0wXg0K/6tDZKHfs9maicRl7MQw0l0bWEGJmccTDfED GkQw== 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=HbBcDoltU9OhLqzRAxaDr5W9lxw3mmHUK90TldIcKck=; b=fnbnwvVAD/h4DRpO/VaVL/xzlgeD+mzSU3bc4ugTvFrZppFgOYa4BpSFUMXGW31mK1 iIOsRdpmBERAAbisFbliOvKvllQkoG1TvCkadmFPiYzgMOTBYw2O1UzInZ9IRz31VJG+ CsE8wUmPTOj7wH812N+LwZ3MA5TPQpqFVxsmovAezACSZdupNLuU9gO7P13qHXNsHN4U b05O1e3oaHev3JijWMKzFDIJg2RjAQULjZbQ7iJTf/+1oiGC6TYKSG60cVMjpRWEmtyB gjC6d2ryzEr5xTRfiaTvDywZb6KOdtuQReBxtDLKPXGKXQtLrvRMOSeim2DJYij9sOSa vzLQ== X-Gm-Message-State: AOAM531gqvS2rq50JHR+IY28P96dV5uXTjqkT5exDHFpRBNWD1mxzGf4 ysfQBwJCYnIxWf2npSHeOCokZYtgeE3oPg== X-Google-Smtp-Source: ABdhPJwjL/T3liGQ0ubKXRuWyEVfAxlHmbgmoDv12fPVVUpjBjXVvsBKw04px0IXHdeWprhY2MbNGA== X-Received: by 2002:ac8:4a0a:: with SMTP id x10mr4718989qtq.3.1603842958909; Tue, 27 Oct 2020 16:55: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 69sm1907543qko.48.2020.10.27.16.55.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2020 16:55:58 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v4 03/22] log: Add additional const qualifier to arrays Date: Tue, 27 Oct 2020 19:55:22 -0400 Message-Id: <20201027235541.706077-4-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201027235541.706077-1-seanga2@gmail.com> References: <20201027235541.706077-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 --- (no changes since v2) 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 6aab189a46..8d5d71ccb4 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", @@ -28,7 +28,7 @@ static const char *log_cat_name[LOGC_COUNT - LOGC_NONE] = { "acpi", }; -static const char *log_level_name[LOGL_COUNT] = { +static const char *const log_level_name[LOGL_COUNT] = { "EMERG", "ALERT", "CRIT", From patchwork Tue Oct 27 23:55:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1389052 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=nElSdjhP; 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 4CLTBx0Bbjz9sV1 for ; Wed, 28 Oct 2020 10:56:56 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C5FC6824E8; Wed, 28 Oct 2020 00:56:13 +0100 (CET) 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="nElSdjhP"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1A1DB81260; Wed, 28 Oct 2020 00:56:04 +0100 (CET) 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-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) (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 4223F81260 for ; Wed, 28 Oct 2020 00:56:01 +0100 (CET) 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-x744.google.com with SMTP id b18so3022531qkc.9 for ; Tue, 27 Oct 2020 16:56: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=7qVo7XsKjnkXMWcNhCdQ/B7PiPBPeCQpYDsNTXJ9+0A=; b=nElSdjhPKXNK+vPT0PRIiU03sf5x7cjGDGlcnL8t5Nr0FuyhykXDS9lbBHpV4bXEBe EFcfmrLEqJDb+OhzJV0PkdB3beFNgZrgl6BeaVZccRy0vBpFGTqOYPZXMHePY7EfjN0P uQerCOaNfuOQA+8KCwekwCRDyQuHOEgStnQ5+lJ5FstQrucPo7xZYQXgAOKaJMw/SzM8 GE0YUGAZuKYc8Xgkfnyy4gk8xtnxVusPS8eMXby9jqxo+M7QuPNMD2KRiB+Sh7pKcWx1 AAAtEvbZOH4pPPn/k6e3wo4WdxwZdKb5x8ThEIvf7XkcKBh13cQ6zUE3BuWu+necUUo5 wVaQ== 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=7qVo7XsKjnkXMWcNhCdQ/B7PiPBPeCQpYDsNTXJ9+0A=; b=Sq3GaceYrCVJlkxl2BIvmsIN/aUUyZy5S7K1nbef1PMRNYYMXwd4T+27HpNMPMR1N4 mz/K1+vcFkd70bo8u5ak+i37Ywh5M0ttuzO8yKD6W1pdBHdkCUezHi+qmNbM7KJWW5WD 0c5LrtpCla6l2UZjSk7OJg2ME58adORAxSoAGofxuc3kgjscq1vgsX69gXi+nCHEr2Pv XJr8PM07+ky9miY8RmwVsNcvqJiB9TxtnNVT7XeFFErJyIjMH/OBuIugoM8yOFeeovHY 7YWuCT+lQylq7JmFUpCnG3OE41GENcxU1uNNfLacvMfUn+lhciB7KYb6cBOMIZFHp80/ TZNQ== X-Gm-Message-State: AOAM5331/LbVcTh3U2nMAZBwnEeCbCGq6QX/Lx5v631BSi2DOSkO6bYB lJ/m8WB5AUFwsEQS5JBokEV4BaCAUyFMmA== X-Google-Smtp-Source: ABdhPJwKInjvkl94Dt51ZlRkUI1um+bZa4/Pwb8lars/FCg6LPe3OZeFUs1ELkNsjyEAOplOt+rteA== X-Received: by 2002:a37:648d:: with SMTP id y135mr4781596qkb.115.1603842959971; Tue, 27 Oct 2020 16:55: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 69sm1907543qko.48.2020.10.27.16.55.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2020 16:55:59 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v4 04/22] log: Use CONFIG_IS_ENABLED() for LOG_TEST Date: Tue, 27 Oct 2020 19:55:23 -0400 Message-Id: <20201027235541.706077-5-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201027235541.706077-1-seanga2@gmail.com> References: <20201027235541.706077-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 Reviewed-by: Simon Glass --- (no changes since v1) cmd/log.c | 4 ++-- 1 file changed, 2 insertions(+), 2 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" From patchwork Tue Oct 27 23:55:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1389053 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=Kmiz8UzQ; 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 4CLTCB04Rsz9sV1 for ; Wed, 28 Oct 2020 10:57:09 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 94D5F824C5; Wed, 28 Oct 2020 00:56:15 +0100 (CET) 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="Kmiz8UzQ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6457B823DD; Wed, 28 Oct 2020 00:56:06 +0100 (CET) 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-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 7FF36823DD for ; Wed, 28 Oct 2020 00:56:02 +0100 (CET) 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 h19so2406247qtq.4 for ; Tue, 27 Oct 2020 16:56: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=B9PT12YVawMTsxh2me3mO5TGI24L2fZK+4WeRAdQwR4=; b=Kmiz8UzQRuOyZ5VKREmDwrjh8MMcD2NH1E95c/8p9zysAXvPgCgyTLmrxocms5OwTV 7CqaA2FGjyI4npeCI7AW7zccC0RxSxvk/WjVaOgIet+2VHAeNXXjanOXdvtd1FPifkZN lIyl2A24QWpSgqFZPzg3NhKeEKGt6Foj9tPZnJYv0Sa9COPZrXSz4HrFgRRy8GS5s320 mkGnSLydIWaVs/n2aFEbtaOztCVulVACHYhnNXGS32weY1796MrmwxOKxwG0yG39s+QJ vO2CLzpMHNfrUUuYewfAoTsqRsA9imDvU4I9eWOowzIAf8GMtMRYvbtU2LlJV/1zkj2u Fzjg== 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=B9PT12YVawMTsxh2me3mO5TGI24L2fZK+4WeRAdQwR4=; b=AA0X9InckDAHZdjRu5VQMytewpK8UXCThbgSuX0gPOdqh/U1mwK0BduZeRTLsGVhyN eFyYI5IXu9E+wiBpSGNLxye4FJRQH2yfm3g7rfZbVKv6IqiQHdVdDLbpMyegJ5PsCJ44 OAuO0Zxcj35qm8VQ5KzP5fiFR201jZzIzsopWfl14C60TbHQPnbCGVnv+LIJfKFF44By KRe9nA2k3e6VMtwZNMAB4Rfe5kCMEa42wUZ8t7SWldR/+QDBZb26oYz5Jb5/4yoNMnYS sxj8LHkDNgbK6R6l2tFz9vIC/Ey3qB8lMkhO1ZHaP+58uqF9csyyt8aTG7seosJ9Qt68 0RxQ== X-Gm-Message-State: AOAM533C3VlMhgTlccWDEhIlSHHkMy46YidskyjndTXI5IiUVChuIwYk EsUhZ8AZacLoOoLRyX9xUgYxxHvzQs1w5g== X-Google-Smtp-Source: ABdhPJygaJOxV8apkJTh7rwJLHbfdsIVZLt6Z6mQhJ300vwKkjLgVL/wjnYkiLAzSdeUQ04+bHq7hw== X-Received: by 2002:ac8:360e:: with SMTP id m14mr4385381qtb.99.1603842961150; Tue, 27 Oct 2020 16:56: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 69sm1907543qko.48.2020.10.27.16.56.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2020 16:56:00 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v4 05/22] log: Expose some helper functions Date: Tue, 27 Oct 2020 19:55:24 -0400 Message-Id: <20201027235541.706077-6-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201027235541.706077-1-seanga2@gmail.com> References: <20201027235541.706077-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 --- (no changes since v2) 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 8d5d71ccb4..74ae7f0ea8 100644 --- a/common/log.c +++ b/common/log.c @@ -93,7 +93,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; @@ -105,15 +105,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; @@ -125,16 +117,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 5fde401bd9..06eb0003fe 100644 --- a/include/log.h +++ b/include/log.h @@ -427,6 +427,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 Tue Oct 27 23:55:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1389054 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=EwndfO+c; 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 4CLTCP5RVGz9sV1 for ; Wed, 28 Oct 2020 10:57:21 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 66B5D8250C; Wed, 28 Oct 2020 00:56:17 +0100 (CET) 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="EwndfO+c"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C6D10824D3; Wed, 28 Oct 2020 00:56:06 +0100 (CET) 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-xf42.google.com (mail-qv1-xf42.google.com [IPv6:2607:f8b0:4864:20::f42]) (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 9323A8243D for ; Wed, 28 Oct 2020 00:56:03 +0100 (CET) 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-xf42.google.com with SMTP id w5so1579489qvn.12 for ; Tue, 27 Oct 2020 16:56: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=jUtiK9n8QLLaK0bgkg9UkFrEUw96T2paf/AZ+mJN9i0=; b=EwndfO+czZwTcbNdYggA6Xy4WCKJ/mBax5vgioxtQbHKmWsJiLmMwa+lqdx2/0t32Y 4nH2hFHkqKtSJmAXuz2/4Dv4pJf6VqFT8SgTQZqlutGdp/qa/CcQ11Sj7X/Va9Ux0+L3 iSOftvGoI7EheabDXdXt9EpdyxeUannJF98CATV+SDT3Bog8pqd9Q81EtJJZ0RaQD8uz 0zizg+ifHtMTXRGiAxq/xkMRAmlZ6o4a1kcr8Xey6ERKoobUPClOXi+7VREo7kBEEycP TY/Nk6IKUn+AxtsAvA9rZU0qQJoyGicSzuuUJSAkAxi0vC3F8VIpr8QVKREqv1F+c0Ch 99aA== 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=jUtiK9n8QLLaK0bgkg9UkFrEUw96T2paf/AZ+mJN9i0=; b=PijG8azHYqQZ7L+EMf69VsAuEWdYO0jYTjFnQfdyEjL1jdJypyMAFC0SE5BS4sEOJ0 rVN2Hk3YO3molYLus1YqEaMh9WXtZ9sIAYbccu4X2PSBJpy5HP0YQ9b0r1B0drvT7ubf BTnXd8ynWoUk0L6cDFMrX622WmBH4vbSUFTorkEBdQdzbAigQNrUrZUYMlFNe0snevHH l8WYEWs5H7wPwPTr/sZr4WHUQdrLCmHpw7ovwFwMjKNVdUs/FVmVaCTJN9xlRFfeJxyH s+/v8MudaKt53JaSZ33Oq8x/YRhscYaPN+/TvFQ9SaQVcXOoZtuIzcjr09M8CxCyGvxV WQDg== X-Gm-Message-State: AOAM531+I2635E1kKaqz+2E7lZDGY4tYspdxV+gPHeiJ0mucLhJNaCZA Yt2gYjWqjV7nCvNUFJMnZzLd2GV8tHHU/g== X-Google-Smtp-Source: ABdhPJycJW9Vw3HKvga20elijNrPLQynt/aqvHYuzlcLLpltOoGN4AycFtLxsO3W/IZODerMia3+xg== X-Received: by 2002:a0c:fbc3:: with SMTP id n3mr5008814qvp.59.1603842962324; Tue, 27 Oct 2020 16:56: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 69sm1907543qko.48.2020.10.27.16.56.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2020 16:56:01 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v4 06/22] log: Add function to create a filter with flags Date: Tue, 27 Oct 2020 19:55:25 -0400 Message-Id: <20201027235541.706077-7-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201027235541.706077-1-seanga2@gmail.com> References: <20201027235541.706077-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 74ae7f0ea8..a14b227231 100644 --- a/common/log.c +++ b/common/log.c @@ -230,8 +230,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; @@ -245,6 +246,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 06eb0003fe..4e59a2cf74 100644 --- a/include/log.h +++ b/include/log.h @@ -474,6 +474,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 * @@ -488,8 +507,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 Tue Oct 27 23:55: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: 1389055 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=AOuZcfG4; 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 4CLTCd73jRz9sV1 for ; Wed, 28 Oct 2020 10:57:33 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3E2D48250A; Wed, 28 Oct 2020 00:56:19 +0100 (CET) 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="AOuZcfG4"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7EB6F81260; Wed, 28 Oct 2020 00:56:07 +0100 (CET) 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-xf41.google.com (mail-qv1-xf41.google.com [IPv6:2607:f8b0:4864:20::f41]) (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 8640B81260 for ; Wed, 28 Oct 2020 00:56:04 +0100 (CET) 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-xf41.google.com with SMTP id 63so1586832qva.7 for ; Tue, 27 Oct 2020 16:56: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=pm6Xxna0F2Rugn08fTq9hI/cQxFWY+FAMPqnSe+YH5s=; b=AOuZcfG4Iiz1cG4CvFHQmTbHHfcOzk5dXgFd5DycT6/SHDqbYap2/6/TyVbBnrYZpU s8ShD15jE4FOPN+mBsaJtDSWMGXUkivaA7lUoRDvusarRZUWL0CAOvmY6wd8PNY+lGGM 6FjXbmFleYU6zwnPeiq83ZDt/Enyrk7Ni1VMNoQVj1C7GlqbsZzQulfhKVPqi0qg/tX+ bpLnGj1TXsuAw0YXVUpoy3aWIaAFvdyOU4sMBrjWEHPyu0+wZjJOuR95MpSwvbKj3F11 +ex46ya3zzK8dSdnQBM+sTykoBtY7adzQzXsEQo9NGrPVV84Tep7DrDZ6LuQm6HYEaxw /ePQ== 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=pm6Xxna0F2Rugn08fTq9hI/cQxFWY+FAMPqnSe+YH5s=; b=rsT7ctIqB56g7KwyOzyRfni+LeskZks0v+/51Nd/E+tWL5JB1y8ZvvmKF+AtBVuYVU sQlK4zOgowjIFH/lwkKNwOqQUk6A+hb5icdipLgs/1IfXdtyGga3wbZk1zEIwdmfBPOp keV845PpX+OSFofuWdU1Jy3H8/PMLZJvuJXw3hVhRvKQUbdfzqGroqBeDCJfdLjZ1Eot g6LDS4bpsknFIp57AzMd9Re7pqWnu86jphcl8hUwLtVVzL/2knd3WPNsnFDuk7GumrtG HhuS6h21AC5ly0daaI0klDOiCf8T7YlHuqs/6hpROh7vXv2UP5+91yecFyHD0ttgbZi0 l0kA== X-Gm-Message-State: AOAM531ujVV5MZDZlT53W3/zCCec/eUkAikTfyFZUMfrW3x/TK5p7nPZ bCDsRWh+3Sx2N0EcFW21wuxJIAyKfo3FwQ== X-Google-Smtp-Source: ABdhPJz42ThkH/cEXtS7gLnSw0K32bxktQvqzWHFmNbPis9j/2xvzP5PUEKX2hZK8AqOZsSgxbLJLQ== X-Received: by 2002:a05:6214:104d:: with SMTP id l13mr5346364qvr.38.1603842963311; Tue, 27 Oct 2020 16:56: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 69sm1907543qko.48.2020.10.27.16.56.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2020 16:56:02 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v4 07/22] log: Add filter flag to deny on match Date: Tue, 27 Oct 2020 19:55:26 -0400 Message-Id: <20201027235541.706077-8-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201027235541.706077-1-seanga2@gmail.com> References: <20201027235541.706077-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 a14b227231..6299c8b2d4 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; @@ -268,7 +272,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 4e59a2cf74..018180e788 100644 --- a/include/log.h +++ b/include/log.h @@ -359,13 +359,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 Tue Oct 27 23:55: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: 1389058 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=t5rAipsD; 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 4CLTDL6SG8z9sV1 for ; Wed, 28 Oct 2020 10:58:10 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8E09B824F4; Wed, 28 Oct 2020 00:56:24 +0100 (CET) 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="t5rAipsD"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BC84B824DA; Wed, 28 Oct 2020 00:56:10 +0100 (CET) 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-xf41.google.com (mail-qv1-xf41.google.com [IPv6:2607:f8b0:4864:20::f41]) (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 ED7DE824C4 for ; Wed, 28 Oct 2020 00:56:05 +0100 (CET) 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-xf41.google.com with SMTP id s17so1580073qvr.11 for ; Tue, 27 Oct 2020 16:56: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=tSmLI7H68yJCAiacZL8ufwXU1fzjL7Elv5a8PxgGePw=; b=t5rAipsDTZQNDeO2ds3pm4267eAFaVk3cnGOyr4lLpFdadwUF7mVwhIRbXVV/DkhSX S25mEanrY68PeilDoV2Jnh+NIbvjUJy19qQFxm20GGpkT3+kwIH9k/hGn9v0nm/o7pyR JBJwlpwwBiijBJmaf3JNd/H6l11q0ZkQd0YkOZi6DBZ7hsmAh5xEUMMYR5Ri4kkft+n3 86vPzyAIHmgsoiamLb4XNcUsKvS6tPN7MPTSNE0xgPRmw5rX48ArKsPQU5yWBlzRjQPs DWHLuTPyJWGqVIVqKBlRRyjG+R9LgY9259+OOQQ/1w2vS1WRccjVedjswQQFLwuWRuLb IxjA== 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=tSmLI7H68yJCAiacZL8ufwXU1fzjL7Elv5a8PxgGePw=; b=ObfPNS0iekVzoxurL5qVGjz/AJfblqCui/qdahErIm9MHKoZ5KKhUIAD/+vGZa7ksN IXlR2GfPx+uK8okn9zHQPNR41MKZQZL6pY1wa1S+Nan/F9vNNZwgPd/SzqAi9de5kl+W M4Bki09BWT1DkSyUJwUoTM9SrVRUZvc2bnS77MDTh4EEoRD/2vqjjaUIYf5Yw9cnZJYv f6q6b9Wh6xp5xLW7wZ6O7uZzu1CGqWwlLbSALNwU24rvM2TPcYfMiT9uqeiHtz5/v/zE Z+GrF7IX/p4oAW+OsNvBMZdpbrZKzleghorDN4DrGU6SMrwMvuVpNaEyM5saL0H9Tlda 3wBA== X-Gm-Message-State: AOAM530yrZgAgYxAdMh6Ix/ldImYF5jyJ5abcWc/OKdTghPdq9ZrdUph x1xF/7ZZM8HXENB00HmIXIUIrmeWuBYD6g== X-Google-Smtp-Source: ABdhPJye22yALWgSw1i3/fEEw+Jz8R0HvAI585OOS73+eU1co4x1ks7BbdYYOmxNs1AfsJW2cYbo7Q== X-Received: by 2002:ad4:5387:: with SMTP id i7mr4802605qvv.43.1603842964350; Tue, 27 Oct 2020 16:56: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 69sm1907543qko.48.2020.10.27.16.56.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2020 16:56:03 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v4 08/22] test: log: Convert log_test from python to C Date: Tue, 27 Oct 2020 19:55:27 -0400 Message-Id: <20201027235541.706077-9-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201027235541.706077-1-seanga2@gmail.com> References: <20201027235541.706077-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 When rebasing this series I had to renumber all my log tests because someone made another log test in the meantime. This involved updaing a number in several places (C and python), and it wasn't checked by the compiler. So I though "how hard could it be to just rewrite in C?" And though it wasn't hard, it *was* tedious. Tests are numbered the same as before to allow for easier review. A note that if a test fails, everything after it will probably also fail. This is because that test won't clean up its filters. There's no easy way to do the cleanup, except perhaps removing all filters in a wrapper function. Signed-off-by: Sean Anderson --- (no changes since v3) Changes in v3: - New cmd/log.c | 6 - include/test/log.h | 2 + test/log/log_test.c | 446 ++++++++++++++++++++++---------------- test/log/syslog_test.h | 2 - test/py/tests/test_log.py | 104 --------- 5 files changed, 260 insertions(+), 300 deletions(-) diff --git a/cmd/log.c b/cmd/log.c index 16a6ef7539..d20bfdf744 100644 --- a/cmd/log.c +++ b/cmd/log.c @@ -105,9 +105,6 @@ static int do_log_rec(struct cmd_tbl *cmdtp, int flag, int argc, static struct cmd_tbl log_sub[] = { U_BOOT_CMD_MKENT(level, CONFIG_SYS_MAXARGS, 1, do_log_level, "", ""), -#if CONFIG_IS_ENABLED(LOG_TEST) - U_BOOT_CMD_MKENT(test, 2, 1, do_log_test, "", ""), -#endif U_BOOT_CMD_MKENT(format, CONFIG_SYS_MAXARGS, 1, do_log_format, "", ""), U_BOOT_CMD_MKENT(rec, CONFIG_SYS_MAXARGS, 1, do_log_rec, "", ""), }; @@ -133,9 +130,6 @@ static int do_log(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) #ifdef CONFIG_SYS_LONGHELP static char log_help_text[] = "level - get/set log level\n" -#if CONFIG_IS_ENABLED(LOG_TEST) - "log test - run log tests\n" -#endif "log format - set log output format. is a string where\n" "\teach letter indicates something that should be displayed:\n" "\tc=category, l=level, F=file, L=line number, f=function, m=msg\n" diff --git a/include/test/log.h b/include/test/log.h index c661cde75a..772e197806 100644 --- a/include/test/log.h +++ b/include/test/log.h @@ -10,6 +10,8 @@ #include +#define LOGF_TEST (BIT(LOGF_FUNC) | BIT(LOGF_MSG)) + /* Declare a new logging test */ #define LOG_TEST(_name) UNIT_TEST(_name, 0, log_test) diff --git a/test/log/log_test.c b/test/log/log_test.c index 6a60ff6be3..c5ca6dcb7a 100644 --- a/test/log/log_test.c +++ b/test/log/log_test.c @@ -9,12 +9,17 @@ #include #include #include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; /* emit some sample log records in different ways, for testing */ -static int log_run(enum uclass_id cat, const char *file) +static int do_log_run(int cat, const char *file) { int i; + gd->log_fmt = LOGF_TEST; debug("debug\n"); for (i = LOGL_FIRST; i < LOGL_COUNT; i++) { log(cat, i, "log %d\n", i); @@ -22,203 +27,268 @@ static int log_run(enum uclass_id cat, const char *file) i); } + gd->log_fmt = log_get_default_format(); return 0; } -static int log_test(int testnum) +#define log_run_cat(cat) do_log_run(cat, "file") +#define log_run_file(file) do_log_run(UCLASS_SPI, file) +#define log_run() do_log_run(UCLASS_SPI, "file") + +#define EXPECT_LOG BIT(0) +#define EXPECT_DIRECT BIT(1) +#define EXPECT_EXTRA BIT(2) + +static int do_check_log_entries(struct unit_test_state *uts, int flags, int min, + int max) { - int ret; + int i; - printf("test %d\n", testnum); - switch (testnum) { - case 0: { - /* Check a category filter using the first category */ - enum log_category_t cat_list[] = { - log_uc_cat(UCLASS_MMC), log_uc_cat(UCLASS_SPI), - LOGC_NONE, LOGC_END - }; - - ret = log_add_filter("console", cat_list, LOGL_MAX, NULL); - if (ret < 0) - return ret; - log_run(UCLASS_MMC, "file"); - ret = log_remove_filter("console", ret); - if (ret < 0) - return ret; - break; - } - case 1: { - /* Check a category filter using the second category */ - enum log_category_t cat_list[] = { - log_uc_cat(UCLASS_MMC), log_uc_cat(UCLASS_SPI), LOGC_END - }; - - ret = log_add_filter("console", cat_list, LOGL_MAX, NULL); - if (ret < 0) - return ret; - log_run(UCLASS_SPI, "file"); - ret = log_remove_filter("console", ret); - if (ret < 0) - return ret; - break; - } - case 2: { - /* Check a category filter that should block log entries */ - enum log_category_t cat_list[] = { - log_uc_cat(UCLASS_MMC), LOGC_NONE, LOGC_END - }; - - ret = log_add_filter("console", cat_list, LOGL_MAX, NULL); - if (ret < 0) - return ret; - log_run(UCLASS_SPI, "file"); - ret = log_remove_filter("console", ret); - if (ret < 0) - return ret; - break; - } - case 3: { - /* Check a passing file filter */ - ret = log_add_filter("console", NULL, LOGL_MAX, "file"); - if (ret < 0) - return ret; - log_run(UCLASS_SPI, "file"); - ret = log_remove_filter("console", ret); - if (ret < 0) - return ret; - break; - } - case 4: { - /* Check a failing file filter */ - ret = log_add_filter("console", NULL, LOGL_MAX, "file"); - if (ret < 0) - return ret; - log_run(UCLASS_SPI, "file2"); - ret = log_remove_filter("console", ret); - if (ret < 0) - return ret; - break; - } - case 5: { - /* Check a passing file filter (second in list) */ - ret = log_add_filter("console", NULL, LOGL_MAX, "file,file2"); - if (ret < 0) - return ret; - log_run(UCLASS_SPI, "file2"); - ret = log_remove_filter("console", ret); - if (ret < 0) - return ret; - break; - } - case 6: { - /* Check a passing file filter */ - ret = log_add_filter("console", NULL, LOGL_MAX, - "file,file2,log/log_test.c"); - if (ret < 0) - return ret; - log_run(UCLASS_SPI, "file2"); - ret = log_remove_filter("console", ret); - if (ret < 0) - return ret; - break; - } - case 7: { - /* Check a log level filter */ - ret = log_add_filter("console", NULL, LOGL_WARNING, NULL); - if (ret < 0) - return ret; - log_run(UCLASS_SPI, "file"); - ret = log_remove_filter("console", ret); - if (ret < 0) - return ret; - break; - } - case 8: { - /* Check two filters, one of which passes everything */ - int filt1, filt2; - - ret = log_add_filter("console", NULL, LOGL_WARNING, NULL); - if (ret < 0) - return ret; - filt1 = ret; - ret = log_add_filter("console", NULL, LOGL_MAX, NULL); - if (ret < 0) - return ret; - filt2 = ret; - log_run(UCLASS_SPI, "file"); - ret = log_remove_filter("console", filt1); - if (ret < 0) - return ret; - ret = log_remove_filter("console", filt2); - if (ret < 0) - return ret; - break; - } - case 9: { - /* Check three filters, which together pass everything */ - int filt1, filt2, filt3; - - ret = log_add_filter("console", NULL, LOGL_MAX, "file)"); - if (ret < 0) - return ret; - filt1 = ret; - ret = log_add_filter("console", NULL, LOGL_MAX, "file2"); - if (ret < 0) - return ret; - filt2 = ret; - ret = log_add_filter("console", NULL, LOGL_MAX, - "log/log_test.c"); - if (ret < 0) - return ret; - filt3 = ret; - log_run(UCLASS_SPI, "file2"); - ret = log_remove_filter("console", filt1); - if (ret < 0) - return ret; - ret = log_remove_filter("console", filt2); - if (ret < 0) - return ret; - ret = log_remove_filter("console", filt3); - if (ret < 0) - return ret; - break; - } - case 10: { - log_err("level %d\n", LOGL_EMERG); - log_err("level %d\n", LOGL_ALERT); - log_err("level %d\n", LOGL_CRIT); - log_err("level %d\n", LOGL_ERR); - log_warning("level %d\n", LOGL_WARNING); - log_notice("level %d\n", LOGL_NOTICE); - log_info("level %d\n", LOGL_INFO); - log_debug("level %d\n", LOGL_DEBUG); - log_content("level %d\n", LOGL_DEBUG_CONTENT); - log_io("level %d\n", LOGL_DEBUG_IO); - break; - } - case 11: - log_err("default\n"); - ret = log_device_set_enable(LOG_GET_DRIVER(console), false); - log_err("disabled\n"); - ret = log_device_set_enable(LOG_GET_DRIVER(console), true); - log_err("enabled\n"); - break; - } + for (i = min; i <= max; i++) { + if (flags & EXPECT_LOG) + ut_assert_nextline("do_log_run() log %d", i); + if (flags & EXPECT_DIRECT) + ut_assert_nextline("func() _log %d", i); + } + if (flags & EXPECT_EXTRA) + for (; i <= LOGL_MAX ; i++) + ut_assert_nextline("func() _log %d", i); + ut_assert_console_end(); return 0; } -int do_log_test(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) +#define check_log_entries_flags_levels(flags, min, max) do {\ + int ret = do_check_log_entries(uts, flags, min, max); \ + if (ret) \ + return ret; \ +} while (0) + +#define check_log_entries_flags(flags) \ + check_log_entries_flags_levels(flags, LOGL_FIRST, _LOG_MAX_LEVEL) +#define check_log_entries() check_log_entries_flags(EXPECT_LOG | EXPECT_DIRECT) +#define check_log_entries_extra() \ + check_log_entries_flags(EXPECT_LOG | EXPECT_DIRECT | EXPECT_EXTRA) +#define check_log_entries_none() check_log_entries_flags(0) + +/* Check a category filter using the first category */ +int log_test_00(struct unit_test_state *uts) +{ + enum log_category_t cat_list[] = { + log_uc_cat(UCLASS_MMC), log_uc_cat(UCLASS_SPI), + LOGC_NONE, LOGC_END + }; + int filt; + + filt = log_add_filter("console", cat_list, LOGL_MAX, NULL); + ut_assert(filt >= 0); + + ut_assertok(console_record_reset_enable()); + log_run_cat(UCLASS_MMC); + check_log_entries_extra(); + + ut_assertok(console_record_reset_enable()); + log_run_cat(UCLASS_SPI); + check_log_entries_extra(); + + ut_assertok(log_remove_filter("console", filt)); + return 0; +} +LOG_TEST_FLAGS(log_test_00, UT_TESTF_CONSOLE_REC); + +/* Check a category filter that should block log entries */ +int log_test_02(struct unit_test_state *uts) +{ + enum log_category_t cat_list[] = { + log_uc_cat(UCLASS_MMC), LOGC_NONE, LOGC_END + }; + int filt; + + filt = log_add_filter("console", cat_list, LOGL_MAX, NULL); + ut_assert(filt >= 0); + + ut_assertok(console_record_reset_enable()); + log_run_cat(UCLASS_SPI); + check_log_entries_none(); + + ut_assertok(log_remove_filter("console", filt)); + return 0; +} +LOG_TEST_FLAGS(log_test_02, UT_TESTF_CONSOLE_REC); + +/* Check passing and failing file filters */ +int log_test_03(struct unit_test_state *uts) +{ + int filt; + + filt = log_add_filter("console", NULL, LOGL_MAX, "file"); + ut_assert(filt >= 0); + + ut_assertok(console_record_reset_enable()); + log_run_file("file"); + check_log_entries_flags(EXPECT_DIRECT | EXPECT_EXTRA); + + ut_assertok(console_record_reset_enable()); + log_run_file("file2"); + check_log_entries_none(); + + ut_assertok(log_remove_filter("console", filt)); + return 0; +} +LOG_TEST_FLAGS(log_test_03, UT_TESTF_CONSOLE_REC); + +/* Check a passing file filter (second in list) */ +int log_test_05(struct unit_test_state *uts) +{ + int filt; + + filt = log_add_filter("console", NULL, LOGL_MAX, "file,file2"); + ut_assert(filt >= 0); + + ut_assertok(console_record_reset_enable()); + log_run_file("file2"); + check_log_entries_flags(EXPECT_DIRECT | EXPECT_EXTRA); + + ut_assertok(log_remove_filter("console", filt)); + return 0; +} +LOG_TEST_FLAGS(log_test_05, UT_TESTF_CONSOLE_REC); + +/* Check a passing file filter (middle of list) */ +int log_test_06(struct unit_test_state *uts) +{ + int filt; + + filt = log_add_filter("console", NULL, LOGL_MAX, + "file,file2,log/log_test.c"); + ut_assert(filt >= 0); + + ut_assertok(console_record_reset_enable()); + log_run_file("file2"); + check_log_entries_extra(); + + ut_assertok(log_remove_filter("console", filt)); + return 0; +} +LOG_TEST_FLAGS(log_test_06, UT_TESTF_CONSOLE_REC); + +/* Check a log level filter */ +int log_test_07(struct unit_test_state *uts) +{ + int filt; + + filt = log_add_filter("console", NULL, LOGL_WARNING, NULL); + ut_assert(filt >= 0); + + ut_assertok(console_record_reset_enable()); + log_run(); + check_log_entries_flags_levels(EXPECT_LOG | EXPECT_DIRECT, LOGL_FIRST, + LOGL_WARNING); + + ut_assertok(log_remove_filter("console", filt)); + return 0; +} +LOG_TEST_FLAGS(log_test_07, UT_TESTF_CONSOLE_REC); + +/* Check two filters, one of which passes everything */ +int log_test_08(struct unit_test_state *uts) +{ + int filt1, filt2; + + filt1 = log_add_filter("console", NULL, LOGL_WARNING, NULL); + ut_assert(filt1 >= 0); + filt2 = log_add_filter("console", NULL, LOGL_MAX, NULL); + ut_assert(filt2 >= 0); + + ut_assertok(console_record_reset_enable()); + log_run(); + check_log_entries_extra(); + + ut_assertok(log_remove_filter("console", filt1)); + ut_assertok(log_remove_filter("console", filt2)); + return 0; +} +LOG_TEST_FLAGS(log_test_08, UT_TESTF_CONSOLE_REC); + +/* Check three filters, which together pass everything */ +int log_test_09(struct unit_test_state *uts) +{ + int filt1, filt2, filt3; + + filt1 = log_add_filter("console", NULL, LOGL_MAX, "file)"); + ut_assert(filt1 >= 0); + filt2 = log_add_filter("console", NULL, LOGL_MAX, "file2"); + ut_assert(filt2 >= 0); + filt3 = log_add_filter("console", NULL, LOGL_MAX, "log/log_test.c"); + ut_assert(filt3 >= 0); + + ut_assertok(console_record_reset_enable()); + log_run_file("file2"); + check_log_entries_extra(); + + ut_assertok(log_remove_filter("console", filt1)); + ut_assertok(log_remove_filter("console", filt2)); + ut_assertok(log_remove_filter("console", filt3)); + return 0; +} +LOG_TEST_FLAGS(log_test_09, UT_TESTF_CONSOLE_REC); + +int do_log_test_10(struct unit_test_state *uts) +{ + int i; + + ut_assertok(console_record_reset_enable()); + log_err("level %d\n", LOGL_EMERG); + log_err("level %d\n", LOGL_ALERT); + log_err("level %d\n", LOGL_CRIT); + log_err("level %d\n", LOGL_ERR); + log_warning("level %d\n", LOGL_WARNING); + log_notice("level %d\n", LOGL_NOTICE); + log_info("level %d\n", LOGL_INFO); + log_debug("level %d\n", LOGL_DEBUG); + log_content("level %d\n", LOGL_DEBUG_CONTENT); + log_io("level %d\n", LOGL_DEBUG_IO); + + for (i = LOGL_EMERG; i <= _LOG_MAX_LEVEL; i++) + ut_assert_nextline("%s() level %d", __func__, i); + ut_assert_console_end(); + return 0; +} + +int log_test_10(struct unit_test_state *uts) { - int testnum = 0; int ret; - if (argc > 1) - testnum = simple_strtoul(argv[1], NULL, 10); - - ret = log_test(testnum); - if (ret) - printf("Test failure (err=%d)\n", ret); - - return ret ? CMD_RET_FAILURE : 0; + gd->log_fmt = LOGF_TEST; + ret = do_log_test_10(uts); + gd->log_fmt = log_get_default_format(); + return ret; } +LOG_TEST_FLAGS(log_test_10, UT_TESTF_CONSOLE_REC); + +int do_log_test_11(struct unit_test_state *uts) +{ + ut_assertok(console_record_reset_enable()); + log_err("default\n"); + ut_assert_nextline("%s() default", __func__); + + ut_assertok(log_device_set_enable(LOG_GET_DRIVER(console), false)); + log_err("disabled\n"); + + ut_assertok(log_device_set_enable(LOG_GET_DRIVER(console), true)); + log_err("enabled\n"); + ut_assert_nextline("%s() enabled", __func__); + ut_assert_console_end(); + return 0; +} + +int log_test_11(struct unit_test_state *uts) +{ + int ret; + + gd->log_fmt = LOGF_TEST; + ret = do_log_test_10(uts); + gd->log_fmt = log_get_default_format(); + return ret; +} +LOG_TEST_FLAGS(log_test_11, UT_TESTF_CONSOLE_REC); diff --git a/test/log/syslog_test.h b/test/log/syslog_test.h index 1310257bfe..bfaa6daef8 100644 --- a/test/log/syslog_test.h +++ b/test/log/syslog_test.h @@ -8,8 +8,6 @@ #ifndef __SYSLOG_TEST_H #define __SYSLOG_TEST_H -#define LOGF_TEST (BIT(LOGF_FUNC) | BIT(LOGF_MSG)) - /** * struct sb_log_env - private data for sandbox ethernet driver * diff --git a/test/py/tests/test_log.py b/test/py/tests/test_log.py index 275f9382d2..387b392ce9 100644 --- a/test/py/tests/test_log.py +++ b/test/py/tests/test_log.py @@ -10,110 +10,6 @@ and checks that the output is correct. import pytest -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): - """Check that the expected log records appear in the output - - Args: - lines: iterator containing lines to check - mask: bit mask to select which lines to check for: - bit 0: standard log line - bit 1: _log line - max_level: maximum log level to expect in the output - """ - for i in range(max_level): - if mask & 1: - assert 'log_run() log %d' % i == next(lines) - if mask & 3: - assert 'func() _log %d' % i == next(lines) - - def run_test(testnum): - """Run a particular test number (the 'log test' command) - - Args: - testnum: Test number to run - Returns: - iterator containing the lines output from the command - """ - output = u_boot_console.run_command('log format fm') - assert output == '' - with cons.log.section('basic'): - output = u_boot_console.run_command('log test %d' % testnum) - split = output.replace('\r', '').splitlines() - lines = iter(split) - assert 'test %d' % testnum == next(lines) - return lines - - def test0(): - lines = run_test(0) - check_log_entries(lines, 3) - - def test1(): - lines = run_test(1) - check_log_entries(lines, 3) - - def test2(): - lines = run_test(2) - - def test3(): - lines = run_test(3) - check_log_entries(lines, 2) - - def test4(): - lines = run_test(4) - assert next(lines, None) == None - - def test5(): - lines = run_test(5) - check_log_entries(lines, 2) - - def test6(): - lines = run_test(6) - check_log_entries(lines, 3) - - def test7(): - lines = run_test(7) - check_log_entries(lines, 3, LOGL_WARNING) - - def test8(): - lines = run_test(8) - check_log_entries(lines, 3) - - def test9(): - lines = run_test(9) - check_log_entries(lines, 3) - - def test10(): - lines = run_test(10) - for i in range(7): - assert 'log_test() level %d' % i == next(lines) - - def test11(): - """Test use of log_device_set_enable()""" - lines = run_test(11) - assert 'log_test() default' - # disabled should not be displayed - assert 'log_test() enabled' - - # TODO(sjg@chromium.org): Consider structuring this as separate tests - cons = u_boot_console - test0() - test1() - test2() - test3() - test4() - test5() - test6() - test7() - test8() - test9() - test10() - test11() - @pytest.mark.buildconfigspec('cmd_log') def test_log_format(u_boot_console): """Test the 'log format' and 'log rec' commands""" From patchwork Tue Oct 27 23:55: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: 1389056 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=XfnalaTY; 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 4CLTCt5B6Xz9sV1 for ; Wed, 28 Oct 2020 10:57:46 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1992882515; Wed, 28 Oct 2020 00:56:21 +0100 (CET) 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="XfnalaTY"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0016F824D6; Wed, 28 Oct 2020 00:56:09 +0100 (CET) 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-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 90FD3824BC for ; Wed, 28 Oct 2020 00:56:06 +0100 (CET) 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 de3so1588706qvb.5 for ; Tue, 27 Oct 2020 16:56: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=E8kA8PNwoUI9NCVNAKigvsoXQvai3g7QL5MvImYUQ14=; b=XfnalaTYt2/hf5D6FZRqMsGo8RkM76t8LfM38abkwLjwGgxUwGHFCvXDAwM5Yadbb1 LTE7EETi4hV56+3EAvE2D9fsDQwvX0AoB9AD1Nep9syGTLTjZT24BWJV0vKQIkz8NHYV cd7lGaVJButUYN/i9i2/jIHAgY3LO7J6YiAybjMtqTiM3Es57SGykEvFw+39OWQeSPAQ XQRtEWQPWbdF1kZxsiY434tcmE7ijworEf+zkFcq9KGoJRsxEMlGIY9eGSPv1Elvlzly /Ohl/Sg6SXInkXg4p4Hvi0rhNSZBWRJAY6+ZWSDxDx2dXW/Rgs8UHHphrDDA67Y5PtCM vJTA== 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=E8kA8PNwoUI9NCVNAKigvsoXQvai3g7QL5MvImYUQ14=; b=c5VVWsiYfBTZEFvM9VEZJEn5OZwbh9LMsB5asX2dIHgaovnXxh9o4flI0+g36hLKR0 SXoJk/T39i0+gWQsGfmG+q+fT0agXnUySuUKQeZ2fWEqTw1ZL/zUKjv0za5BAMmLCyXU tQUY+z/BeC0F4bRfQ3mG/DWeK6/kmbGsM/MvveV+eiskUZmuAQrwtuYJosJ6fm0I5Yp6 Y2xY4mktgN0Hzp8i7rOVy9lewifdyzMRatSGv8rYVVwOGLPx/1s33BFN4Gw2zOMneoo0 UvVObjimWWQ1ucTVStNo2qrSKbGPGFLxAivNavWsMr0SioJBoiz4yo/V3FOYb2mKKKB7 J7+A== X-Gm-Message-State: AOAM5317XCA+ry5Ziz96Sk8kMEZTG1mgO0MSfHrLXq1/iFLcq5gKzpnK VUbB+jzYoemkZmMj+gIx55IEN6D722c7bg== X-Google-Smtp-Source: ABdhPJwCrk3yGIuIf12P9UL5Msh7/ojFp18CuwJbjmDA/HVQXQUJ7j9UoxITn4FUMvHChOzcgGlZBg== X-Received: by 2002:a0c:cd0e:: with SMTP id b14mr5000352qvm.3.1603842965311; Tue, 27 Oct 2020 16:56: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 69sm1907543qko.48.2020.10.27.16.56.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2020 16:56:04 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v4 09/22] test: log: Give tests names instead of numbers Date: Tue, 27 Oct 2020 19:55:28 -0400 Message-Id: <20201027235541.706077-10-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201027235541.706077-1-seanga2@gmail.com> References: <20201027235541.706077-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 Now that the log test command is no more, we can give the log tests proper names. Signed-off-by: Sean Anderson --- (no changes since v3) Changes in v3: - New test/log/log_test.c | 48 ++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/test/log/log_test.c b/test/log/log_test.c index c5ca6dcb7a..4ac378fdad 100644 --- a/test/log/log_test.c +++ b/test/log/log_test.c @@ -72,7 +72,7 @@ static int do_check_log_entries(struct unit_test_state *uts, int flags, int min, #define check_log_entries_none() check_log_entries_flags(0) /* Check a category filter using the first category */ -int log_test_00(struct unit_test_state *uts) +int log_test_cat_allow(struct unit_test_state *uts) { enum log_category_t cat_list[] = { log_uc_cat(UCLASS_MMC), log_uc_cat(UCLASS_SPI), @@ -94,10 +94,10 @@ int log_test_00(struct unit_test_state *uts) ut_assertok(log_remove_filter("console", filt)); return 0; } -LOG_TEST_FLAGS(log_test_00, UT_TESTF_CONSOLE_REC); +LOG_TEST_FLAGS(log_test_cat_allow, UT_TESTF_CONSOLE_REC); /* Check a category filter that should block log entries */ -int log_test_02(struct unit_test_state *uts) +int log_test_cat_deny_implicit(struct unit_test_state *uts) { enum log_category_t cat_list[] = { log_uc_cat(UCLASS_MMC), LOGC_NONE, LOGC_END @@ -114,10 +114,10 @@ int log_test_02(struct unit_test_state *uts) ut_assertok(log_remove_filter("console", filt)); return 0; } -LOG_TEST_FLAGS(log_test_02, UT_TESTF_CONSOLE_REC); +LOG_TEST_FLAGS(log_test_cat_deny_implicit, UT_TESTF_CONSOLE_REC); /* Check passing and failing file filters */ -int log_test_03(struct unit_test_state *uts) +int log_test_file(struct unit_test_state *uts) { int filt; @@ -135,10 +135,10 @@ int log_test_03(struct unit_test_state *uts) ut_assertok(log_remove_filter("console", filt)); return 0; } -LOG_TEST_FLAGS(log_test_03, UT_TESTF_CONSOLE_REC); +LOG_TEST_FLAGS(log_test_file, UT_TESTF_CONSOLE_REC); /* Check a passing file filter (second in list) */ -int log_test_05(struct unit_test_state *uts) +int log_test_file_second(struct unit_test_state *uts) { int filt; @@ -152,10 +152,10 @@ int log_test_05(struct unit_test_state *uts) ut_assertok(log_remove_filter("console", filt)); return 0; } -LOG_TEST_FLAGS(log_test_05, UT_TESTF_CONSOLE_REC); +LOG_TEST_FLAGS(log_test_file_second, UT_TESTF_CONSOLE_REC); /* Check a passing file filter (middle of list) */ -int log_test_06(struct unit_test_state *uts) +int log_test_file_mid(struct unit_test_state *uts) { int filt; @@ -170,10 +170,10 @@ int log_test_06(struct unit_test_state *uts) ut_assertok(log_remove_filter("console", filt)); return 0; } -LOG_TEST_FLAGS(log_test_06, UT_TESTF_CONSOLE_REC); +LOG_TEST_FLAGS(log_test_file_mid, UT_TESTF_CONSOLE_REC); /* Check a log level filter */ -int log_test_07(struct unit_test_state *uts) +int log_test_level(struct unit_test_state *uts) { int filt; @@ -188,10 +188,10 @@ int log_test_07(struct unit_test_state *uts) ut_assertok(log_remove_filter("console", filt)); return 0; } -LOG_TEST_FLAGS(log_test_07, UT_TESTF_CONSOLE_REC); +LOG_TEST_FLAGS(log_test_level, UT_TESTF_CONSOLE_REC); /* Check two filters, one of which passes everything */ -int log_test_08(struct unit_test_state *uts) +int log_test_double(struct unit_test_state *uts) { int filt1, filt2; @@ -208,10 +208,10 @@ int log_test_08(struct unit_test_state *uts) ut_assertok(log_remove_filter("console", filt2)); return 0; } -LOG_TEST_FLAGS(log_test_08, UT_TESTF_CONSOLE_REC); +LOG_TEST_FLAGS(log_test_double, UT_TESTF_CONSOLE_REC); /* Check three filters, which together pass everything */ -int log_test_09(struct unit_test_state *uts) +int log_test_triple(struct unit_test_state *uts) { int filt1, filt2, filt3; @@ -231,9 +231,9 @@ int log_test_09(struct unit_test_state *uts) ut_assertok(log_remove_filter("console", filt3)); return 0; } -LOG_TEST_FLAGS(log_test_09, UT_TESTF_CONSOLE_REC); +LOG_TEST_FLAGS(log_test_triple, UT_TESTF_CONSOLE_REC); -int do_log_test_10(struct unit_test_state *uts) +int do_log_test_helpers(struct unit_test_state *uts) { int i; @@ -255,18 +255,18 @@ int do_log_test_10(struct unit_test_state *uts) return 0; } -int log_test_10(struct unit_test_state *uts) +int log_test_helpers(struct unit_test_state *uts) { int ret; gd->log_fmt = LOGF_TEST; - ret = do_log_test_10(uts); + ret = do_log_test_helpers(uts); gd->log_fmt = log_get_default_format(); return ret; } -LOG_TEST_FLAGS(log_test_10, UT_TESTF_CONSOLE_REC); +LOG_TEST_FLAGS(log_test_helpers, UT_TESTF_CONSOLE_REC); -int do_log_test_11(struct unit_test_state *uts) +int do_log_test_disable(struct unit_test_state *uts) { ut_assertok(console_record_reset_enable()); log_err("default\n"); @@ -282,13 +282,13 @@ int do_log_test_11(struct unit_test_state *uts) return 0; } -int log_test_11(struct unit_test_state *uts) +int log_test_disable(struct unit_test_state *uts) { int ret; gd->log_fmt = LOGF_TEST; - ret = do_log_test_10(uts); + ret = do_log_test_disable(uts); gd->log_fmt = log_get_default_format(); return ret; } -LOG_TEST_FLAGS(log_test_11, UT_TESTF_CONSOLE_REC); +LOG_TEST_FLAGS(log_test_disable, UT_TESTF_CONSOLE_REC); From patchwork Tue Oct 27 23:55: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: 1389057 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=sMFeI14a; 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 4CLTD64QPNz9sV1 for ; Wed, 28 Oct 2020 10:57:58 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E9B2E8250B; Wed, 28 Oct 2020 00:56:22 +0100 (CET) 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="sMFeI14a"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 65A47824D6; Wed, 28 Oct 2020 00:56:10 +0100 (CET) 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 892C0823DD for ; Wed, 28 Oct 2020 00:56:07 +0100 (CET) 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 w9so1595618qvj.0 for ; Tue, 27 Oct 2020 16:56: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=9dOn61+pA40A5Ktb6sHsbYJ8ycpBT/MZ8v9CTBdThhE=; b=sMFeI14aoJEg8qqEK2kuzSS0qMFfY6WWtV2AjA1YMwxf/IIW/Z11vA+F7ooxuVNNUr 36fi6s0Andvhm9ixyYdUFZhEDBJWQ3Y0XY93/860376JwviIKs2Ws2s2DaBv44D3ocaZ bFK+5km10ETS3fE3YhSBkLg37u0w9fZFXWrln1X0eOiI1MsqQQ1L7CEenPNKJxWfzWox MP/flVQhwvXoCY+wSLjjHwzBei06+n3+vXsHvZ9Ji0jO9/93htpqYSpAtGmZJKr3D1uc OJ08g4yIj6Zclcrh8pTZUg/GgzjW4K8NezrZuhf1soJq9ysY+fETPQmxo016lKcC8CfN PMvQ== 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=9dOn61+pA40A5Ktb6sHsbYJ8ycpBT/MZ8v9CTBdThhE=; b=U3bKdak2y0Y5pkaaY/ok3CICxzm5DcEaXFLyeHN8MreheGGFIrBWzTR+97R3ULeWud 7nd/w/8AwezA5OJ0S3UtX3nJ0rfqmha9bDI7CGgaPSfwNanbb70Uj/z3aRYyt8q0HoLD qWNdNP+h98QJAtTC+9JV32VBzLwQP6KbsgpqUZR4CdJnlv7JLtlZ+LM29N+SZGa9Czlf bBYCV9wrD6c+aJyWo2B+sbW4+5bNrZ93F2UwFrXxUN7xXlCviiaGnQewAy0pNMVSXmET t2Oh++GqZCPv164hZMK1GLqe/76yCmCOXpHefhNloReteYe0wmUIhPS8yjMOuVLi5fqZ MsDQ== X-Gm-Message-State: AOAM533vw1J4AZvYy2kJjclOZnILEfTA9KuX63t9eixAWZlCX3f+fsb2 Gsm4M+RKYZ0QejRS+FAd1gBrcMCs76W40w== X-Google-Smtp-Source: ABdhPJzqzq1lE27OONVftERjohdrI2fOkcuIWCOuQ7jmuJd0f9d14Ba4F4gxl7FYHvn4Smvx19bXsA== X-Received: by 2002:a0c:8d05:: with SMTP id r5mr5109734qvb.31.1603842966316; Tue, 27 Oct 2020 16:56: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 69sm1907543qko.48.2020.10.27.16.56.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2020 16:56:05 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v4 10/22] test: Add tests for LOGFF_DENY Date: Tue, 27 Oct 2020 19:55:29 -0400 Message-Id: <20201027235541.706077-11-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201027235541.706077-1-seanga2@gmail.com> References: <20201027235541.706077-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 v3) Changes in v3: - Modified to be completely written in C test/log/log_test.c | 67 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/test/log/log_test.c b/test/log/log_test.c index 4ac378fdad..e4ab999a7d 100644 --- a/test/log/log_test.c +++ b/test/log/log_test.c @@ -292,3 +292,70 @@ int log_test_disable(struct unit_test_state *uts) return ret; } LOG_TEST_FLAGS(log_test_disable, UT_TESTF_CONSOLE_REC); + +/* Check denying based on category */ +int log_test_cat_deny(struct unit_test_state *uts) +{ + int filt1, filt2; + enum log_category_t cat_list[] = { + log_uc_cat(UCLASS_SPI), LOGC_END + }; + + filt1 = log_add_filter("console", cat_list, LOGL_MAX, NULL); + ut_assert(filt1 >= 0); + filt2 = log_add_filter_flags("console", cat_list, LOGL_MAX, NULL, + LOGFF_DENY); + ut_assert(filt2 >= 0); + + ut_assertok(console_record_reset_enable()); + log_run_cat(UCLASS_SPI); + check_log_entries_none(); + + ut_assertok(log_remove_filter("console", filt1)); + ut_assertok(log_remove_filter("console", filt2)); + return 0; +} +LOG_TEST_FLAGS(log_test_cat_deny, UT_TESTF_CONSOLE_REC); + +/* Check denying based on file */ +int log_test_file_deny(struct unit_test_state *uts) +{ + int filt1, filt2; + + filt1 = log_add_filter("console", NULL, LOGL_MAX, "file"); + ut_assert(filt1 >= 0); + filt2 = log_add_filter_flags("console", NULL, LOGL_MAX, "file", + LOGFF_DENY); + ut_assert(filt2 >= 0); + + ut_assertok(console_record_reset_enable()); + log_run_file("file"); + check_log_entries_none(); + + ut_assertok(log_remove_filter("console", filt1)); + ut_assertok(log_remove_filter("console", filt2)); + return 0; +} +LOG_TEST_FLAGS(log_test_file_deny, UT_TESTF_CONSOLE_REC); + +/* Check denying based on level */ +int log_test_level_deny(struct unit_test_state *uts) +{ + int filt1, filt2; + + filt1 = log_add_filter("console", NULL, LOGL_INFO, NULL); + ut_assert(filt1 >= 0); + filt2 = log_add_filter_flags("console", NULL, LOGL_WARNING, NULL, + LOGFF_DENY); + ut_assert(filt2 >= 0); + + ut_assertok(console_record_reset_enable()); + log_run(); + check_log_entries_flags_levels(EXPECT_LOG | EXPECT_DIRECT, + LOGL_WARNING + 1, _LOG_MAX_LEVEL); + + ut_assertok(log_remove_filter("console", filt1)); + ut_assertok(log_remove_filter("console", filt2)); + return 0; +} +LOG_TEST_FLAGS(log_test_level_deny, UT_TESTF_CONSOLE_REC); From patchwork Tue Oct 27 23:55: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: 1389059 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=GE0M5kWd; 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 4CLTDZ3mGlz9sV1 for ; Wed, 28 Oct 2020 10:58:22 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1142782523; Wed, 28 Oct 2020 00:56:26 +0100 (CET) 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="GE0M5kWd"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6EE68824DE; Wed, 28 Oct 2020 00:56:11 +0100 (CET) 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-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 9A30581260 for ; Wed, 28 Oct 2020 00:56:08 +0100 (CET) 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 c5so2418160qtw.3 for ; Tue, 27 Oct 2020 16:56: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=rmQYK5d3Ul9JsqHTzqH89XuHFf/EICxb47EqLETAh1o=; b=GE0M5kWdKOS2qnofMPzIIdcIUq6grUhdEfskhnFd9STBN+s1deYrLiKySCjZydzZ91 Sk1iMXFrnrYERdOTTLy/UVu6lQanlN2qNQ1RgPo4tBHelozPq86cun8rDFA1FW53+YVW LGDdTo0DqdiJDKs4UN9la77sXK0seLpf16l1twlysZ095aX6c06Y1Si1z26hrAPWCI1O JqkygTCpAkonS/LuWf33NUyxGHkdrpseGnOQrRK3lh/JUw6Fgrdw4MmtouET9SF9KjRc 3em8oxy1aLX8JZUl1LRSyWkQaQt+gzZ/GzE3Mk6NNCF0eFUjQtltXn1pQ4l9PdElwJ3p 9mkw== 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=rmQYK5d3Ul9JsqHTzqH89XuHFf/EICxb47EqLETAh1o=; b=eIsVxwJdG/jMIZrDhbm7bBAURCoSkzGylcHenfP9yzuZkRFxApyC6Y0fvXifMfGRsA RADUMLVpO92NRMaNwhnLtRxRIMrSILyM/7QE4bC7cSt3dAmx1m35seVL/rkPfJ11MIRr 8AdaeUAzFxSL/BnBtQWoX9Yl7yUygjd5UIYHUMvlAZMDhEEelLOIkNE+/KAl0E8mlqUw HRfA9Hou9OKNehJ9Qsgjyb0HybvmKOFVrYhi4s+kdhDlgkspibBzly8w6WNs3Y77X4UP P57q857G80wVt3/UDACXAbOyvgJ1/f3unfHcNpxl7pB1uBQOfIII8oYsb/mbIwo7NWX0 dvrA== X-Gm-Message-State: AOAM532d8g49cxmnpE74IyWApzFieikKoNgfLtB9F2y1VLSTkRCKbsTF c85RtedPVkeZOOrdFOS4uthw2SpsfLaqyw== X-Google-Smtp-Source: ABdhPJw3khovkXselAa4UvQQTMMXt5q95c9kydaLhKeIMD+Dkz1oJpYdlm3QOZWOLcf36Z+fquUOlQ== X-Received: by 2002:ac8:7942:: with SMTP id r2mr116776qtt.238.1603842967309; Tue, 27 Oct 2020 16:56: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 69sm1907543qko.48.2020.10.27.16.56.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2020 16:56:06 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v4 11/22] log: Add filter flag to match greater than a log level Date: Tue, 27 Oct 2020 19:55:30 -0400 Message-Id: <20201027235541.706077-12-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201027235541.706077-1-seanga2@gmail.com> References: <20201027235541.706077-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 complement 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 6299c8b2d4..9a79b95a95 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; @@ -235,7 +241,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; @@ -263,7 +269,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 018180e788..ec2d6fdb01 100644 --- a/include/log.h +++ b/include/log.h @@ -367,6 +367,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, }; /** @@ -382,7 +384,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 @@ -391,7 +393,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; }; @@ -492,14 +494,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 Tue Oct 27 23:55: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: 1389060 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=h37hJAfT; 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 4CLTDn1LMKz9sV1 for ; Wed, 28 Oct 2020 10:58:33 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8450B82531; Wed, 28 Oct 2020 00:56:27 +0100 (CET) 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="h37hJAfT"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 93DBA824E5; Wed, 28 Oct 2020 00:56:12 +0100 (CET) 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-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 85F63824C5 for ; Wed, 28 Oct 2020 00:56:09 +0100 (CET) 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 i7so2408958qti.6 for ; Tue, 27 Oct 2020 16:56: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=iJ7f0BVtRBN4aySzX6yfjQ5IL0NhlHHKm1KtZCxIF5U=; b=h37hJAfTUYqnb4kSyqnl+91oKcWbZLlO26F1pqZVt4dePpxPh/kNJHhcZda9gQy3c1 fen7nJLPqEztsNXNZF2i5cV0UctI3NkKUOIuDHojcRXgbNF4Ba6c94K9SVaY9qCmPQ71 eB10Oxg5hw4ZnAyN5RxIMaEUuLYpbGNohiLjn4xjfbuU5A3H73BbJKcBm7qEnij4BIA9 keuGKqEfUn8PUj0MLEsLbSom9TWJocyCzUJ/xXtuGlDpM/pcaT4aKVuKjiuGP//1iIJO HLk4Npn+oH6ytBUlX2qwdmaBf5O41cEOCY459w61zc1RY8Wj1mM+HB2nCt65Os0HtAzQ T+Xw== 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=iJ7f0BVtRBN4aySzX6yfjQ5IL0NhlHHKm1KtZCxIF5U=; b=STz1aD80/8utayuJ4cworFi5kewzQIGrXBktzpfz+gFSIgr+Qtiiq8HUy4JdI8kXHL rpMKz9Cf0qorq20kYmRkSRaSEkXugVR4gtmf+YkCtcV/hDETwUhGjj/ichwMmMZoiJqg lIommCr3q1/ytwqs80KbYpe03EgEL1DIS12XTxIJCVZy+6MCrcAQ9Z8aR3sd3NipkoBR Ifv9ePz/TVhtSoe5d+QelHipnROEIR3+2IOCV6ZBQO3BKGS0lleOKa67nPnUHltVsgNE YSa4VT5wjrlDV5oZ9HDHcv+ucAakwdoUOHrIW6V3Z8c0bMkB9cW+qUQC3nfVW5l7jOTG Ga+Q== X-Gm-Message-State: AOAM532JDHhGl96nGwhM/2AAprXZAXjciW39JovkCqdCsvl92CT/Egmp Hzmai9ldy3CQ4onKcsXYCok9XNgtrOLlpA== X-Google-Smtp-Source: ABdhPJwbngVqRU1I5rm/IItGrdPR1ahsDDfUUCMRICjo9g3lJtn/GLMbklwqkqNv+vLNXHXl9IvqDA== X-Received: by 2002:ac8:6b8d:: with SMTP id z13mr4714221qts.41.1603842968340; Tue, 27 Oct 2020 16:56: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 69sm1907543qko.48.2020.10.27.16.56.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2020 16:56:07 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v4 12/22] test: Add test for LOGFF_MIN Date: Tue, 27 Oct 2020 19:55:31 -0400 Message-Id: <20201027235541.706077-13-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201027235541.706077-1-seanga2@gmail.com> References: <20201027235541.706077-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 v3) Changes in v3: - Modified to be completely written in C test/log/log_test.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/log/log_test.c b/test/log/log_test.c index e4ab999a7d..ea4fc6bc30 100644 --- a/test/log/log_test.c +++ b/test/log/log_test.c @@ -359,3 +359,26 @@ int log_test_level_deny(struct unit_test_state *uts) return 0; } LOG_TEST_FLAGS(log_test_level_deny, UT_TESTF_CONSOLE_REC); + +/* Check matching based on minimum level */ +int log_test_min(struct unit_test_state *uts) +{ + int filt1, filt2; + + filt1 = log_add_filter_flags("console", NULL, LOGL_WARNING, NULL, + LOGFF_LEVEL_MIN); + ut_assert(filt1 >= 0); + filt2 = log_add_filter_flags("console", NULL, LOGL_INFO, NULL, + LOGFF_DENY | LOGFF_LEVEL_MIN); + ut_assert(filt2 >= 0); + + ut_assertok(console_record_reset_enable()); + log_run(); + check_log_entries_flags_levels(EXPECT_LOG | EXPECT_DIRECT, + LOGL_WARNING, LOGL_INFO - 1); + + ut_assertok(log_remove_filter("console", filt1)); + ut_assertok(log_remove_filter("console", filt2)); + return 0; +} +LOG_TEST_FLAGS(log_test_min, UT_TESTF_CONSOLE_REC); From patchwork Tue Oct 27 23:55: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: 1389061 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=n3MpPpTL; 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 4CLTF03xlVz9sV1 for ; Wed, 28 Oct 2020 10:58:44 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 244D782539; Wed, 28 Oct 2020 00:56:29 +0100 (CET) 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="n3MpPpTL"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 61D2F824E8; Wed, 28 Oct 2020 00:56:13 +0100 (CET) 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 93BF3824BC for ; Wed, 28 Oct 2020 00:56:10 +0100 (CET) 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 j129so3037582qke.5 for ; Tue, 27 Oct 2020 16:56:10 -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=pdQkfmG3J5z46p027wzAbBLEt/2KyY9/zU4oSQwwA1Y=; b=n3MpPpTLaebJJJFFLqbKuz0+2gumH6sPL8wy92u1i1Zo5iuwaVG9Yo0JokbrnlXr7z SXSJxJwN37/msLslSCZfaLe417pab3Osityo2+JbzF9SosQY0xVxTeomPvsfJ7wkTXdH NULAfQAv/kCXSOBLr8TS5P2qMsTBXw0XFOZo4K0SmTeKGGBNodVAMxirSPl+LDH6GIxe FdGVcl/Y75lB8OxMbXpw42U7Ztyz0rm9Ljd7n75UYOShi7u7yJTIuRQ0L14K1JgNpine ElolmbhOKyz+2uwNhk9zM6cpDAMjyrNwYMZ4400f06+xmiuxEgQAMFjHtcQ6F4F6uab/ MZ9g== 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=pdQkfmG3J5z46p027wzAbBLEt/2KyY9/zU4oSQwwA1Y=; b=dreOswScMvRVZWscQgOuJ+S+A65RKcBR13Qs5NQ2lZVO339Hrjije0dY4/VAG7Uuiq 4kSoloH7xJ50KsE3RjakFstAAm6hIB8YfjyCCuOiH96WfN+YLMi3IfRAjiIBg3J8agHi hRIzgDxtJYPECxN0vSD+TttRtZ9YeYsK/Sjvge/eYpP+cSB2bVkhoOOUcpWN93uWuBl9 ucFVT94cKdls1VDDr4iCdy9TEZHbaAtzPx3Ya5mPUx1umrIMCZlbCUxtHcKJpEvXMwjU ekSzu6yD9vutvEGHM6sW1L1Eo/QjWcGXttKygqMBfddTcMuFtovgWzFp+hx1Iz6Kg1nR eEjg== X-Gm-Message-State: AOAM5323AJwfojdswmD6QEEAftVIbUtDvl06ewbuXSjAmjOGoMiLSGUK +O+ouFF1CjM/fw1sJBqQHcsqSCYP38lu8g== X-Google-Smtp-Source: ABdhPJxZyzzNgdWAEjFyhDnHPE5YHbTrjkCu/frRGZQJ1DyP44+zfwHbKpM61Os5GLPNRdpTPpm5XQ== X-Received: by 2002:a05:620a:19:: with SMTP id j25mr4878126qki.498.1603842969357; Tue, 27 Oct 2020 16:56: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 69sm1907543qko.48.2020.10.27.16.56.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2020 16:56:08 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v4 13/22] cmd: log: Use sub-commands for log Date: Tue, 27 Oct 2020 19:55:32 -0400 Message-Id: <20201027235541.706077-14-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201027235541.706077-1-seanga2@gmail.com> References: <20201027235541.706077-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 | 31 ++++--------------------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/cmd/log.c b/cmd/log.c index d20bfdf744..82e3a7b62f 100644 --- a/cmd/log.c +++ b/cmd/log.c @@ -103,30 +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, "", ""), - 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" @@ -139,7 +115,8 @@ 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), + U_BOOT_SUBCMD_MKENT(format, 2, 1, do_log_format), + U_BOOT_SUBCMD_MKENT(rec, 7, 1, do_log_rec), ); From patchwork Tue Oct 27 23:55: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: 1389062 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=Kk3K079X; 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 4CLTF94WF5z9s0b for ; Wed, 28 Oct 2020 10:58:53 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0C21C8246A; Wed, 28 Oct 2020 00:56:49 +0100 (CET) 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="Kk3K079X"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7F99D824FC; Wed, 28 Oct 2020 00:56:14 +0100 (CET) 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 942A681260 for ; Wed, 28 Oct 2020 00:56:11 +0100 (CET) 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 i7so2409004qti.6 for ; Tue, 27 Oct 2020 16:56: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=AuSpVGmYG5eGMFYGwDb6+YQQZzUi5h0r/fyKJMLPjJQ=; b=Kk3K079XS9qme9RTEdNTsr/CaOQuzIeT2M8+2tV+FGRUCZ/5t0Pz9rCyqj52Skc7Ip bO8se69TJVOfayhaB2TenLQX4CNyJ6Dxp6rnLdVdqvXIB/JTPGW5HMz3cZVUHbe1xgPQ CyCAx1TZv/YutPWXJFvEvKd8pPvOTkT+2/aVwIpXdqrqEzXHZLev752xXlMO3gC7CBpZ 72fu0/g7efW6VrQdEEPq/bb/4XgWU6XkzizktXWs09qyZqsNpfb911PSWArpeH4K95oP HM09nCsJI4ld5iFCpNNEMejEuGHQSWi+JwOr+Ylmkj2kTdhbLmxzEvoDhHrj8mdJI7XQ xKQw== 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=AuSpVGmYG5eGMFYGwDb6+YQQZzUi5h0r/fyKJMLPjJQ=; b=XKuYc35TcUgOZfyqmmFOFvaVVR7VgvJKbCaE5vJkTcoeAZEJW2NrugbejLHQVbcIzN GHujJjXTdSmXs1s0lAHcOlXkFVnFpxDhCXthOH099t8qZ3R04CQkQD78urw38dk0dZDz 2nNw9OHZgess3OgmyBl7fhhtQiGKofM4EQw3weaSbAwBlSkiNYP5JKJ2fQRWXa5Wb+/K KptI/aNNK6/m1+Hx7ijdPKtFfAjv6WOp/p/cCk+NZdz5BRw5D8KQ6HydKg/IFGuq6oY2 8HAAwrODUjxL8zvP4qwEeVYNxhlq5x+5AtfIFpnOcFVVkBI9QnKJq8Z6c0jUMUlgJ7Qp qbMQ== X-Gm-Message-State: AOAM530uzZHG5cFFt3RB+ll69HvOFS3T/svIZBL0nyE5BzmF6mXP/n67 DP86pHkrvGz+uXtFaazByl9xnaPo7Hfnrg== X-Google-Smtp-Source: ABdhPJylExcAOBLsLTp0/l04VH1ZZv9QSsORgXA4M1tyv9jJiCtyGOCHfH3DJzfWeqlSJEPF6l+ZtQ== X-Received: by 2002:ac8:51cd:: with SMTP id d13mr4807838qtn.148.1603842970332; Tue, 27 Oct 2020 16:56: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 69sm1907543qko.48.2020.10.27.16.56.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2020 16:56:09 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v4 14/22] cmd: log: Split off log level parsing Date: Tue, 27 Oct 2020 19:55:33 -0400 Message-Id: <20201027235541.706077-15-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201027235541.706077-1-seanga2@gmail.com> References: <20201027235541.706077-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 --- (no changes since v2) 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 82e3a7b62f..651e50358c 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 Tue Oct 27 23:55: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: 1389063 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=BnzRN9PT; 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 4CLTFL56HPz9s0b for ; Wed, 28 Oct 2020 10:59:02 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D3AEB82540; Wed, 28 Oct 2020 00:56:52 +0100 (CET) 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="BnzRN9PT"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8A69C82505; Wed, 28 Oct 2020 00:56:15 +0100 (CET) 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-x833.google.com (mail-qt1-x833.google.com [IPv6:2607:f8b0:4864:20::833]) (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 A8E4B824C5 for ; Wed, 28 Oct 2020 00:56:12 +0100 (CET) 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-x833.google.com with SMTP id h12so2402864qtc.9 for ; Tue, 27 Oct 2020 16:56:12 -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=E/IyPiO+MlPxGluujQH1SnoRn5gjuqYoimEW6S2BRkc=; b=BnzRN9PTHWYNfNV3DCEyMQ45iQKJFKifefJKL+pY2O4hIBKSf7IAymDT81PGzEKigJ ms4ZapbUKLoYW06JzFGE7skX65xur96CqFvaZjmgE/CLUk1skmc0gTYDxmB5YpE70yqZ EK4LjWFX5P+da6vDwf4kFHVeNJmo578sblbWAll3Cnj5xN3hy9PVsOwbrCxe8BhNgh5C 5FdkXMI2/+hxF9Ad0LCPUQuBtqidJbyKog2qxXYomTgVvlQ0lrfAMqeHNmSSDVjzKeeB Oeb0YA8MCmdF6RMUMKh11pOFipK+awOGpHf+UK7BExcsnESx0nv+eLRppUm/6gbFbo6o 1zEg== 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=E/IyPiO+MlPxGluujQH1SnoRn5gjuqYoimEW6S2BRkc=; b=B4VPYtTLaAI2CVhxKgoJ/hUvsZSU4qWntJfCUJaI/CHXw/sA3AccLpfD/RMjttHTox Y3kn9Z2/kU9IaBLnp9U2gGFyTIo6/heMSJ01JDOB4MLeslW7LNNPjofYQbN2Ov8mCis/ kjzp9Pe1QuLGHb1AIYDX8rmfLY8CKFxAdwlKizndIIYUCiRrsm/ccIPhRpn+W3ew5kNe idiLy4/l2K0jyXAPshig263ctz2OBOanjYeqbU5j/ikXgyZ24/tUnieVLL0xiQh5jqZd NQwFDyEPeXgDeBL68hHpwn4T7BzNwG5VBuJJMYpPCtFHo4QcjtLkAIsnyDwxRuZZNrJb tTgg== X-Gm-Message-State: AOAM531zt8avEthLrEeWfbPS3FC/0dQffzovyrdUatvD+eJ8VkjVgd3z t8/uDxHPjQyKgIqTIVCkfuOLEVJWuoB15Q== X-Google-Smtp-Source: ABdhPJyWSoOJUx+hqbNjc/ahG8JztkjMOen9FntGnhu/UzM3JKm91FQHiOshFpRk65ULLqFA/tJHxg== X-Received: by 2002:aed:237c:: with SMTP id i57mr4721513qtc.324.1603842971402; Tue, 27 Oct 2020 16:56: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 69sm1907543qko.48.2020.10.27.16.56.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2020 16:56:10 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v4 15/22] cmd: log: Add commands to list categories and drivers Date: Tue, 27 Oct 2020 19:55:34 -0400 Message-Id: <20201027235541.706077-16-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201027235541.706077-1-seanga2@gmail.com> References: <20201027235541.706077-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 --- (no changes since v3) Changes in v3: - Document assumption that erroneous results from log_get_cat_name begin with '<' Changes in v2: - New cmd/log.c | 35 +++++++++++++++++++++++++++++++++++ common/log.c | 1 + include/log.h | 5 +++-- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/cmd/log.c b/cmd/log.c index 651e50358c..8d8d8a8172 100644 --- a/cmd/log.c +++ b/cmd/log.c @@ -47,6 +47,37 @@ 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 '<'. + */ + 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 +154,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" @@ -134,6 +167,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), ); diff --git a/common/log.c b/common/log.c index 9a79b95a95..95ba8350c6 100644 --- a/common/log.c +++ b/common/log.c @@ -41,6 +41,7 @@ static const char *const log_level_name[LOGL_COUNT] = { "IO", }; +/* All error responses MUST begin with '<' */ const char *log_get_cat_name(enum log_category_t cat) { const char *name; diff --git a/include/log.h b/include/log.h index ec2d6fdb01..7a839d55aa 100644 --- a/include/log.h +++ b/include/log.h @@ -409,8 +409,9 @@ 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. All error + * responses begin with '<'. */ const char *log_get_cat_name(enum log_category_t cat); From patchwork Tue Oct 27 23:55: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: 1389064 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=MwW9W48J; 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 4CLTFW6kcMz9sV7 for ; Wed, 28 Oct 2020 10:59:11 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A6A8282545; Wed, 28 Oct 2020 00:56:54 +0100 (CET) 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="MwW9W48J"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6996A82509; Wed, 28 Oct 2020 00:56:16 +0100 (CET) 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-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) (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 AFCE0824EC for ; Wed, 28 Oct 2020 00:56:13 +0100 (CET) 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-x744.google.com with SMTP id r7so3039612qkf.3 for ; Tue, 27 Oct 2020 16:56: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=HmDOJ6MKsys0yHRNY3RLY42a/rKjZS7EX0WqLgNkI/c=; b=MwW9W48JTPUP8LEtDMoBjcg/SYzohDx9Dtje8AA+tePokv5/amLeZS17moqopkSfJ6 amYhi5J8uoIcVGgBsiEbG31SPGVX8Smj2LMxdLkDGLUfaPvE3aDLDkUYRXecQO2pejiB 6aQiRdj344nCR4sZmMlUgSWfXFTlCi4aWizgxE3Q39jt3ND9T+rgoC1YWEMke1BqkpGn jEeyEytVgYN2G0d4Qjw3ghqpPxh1t5y3AP9oC6+bWaMbaxjW641Un+Xfy3nUmAmP2Anw cvguXUdtbjFgxXvSWP5UTDWITEqq4AFvKpwK23t3PbpcjiAJODTWux0qSGHIQ8jctVS3 zyBQ== 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=HmDOJ6MKsys0yHRNY3RLY42a/rKjZS7EX0WqLgNkI/c=; b=gJ+m8G/6bUw0Xo9eMjp7HiJWrX7D/BpdwkPm7mv5wrEuPWxKb4toztUkd536uZBWSG EC5ZN9KsFc/gpsStwAs40RNxOyPlkSEbJPL6onGfGl10/vNPvVmNDedEfloaf4UpF5F1 dpDYh/ONkTNnaWwBUyOPRsVnKObD81067BFzOb8OJUXEDQ7MrHG/eTDCnonxBd/KFOA9 umKxCfHmlJyOq2Vd2v03ahd5RPBViPKp7yWSZ7JX4185yK9xyHceluwrXSuv+CZYA5KP d9iQ0+WlpGvPEH8/chy7gVbOIsDiSTk5cV1xkKTe5x8CoY7zThNqTKiHO+3d73ZvyMC+ d2lA== X-Gm-Message-State: AOAM533JoblhjT06ATPcKJfugH2UhOZzIKxtqxFCvq2fxa6zhx0QLTAU XIPaFHWkI7fttgbGfygUPXQ4aHX2Em3iKw== X-Google-Smtp-Source: ABdhPJxibg5JQ9eFOw1BcmtEUsB2YBP4udpSAf5yS7wSgJslt3cbpjzyOagniBiPn4wJ9/qF7L3cYw== X-Received: by 2002:a05:620a:214b:: with SMTP id m11mr4758775qkm.6.1603842972390; Tue, 27 Oct 2020 16:56: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 69sm1907543qko.48.2020.10.27.16.56.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2020 16:56:11 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v4 16/22] cmd: log: Make "log level" print all log levels Date: Tue, 27 Oct 2020 19:55:35 -0400 Message-Id: <20201027235541.706077-17-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201027235541.706077-1-seanga2@gmail.com> References: <20201027235541.706077-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 --- (no changes since v2) 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 8d8d8a8172..596bc73f47 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; @@ -153,7 +159,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 Tue Oct 27 23:55: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: 1389066 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=B+d+bKok; 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 4CLTFr73Flz9s0b for ; Wed, 28 Oct 2020 10:59:28 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BCE5482551; Wed, 28 Oct 2020 00:56:58 +0100 (CET) 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="B+d+bKok"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6F64F824F4; Wed, 28 Oct 2020 00:56:19 +0100 (CET) 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-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) (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 E1A9B824FB for ; Wed, 28 Oct 2020 00:56:14 +0100 (CET) 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-x744.google.com with SMTP id 188so3010695qkk.12 for ; Tue, 27 Oct 2020 16:56:14 -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=tS2JzFLVqjAlFGoqdEuijkZ0MK0twb9yr+Mio/SQGBc=; b=B+d+bKokJvcTfc2Z1gdOXpHf+jGF2fUaa7R6T5pAdVL/E40iMTEesKmqP1Eb2MrlJQ FkKx9JCc6ZZQZDzZ8Kx9SeaTawaAUCBk0JwHKCejhkycAiXbdJW8lStBy8LAoPiGV3kU qNrPIDa3J6S0c6x+wu1g3XyuG/bXFrZA7Evr5jYX2pO/xqvS8/IcKA510bHA7dde0C5X T9NboR9g9OqhNlOyOwzDDIDhz1zhn8Obe2T0KARjDFQTYzdWBSpqGzfKTxeJpMGhcdfq /hLtsR5RjWyVqZISqU0Ijb5z/Q+i5j1Xjt6qwOGKT8ScE4iI4V5wppZCiPblrImvrLkE 3sbg== 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=tS2JzFLVqjAlFGoqdEuijkZ0MK0twb9yr+Mio/SQGBc=; b=tqSUXQsyUA09g0tTTaSlaak4yDt1JLDnFh3fn9BClRWWf8pUywWFLPblbSrQiv8RhJ iSS8hVIT8bYvEpFRXc+KMRXl2eu1DU/Q1OlIogj1z86hWxFSNLx5d2C3oy2KX2FGCaiN IuGDxM81P8XLSUcZTACplxFS4v4996WXZ+NsSlJzald1T/+4R5yI4RHVV5GpI7Wm7YLP Hf6yOd5/qdQPn9C5AOTCvW/3w7bdm/Cmw/JNqPZKu3FOzvuNya9387eIxxdgK0yPiRdk Z5+gc/Eb7ErvFz2EzCW6+3K9xFknmx2b9whVCW5FW40LlKSnovLYCmDlqqe9vGEdIGuG nuyw== X-Gm-Message-State: AOAM5331Uwg00hSpU4zPqmZWL+LgUZQ3immgE7GxvCPDTjdfAsOKpBGJ dkbNh0Ld8TT6SPsbqYYWxlntYmEOaS7qnA== X-Google-Smtp-Source: ABdhPJzFCuCpSTZTr1huGVCLuh11zcFn6JdYK0R+5q03+UYvZKQS2oviOMmMgv+3ibzs8SfSMvShJw== X-Received: by 2002:a37:4d8:: with SMTP id 207mr4638680qke.360.1603842973420; Tue, 27 Oct 2020 16:56: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 69sm1907543qko.48.2020.10.27.16.56.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2020 16:56:12 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v4 17/22] lib: Add getopt Date: Tue, 27 Oct 2020 19:55:36 -0400 Message-Id: <20201027235541.706077-18-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201027235541.706077-1-seanga2@gmail.com> References: <20201027235541.706077-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 --- (no changes since v2) 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 fc4fad46ee..cb3151c765 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -756,6 +756,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 787b6778e5..ae4a1b6c63 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 37aae73a26..79651eaad1 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -550,6 +550,11 @@ config SPL_HEXDUMP This enables functions for printing dumps of binary data in SPL. +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 Tue Oct 27 23:55: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: 1389065 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=TilhedV8; 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 4CLTFl1cvMz9s0b for ; Wed, 28 Oct 2020 10:59:20 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 707F4824A8; Wed, 28 Oct 2020 00:56:56 +0100 (CET) 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="TilhedV8"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 03532824F4; Wed, 28 Oct 2020 00:56:19 +0100 (CET) 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-x72d.google.com (mail-qk1-x72d.google.com [IPv6:2607:f8b0:4864:20::72d]) (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 C690682504 for ; Wed, 28 Oct 2020 00:56:15 +0100 (CET) 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-x72d.google.com with SMTP id 188so3010723qkk.12 for ; Tue, 27 Oct 2020 16:56: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=FeKSVTjAs50FtMTWScEZSawFqN8RFhFDEcFysjpenII=; b=TilhedV8mPtkn32NzywwlAR2/eXPL85etya6Q4m71p4fmXl8z0FYBJUel4reJP/HCp cORMhCJ2QaXr/R8K+m03rE1pEyvsf3mx8n6A0dg9GUdSAKyF5ewxuRHUP1DFiEKPwLjM yGVotcLO9d7tmdE8LoKdvwqQkuFRGsy98BlMCf3AkG69vu3nYMJYabGHBSYirKeCT57u SG2nGwTbuoBQkEtp27nIOPZaoY0/OQQKDccWJIbQtyDNZPL+72tUJpNVthEhYmgdJLtm oT/qKuFzTbjcgyNAdnlE0twaHdQ8vpQR1Uq3BF7WUS8oY49s/BL1rJsCAtkUibLElUgF MgRw== 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=FeKSVTjAs50FtMTWScEZSawFqN8RFhFDEcFysjpenII=; b=Xa5FIWZ7PwwRo4ss+s50Dh8nzkMl5aNT2+ElFlVJrh3Nja3jyBjGp6REgrvRe5xBq7 yrbajf6c+u9QCd0RrrJ/LsORSCpwtSXYehZxFN/CLFlaeis0zKS4np1v9YSHVS7bMwtH UFAhcRhF7cFcS9StOU6FaaxBtUj1TMOa4TEJXaO/TfpTTAdEYpbNHKyvoKrdq54jKEwa MSfEYco78CixX5XutnWX1KWjm5AafSAA3fF7qen+Mi+Pu3yse1mgVJ1aH/qLeIuIHFg2 ePMhrYk45CzQ53KLlN8X6elPphl1WoWT2m/ytUGiRfNJWUQE7/7EiNOFq/YAuGqfJKup Ielg== X-Gm-Message-State: AOAM532LPyJkBS/qGbKF9y3qLvfraeGb/KWOlBYYsurl+JOjSAn3wRWN WbA6zSHdA2HnvgfU2k5fxzA4J3kuXR3nlA== X-Google-Smtp-Source: ABdhPJy51WDq1FH/+cEf/sxSfv8jy0/pc1dOGpTx/tqlhHwNvQVxCH7ZdpfA6EZwuI1tI3OzLrhuag== X-Received: by 2002:a05:620a:210f:: with SMTP id l15mr4692171qkl.200.1603842974467; Tue, 27 Oct 2020 16:56: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 69sm1907543qko.48.2020.10.27.16.56.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2020 16:56:13 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v4 18/22] test: Add a test for getopt Date: Tue, 27 Oct 2020 19:55:37 -0400 Message-Id: <20201027235541.706077-19-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201027235541.706077-1-seanga2@gmail.com> References: <20201027235541.706077-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 15cd512506..98a9abf40e 100644 --- a/test/lib/Makefile +++ b/test/lib/Makefile @@ -14,3 +14,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 Tue Oct 27 23:55: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: 1389067 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=q1+56YZU; 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 4CLTG14xBNz9s0b for ; Wed, 28 Oct 2020 10:59:37 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5774C8254E; Wed, 28 Oct 2020 00:57:00 +0100 (CET) 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="q1+56YZU"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6E95082517; Wed, 28 Oct 2020 00:56:20 +0100 (CET) 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-x72a.google.com (mail-qk1-x72a.google.com [IPv6:2607:f8b0:4864:20::72a]) (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 E81DB82508 for ; Wed, 28 Oct 2020 00:56:16 +0100 (CET) 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-x72a.google.com with SMTP id q199so3009506qke.10 for ; Tue, 27 Oct 2020 16:56: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=ed3shE6i2arr4kMdul1P0dOBranTC0B3Ab6PAJv5Sj8=; b=q1+56YZU0lw7jNTCf4fWiMB7Y8SkXQOIeDl0Xr8KwbXpwLRUpySR2PErWwX7t4TCru CLYhgZ1qr1Do5OFj0y6kmINqlRGb/zPVHF/6KxPUhG4Xc5waJvvdHruUTA2GmXhKu45L zmrrpse7pANtgRT10o27avQ5brT+szynnNTqDcEaaZwoBByHhXrqkgxGPzbUayoVjEwX K8yQ6MtxEMzz9KYETPCDJXYyQzlyZOsrdmREyLUMF7FE6CVd7N/3sw8aK+YaPiIMWCem C2OSIU06Rm41km+KeXG6xh7PBF51CX1CUHqRVzKbDLWoxDMcu9dq2j13NYx1Lj9rxXE9 aAEw== 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=ed3shE6i2arr4kMdul1P0dOBranTC0B3Ab6PAJv5Sj8=; b=KLoPWVghquaqcqB/PqxQB21P8KYo8UhQbILM87FBn6bYrF8pJrUM6CFPOW6hQCYVZ5 C4FcH5AhRjZRUWa7NXB2K6Y7Mh1V91FZ1D6j+5Q2xLG0o4nbe9FP71qnvSJg22VohCf8 2nDuMTnTZdpXIcBN14Rldc2DvLa8oVEyOZpYgLNbH8wUmHcXPTZUENn8tbmXV17/pjXz 8d1uLRqq1nJCCTg1ftMSXBPdvysjfTxCR9awzgmznsoQ9OfXwNv6pQuFtlsnr86QqaZO zn5GqqnEsSX/c3UoWQ+tGJQNAtE5Cp3iLwSFkAkijuw/gaQI4q/9oCqKUUs5V9V4+qfk PjWA== X-Gm-Message-State: AOAM531xYvUPHvESEVk7SDllTMeD+9oNsP+GK5n6rue34IucC6yYU4Jv aUEJFF7gh2zE9XgJ9RX/jgGK6T14b+KZjw== X-Google-Smtp-Source: ABdhPJyRCm5bWCwLXKO7HUHnsxwhHNyu8ktjvYennu8RTCKQ5DdPUT/Lfr/uAagFHjf04CfGHleiNQ== X-Received: by 2002:a05:620a:21da:: with SMTP id h26mr4826536qka.123.1603842975533; Tue, 27 Oct 2020 16:56:15 -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 69sm1907543qko.48.2020.10.27.16.56.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2020 16:56:15 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v4 19/22] cmd: log: Add commands to manipulate filters Date: Tue, 27 Oct 2020 19:55:38 -0400 Message-Id: <20201027235541.706077-20-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201027235541.706077-1-seanga2@gmail.com> References: <20201027235541.706077-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 v4: - Add a space in between the <= operator and the log level Changes in v2: - Add option to remove all filters to filter-remove - Clarify filter-* help text cmd/Kconfig | 1 + cmd/log.c | 241 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 242 insertions(+) diff --git a/cmd/Kconfig b/cmd/Kconfig index 11f299da2b..debe2f5401 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -2225,6 +2225,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 596bc73f47..ca1c51e067 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"; @@ -84,6 +86,221 @@ 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; + } + + /* <3> < 6 > <2+1 + 7 > < 16 > < unbounded... */ + 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("%21c %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[]) { @@ -162,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" @@ -175,6 +412,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), ); From patchwork Tue Oct 27 23:55: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: 1389068 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=apbOvpO5; 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 4CLTG96r5Mz9s0b for ; Wed, 28 Oct 2020 10:59:45 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 995C482558; Wed, 28 Oct 2020 00:57:02 +0100 (CET) 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="apbOvpO5"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DA46382517; Wed, 28 Oct 2020 00:56:20 +0100 (CET) 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-xf41.google.com (mail-qv1-xf41.google.com [IPv6:2607:f8b0:4864:20::f41]) (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 DC03E824FF for ; Wed, 28 Oct 2020 00:56:17 +0100 (CET) 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-xf41.google.com with SMTP id bl9so1585907qvb.10 for ; Tue, 27 Oct 2020 16:56:17 -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=UjnbN5jah0KI7708Z4JYc5hIBEODZ6Lxt1u2QwMuDGI=; b=apbOvpO5BLFMzVQ28DXYGde0/b5G6k+gs3Qf4heMjqOFCbgDrYWsx+WVgiJu6U6Snf cEyhlogyhQ0/2EleD7bpWBDArBdm5W4HfT/ZDsRNw3eOqaQ0r997GV2REptTith+s8Oe diw+5IZrYXNNvVImf1rwj7eJnJ3EyZ5R8FGn0BNl4SI3hZIQbNWLXebjUbQv9qDcSQI3 5NM0MY3F2TmfDcxWmsRmcvvwNUuLnhvpoyyHks/iIyqhs8+yQKnIkWeKmRw3UTn/dIQa Tg2KhX58WxLy1HQzcTLzonwCVSMCLtpodQT7EWjGrUZkOAj99a4WT5WPky3Do5TNcJAf vKSw== 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=UjnbN5jah0KI7708Z4JYc5hIBEODZ6Lxt1u2QwMuDGI=; b=d/VG5CHBcapP+H03wV9TPMpJ0L7fCqQixh+KRW27VjDfj+TqaYfn/1Fsw4J/871BYr qVRzNMvaQpcXN/ZqnYofBf5MacpjuFloJAkW7NInP7qnAwUKgBK8yNN7BTF44ehLcN0z KK5UyvI376jyXyPy6ynl4Vd8D3AB36JO8N0GqjKzILk0ZFWpXFdIbGPiyBP3B9DzVTF3 eqqANMmY/djKcfOFhw+SorjCCHHFVJL7mFemf7HU6x4yGv/OfHRcngznrgtZNrebiggV safBFAsjXSXd1BFGQWA2xrOLgTYhAGBKjS0rAXXZKxIatyGjfjqmjzAFPwP033WkkbEN DcMA== X-Gm-Message-State: AOAM5328ezOVfqMtyyCFx1W5BvLm9U9/EjU2RBWBRrh97W5LfzeGCIkq 8sfcmyU2XqLWgAr4OhVtdmanBuXcYQKdDg== X-Google-Smtp-Source: ABdhPJxHapwyL1Me6cZxaAzNQOEbCW2V78uPc6VD+A+O83Ll/olGqQ2/Uy5FOAY0b2bZrwT+HY4L/A== X-Received: by 2002:ad4:4e73:: with SMTP id ec19mr5362660qvb.58.1603842976623; Tue, 27 Oct 2020 16:56:16 -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 69sm1907543qko.48.2020.10.27.16.56.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2020 16:56:16 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v4 20/22] test: Add a test for log filter-* Date: Tue, 27 Oct 2020 19:55:39 -0400 Message-Id: <20201027235541.706077-21-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201027235541.706077-1-seanga2@gmail.com> References: <20201027235541.706077-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 v4: - Wrap UCLASS_ literals with log_uc_cat when used as log categories Changes in v3: - Update copyright for log_filter.c 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 | 108 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 test/log/log_filter.c diff --git a/include/test/log.h b/include/test/log.h index 772e197806..e902891450 100644 --- a/include/test/log.h +++ b/include/test/log.h @@ -14,5 +14,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 52e2f7b41c..9a6cdbe643 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..e8a6e01a5c --- /dev/null +++ b/test/log/log_filter.c @@ -0,0 +1,108 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2020 Sean Anderson + */ + +#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, + log_uc_cat(UCLASS_MMC))); + ut_asserteq(true, log_has_cat(filt->cat_list, + log_uc_cat(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 Tue Oct 27 23:55: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: 1389069 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=H/uDOBtP; 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 4CLTGL0zrtz9s0b for ; Wed, 28 Oct 2020 10:59:54 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 687938255D; Wed, 28 Oct 2020 00:57:04 +0100 (CET) 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="H/uDOBtP"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D635882523; Wed, 28 Oct 2020 00:56:22 +0100 (CET) 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-x82d.google.com (mail-qt1-x82d.google.com [IPv6:2607:f8b0:4864:20::82d]) (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 3FBB68250B for ; Wed, 28 Oct 2020 00:56:19 +0100 (CET) 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-x82d.google.com with SMTP id h19so2406629qtq.4 for ; Tue, 27 Oct 2020 16:56:19 -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=xXcPnkZVxmZGI1VhXYd5y4DJ/NfEXsGnBpSnETsGt4E=; b=H/uDOBtP1rqo4BDVpWg2gDXGpOuZkndzmlViIwQHOU4ZWh9fEKXHqTj/KKvkbIDMUv t8J4r2QYJsrdRaDIxTr/HxzSSVU8uQydkz5d+yprt40Nzk3pR5r4pH56jUcqj9JQsOmo I6qFsnUZqVK+I22pi7/w/nr7aid9VmxhiYib8dbtXpND2DEqAf4qe02hdB4f1GFdTsaR Z6M6g9EDEpCNahu44uXO7fqnQpr6cSjSmuy2xAadRSEN8H3hxEXWH049GFRlO/Jm8TOA OXyigpaDBM1kupKue3IVVsLKaEaiGna4fojHgW4n3vHbz66Ga0C3eKMuPvJ1qF+E4eSw DXnQ== 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=xXcPnkZVxmZGI1VhXYd5y4DJ/NfEXsGnBpSnETsGt4E=; b=myqxqDP6PxeCFmNAO6xF76cz+LQ9qKHnt/XHenGCQb7wqPnAKdg0URaIZcACoY3l6R soO0JSGi0+nNfmv1Kuc+3JeWGug6krtxdSoKK7PfJ1HZZZz2IPqBlywKepTdEm/LcWvz lOy7Ib4qcwspWCcjBa7muey+uCDyygUP7Wjji0Xup8PhO5ymNAvJuULluhlJh+LQ3BaP nWowrZW/osWxK74e77dB0HQaTv3KBxOKChfTZUzMRQ2q8XXR0LYdUT+Djlfe4yWWuY4a GC4fpRFZXsFvHr1BtdtSspkDeTg8GAMI7ObAK+GhwPDxYk0OUvCts7cVDL1ieRgNWa6B XLtg== X-Gm-Message-State: AOAM533GRdBlabzi4SHT+3Vtt3PtB6/kugsIA5eTnMKvGE9vizriOC41 iuyXFLBTZBEx+dHbaFJA63iaBUIAqxh6AQ== X-Google-Smtp-Source: ABdhPJx+nrObhLuO1SA+/tYYw5nqDzYoXudyvp6AhdmNin/lpLm3MSpu4yZDAJWrB6NWmo6VOD8Ypg== X-Received: by 2002:ac8:454e:: with SMTP id z14mr4858333qtn.392.1603842977671; Tue, 27 Oct 2020 16:56:17 -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 69sm1907543qko.48.2020.10.27.16.56.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2020 16:56:17 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v4 21/22] doc: Add log kerneldocs to documentation Date: Tue, 27 Oct 2020 19:55:40 -0400 Message-Id: <20201027235541.706077-22-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201027235541.706077-1-seanga2@gmail.com> References: <20201027235541.706077-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 --- (no changes since v2) 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 | 142 +++++++++++++++++++++++++--------------- 2 files changed, 95 insertions(+), 52 deletions(-) diff --git a/doc/develop/logging.rst b/doc/develop/logging.rst index 28340a4aac..52ccd2009e 100644 --- a/doc/develop/logging.rst +++ b/doc/develop/logging.rst @@ -291,3 +291,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 7a839d55aa..952d407068 100644 --- a/include/log.h +++ b/include/log.h @@ -17,54 +17,88 @@ 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_LEVEL_MASK = 0xf, /* Mask for valid log levels */ - LOGL_FORCE_DEBUG = 0x10, /* Mask to force output due to LOG_DEBUG */ + /** @LOGL_LEVEL_MASK: Mask for valid log levels */ + LOGL_LEVEL_MASK = 0xf, + /** @LOGL_FORCE_DEBUG: Mask to force output due to LOG_DEBUG */ + LOGL_FORCE_DEBUG = 0x10, + /** @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. * * Remember to update log_cat_name[] after adding a new category. */ 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 */ @@ -83,7 +117,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, ...) @@ -238,7 +272,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); \ @@ -322,8 +356,9 @@ enum log_device_flags { */ 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. @@ -380,11 +415,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 @@ -409,7 +444,7 @@ 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 + * Return: category name (which may be a uclass driver name) if found, or * "" if invalid, or "" if not found. All error * responses begin with '<'. */ @@ -419,7 +454,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); @@ -427,7 +462,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); @@ -435,7 +470,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); @@ -443,7 +478,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); @@ -491,15 +526,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, @@ -511,13 +547,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[], @@ -534,8 +571,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); @@ -556,7 +594,7 @@ int log_device_set_enable(struct log_driver *drv, bool enable); /** * 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 @@ -570,7 +608,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 Tue Oct 27 23:55: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: 1389070 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=Y73t7tcj; 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 4CLTGW0ls1z9s0b for ; Wed, 28 Oct 2020 11:00:03 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1A4DD82569; Wed, 28 Oct 2020 00:57:06 +0100 (CET) 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="Y73t7tcj"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 523088251D; Wed, 28 Oct 2020 00:56:24 +0100 (CET) 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-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) (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 6B1A7824F4 for ; Wed, 28 Oct 2020 00:56:20 +0100 (CET) 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-x82f.google.com with SMTP id h19so2406655qtq.4 for ; Tue, 27 Oct 2020 16:56:20 -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=siQ0aopy0j6Y5cFqud9iFyO6/GJPUKkS21SBnEdzPm4=; b=Y73t7tcjKoVM5mSx/o/qhArN4xg2ejqNxjo2pygXLdSDRe1GLDMpHuQteAu2tevuDx MdR1xvrnGAlidwzlc4YEDNl7I0sTsjfLm3vAOBYv/1TUHB8EiGjJfnK+2EZ71iY4xkeP IU0X99lceSsBebKGecCz6wXYeeiBybqcv7GsZwQ6Kgh1vkC1Xu2gSKatbcbNuAYlKWLX bJc/YLx6lQUhODK3dd/PfpQ29XuRgo8OjwU4WRnVH1pkcygulak1Yt4EUaEwhDTJ7zq2 nVxSkKgULFvd2LBQ859cEL0icedswGL4Y1iqT7R7+hczMqOSJZ84cJOmla/5Z1/ovGVt k0DQ== 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=siQ0aopy0j6Y5cFqud9iFyO6/GJPUKkS21SBnEdzPm4=; b=YrUbblgqRcHypAX0MOtDKKUCpA5++0jgNmlaLQ3V8E3rv+aL25ajZY2unOD5qJM6yn raMY8CKCWS+/lrZKDOpC9lPBvNTTz98BocSFPS4K77EswBO3g08WB9W0Bj5/5dRuJasZ Bz/28LS0zj+bn6hP0hUWHgwj2RNqzGM6h0YCma63lrJqUe83ce7AaRLnX3N/dZhZ/zEl y1qaXvIc4vFvjLcdSQBmbkpIGQTdc3BuKaCthC/FDdDgR3lBo3wsiFguklQtFPcBUXFH eDR/ZT/0pHNH9VQ2SO+Wkuy438p7WE8hdVhu8PNu0J84HPzB/FcEKbKPsM5WfS1wzIVx JA8Q== X-Gm-Message-State: AOAM532Bkds5rkTV+wgwWSYWPFq6XAtWrwzBC8bQV4iqP2h3Uf1T/BTD o4eCt3F+DwB6QQOXIPkOz0Y37prFI9tuNg== X-Google-Smtp-Source: ABdhPJwclCqPcVdxGDeCx8ehzUV+2skx5CR+oBSA5ZWOcM3UoSvvgeS/2u3YXYFF/9p9yZ3cCct+Gw== X-Received: by 2002:ac8:578f:: with SMTP id v15mr4484141qta.81.1603842978813; Tue, 27 Oct 2020 16:56:18 -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 69sm1907543qko.48.2020.10.27.16.56.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2020 16:56:18 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , Sean Anderson Subject: [PATCH v4 22/22] doc: Update logging documentation Date: Tue, 27 Oct 2020 19:55:41 -0400 Message-Id: <20201027235541.706077-23-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201027235541.706077-1-seanga2@gmail.com> References: <20201027235541.706077-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 v4: - Add some more examples to docs Changes in v3: - Fix heading level of Filters section - Remove a few more already-implemented features from the TODO list Changes in v2: - Add a few informational commands - 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 | 221 ++++++++++++++++++++-------------------- 1 file changed, 110 insertions(+), 111 deletions(-) diff --git a/doc/develop/logging.rst b/doc/develop/logging.rst index 52ccd2009e..7fdd1132ef 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 -------------------------------------- @@ -83,12 +64,52 @@ Sometimes it is useful to turn on logging just in one file. You can use this #define LOG_DEBUG to enable building in of all logging statements in a single file. Put it at -the top of the file, before any #includes. This overrides any log-level setting -in U-Boot, including CONFIG_LOG_DEFAULT_LEVEL, but just for that file. +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 (:c:type:`LOGL_DEBUG`) or more. +Otherwise debug output is suppressed and will not be generated. + +Using DEBUG +----------- + +U-Boot has traditionally used a #define called DEBUG to enable debugging on a +file-by-file basis. The debug() macro compiles to a printf() statement if +DEBUG is enabled, and an empty statement if not. + +With logging enabled, debug() statements are interpreted as logging output +with a level of LOGL_DEBUG and a category of LOGC_NONE. + +The logging facilities are intended to replace DEBUG, but if DEBUG is defined +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 statements +------------------ + +The main logging function is: + +.. code-block:: c + + log(category, level, format_string, ...) + +Also debug() and error() will generate log records - these use LOG_CATEGORY +as the category, so you should #define this right at the top of the source +file to ensure the category is correct. + +You can also define CONFIG_LOG_ERROR_RETURN to enable the log_ret() macro. This +can be used whenever your function returns an error value: + +.. code-block:: c + + return log_ret(uclass_first_device(UCLASS_MMC, &dev)); + +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: @@ -116,36 +137,6 @@ or 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. - - -Using DEBUG ------------ - -U-Boot has traditionally used a #define called DEBUG to enable debugging on a -file-by-file basis. The debug() macro compiles to a printf() statement if -DEBUG is enabled, and an empty statement if not. - -With logging enabled, debug() statements are interpreted as logging output -with a level of LOGL_DEBUG and a category of LOGC_NONE. - -The logging facilities are intended to replace DEBUG, but if DEBUG is defined -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 -------------------- @@ -159,9 +150,40 @@ enabled or disabled independently: 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 - list log levels or set the default 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 + +Type 'help log' for details. Log format ----------- +~~~~~~~~~~ You can control the log format using the 'log format' command. The basic format is:: @@ -169,50 +191,43 @@ 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. +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 +~~~~~~~~~~~~~~ -Filters -------- +To add new filters at runtime, use the 'log filter-add' command. For example, to +suppress messages from the SPI and MMC subsystems, run:: -Filters are attached to log drivers to control what those drivers emit. Only -records that pass through the filter make it to the driver. + log filter-add -D -c spi -c mmc -Filters can be based on several criteria: +You will also need to add another filter to allow other messages (because the +default filter no longer applies):: -* maximum log level -* in a set of categories -* in a set of files + log filter-add -A -l info -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 levels may be either symbolic names (like above) or numbers. For example, to +disable all debug and above (log level 7) messages from ``drivers/core/lists.c`` +and ``drivers/core/ofnode.c``, run:: + log filter-add -D -f drivers/core/lists.c,drivers/core/ofnode.c -L 7 -Logging statements ------------------- +To view active filters, use the 'log filter-list' command. Some example output +is:: -The main logging function is: - -.. code-block:: c - - log(category, level, format_string, ...) - -Also debug() and error() will generate log records - these use LOG_CATEGORY -as the category, so you should #define this right at the top of the source -file to ensure the category is correct. - -You can also define CONFIG_LOG_ERROR_RETURN to enable the log_ret() macro. This -can be used whenever your function returns an error value: - -.. code-block:: c - - return log_ret(uclass_first_device(UCLASS_MMC, &dev)); - -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. + => log filter-list + num policy level categories files + 2 deny >= DEBUG drivers/core/lists.c,drivers/core/ofnode.c + 0 deny <= IO spi + mmc + 1 allow <= INFO +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 --------- @@ -229,13 +244,12 @@ 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 ----- There are lots of useful additions that could be made. None of the below is -implemented! If you do one, please add a test in test/py/tests/test_log.py - +implemented! If you do one, please add a test in test/log/log_test.c +log filter-add -D -f drivers/core/lists.c,drivers/core/ofnode.c -l 6 Convenience functions to support setting the category: * log_arch(level, format_string, ...) - category LOGC_ARCH @@ -256,25 +270,15 @@ Convert error() statements in the code to log() statements Figure out what to do with BUG(), BUG_ON() and warn_non_spl() -Figure out what to do with assert() - 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 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 @@ -285,12 +289,7 @@ 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 +Add a command to delete existing log records. Logging API -----------