From patchwork Sat Oct 17 18:07: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: 1383733 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=q5zT/Fyh; 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 4CD9x71lqyz9sSs for ; Sun, 18 Oct 2020 05:08:11 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 791578236F; Sat, 17 Oct 2020 20:08:02 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=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="q5zT/Fyh"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E04F281BD2; Sat, 17 Oct 2020 20:07:57 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x142.google.com (mail-il1-x142.google.com [IPv6:2607:f8b0:4864:20::142]) (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 584DA81BD2 for ; Sat, 17 Oct 2020 20:07:55 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-il1-x142.google.com with SMTP id z2so6186014ilh.11 for ; Sat, 17 Oct 2020 11:07:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kSxdmaJxYWCXemr6RLF98I4Z98KupSZizyFI/hmWdW0=; b=q5zT/Fyhlt7w913NiI4LBnzm1ehJEE8HouVQyKUOR1qQRwHnMQk7QIIT9K3Z1WwWD9 oAUNxz4a1XqY1gp3Ke/mLG4Z4frjcSYtXznhRrom31ptIP26DlBUwPjPuUkJHPS6TgdR xGFCMaJgNYpWlvFmrVEqxB6BIcaXKQ1CmjrkLbVJDkePujZU+I5c+uc16PM/kJyMchZ8 SkIOSfdByh4q7j2YAqNstjs2hs4aikJsiEK8akLAxYj1dOJPY/WwevtvZKwyTl+AVbUL fO24jcn4azsdsFcHR1BFZcpx2TIcACL1UmxCDKhevRLCJ0GwTkRMccRKWWPUku/oY3GK M84Q== 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=kSxdmaJxYWCXemr6RLF98I4Z98KupSZizyFI/hmWdW0=; b=tfEr/ozcPRnmkc/NzjxIFS0mfqOcoUVHKZNqOEMFVFaptPKg/adeFTeFkYYm/RSI9B MTQjn7iJR3ZQpPB27bRrzLXPqnMCEz96uPkOX05g9+OQcB/E8pKljzH3Y1adbCHhVZM0 uiswY119ZEtf+oZPknLF79NxABM0gdwAcM2eJh0qKp7y8DWVh4ddTDJO4hjYFmu9yg8c FGQrDUuLZ/+EErZsNX/B+C+UCX5bbHdlfLl2STQLWJ+SvqnDWAdNH+En8MfudjOKuutd gxQCJ6uyXSFg7Ins6zD+95QR3YmK0Sgs5MopYCsGL6KMUuJI3GDTEKpQBvMBYtQglzr2 oBEg== X-Gm-Message-State: AOAM530BWYn67FzhoS8xmQ2emW8fbz2u7OwCjDAtx//va6yp5+aSsu6v SZAjlqqMGOfXh7KBIPouH62vhisIEIz45g== X-Google-Smtp-Source: ABdhPJz+qMNpLwkSjS55ACvTSDQf+EeEBB7KdzaJQn8ysFdmvvZsHj2a4Qhec5BQqWopw69TY8SoQw== X-Received: by 2002:a92:d14c:: with SMTP id t12mr2997801ilg.273.1602958074053; Sat, 17 Oct 2020 11:07:54 -0700 (PDT) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id k7sm5337730iog.26.2020.10.17.11.07.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Oct 2020 11:07:53 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Simon Glass , Heinrich Schuchardt , Tom Rini , Sean Anderson Subject: [PATCH v3 01/23] log: Fix missing negation of ENOMEM Date: Sat, 17 Oct 2020 14:07:26 -0400 Message-Id: <20201017180749.119271-2-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201017180749.119271-1-seanga2@gmail.com> References: <20201017180749.119271-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 1b10f6f180..807babbb6e 100644 --- a/common/log.c +++ b/common/log.c @@ -273,7 +273,7 @@ int log_add_filter(const char *drv_name, enum log_category_t cat_list[], if (file_list) { filt->file_list = strdup(file_list); if (!filt->file_list) { - ret = ENOMEM; + ret = -ENOMEM; goto err; } } From patchwork Sat Oct 17 18:07: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: 1383734 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=iOFBBWcZ; 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 4CD9xN6J5nz9sSs for ; Sun, 18 Oct 2020 05:08:24 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B59A1823ED; Sat, 17 Oct 2020 20:08:04 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="iOFBBWcZ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7751882396; Sat, 17 Oct 2020 20:07:59 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x142.google.com (mail-il1-x142.google.com [IPv6:2607:f8b0:4864:20::142]) (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 8FC93821A4 for ; Sat, 17 Oct 2020 20:07:56 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-il1-x142.google.com with SMTP id j17so6273623ilr.2 for ; Sat, 17 Oct 2020 11:07:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tV0bObHi5yODbzZxHdTCBLf6VbNa9jqx3JDN4KhCcps=; b=iOFBBWcZJpJCtnWUt4oTPVCxCgYuOG+hmIJfxHB1Rg1ZXjuUbPBHSgH6+Fc8+PElDO cEF+6ll1vAUZhFTbExPKUHI/milrgInfwp/GGU39t62OHkJWZo5ZSVr0RVquW69NAGsY 8OHvQbFH3KQcO7P4+yGUyRLtenE7x3wHbOSh0rhUdy6cErarm9S3XDi+LeC9Zqqz1bHR zQXWCYr1Xn/M5duhOf22MYWNdYYF0W3EkH78r65E4KPXrsNBrpX579Jqzsvt1q4w9+1c Fc6gmu24e1gaYf1X3DwnmWTlakEIZEWdECat1I9aIfvX6IMkC6GStCxihQw1WiQasK7P cnmA== 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=tV0bObHi5yODbzZxHdTCBLf6VbNa9jqx3JDN4KhCcps=; b=dBHXLv8kCJEIVn2h6etWMFiOnBsEKTBQ23P1Nqlrb/h/XQWmiZ+X7JQqlUmy7thXwv G/tT7mAj6cd87a8hWqmZoE0KTWvHaR86o3XJZm7Z6TID3f4LI+YaK6ctnnyW7NVJztRk MEuRo/Xagel5pNv+0o4yoRynkLzIKEDWjIVvZLrTEHKT2unXjKMyooTx7XXvF5rebtSQ e2GM2CWAkkCYBrjyeBTR8F5tPQioEODNeR3OWKHAwCzGdsmuFIa/Rpow43ZWU9oWHdbH qcmsaibIIESz9RV4fv7xRvCIapir581dUbS99Qjcw048OO/7Rai/MTJjDjSvGG29yAIi 237g== X-Gm-Message-State: AOAM533Z5tLyoGx6IcQkeuGvGNVLNKOo3brj6RxtxCKyT2FsZLs4/cVx Vi1GEK6xV+/nROv8opwxYIrrB5LsY2lHJQ== X-Google-Smtp-Source: ABdhPJxcNHLcdMoYXksSv/KrVwp02bo9QBBTPt5b2YdxPcgk/Dpv+Lmakz0L6QTSi+Ph04oWr0FJPg== X-Received: by 2002:a92:cb0c:: with SMTP id s12mr5952872ilo.215.1602958075310; Sat, 17 Oct 2020 11:07:55 -0700 (PDT) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id k7sm5337730iog.26.2020.10.17.11.07.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Oct 2020 11:07:54 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Simon Glass , Heinrich Schuchardt , Tom Rini , Sean Anderson Subject: [PATCH v3 02/23] log: Fix incorrect documentation of log_filter.cat_list Date: Sat, 17 Oct 2020 14:07:27 -0400 Message-Id: <20201017180749.119271-3-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201017180749.119271-1-seanga2@gmail.com> References: <20201017180749.119271-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 4acc087b2e..3487c936c9 100644 --- a/include/log.h +++ b/include/log.h @@ -368,7 +368,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 @@ -446,7 +446,7 @@ int do_log_test(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); * * @drv_name: Driver name to add the filter to (since each driver only has a * single device) - * @cat_list: List of categories to allow (terminated by LOGC_none). If empty + * @cat_list: List of categories to allow (terminated by %LOGC_END). If empty * then all categories are permitted. Up to LOGF_MAX_CATEGORIES entries * can be provided * @max_level: Maximum log level to allow From patchwork Sat Oct 17 18:07: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: 1383735 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=vHi2doit; 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 4CD9xs5g4kz9sSs for ; Sun, 18 Oct 2020 05:08:49 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A84C9823C9; Sat, 17 Oct 2020 20:08:06 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="vHi2doit"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 84BD782396; Sat, 17 Oct 2020 20:08:00 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x144.google.com (mail-il1-x144.google.com [IPv6:2607:f8b0:4864:20::144]) (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 CB8A8822C8 for ; Sat, 17 Oct 2020 20:07:57 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-il1-x144.google.com with SMTP id p16so6250505ilq.5 for ; Sat, 17 Oct 2020 11:07:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=p3CrXoiohYpHp4xIk6ZnY8wia1J1mF7sUjvZUKA/aDA=; b=vHi2doitQuQ856peuOjNei5b5gnvxZPL1BtPb6/jJtKuwUITAll7W5jAc1AGk1pH4r yHfahQ1UXIfyQ3Av69woDHjA0jxxu0gC/kQpwFxUgo5zNMuV7Soe5SL2RGyz9l/4eLml O7sa22ipkO0H9eYpSIvo6pDlS18cZ3QlU1pG/8QIpDfo2i9G5P0+Lju0u0Jz5uK2s4PG 7m0Tn4p6d80ruz+1qsy8YyY6j/Btws2GWHFDvOUBCJWfU548pQJ6YPRTtOT2G+wbJa2l 1ru9zQoNKY1+wSpcvcXZrZU4uVcTgmhnHi1ec0kCmiVlknaB8FwCTjJ5ZcbSCy+r1muP 1AGw== 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=p3CrXoiohYpHp4xIk6ZnY8wia1J1mF7sUjvZUKA/aDA=; b=XuvtFxQvHBE8j6ZFycjfzmgPedIv6iRgoaG1IWIBmr50scAL5W2DeIUHTffzsTUAhp NmvvmmWyScZWPEJxiU1mYyjWY1fTdHxXoxNFUMrRttKJVutBPIxkJqfxlLatm23BkRWX RGB7zYlAcsvUty/JuxQJS8z6Twds1L0Wr6r1ePF29jbktNH+u78SG6WmZQbu71go7AdC 7XhDv2CZzScy11opDPR7raFXfE18KX41jIzXpz1nAdd9+JopP+tpSPRcZzg1iFqtisky SXhl2lY5viBf4b12lNB5ohbIy+EyyiR8KCQBOKNj0V2dhvJ6PLN+yGNIaIHwS0NtTvBX CV/g== X-Gm-Message-State: AOAM531uOrz3Io1WfI0qOi1Fgg9YVfg0GE1diRoMWUL2lRyg3HCXhwfR NCgrUSzyWNN2A4vg1Iy8NBjqNkW+I7+VRw== X-Google-Smtp-Source: ABdhPJwIrWNOkxfNkZfD1BJR3BZapYcDmQHLSSwb0/Eb1kXnzIEZRaXWG5kwGcb1XMkcmlRwNE+wqw== X-Received: by 2002:a92:aa43:: with SMTP id j64mr6142002ili.179.1602958076531; Sat, 17 Oct 2020 11:07: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 k7sm5337730iog.26.2020.10.17.11.07.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Oct 2020 11:07:56 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Simon Glass , Heinrich Schuchardt , Tom Rini , Sean Anderson Subject: [PATCH v3 03/23] log: Add additional const qualifier to arrays Date: Sat, 17 Oct 2020 14:07:28 -0400 Message-Id: <20201017180749.119271-4-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201017180749.119271-1-seanga2@gmail.com> References: <20201017180749.119271-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 807babbb6e..f3d9f4a728 100644 --- a/common/log.c +++ b/common/log.c @@ -13,7 +13,7 @@ DECLARE_GLOBAL_DATA_PTR; -static const char *log_cat_name[LOGC_COUNT - LOGC_NONE] = { +static const char *const log_cat_name[LOGC_COUNT - LOGC_NONE] = { "none", "arch", "board", @@ -23,7 +23,7 @@ static const char *log_cat_name[LOGC_COUNT - LOGC_NONE] = { "efi", }; -static const char *log_level_name[LOGL_COUNT] = { +static const char *const log_level_name[LOGL_COUNT] = { "EMERG", "ALERT", "CRIT", From patchwork Sat Oct 17 18:07: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: 1383736 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=SpzA2xta; 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 4CD9y24S6kz9sSs for ; Sun, 18 Oct 2020 05:08:58 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EACF982413; Sat, 17 Oct 2020 20:08:09 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=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="SpzA2xta"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5C96A823C4; Sat, 17 Oct 2020 20:08:02 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x142.google.com (mail-il1-x142.google.com [IPv6:2607:f8b0:4864:20::142]) (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 131748236F for ; Sat, 17 Oct 2020 20:07:59 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-il1-x142.google.com with SMTP id j13so6263739ilc.4 for ; Sat, 17 Oct 2020 11:07: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=gRaOsux2wsnBqQLA3UJ37RbY12wOylG3c+b0LU8OrSI=; b=SpzA2xtaBIZbPtZsAR6lMBhDSX2UX72NyG//evfDg5MDFExSntBUzLRqJwj+DocuHG 6lconsITZ1ywnta2oYRQ8EVtpsscJjb4Jc0uwO0sMfy2U3zxlgMEqb84Dz3W+jC7yGhx fJTVOTPccp7H0mEPx+3xYKFRwSOQ3LK8qmVsWx1/FFMcibVZIkvHE1dZW1ZhBQbH3WsJ uAkLYnPt2ynDpBIWtrU6WiX58WIbhN91YlOX+nnhLZrKW/G0PX8JkVKrNJ9JaahC5pZ2 pEFvmZFtJZ0b9RAJPZiJiDrFh1jf2gxohh0Hfi+Q2AMj1a39Fqukfm0U2I0TWOvfPFFa sInw== 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=gRaOsux2wsnBqQLA3UJ37RbY12wOylG3c+b0LU8OrSI=; b=Qw0y4dgGDIvl4jprC91ofkv/i5PM7yJos1RlI/LlowdEb2iZT1dV6tT1coxg+GUOhe eIiWyJWA4LlLD6LpRjvTWctRAvlTXBVbGnKKOEZvLhIeg1L5tG4q4zg5kCHKIZD/LL/9 3yHPvHnoySBsIJhQl2p2Qn5Dq2+cjN/alpHsCqKxEW76RQ4JzBukdi1EC6V19QMm2rE0 LY0Jox2B06SAU3/lfIwxxTTm7XCXnDjgD0vQM3eBmVjiY3bqK3dj2GqgIKCumfna2A0y i5KkhQTxH83XCmffSWXHWmieNqh6Q7VE0N46P8hR6PcxH16RQUIbTLrx09dmK3v7kj3q M1Jg== X-Gm-Message-State: AOAM531HFZyUdE97mEnjN2hXMqFQeH+VIKjUiH16kyvMU1SjrDg+RvYI qAOITAE3SmvY8zdqynLtitIsdPBoGO5DhQ== X-Google-Smtp-Source: ABdhPJydNRFv4S5mx/ecuTz3BFjQ7OsNxqzqj9NadCIvzaGlT3GKIZ5GUdJdH6ABjJjbUBqz7nQHQw== X-Received: by 2002:a92:99da:: with SMTP id t87mr6545933ilk.76.1602958077749; Sat, 17 Oct 2020 11:07: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 k7sm5337730iog.26.2020.10.17.11.07.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Oct 2020 11:07:57 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Simon Glass , Heinrich Schuchardt , Tom Rini , Sean Anderson Subject: [PATCH v3 04/23] log: Add new category names to log_cat_name Date: Sat, 17 Oct 2020 14:07:29 -0400 Message-Id: <20201017180749.119271-5-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201017180749.119271-1-seanga2@gmail.com> References: <20201017180749.119271-1-seanga2@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Without every category between LOGC_NONE and LOGC_COUNT present in log_cat_name, log_get_cat_by_name will dereference NULL pointers if it doesn't find a name early enough. Fixes: c3aed5db59 ("sandbox: spi: Add more logging") Fixes: a5c13b68e7 ("sandbox: log: Add a category for sandbox") Fixes: 9f407d4ef0 ("Add core support for a bloblist to convey data from SPL") Fixes: cce61fc428 ("dm: devres: Convert to use logging") Fixes: 7ca2850cbc ("dm: core: Add basic ACPI support") Signed-off-by: Sean Anderson Reviewed-by: Simon Glass --- (no changes since v2) Changes in v2: - Add compiletime assert on size of log_cat_name common/log.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/common/log.c b/common/log.c index f3d9f4a728..5a588c4152 100644 --- a/common/log.c +++ b/common/log.c @@ -13,7 +13,7 @@ DECLARE_GLOBAL_DATA_PTR; -static const char *const log_cat_name[LOGC_COUNT - LOGC_NONE] = { +static const char *const log_cat_name[] = { "none", "arch", "board", @@ -21,6 +21,11 @@ static const char *const log_cat_name[LOGC_COUNT - LOGC_NONE] = { "driver-model", "device-tree", "efi", + "alloc", + "sandbox", + "bloblist", + "devres", + "acpi", }; static const char *const log_level_name[LOGL_COUNT] = { @@ -40,6 +45,9 @@ const char *log_get_cat_name(enum log_category_t cat) { const char *name; + compiletime_assert(ARRAY_SIZE(log_cat_name) == LOGC_COUNT - LOGC_NONE, + "missing logging category name"); + if (cat < 0 || cat >= LOGC_COUNT) return ""; if (cat >= LOGC_NONE) From patchwork Sat Oct 17 18:07: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: 1383739 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=G/DleYde; 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 4CD9yY3Qjkz9sSs for ; Sun, 18 Oct 2020 05:09:25 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 07CFB82424; Sat, 17 Oct 2020 20:08:11 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="G/DleYde"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 24681823FC; Sat, 17 Oct 2020 20:08:03 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x142.google.com (mail-il1-x142.google.com [IPv6:2607:f8b0:4864:20::142]) (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 3D8DA8235C for ; Sat, 17 Oct 2020 20:08:00 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-il1-x142.google.com with SMTP id p16so6250573ilq.5 for ; Sat, 17 Oct 2020 11:08: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=7qVo7XsKjnkXMWcNhCdQ/B7PiPBPeCQpYDsNTXJ9+0A=; b=G/DleYdefaHf/0ze+VUPssKbMQltxFJMvBFE7NSwBhD5W+4u8MZCTxuAD9tDCbuu0Q qKW9j3+tJTNPpMdSOpfh7JL+cl54jr+j80cxvLQpyF0a22U9xN0urfwtsA2xcTsMACD4 EOdnH2HMl+CfUn0kBgjX4pENxOJx2kOf0XMYf7NvDETydOSkY+U9mcVQpa3DROei9Jyp 7l48P5M2dTY51Kya9GYehjbCyKGd+jLCtnTrgKB4ixjdi+peJM5RrPAyjcGJLUmd3YaM rqMgFlbUHIfDCvohtwOWg91SgwxpRaJxjxn1BTVcEAvQzfG2qpmmJ+dHmn94TwCt3RE5 bMjA== 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=gvgp3Cs59F1onadqXkKXo/NErqawTSXL8H7/OWce0ERDM6egfNWp4wuv4BMxwPXTKF gq5Zw2DaPapvqvzSkdrtwoXQXnJhFaDfql8Z02y0VMWbE/KqJ+/vW5dVnH2V9IjfTbx/ aqTLhYuO1Hj5hIdkGG73nDqEh8US3kuWuLX94qRtzoUPl1B0FggjDqPIkwkHHlLBjn0L saKM7roHxmHyJB7mfcwgbsiCOREdYPD3cb6nPccD2BnZLqYIyOOvdrCxQQCxrxadLrQ6 FVTTUBSscePAYnPgi8JkRrfKhfszlfQz02Juz/5RVVxFLGC4RELNJLU6CMFInv1fhBPW Hhxg== X-Gm-Message-State: AOAM531uxqFrBVtlNGULcLOif/wtFvLoVl+mmYrVkxSUnDFiwSckFAAs H/dQQQSeRLQyPKrXrbVZHtq+eWDC4sP+tw== X-Google-Smtp-Source: ABdhPJwuLNfMi9F5xjV4gAHL6iv3GjUU+I7h1iHWwNwTOauHsExqh3DPq3H6zdwpZYGbYoXd7KJRCg== X-Received: by 2002:a92:1501:: with SMTP id v1mr6287411ilk.272.1602958079010; Sat, 17 Oct 2020 11:07: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 k7sm5337730iog.26.2020.10.17.11.07.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Oct 2020 11:07:58 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Simon Glass , Heinrich Schuchardt , Tom Rini , Sean Anderson Subject: [PATCH v3 05/23] log: Use CONFIG_IS_ENABLED() for LOG_TEST Date: Sat, 17 Oct 2020 14:07:30 -0400 Message-Id: <20201017180749.119271-6-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201017180749.119271-1-seanga2@gmail.com> References: <20201017180749.119271-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 Sat Oct 17 18:07: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: 1383740 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=tXrxsAjX; 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 4CD9yz37pFz9sTD for ; Sun, 18 Oct 2020 05:09:47 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 79D528243C; Sat, 17 Oct 2020 20:08:12 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="tXrxsAjX"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5EB9582413; Sat, 17 Oct 2020 20:08:05 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x131.google.com (mail-il1-x131.google.com [IPv6:2607:f8b0:4864:20::131]) (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 8B2E6822C8 for ; Sat, 17 Oct 2020 20:08:01 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-il1-x131.google.com with SMTP id q1so6254849ilt.6 for ; Sat, 17 Oct 2020 11:08: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=3x4WjaLw7rBjCkCr+LJPn2M7/fbUrrBTLSDPXwv7TRY=; b=tXrxsAjXlQIlnH+t3t43ZgCc9lBpw8QBEzaAnZFMesFR7mOva621Ka1jPm7ChCsokX KQ99vOvUmdHPSeJq5mUUNArxwItIi6rAEzgllN2kDzqBGDGJyAEbezMKCkdLVndKzQxL FcuklHr6pTsU/TjjYgRG77oGQP5Vl7ZXKJ/yvxv6mRdOI0n+wmrjKbSnmuzfI1Qtd1hd JynhZ2JTIrHJvA1WFrwoPB5LTz4d1kRaTkio/8tjxuuaGmnLkBkJZW7U+CZrZrO/utDa TNRmUQKg1x168cVLB/abQK2KIEn8WczCLehr6ZTuPkOkkGzXVC4WU9k+udBryC5uw7WG hnOg== 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=3x4WjaLw7rBjCkCr+LJPn2M7/fbUrrBTLSDPXwv7TRY=; b=WRASG7DnbJnawWLuUtl5YCIq8Q6zYOJYEJD6ALNvZuyX9wDrOX11H+c0gaDR9qaPal zGT1vIjN+HlMz5v+MTN1QifMcbvvqdbMK8aVpfnO9dFYaf8qieBss4QTPv4Ch0tt99YY 1fl3EPEMJHW3x+bzAh/kmCE1CwuAR/vSIYUIudQPaCszHXB0gFhExfojr1XjjcJuC0+Q Q1t3cqEa/obdkFMKwS6mhCd1M89GW4d6ZjIFvTVr+n0wtrIIHYnCAjxNi0z3D8JPnmh9 NQ8knmo3Vupk/AoJk4IVZsdDE0tyCKvl7MBQvYu8xeWIRvACtLWvDl9DWq0pS/63KGwg gA7A== X-Gm-Message-State: AOAM530Xew91lQAnCgzhhq/700NSj9ggHauy5J40+CnF1MD+qCDg0iUG sXkNcp35eEJjTi9GO31Oruxr/l0h1Nhh9Q== X-Google-Smtp-Source: ABdhPJyZw55bT0UdEJtsFhmV9Q7sizV+1GC1ZBMy+o6LPe2nC0zcH1CP4Avh1juBVisYSQ0yH5QPew== X-Received: by 2002:a92:85d5:: with SMTP id f204mr6811432ilh.108.1602958080225; Sat, 17 Oct 2020 11:08:00 -0700 (PDT) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id k7sm5337730iog.26.2020.10.17.11.07.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Oct 2020 11:07:59 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Simon Glass , Heinrich Schuchardt , Tom Rini , Sean Anderson Subject: [PATCH v3 06/23] log: Expose some helper functions Date: Sat, 17 Oct 2020 14:07:31 -0400 Message-Id: <20201017180749.119271-7-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201017180749.119271-1-seanga2@gmail.com> References: <20201017180749.119271-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 5a588c4152..63e8df820e 100644 --- a/common/log.c +++ b/common/log.c @@ -96,7 +96,7 @@ enum log_level_t log_get_level_by_name(const char *name) return LOGL_NONE; } -static struct log_device *log_device_find_by_name(const char *drv_name) +struct log_device *log_device_find_by_name(const char *drv_name) { struct log_device *ldev; @@ -108,15 +108,7 @@ static struct log_device *log_device_find_by_name(const char *drv_name) return NULL; } -/** - * log_has_cat() - check if a log category exists within a list - * - * @cat_list: List of categories to check, at most LOGF_MAX_CATEGORIES entries - * long, terminated by LC_END if fewer - * @cat: Category to search for - * @return true if @cat is in @cat_list, else false - */ -static bool log_has_cat(enum log_category_t cat_list[], enum log_category_t cat) +bool log_has_cat(enum log_category_t cat_list[], enum log_category_t cat) { int i; @@ -128,16 +120,7 @@ static bool log_has_cat(enum log_category_t cat_list[], enum log_category_t cat) return false; } -/** - * log_has_file() - check if a file is with a list - * - * @file_list: List of files to check, separated by comma - * @file: File to check for. This string is matched against the end of each - * file in the list, i.e. ignoring any preceding path. The list is - * intended to consist of relative pathnames, e.g. common/main.c,cmd/log.c - * @return true if @file is in @file_list, else false - */ -static bool log_has_file(const char *file_list, const char *file) +bool log_has_file(const char *file_list, const char *file) { int file_len = strlen(file); const char *s, *p; diff --git a/include/log.h b/include/log.h index 3487c936c9..8d0227a384 100644 --- a/include/log.h +++ b/include/log.h @@ -425,6 +425,37 @@ const char *log_get_level_name(enum log_level_t level); */ enum log_level_t log_get_level_by_name(const char *name); +/** + * log_device_find_by_name() - Look up a log device by its driver's name + * + * @drv_name: Name of the driver + * @return the log device, or NULL if not found + */ +struct log_device *log_device_find_by_name(const char *drv_name); + +/** + * log_has_cat() - check if a log category exists within a list + * + * @cat_list: List of categories to check, at most %LOGF_MAX_CATEGORIES entries + * long, terminated by %LC_END if fewer + * @cat: Category to search for + * + * Return: ``true`` if @cat is in @cat_list, else ``false`` + */ +bool log_has_cat(enum log_category_t cat_list[], enum log_category_t cat); + +/** + * log_has_file() - check if a file is with a list + * + * @file_list: List of files to check, separated by comma + * @file: File to check for. This string is matched against the end of each + * file in the list, i.e. ignoring any preceding path. The list is + * intended to consist of relative pathnames, e.g. common/main.c,cmd/log.c + * + * Return: ``true`` if @file is in @file_list, else ``false`` + */ +bool log_has_file(const char *file_list, const char *file); + /* Log format flags (bit numbers) for gd->log_fmt. See log_fmt_chars */ enum log_fmt { LOGF_CAT = 0, From patchwork Sat Oct 17 18:07: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: 1383741 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=tCff1o08; 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 4CD9zW5W08z9sSs for ; Sun, 18 Oct 2020 05:10:15 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A79F682441; Sat, 17 Oct 2020 20:08:13 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="tCff1o08"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E98FC82413; Sat, 17 Oct 2020 20:08:05 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x143.google.com (mail-il1-x143.google.com [IPv6:2607:f8b0:4864:20::143]) (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 D5001823E0 for ; Sat, 17 Oct 2020 20:08:02 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-il1-x143.google.com with SMTP id j17so6273817ilr.2 for ; Sat, 17 Oct 2020 11:08: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=E646sODKXnbPCAvIRelwSMhXW7BHy/tvdpMTArlwti0=; b=tCff1o08TGCL4NiFB4MHZLA7yVcSV7cs6uuk1YEZBS/d4SArAUcJbt6Q151f5z7/nm XqkFfEABSeFE9e4gStwCwjbplwiaYqKFLkWYMXJ0TqUUQcjNLD9JtXpczyJZw3RIjJOt R9Qu7bjCa3WvymWeObZQ92ZhY7zn5U9AdwYPpHLWfSrbKUIZFRyLYQdRXFXQJSYX+Lkz 0mi+DtkjqywP4SFiWKflggX7l8u39NbKFLmveg9643ssWXe1jYqfWFcrEW6mPK6TlK+5 m3nj3Oti4v0xWuX3T/A/w+EtWMVoq6fsV9LB0oP/OhgEz9KwkbCVviXKzQHdk3sm3ze9 rKYA== 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=E646sODKXnbPCAvIRelwSMhXW7BHy/tvdpMTArlwti0=; b=b4pYDAuJhVjpLZIQEKYn76JcyFp9g3tSfcA/OgL9FeXxGAJdIyharEyzAROkBPya5L t31NGo7Q6YGQTXvURU0gG4mt1AR65mDmyoeJMczDS0CKfkh+hMYktSDoPGtIu2n3u6d/ cM7/kYDEzY7SA/7dLlqApGlazfhyoxkkR9XOj2Dt24rXVenASnLua50uTRG7iE9Z8ODv 9upHFzB31Jzp/n+2MuIbHITsiGFlUQm/ypXaQRjQ5i2ycEMGnULCd2mNeSJAxtt1pc51 LyK2UVCYf3wpg4L1oLiFZaEeoLGKu8ARETk9DvK98dXGAprCyfP0RCHlNstSEATI8Rkm BQpg== X-Gm-Message-State: AOAM532H+OBLicxl6vkzu0qeA5ljQjprp3mNfWmwZqX9FaljaFg5HEgP p21kY8C65FDD/PlrhxtYPgJjVBOfN+T4tw== X-Google-Smtp-Source: ABdhPJyfRDlwXPKqDbKyVZ781yFqUjQWC3NGoZ/Glym6kQ2a7fFHwO0tQ/jdnwKFHbS3mjjOkqpmDQ== X-Received: by 2002:a92:d906:: with SMTP id s6mr6529383iln.225.1602958081421; Sat, 17 Oct 2020 11:08: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 k7sm5337730iog.26.2020.10.17.11.08.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Oct 2020 11:08:00 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Simon Glass , Heinrich Schuchardt , Tom Rini , Sean Anderson Subject: [PATCH v3 07/23] log: Add function to create a filter with flags Date: Sat, 17 Oct 2020 14:07:32 -0400 Message-Id: <20201017180749.119271-8-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201017180749.119271-1-seanga2@gmail.com> References: <20201017180749.119271-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 63e8df820e..d43c9eb15d 100644 --- a/common/log.c +++ b/common/log.c @@ -233,8 +233,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; @@ -248,6 +249,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 8d0227a384..4b33815f01 100644 --- a/include/log.h +++ b/include/log.h @@ -472,6 +472,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 * @@ -486,8 +505,14 @@ int do_log_test(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); * @return the sequence number of the new filter (>=0) if the filter was added, * or a -ve value on error */ -int log_add_filter(const char *drv_name, enum log_category_t cat_list[], - enum log_level_t max_level, const char *file_list); +static inline int log_add_filter(const char *drv_name, + enum log_category_t cat_list[], + enum log_level_t max_level, + const char *file_list) +{ + return log_add_filter_flags(drv_name, cat_list, max_level, file_list, + 0); +} /** * log_remove_filter() - Remove a filter from a log device From patchwork Sat Oct 17 18:07: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: 1383742 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=mI9XJE6b; 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 4CD9zr59sHz9sTD for ; Sun, 18 Oct 2020 05:10:32 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9EFD18244A; Sat, 17 Oct 2020 20:08:14 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="mI9XJE6b"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2EA1982413; Sat, 17 Oct 2020 20:08:07 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) (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 2A3728235C for ; Sat, 17 Oct 2020 20:08:04 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-io1-xd35.google.com with SMTP id k21so8005605ioa.9 for ; Sat, 17 Oct 2020 11:08: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=dWQR8tYN+bmY52fqAcm1JBKxzWR1rjmqpracED71Pk8=; b=mI9XJE6bcCdhlmv3pd6NMHSzbGeogzOZnMV2616fWb/1SepIlNU6Ic/nIaEBYlhzOj jOcoUivDLcptlHwH3GO8aXMeyB1srq+9HTIMTlReuBw3mYYQBfG72IzMomFtAsAJnsyJ yBUYYiA+aTkmJ99t3LDU6JzXKzuHBJflBn77OEr4Pvp3B3dTUZSYw53JRqh+kCkHKNFk g0F2TWXWZ9w1vgBqJq/4tfooUnIccpMKrBREzzZeRL8NIj3KMK6fmDjWmesW2F3UZtF0 m47MaCtUeXykmn7ZA+KLI/kHMJ4RMlI3il4FjVU4seBRahhe1VQ367S7KHLih1Wi+s+a cHxQ== 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=dWQR8tYN+bmY52fqAcm1JBKxzWR1rjmqpracED71Pk8=; b=oqGL9z3qrDIsyLHp+Kk4MUpvHIUFm0ArQAMbCBZGSepMn5EVPHxqzZBUdEuGEi75p/ nxXn0latcg6N0beQUsrYgJV7Fo8N5+ABAoq32MuunNApTUGU8U/G7Ma2Sl+tijtXseqw DkugwsyuvnSaFr21SoPsu3l7qq2jdPhM2U+h3VHr5JYykAevRG1ZYfYJpUlWBPWmHUJW ct+kEwJlpaG8pk3r4kOClmECn6IdLljgdsjOssZAHACX3sX69GdnhRKd7EOSZ0Fm9gIx tRZZNoNPHSk5csTLnI4FG/biljeZ83xp9Egdgh0dy2H5O+hVgjdywM9ElgBdwV1CuoKV rPhQ== X-Gm-Message-State: AOAM530WjAE9YbpoeJ2lI8GsRhNVJ/TZwJ7uBV59QDsGG5hp7bgk76Go 7nC2S9McMjYxlzG+KfoMLfwqp7LSu+eujg== X-Google-Smtp-Source: ABdhPJy5I5m0pGEIRFGcn66LmSbmzkOiHPlcWlKMjSa0tAfRQBo3E9zns+MAa3fYdJoghZCp65EgpA== X-Received: by 2002:a05:6638:1502:: with SMTP id b2mr6881420jat.142.1602958082651; Sat, 17 Oct 2020 11:08: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 k7sm5337730iog.26.2020.10.17.11.08.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Oct 2020 11:08:02 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Simon Glass , Heinrich Schuchardt , Tom Rini , Sean Anderson Subject: [PATCH v3 08/23] log: Add filter flag to deny on match Date: Sat, 17 Oct 2020 14:07:33 -0400 Message-Id: <20201017180749.119271-9-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201017180749.119271-1-seanga2@gmail.com> References: <20201017180749.119271-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 d43c9eb15d..878800b3bb 100644 --- a/common/log.c +++ b/common/log.c @@ -167,7 +167,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; @@ -271,7 +275,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 4b33815f01..8cabe82eb5 100644 --- a/include/log.h +++ b/include/log.h @@ -357,13 +357,22 @@ enum { LOGF_MAX_CATEGORIES = 5, /* maximum categories per filter */ }; +/** + * enum log_filter_flags - Flags which modify a filter + */ enum log_filter_flags { - LOGFF_HAS_CAT = 1 << 0, /* Filter has a category list */ + /** @LOGFF_HAS_CAT: Filter has a category list */ + LOGFF_HAS_CAT = 1 << 0, + /** @LOGFF_DENY: Filter denies matching messages */ + LOGFF_DENY = 1 << 1, }; /** * struct log_filter - criterial to filter out log messages * + * If a message matches all criteria, then it is allowed. If LOGFF_DENY is set, + * then it is denied instead. + * * @filter_num: Sequence number of this filter. This is returned when adding a * new filter, and must be provided when removing a previously added * filter. From patchwork Sat Oct 17 18:07: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: 1383743 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=hc2kn2zj; 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 4CDB072nCNz9sTK for ; Sun, 18 Oct 2020 05:10:47 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5D9F382449; Sat, 17 Oct 2020 20:08:19 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="hc2kn2zj"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6D83282421; Sat, 17 Oct 2020 20:08:09 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd42.google.com (mail-io1-xd42.google.com [IPv6:2607:f8b0:4864:20::d42]) (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 8F41B8241C for ; Sat, 17 Oct 2020 20:08:05 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-io1-xd42.google.com with SMTP id u19so8084302ion.3 for ; Sat, 17 Oct 2020 11:08: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=vYN/cpdUXSX41oi8aE67Hm/Mk/cvPc+qgHnL3c3KvrU=; b=hc2kn2zj5Rf7wVCLxAn9GFRMLrluehnLc+PMYuVOiJytb/2CUW3iX8atUPadAIiFNN 4Z1QXh44VsSNJFMol9cwwMA6PXoZtKhQ1R/Z91K/MUcM7+Snn2TnNBSNVeWVMnzUyDVG au1l3in1Ep6YPy7neW2zeLX7T4m6FhzRdS5bjhEFDltgqVSqnahO1jntzDcgq4uCyzs/ lmGoFuHYDhp2r+o7tZt3Jm+I/KS5hQGSadq2bpmqVVMup0u/0hUH5O/yamwrFzotidOi f1F/Kc60M0xakbTX+1AVYNJPaVG12Ic6TBcb+I84vC0jVhrhs4mH2UfnXe8uRIY+eQDY zdKQ== 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=vYN/cpdUXSX41oi8aE67Hm/Mk/cvPc+qgHnL3c3KvrU=; b=Valr0eFwelBNnm5uo3v7xworBiUZdypa6F4kFhH0C/mOLAEjmeBdsoP2MHViHT79fV Jzp6Okg/YsqxZnegIUbhT7LMm4Bd7ktyDpKeg04IFMu8UHVjSryiqNta9ocjTDCSYe0C ERb8+gapNSkPQzmEyVjsO0SYkNZ3UruQ285OgjRPeFPn84oVb3KeGfnMr2h7bg9Hy+Dy bZdQ5jQ36MaHjOBkfAOK2v/WKHHXT+TKgUBoCEvsZZLFfY1wJ6AthGxnvn4PhWpGezTs 1PohP3gMxbcUHAl5RWd7256e2egrfqXc8Mxh1tD5xRsQt7FEygXG+2+Gmb3hxgxtCz95 VZzg== X-Gm-Message-State: AOAM530pBoqhGnnDscpsFh+cpMMbbQKiETk0mBcsBjS96kOHLpNw7TYk GIDs0gCXnSG0DqrwsouDmWWo8aY0xdR05Q== X-Google-Smtp-Source: ABdhPJzQsr7XoycNpi+CxlXL4fabSZdaOwFHFrGfWVpmUjbDFdwTmlvwIoFHLaMZ5iDpavHWo1HlLA== X-Received: by 2002:a5e:9e42:: with SMTP id j2mr5935739ioq.87.1602958083916; Sat, 17 Oct 2020 11:08: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 k7sm5337730iog.26.2020.10.17.11.08.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Oct 2020 11:08:03 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Simon Glass , Heinrich Schuchardt , Tom Rini , Sean Anderson Subject: [PATCH v3 09/23] test: log: Convert log_test from python to C Date: Sat, 17 Oct 2020 14:07:34 -0400 Message-Id: <20201017180749.119271-10-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201017180749.119271-1-seanga2@gmail.com> References: <20201017180749.119271-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 Reviewed-by: Simon Glass --- 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 Sat Oct 17 18:07: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: 1383745 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=nTGc125l; 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 4CDB0h2hSxz9sSs for ; Sun, 18 Oct 2020 05:11:16 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7E48A82456; Sat, 17 Oct 2020 20:08:20 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="nTGc125l"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 81FB882396; Sat, 17 Oct 2020 20:08:09 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd41.google.com (mail-io1-xd41.google.com [IPv6:2607:f8b0:4864:20::d41]) (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 9C0BF82396 for ; Sat, 17 Oct 2020 20:08:06 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-io1-xd41.google.com with SMTP id m17so8087361ioo.1 for ; Sat, 17 Oct 2020 11:08: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=+btvyM3Pp7HjKK3kdylB6r8Y2wJ1ANKIZ4TUvLIZfAM=; b=nTGc125luXeVI9xuqJLjXRqztgogShyzY+vjtVpei2eFMvTxaGxzTE3mh/FhYLh1rj VTp2hsDlKdJn4dwWrRsVgSvL4CRLlcDkBTyx/DyK1FbQlPrbTXDPSx1lSqneku0PWmHk FUwTzQ8U4bSGjMnh6tN4awvxyBOkg0qDmLu1bEjfU3oGC+4x0RZYcwZpWLvzOSVMHUSh kSLEEVPUC2a3BUqKreYTklNfCi/XxV28AKiG10gGy/Rzj+iSPjhj9BBMpoQFrWuT9w0+ ANt9Zzk2tI4qZaSCjgvGW7oSTqQ5QtL8s34j7X/KqUXfasqgYZOK/qMpFYLUnBou7Owe Y9gQ== 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=+btvyM3Pp7HjKK3kdylB6r8Y2wJ1ANKIZ4TUvLIZfAM=; b=tobt1ywxRYQC+gCfV3UkikBrZeQ4BggRursT5QNElyAUHR7A/3vKOgwBlUr9pGcayQ fVqLu90RraTFWFT5El0LwLFPafX9RVXXILBKLBujQ1XsUEUsXSh86u1z7AlpmgouuOhK gICXRtnQb+3bA4zM1ITpNJCE6KDFyOkOP+msijVkbQS58ldhiTn3WZkkrAm6NEDqz8W6 gJ0QLEZho86lwzPKBZCT/m321SvO4lpJJ54BqfmaFOSL5VS5t51TDF51RV9BER22YFVr qCJXeR4421chtP6q1wxOnfmdOSxs0dYfHaPyLddDPgWE7PP3ImlDxEwlAHrCz98Ox/k7 NMDg== X-Gm-Message-State: AOAM531CZFXGrqObFMFOrH4SEK75vfBSvkCsjXSpN1IGgkKh3jjw00Bp yPQG+5a2qy9/k7lAgzohZBB9R+FfjTfTtA== X-Google-Smtp-Source: ABdhPJwUpxhz83YTzrT3fqlbbEVk1hl7WOejTXxloy1oiKm71ZIWeH4VeVeYn631hMmJ7eu/lJBtrg== X-Received: by 2002:a02:234f:: with SMTP id u76mr6592956jau.117.1602958085192; Sat, 17 Oct 2020 11:08: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 k7sm5337730iog.26.2020.10.17.11.08.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Oct 2020 11:08:04 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Simon Glass , Heinrich Schuchardt , Tom Rini , Sean Anderson Subject: [PATCH v3 10/23] test: log: Give tests names instead of numbers Date: Sat, 17 Oct 2020 14:07:35 -0400 Message-Id: <20201017180749.119271-11-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201017180749.119271-1-seanga2@gmail.com> References: <20201017180749.119271-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 Reviewed-by: Simon Glass --- 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 Sat Oct 17 18:07: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: 1383746 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=rNlu3PAI; 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 4CDB135Gs4z9sSs for ; Sun, 18 Oct 2020 05:11:35 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 975AF82468; Sat, 17 Oct 2020 20:08:21 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="rNlu3PAI"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7AC1E82424; Sat, 17 Oct 2020 20:08:10 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd41.google.com (mail-io1-xd41.google.com [IPv6:2607:f8b0:4864:20::d41]) (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 CAF02823F8 for ; Sat, 17 Oct 2020 20:08:07 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-io1-xd41.google.com with SMTP id r4so8116652ioh.0 for ; Sat, 17 Oct 2020 11:08: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=gIZGPfQazbFeQo9MriJkARAJl2QIG2y7rmtWNtKAcWo=; b=rNlu3PAIBqjCm9QSUE+SOXIEIlCOv+lZlk+IbfX09cj1B36qXFE5exxgW+v65sqnQp TgUJ0cG2Bn1ypJ9PhN1JZgPmvXbIbKePVaCVqYPX1DW4qPo/3rNqT3yYSXWAHUUBjqNx vuxH7wken1OPOoYii48s4u4R8IUzfLb8O2X22Jv0M7FEGmSSPIANCG/bUot7e4IQqvNp obZrGO674DZ513wCmv3grf2YRwdZYq5NzgivzzvLkX0GrmLJc8+eUDZYHDXgSDfRWhr4 o0lx7J4qaZu5eG+RWyRqGIFI15DVEtF7E0L+hSzWonQO2A3t9NFLl3bojJJzxq/xHJ/Z gs9A== 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=gIZGPfQazbFeQo9MriJkARAJl2QIG2y7rmtWNtKAcWo=; b=I0MnCHNeYJ9A9SCMAgxexB5k1tZWzPIIuG41xas1a6dCk0ung7HMJgsFneovY5TApp HFlLifXI5oo4WbWu8EV5mIUNmKJpx8P56ARY5kiOl6vtg4XQsqhKFz9hFMVNg2QuQWTF 4KLwEDtDdIU4Zh9EYXGKgLVCnah/qvXWRZioBjw84ePYRBkGTum9o04HINWJ1IhDyLaQ 7T0ZrUMJz3YubFaLTmEJn6ARk7jjaakOMAs7MlEiJEKtfYIwU2S613EdBXK7E1obT4wR sEhx5zWbEPr0mHAogIbntQB3cyap8Xt6pMhpkz6QnbxUHUFBxmzH8KnvBTmDMg/kMux4 LlCw== X-Gm-Message-State: AOAM533D/i3kbU40NJNPNLDm0WzpEL+WYi35A+OKhsmRii41rHpLLKLW OI02CJFQY5EzZoumuOisyM1LD0oXQEoP/w== X-Google-Smtp-Source: ABdhPJwSLZtgfGEXc6CgRzXSzBDfQFES3EO8YvIIoITUvyu0hZEqh9/rrvyVcfifNXxuytX04jBxxg== X-Received: by 2002:a05:6638:d0c:: with SMTP id q12mr6672098jaj.95.1602958086515; Sat, 17 Oct 2020 11:08: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 k7sm5337730iog.26.2020.10.17.11.08.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Oct 2020 11:08:05 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Simon Glass , Heinrich Schuchardt , Tom Rini , Sean Anderson Subject: [PATCH v3 11/23] test: Add tests for LOGFF_DENY Date: Sat, 17 Oct 2020 14:07:36 -0400 Message-Id: <20201017180749.119271-12-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201017180749.119271-1-seanga2@gmail.com> References: <20201017180749.119271-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 --- 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 Sat Oct 17 18:07: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: 1383747 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=Ej+c5/Sg; 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 4CDB1R3q7Qz9sSs for ; Sun, 18 Oct 2020 05:11:55 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D48A38244B; Sat, 17 Oct 2020 20:08:22 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Ej+c5/Sg"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3EA6582435; Sat, 17 Oct 2020 20:08:12 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x144.google.com (mail-il1-x144.google.com [IPv6:2607:f8b0:4864:20::144]) (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 5C9CB82423 for ; Sat, 17 Oct 2020 20:08:09 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-il1-x144.google.com with SMTP id p9so6292788ilr.1 for ; Sat, 17 Oct 2020 11:08: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=rr9ibWShjs9oA92B0eooC74CE/mMuF+bbCdOa7CEGh8=; b=Ej+c5/SgZFzQEWl6ByYNHxaCakgfBLTNzwtFL3CysKcFEiRdYp0shLDVWCtwNKes5E cK72g5sH6qht5lwKDY6lRD3iClElc0xSO0rDHc4byWLWQq7Kv6/x+DOGH8byHKgzG5Lg q6PslKPTsnP/11csTINriRwTRseo3efZEDa4+crhBhall82cWt6eEo8MHGiPRx8ENV7v MIMwG/o3djPjwo3y4ISigi+slJvjNgRRnfum8JkHlmuQeZUKxNM/WtH8/g9kI+dyBr+F gwJKbUyAfdelJ+drdWGIdNgQLS3Yo/tYDsRwROrf7Bq0YsF7wEmv7rrOv4cDUYBIbutk VMOA== 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=rr9ibWShjs9oA92B0eooC74CE/mMuF+bbCdOa7CEGh8=; b=e8HkUariF1sODxP8FTYUsXkyguadU/G5kBeSBaxsXxh3ASkcpV4hSqDzXW22pdUVOQ DsR6nCRW6N/zaRookOvpDEPqhHFpLb4+nMz6C3uwlCCUAn4XwXAsax4GnWLvWtfdXYBV Xz/OQT4QrG+gTVRigmcU0wKladPB3FVLhfP1WFFnGZwdCmlJOnd6faduNCF5dne0by4i M9dO6tl6feCv3efbNHbWC7+983f3vNcowr419xS4Lpo/6FgKQBkPgq9Bm8Tzz45yf1RC AwN+w94Ux3I8KglhzG0EjfTg/Rcl7/a6fMPplBwFwSqKd2keIS9zWG1VN9QypFrS6aid 9mSA== X-Gm-Message-State: AOAM533fOMKR+8t3/k7xLfidKUAKppvk0j2Y8Dc9OTRfJs5k4r/JLHdD yIgmIYesxkmrXUgbHmb2hcJkqPgJ3FEQfA== X-Google-Smtp-Source: ABdhPJzcsI6uP+RobXJVTPfOLlD70tdC/ORL6vintl1SCHQhQ23nyLGZS3ztUehtuz+yH9eMjJt9pw== X-Received: by 2002:a05:6e02:10c3:: with SMTP id s3mr6586402ilj.103.1602958087821; Sat, 17 Oct 2020 11:08: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 k7sm5337730iog.26.2020.10.17.11.08.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Oct 2020 11:08:07 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Simon Glass , Heinrich Schuchardt , Tom Rini , Sean Anderson Subject: [PATCH v3 12/23] log: Add filter flag to match greater than a log level Date: Sat, 17 Oct 2020 14:07:37 -0400 Message-Id: <20201017180749.119271-13-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201017180749.119271-1-seanga2@gmail.com> References: <20201017180749.119271-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 878800b3bb..259d922987 100644 --- a/common/log.c +++ b/common/log.c @@ -159,11 +159,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; @@ -238,7 +244,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; @@ -266,7 +272,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 8cabe82eb5..d5e09a838f 100644 --- a/include/log.h +++ b/include/log.h @@ -365,6 +365,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, }; /** @@ -380,7 +382,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 @@ -389,7 +391,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; }; @@ -490,14 +492,14 @@ int do_log_test(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); * @cat_list: List of categories to allow (terminated by %LOGC_END). If empty * then all categories are permitted. Up to LOGF_MAX_CATEGORIES entries * can be provided - * @max_level: Maximum log level to allow + * @level: Maximum (or minimum, if LOGFF_LEVEL_MIN) log level to allow * @file_list: List of files to allow, separated by comma. If NULL then all * files are permitted * @return the sequence number of the new filter (>=0) if the filter was added, * or a -ve value on error */ int log_add_filter_flags(const char *drv_name, enum log_category_t cat_list[], - enum log_level_t max_level, const char *file_list, + enum log_level_t level, const char *file_list, int flags); /** From patchwork Sat Oct 17 18:07: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: 1383748 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=gOCQyunB; 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 4CDB1d6cmYz9sSs for ; Sun, 18 Oct 2020 05:12:05 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5E0F882478; Sat, 17 Oct 2020 20:08:31 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="gOCQyunB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 13B8282441; Sat, 17 Oct 2020 20:08:13 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x143.google.com (mail-il1-x143.google.com [IPv6:2607:f8b0:4864:20::143]) (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 6AB1382425 for ; Sat, 17 Oct 2020 20:08:10 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-il1-x143.google.com with SMTP id p16so6250843ilq.5 for ; Sat, 17 Oct 2020 11:08: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=B0Rx1I9NB7qqBkBlNvESiNqHYQ0GtHCq27PWFblSVrk=; b=gOCQyunBKhef5S3P66ng5UjevRdEAbtkrWukTlb0dgLMq/8JSVAerKpZkJvochxt1P MAknVMJy0dBbp5lrJSDBx62/OQrXPZUT56N+Ykj0xeei4/KOBIM2vGb2+FVTOhdui7mP O5pSMsB24ZgFIbm0NiajVdy4sxZYxGI/gjZC6paD3/RrD+ew3DAFDKP1NmN87jjy2ue7 c9NEYszNwg5CY2qO1jqcCYs531sKdXrUVFEbh+FkX6cESbAcn1HLdrtWtIanH6uhhBWx Xl6tV9vmBh55/zdSOmi3MPEFoK43LS/LLviDnoUOywVPJjHBvMmtvrlW+D4ximS5HaYT HWXw== 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=B0Rx1I9NB7qqBkBlNvESiNqHYQ0GtHCq27PWFblSVrk=; b=ZafMpDYjoz9k5YbAWbKMmsfkIHkHBRJp7Url35k1NFZvBMmF0RHiKc39juveNiQTvS rSw5LhjDu+Gk+UqRultn9otVDFSyNnYQSZmYPVquN6tZUud2EwT33esw6Jvia0BDWbCp VbjamfULEYOZuDDJp8pX/nky6skR4kApAFH8OXQWekWOYqXJ5mhqdsnyejQr8ISwzyrT Lza1nr469+ULvDj2XN7rhPsFQFc4OzBjlQwUz4/OxndTFnMIywy3jC7K9TESALrzd3eg PBR4ym9RQLAWQWtUQiyhftlE8XpLjefgr2vMJ3eUk8lYqnXY1SPiNotyz6cKolarLysc HzLQ== X-Gm-Message-State: AOAM530Fsj+meZKe20qKGS388JIbDaROumL5vvYKVmUvMHxnBMLf0l+d 8/1n0ZGQ2rjsX0OJt4Zt8vVDcdvJi/ayGw== X-Google-Smtp-Source: ABdhPJxjyrWnrAygL6sHg84Y/avbfHL5wbdQM/EJTvT4VAOM+OIszaGVRxteRkQ4tYMFFQ2n7puM9A== X-Received: by 2002:a92:aa43:: with SMTP id j64mr6142328ili.179.1602958089103; Sat, 17 Oct 2020 11:08: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 k7sm5337730iog.26.2020.10.17.11.08.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Oct 2020 11:08:08 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Simon Glass , Heinrich Schuchardt , Tom Rini , Sean Anderson Subject: [PATCH v3 13/23] test: Add test for LOGFF_MIN Date: Sat, 17 Oct 2020 14:07:38 -0400 Message-Id: <20201017180749.119271-14-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201017180749.119271-1-seanga2@gmail.com> References: <20201017180749.119271-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 --- 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 Sat Oct 17 18:07: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: 1383749 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=PpKfcWpL; 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 4CDB1q2cM6z9sSs for ; Sun, 18 Oct 2020 05:12:15 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 37ECB82479; Sat, 17 Oct 2020 20:08:39 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="PpKfcWpL"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BAF538244B; Sat, 17 Oct 2020 20:08:14 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x142.google.com (mail-il1-x142.google.com [IPv6:2607:f8b0:4864:20::142]) (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 8D6C48242A for ; Sat, 17 Oct 2020 20:08:11 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-il1-x142.google.com with SMTP id w17so6230541ilg.8 for ; Sat, 17 Oct 2020 11:08: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=pdQkfmG3J5z46p027wzAbBLEt/2KyY9/zU4oSQwwA1Y=; b=PpKfcWpL8XvP2wZgFWYTCBQ+6z8JaSDNphDxCd1K0lqIcobMsprnixIxkP4JbwG7Eh DEeXkAXBg/YWVcy8qOAUXZVhtLDAVVPC9/UweWFtPBbOCUi0deDPkd0Hcsr/1JFn7V8S +/g5irE28Hgh/2iUSFeSY7Q0WhS4sLYOJHNvCDXFNZaLoQLtuQuoV92dE9XIJT5DOnty ghxiWjOsETuTSRN7qek+mjW/FrXThfoswOSezSP0JF10HbvUDW0s+wg+vjqtqV3OWfqS QqExtm3ztaaErG6NMiqIwD+2VrEaAw75lvF2y3Ch6aPdfPO90qYsjRTHjuaLx4S1HaoY H6gQ== 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=Q+gh97SJysx1WHbtR3EmOWIehhWThoF/dLjJLXUuCjUBElTB2Nlcw/ir9WucrrUEs2 rEOrFwUN3n0UJ9MD8mcRAqhhEiOyY9QLnszSr5ThbqERiweLuESq8UZJ9KK6Gau4OroG h1JH0IqBvYd/bbCdrdX14EwJB5sZFJ+Enxpax1ym6zUcSWCz98uLNw0+iCotNBAO9jmt npwG6JX0S/JnKo23OMhRqIB0S2sTskk7WTb1HTFnx2JKrXpVLCR/qTBMJcLH7pV8ajPY 3BLMN23hWpLWZXnc26c3C1BSZHWRaKsaNkm7G3EsmVI0Fb0oSk10AEgSDmJuYqBc6Np8 z6BA== X-Gm-Message-State: AOAM530H2b57mIKT9htoHI+2f2E/bE+cMkvejHMB3e5FWLd5VklMf6q0 zn2x0RG0C1vx0ShI39rrbksmxIk0DjYYUA== X-Google-Smtp-Source: ABdhPJx1CzXvwkl6BIAyycQD7kcasmcX0SlHmaPglzzM6rpghMUZQvjIlGZ599p66RoSOMbKtDq+Sg== X-Received: by 2002:a05:6e02:bf4:: with SMTP id d20mr6264571ilu.252.1602958090299; Sat, 17 Oct 2020 11:08: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 k7sm5337730iog.26.2020.10.17.11.08.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Oct 2020 11:08:09 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Simon Glass , Heinrich Schuchardt , Tom Rini , Sean Anderson Subject: [PATCH v3 14/23] cmd: log: Use sub-commands for log Date: Sat, 17 Oct 2020 14:07:39 -0400 Message-Id: <20201017180749.119271-15-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201017180749.119271-1-seanga2@gmail.com> References: <20201017180749.119271-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 Sat Oct 17 18:07: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: 1383750 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=XFUcM/vz; 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 4CDB211Q6pz9sSs for ; Sun, 18 Oct 2020 05:12:25 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 37C3382481; Sat, 17 Oct 2020 20:08:47 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="XFUcM/vz"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 939FB8244B; Sat, 17 Oct 2020 20:08:15 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd42.google.com (mail-io1-xd42.google.com [IPv6:2607:f8b0:4864:20::d42]) (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 E879082440 for ; Sat, 17 Oct 2020 20:08:12 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-io1-xd42.google.com with SMTP id n6so7946636ioc.12 for ; Sat, 17 Oct 2020 11:08: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=AuSpVGmYG5eGMFYGwDb6+YQQZzUi5h0r/fyKJMLPjJQ=; b=XFUcM/vzcs7103jSc8peiztB9PXDpU0rOI7kf3rNaKZvDE+adZyldEZMY5YcAMI+7I jAKDBZHlDEdiLMrUb8KgEc0Pq/Fe7hQ+qfv37v5vJDwfkrNR6akfgmgg4Row88gdlGjE zgG6bkDdAKlJtP4G3cbSiqMgFCmZURogehOtzwMi199QfgWoNyqewldBlFGlkG0tl+Cu TpKDxW8OS6ttf1jSBD/VunMovbpRtCAzL3D/wzzW5bxCIK0DZbNEMTR0FPUsR+P47dUf jxyAe8nHPVh1iJKOGALjY8rI/j5bNVSez4RmNFJmZWAVFooTOs2/xKIVLgQgbZ45wdx2 G67Q== 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=kvSvF0J6Ul2p/t7jdirJm2/a0b+Kjdn/K1v+xMygOnKkl65n4e1FWM7eTIkBoXNnQw sRmP5CtrSs+pZZc2A2ImJmfBXYgcrF6xmJKxHxSlO/2t6kXL1CYSPLHDkfYmePxHCXg0 6nZs/xNPwg1dPMvaNXLxgdm4vcxcgm7JZgt9y78JfWyz6pVlI+fhjhvDhJMMKJITlISr BBen1dwsuHI0/GiP9ktGjl1fQlVeDkBp08zH7IcWgmZIqquEV8dAbKTli2Of5DglnOBT 2qo89xyZwyBmP/IPNQ6gM3OlTy/Pnjmwe64PC7YzwhXksMzT5PyPch5PfDXJ5Yj+IjRa +O5Q== X-Gm-Message-State: AOAM533kpu1PnipqVnoHJdE4gPAoq+LEXbunhnVWgl0V2ODZp4XxB20i 0r138+AAKJl39nLxnAPiE56+2FLYxXjS6w== X-Google-Smtp-Source: ABdhPJwfNFpdBFKMm4dd9nUNbAL7mZg3iJH7ELClp+9p4UlseeqY+3UAr33GRPuUtF406DyyJXFaDA== X-Received: by 2002:a6b:5c06:: with SMTP id z6mr6317139ioh.49.1602958091649; Sat, 17 Oct 2020 11:08: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 k7sm5337730iog.26.2020.10.17.11.08.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Oct 2020 11:08:11 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Simon Glass , Heinrich Schuchardt , Tom Rini , Sean Anderson Subject: [PATCH v3 15/23] cmd: log: Split off log level parsing Date: Sat, 17 Oct 2020 14:07:40 -0400 Message-Id: <20201017180749.119271-16-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201017180749.119271-1-seanga2@gmail.com> References: <20201017180749.119271-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 Sat Oct 17 18:07: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: 1383751 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=lZOZ1MMR; 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 4CDB2C088wz9sSs for ; Sun, 18 Oct 2020 05:12:34 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CADD182483; Sat, 17 Oct 2020 20:08:48 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="lZOZ1MMR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F1F6F8244C; Sat, 17 Oct 2020 20:08:18 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x12e.google.com (mail-il1-x12e.google.com [IPv6:2607:f8b0:4864:20::12e]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 33FD182449 for ; Sat, 17 Oct 2020 20:08:14 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-il1-x12e.google.com with SMTP id j17so6274147ilr.2 for ; Sat, 17 Oct 2020 11:08: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=cArNlkV0G2u5QMQhJBfj2YX4XV7mr+mK/IxQCRnWZiE=; b=lZOZ1MMRyLDxTEDrS0kObEnX5CIVEPM5HAgVgygCPsx/UvuIh1NyvH6uWEPc8Bs+BO qHzwU0kb9FNYrFc3EQ9B1F/EB7OuqEIEyMqiCiFlCfGlWzaQSUX7/MuRLzvJsRHxhurK EtlcMq97oWOUD19upFqMb5d88Wd0pWXH+9aS6TiVHnLvAq/b18toavUJ9B+e/7aD0Kt5 saT/TsU/RXUzwwU58Cp5T9rVz1koosItAIW/Z5yWkOvta5apKtk1ayffPKZeQcWwgP+z wzrKNGni5i/5KyNwY5xYqr0RtZFgeu/oU1Mw9O4mrlLnXogAYUmDrsHXRf9FypjaPx37 GJdw== 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=cArNlkV0G2u5QMQhJBfj2YX4XV7mr+mK/IxQCRnWZiE=; b=jEVb4LwuQRrAkk05GL2BAayJkpCR+zsoXsvLaeC3OIBhV6TxgSfzrBOOiIRmUVbKmb 0637Tzy/vvzg8lQK2AArUwKZcRBDXuYFTgLKpdEQLbk4zicF1fbsfgb79IONrltxka6w gZabEPPtoW3IJwN+/QQWXIIxWnAsulijKfGKkVGlWWaT4ziIzDRWh7wtSx57ZCl6MHj9 R5BOwRBgo0k5Xffrlz38K9aLx6VbhcAn1uQ5Ro85m8IkH2syCAlFdN4s0QY6bs+eB4Lz J4nLev7JqRDu+jqP9btWPkt4T2PzWB4furNejY2JmVgQWqudeqN01f6LOy2wGoM0Nly5 nFyQ== X-Gm-Message-State: AOAM5312fDb/QyYL/PuhqnYpRjEuUZhymf1GQn+iyOYoNlMdCFGijdKL YIacIkNpX9uwSDkVDzHwXnPTAntjYOqiaQ== X-Google-Smtp-Source: ABdhPJxAS2s04hXoE5fb04KkDd/1j9R/gzDUj3PZeLSNaHq+bCg9Z52VK+QIpzTRgkY3+cTP87FxVw== X-Received: by 2002:a92:1e07:: with SMTP id e7mr5912477ile.154.1602958092877; Sat, 17 Oct 2020 11:08: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 k7sm5337730iog.26.2020.10.17.11.08.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Oct 2020 11:08:12 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Simon Glass , Heinrich Schuchardt , Tom Rini , Sean Anderson Subject: [PATCH v3 16/23] cmd: log: Add commands to list categories and drivers Date: Sat, 17 Oct 2020 14:07:41 -0400 Message-Id: <20201017180749.119271-17-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201017180749.119271-1-seanga2@gmail.com> References: <20201017180749.119271-1-seanga2@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean This allows users to query which categories and drivers are available on their system. This allows them to construct filter-add commands without (e.g.) adjusting the log format to show categories and drivers. Signed-off-by: Sean Anderson Reviewed-by: Simon Glass --- Changes in 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 259d922987..c4a14e191a 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 d5e09a838f..9f57957aae 100644 --- a/include/log.h +++ b/include/log.h @@ -407,8 +407,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 Sat Oct 17 18:07:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1383752 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=oMkwyDbu; 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 4CDB2N4MkJz9sTD for ; Sun, 18 Oct 2020 05:12:44 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 88F508248E; Sat, 17 Oct 2020 20:08:50 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="oMkwyDbu"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F2E4882456; Sat, 17 Oct 2020 20:08:19 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x141.google.com (mail-il1-x141.google.com [IPv6:2607:f8b0:4864:20::141]) (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 6D22F82432 for ; Sat, 17 Oct 2020 20:08:15 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-il1-x141.google.com with SMTP id l16so6180274ilt.13 for ; Sat, 17 Oct 2020 11:08: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=HmDOJ6MKsys0yHRNY3RLY42a/rKjZS7EX0WqLgNkI/c=; b=oMkwyDbuwLYzao8dfzulT0umAiTzWCtsn0FNn/2rGMDasMiSPMvX5GLL/uVw6zbN35 NsSOa4VMrAKXRW3BRD/t37xbHTAzxYx8F79oGT7Vn8xnanR8Ko643WWJdqHiP9rqzrHO n9wAO70fy3TaDPbr6cIF0tv82Q31hpUhdfAV4dguG4lxaFvMPYd3U3E6tJ5+zP93kl79 AIkTOR4UAQ0p4cvii7nJxv4sbEzDi90g/W8lgkEPH0yf8uEPJGoTmgJqhRBnP/EO1q0K L5GhpSQTfgb1NBLAF359bqPj3BcOtvVhaNlEcvwMIGft+2366czP5Y1tWPVTDdFzjvEr dMmQ== 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=pmVsq/M3lSqxEegUbTST7yG0u4nrxhgyCn3lTeRCGDzng2U7bFq8DHpjkvXKemjOiz cRtgwgpCxXgVs+9InTk3/EBu70RUsgHBFeim63fF4IHMmpUU24EDikKY02/bp4V/HjAT ZYF7olYyLDdo2jHEan0KOeGtYX6tF/wYkl2aQIw/YmlEFPA8bPpOG5DAy1w3QpAYTWyU dLz031+0C7I28C4t4uVwXET2q7OZbXxAqsq2Od4rdtRsUAPo5cdxN2xVsNFX1DiCPYV/ k4ROJRaZpVVIxfcsgMNuxtOcyrfoCnQBHrQhPNVa+1ZpETf0LG4DGgRuuAgVyGszG2C8 5quA== X-Gm-Message-State: AOAM532n0gbL10e9DyQJwsH3bB3R+rvOCv0aPcqU6BBp1yXTBz4+sSjY RUphSMlKmshSNcjCbZronENMdNHzX6bqCg== X-Google-Smtp-Source: ABdhPJxSzOkNd8IoewJ2hneaon2vhnzdZrmPDsGYXBjixt2tpTr+svjuTRm2ZearAgqUlCsnPN3ypQ== X-Received: by 2002:a05:6e02:11b4:: with SMTP id 20mr6526003ilj.271.1602958094105; Sat, 17 Oct 2020 11:08: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 k7sm5337730iog.26.2020.10.17.11.08.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Oct 2020 11:08:13 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Simon Glass , Heinrich Schuchardt , Tom Rini , Sean Anderson Subject: [PATCH v3 17/23] cmd: log: Make "log level" print all log levels Date: Sat, 17 Oct 2020 14:07:42 -0400 Message-Id: <20201017180749.119271-18-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201017180749.119271-1-seanga2@gmail.com> References: <20201017180749.119271-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 Sat Oct 17 18:07:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1383754 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=m+ZsF2Tv; 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 4CDB2l0nBZz9sSs for ; Sun, 18 Oct 2020 05:13:03 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 31B71824A5; Sat, 17 Oct 2020 20:08:52 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="m+ZsF2Tv"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C272E82473; Sat, 17 Oct 2020 20:08:22 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) (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 DD2E28244B for ; Sat, 17 Oct 2020 20:08:16 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-io1-xd35.google.com with SMTP id b8so7977983ioh.11 for ; Sat, 17 Oct 2020 11:08: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=9Qb3WKP+wpzD9C0nI+kLp0Is4nlPAkdzkCkuaF1DrZw=; b=m+ZsF2Tv3A1arAtpHsy2I6mLoyb3WIFhhno3WmleV/0iOmSTrMl764/x59ELxggEgV QduhUHP7O+wvLkp/BKxVtMYinNcV+1wulKeb7daH9Tmv48o4j2CQziN3M/DDXZGWn37j DngFCqAa2t/d6bDCI+nakcoE5YSRejqPb/hPVgpq5StZp62O93Cxsl6fEEkHOsSGPLlb PLRuyQvkYP2ezkAEgsBfNwIbJ87a4J8hFfMsdHfhJzN1flp9IoYQcwYsEG1Tk6KxxHdZ qn/OTFsIqmwqbvUQV80SoQAEBoxL3FC/9itVlE3aOtvMNp5106W5smIb/6WMpNj+cMJe dJCw== 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=9Qb3WKP+wpzD9C0nI+kLp0Is4nlPAkdzkCkuaF1DrZw=; b=LiLZo4WAHROyph8RNxTVN4E+D+8XZ6cxVPw4PfWx+v/PVoEGwvkJxTtuA02MxG8lfK 2DPgg2MEwQaEB9vWcAJsATyJoM23HYXaAv8f42v93mDzBO5VyXM46VibZvRa06eWrtNZ otaeuDtOLQyMkXO78twtV4GjWGovNzesMv/Tn/oql1Gg4L0HKSABY4G+cwtGgg2iEuv3 XD5uqDvn2SXT5gi/gSm0oh0AiPJ/Yy5xX0Jx6J9qerS8zbLczm9imIdeux9s4B27BXnZ aSYzTENEyiOXHsgVv1FZ/JxFeHEyZZ8tzbKykqFioPymIYxcDIVMWJamZAwbpUEECZcH brnw== X-Gm-Message-State: AOAM532TV7ybqq62eZQHiFvLpQX0BXqWuevP4LEyip2hXMxFqjRf/uI+ lnV8oLbwo9S3/pUF1lZsRAqA42HBZxGRkw== X-Google-Smtp-Source: ABdhPJxJxkfvGCRb/frJ3eSHQIYtar965X7AiDhakul+5HPh84uM/scynLTsnJV0bzXDwQyGc/2p+Q== X-Received: by 2002:a5e:930d:: with SMTP id k13mr4449664iom.33.1602958095387; Sat, 17 Oct 2020 11:08: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 k7sm5337730iog.26.2020.10.17.11.08.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Oct 2020 11:08:14 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Simon Glass , Heinrich Schuchardt , Tom Rini , Sean Anderson Subject: [PATCH v3 18/23] lib: Add getopt Date: Sat, 17 Oct 2020 14:07:43 -0400 Message-Id: <20201017180749.119271-19-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201017180749.119271-1-seanga2@gmail.com> References: <20201017180749.119271-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 Reviewed-by: Simon Glass --- (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 fb9ba37984..0f8e1f6d4c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -747,6 +747,7 @@ T: git https://gitlab.denx.de/u-boot/u-boot.git F: common/log* F: cmd/log.c F: doc/develop/logging.rst +F: lib/getopt.c F: test/log/ F: test/py/tests/test_log.py diff --git a/doc/api/getopt.rst b/doc/api/getopt.rst new file mode 100644 index 0000000000..773f79aeb6 --- /dev/null +++ b/doc/api/getopt.rst @@ -0,0 +1,8 @@ +.. SPDX-License-Identifier: GPL-2.0+ +.. Copyright (C) 2020 Sean Anderson + +Option Parsing +============== + +.. kernel-doc:: include/getopt.h + :internal: diff --git a/doc/api/index.rst b/doc/api/index.rst index 1c261bcb73..d90e70e16a 100644 --- a/doc/api/index.rst +++ b/doc/api/index.rst @@ -8,6 +8,7 @@ U-Boot API documentation dfu efi + getopt linker_lists pinctrl rng diff --git a/include/getopt.h b/include/getopt.h new file mode 100644 index 0000000000..6f5811e64b --- /dev/null +++ b/include/getopt.h @@ -0,0 +1,130 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * getopt.h - a simple getopt(3) implementation. + * + * Copyright (C) 2020 Sean Anderson + * Copyright (c) 2007 Sascha Hauer , Pengutronix + */ + +#ifndef __GETOPT_H +#define __GETOPT_H + +/** + * struct getopt_state - Saved state across getopt() calls + */ +struct getopt_state { + /** + * @index: Index of the next unparsed argument of @argv. If getopt() has + * parsed all of @argv, then @index will equal @argc. + */ + int index; + /* private: */ + /** @arg_index: Index within the current argument */ + int arg_index; + union { + /* public: */ + /** + * @opt: Option being parsed when an error occurs. @opt is only + * valid when getopt() returns ``?`` or ``:``. + */ + int opt; + /** + * @arg: The argument to an option, NULL if there is none. @arg + * is only valid when getopt() returns an option character. + */ + char *arg; + /* private: */ + }; +}; + +/** + * getopt_init_state() - Initialize a &struct getopt_state + * @gs: The state to initialize + * + * This must be called before using @gs with getopt(). + */ +void getopt_init_state(struct getopt_state *gs); + +int __getopt(struct getopt_state *gs, int argc, char *const argv[], + const char *optstring, bool silent); + +/** + * getopt() - Parse short command-line options + * @gs: Internal state and out-of-band return arguments. This must be + * initialized with getopt_init_context() beforehand. + * @argc: Number of arguments, not including the %NULL terminator + * @argv: Argument list, terminated by %NULL + * @optstring: Option specification, as described below + * + * getopt() parses short options. Short options are single characters. They may + * be followed by a required argument or an optional argument. Arguments to + * options may occur in the same argument as an option (like ``-larg``), or + * in the following argument (like ``-l arg``). An argument containing + * options begins with a ``-``. If an option expects no arguments, then it may + * be immediately followed by another option (like ``ls -alR``). + * + * @optstring is a list of accepted options. If an option is followed by ``:`` + * in @optstring, then it expects a mandatory argument. If an option is followed + * by ``::`` in @optstring, it expects an optional argument. @gs.arg points + * to the argument, if one is parsed. + * + * getopt() stops parsing options when it encounters the first non-option + * argument, when it encounters the argument ``--``, or when it runs out of + * arguments. For example, in ``ls -l foo -R``, option parsing will stop when + * getopt() encounters ``foo``, if ``l`` does not expect an argument. However, + * the whole list of arguments would be parsed if ``l`` expects an argument. + * + * An example invocation of getopt() might look like:: + * + * char *argv[] = { "program", "-cbx", "-a", "foo", "bar", 0 }; + * int opt, argc = ARRAY_SIZE(argv) - 1; + * struct getopt_state gs; + * + * getopt_init_state(&gs); + * while ((opt = getopt(&gs, argc, argv, "a::b:c")) != -1) + * printf("opt = %c, index = %d, arg = \"%s\"\n", opt, gs.index, gs.arg); + * printf("%d argument(s) left\n", argc - gs.index); + * + * and would produce an output of:: + * + * opt = c, index = 1, arg = "" + * opt = b, index = 2, arg = "x" + * opt = a, index = 4, arg = "foo" + * 1 argument(s) left + * + * For further information, refer to the getopt(3) man page. + * + * Return: + * * An option character if an option is found. @gs.arg is set to the + * argument if there is one, otherwise it is set to ``NULL``. + * * ``-1`` if there are no more options, if a non-option argument is + * encountered, or if an ``--`` argument is encountered. + * * ``'?'`` if we encounter an option not in @optstring. @gs.opt is set to + * the unknown option. + * * ``':'`` if an argument is required, but no argument follows the + * option. @gs.opt is set to the option missing its argument. + * + * @gs.index is always set to the index of the next unparsed argument in @argv. + */ +static inline int getopt(struct getopt_state *gs, int argc, + char *const argv[], const char *optstring) +{ + return __getopt(gs, argc, argv, optstring, false); +} + +/** + * getopt_silent() - Parse short command-line options silently + * @gs: State + * @argc: Argument count + * @argv: Argument list + * @optstring: Option specification + * + * Same as getopt(), except no error messages are printed. + */ +static inline int getopt_silent(struct getopt_state *gs, int argc, + char *const argv[], const char *optstring) +{ + return __getopt(gs, argc, argv, optstring, true); +} + +#endif /* __GETOPT_H */ diff --git a/lib/Kconfig b/lib/Kconfig index 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 Sat Oct 17 18:07:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1383753 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=U42aDa5q; 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 4CDB2Y3kHcz9sSs for ; Sun, 18 Oct 2020 05:12:53 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5BA3A82496; Sat, 17 Oct 2020 20:08:51 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="U42aDa5q"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6A86882474; Sat, 17 Oct 2020 20:08:22 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd43.google.com (mail-io1-xd43.google.com [IPv6:2607:f8b0:4864:20::d43]) (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 9558E82455 for ; Sat, 17 Oct 2020 20:08:19 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-io1-xd43.google.com with SMTP id 67so8009448iob.8 for ; Sat, 17 Oct 2020 11:08: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=xOS2vESCniYX2G4wcTWexTfBwCQfHQybCIJc07nSaEQ=; b=U42aDa5qJ2yW26NotCWawtSC31JbL2YD6POSTasc/k4mDeJ6Z8nE0DR7Fu1Psi9VRu aO6OoJqe8Iluk8niNv05y1g6rZsYfQ+u9QXcQcfwg3chAXxMDDe9XMYziEX9ef1E+Hb3 Bz5s7yP0FO+N8RT9tzZmyvEPRrFwurDH4sB1LO2X7ZhQYes4ZBao7Z8C/5HBJOy33oQO q9eTAuoIB2RxI+aGeeLRrnGGZ9cp+pHV1qUfkpUKnzWOQpNulIjd9RoGtXRpH9vuO9Us qEjMlxCk5qotbSABYuKkQ4Ta/zvBUHpgXZUvbmaoyT5681q+25uldFwkrKYFVOlPNKmq SP3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xOS2vESCniYX2G4wcTWexTfBwCQfHQybCIJc07nSaEQ=; b=l/DkQqpr8VOXrVPKUiSHUGI503vGT7yWWgPnAaLOuYKwoZbypVsEYf65j2NOYr6vAa V4lMWXEYlBVtRHkmR15cx/u4iKOCAH/2kiieLCouxEADJvopj9e0drC8kYgAaKpUBq9Q F0oh0im4CeCMgieYsyjeABTPLW8f0/jsX4iMVC/IwFtJB5sSXT/elx4wNS+7GIzAYFqj WOudQb6tkl8saxwUSvbaHE3sCDScXRcZ/Y+nXqiakibfZ8cW3dCy7vChQL3laMUotMHY 1zw0kkxoaFI2sCelv7Afjavvq7i7z29ePFe8Rk8ahG1fLNZS0lnJtuR17ePZoyqVITqF YYXg== X-Gm-Message-State: AOAM5315aJFP0IcEw2w1VEN9eOLgIT7EIILTr4aUXucIWvnlVk45WyEX h2q4cZzso/ykYwFgIMA63/Ud4GQbe+BO6Q== X-Google-Smtp-Source: ABdhPJzMPBqBH0uGcLKJ8tCM08Zjt0bT314DlEiz/Mq8KrejoLNikvuzEH9/zb/EDTHZU+eQbDeXQg== X-Received: by 2002:a02:1349:: with SMTP id 70mr6830030jaz.130.1602958096678; Sat, 17 Oct 2020 11:08: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 k7sm5337730iog.26.2020.10.17.11.08.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Oct 2020 11:08:16 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Simon Glass , Heinrich Schuchardt , Tom Rini , Sean Anderson Subject: [PATCH v3 19/23] test: Add a test for getopt Date: Sat, 17 Oct 2020 14:07:44 -0400 Message-Id: <20201017180749.119271-20-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201017180749.119271-1-seanga2@gmail.com> References: <20201017180749.119271-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 Reviewed-by: Simon Glass --- (no changes since v1) test/lib/Makefile | 1 + test/lib/getopt.c | 123 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 test/lib/getopt.c diff --git a/test/lib/Makefile b/test/lib/Makefile index 22236f8587..3140c2dad7 100644 --- a/test/lib/Makefile +++ b/test/lib/Makefile @@ -13,3 +13,4 @@ obj-$(CONFIG_ERRNO_STR) += test_errno_str.o obj-$(CONFIG_UT_LIB_ASN1) += asn1.o obj-$(CONFIG_UT_LIB_RSA) += rsa.o obj-$(CONFIG_AES) += test_aes.o +obj-$(CONFIG_GETOPT) += getopt.o diff --git a/test/lib/getopt.c b/test/lib/getopt.c new file mode 100644 index 0000000000..3c68b93c8a --- /dev/null +++ b/test/lib/getopt.c @@ -0,0 +1,123 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2020 Sean Anderson + * + * Portions of these tests were inspired by glibc's posix/bug-getopt1.c and + * posix/tst-getopt-cancel.c + */ + +#include +#include +#include +#include +#include + +static int do_test_getopt(struct unit_test_state *uts, int line, + struct getopt_state *gs, const char *optstring, + int args, char *argv[], int expected_count, + int expected[]) +{ + int opt; + + getopt_init_state(gs); + for (int i = 0; i < expected_count; i++) { + opt = getopt_silent(gs, args, argv, optstring); + if (expected[i] != opt) { + /* + * Fudge the line number so we can tell which test + * failed + */ + ut_failf(uts, __FILE__, line, __func__, + "expected[i] == getopt()", + "Expected '%c' (%d) with i=%d, got '%c' (%d)", + expected[i], expected[i], i, opt, opt); + return CMD_RET_FAILURE; + } + } + + opt = getopt_silent(gs, args, argv, optstring); + if (opt != -1) { + ut_failf(uts, __FILE__, line, __func__, + "getopt() != -1", + "Expected -1, got '%c' (%d)", opt, opt); + return CMD_RET_FAILURE; + } + + return 0; +} + +#define test_getopt(optstring, argv, expected) do { \ + int ret = do_test_getopt(uts, __LINE__, &gs, optstring, \ + ARRAY_SIZE(argv) - 1, argv, \ + ARRAY_SIZE(expected), expected); \ + if (ret) \ + return ret; \ +} while (0) + +static int lib_test_getopt(struct unit_test_state *uts) +{ + struct getopt_state gs; + + /* Happy path */ + test_getopt("ab:c", + ((char *[]){ "program", "-cb", "x", "-a", "foo", 0 }), + ((int []){ 'c', 'b', 'a' })); + ut_asserteq(4, gs.index); + + /* Make sure we pick up the optional argument */ + test_getopt("a::b:c", + ((char *[]){ "program", "-cbx", "-a", "foo", 0 }), + ((int []){ 'c', 'b', 'a' })); + ut_asserteq(4, gs.index); + + /* Test required arguments */ + test_getopt("a:b", ((char *[]){ "program", "-a", 0 }), + ((int []){ ':' })); + ut_asserteq('a', gs.opt); + test_getopt("a:b", ((char *[]){ "program", "-b", "-a", 0 }), + ((int []){ 'b', ':' })); + ut_asserteq('a', gs.opt); + + /* Test invalid arguments */ + test_getopt("ab:c", ((char *[]){ "program", "-d", 0 }), + ((int []){ '?' })); + ut_asserteq('d', gs.opt); + + /* Test arg */ + test_getopt("a::b:c", + ((char *[]){ "program", "-a", 0 }), + ((int []){ 'a' })); + ut_asserteq(2, gs.index); + ut_assertnull(gs.arg); + + test_getopt("a::b:c", + ((char *[]){ "program", "-afoo", 0 }), + ((int []){ 'a' })); + ut_asserteq(2, gs.index); + ut_assertnonnull(gs.arg); + ut_asserteq_str("foo", gs.arg); + + test_getopt("a::b:c", + ((char *[]){ "program", "-a", "foo", 0 }), + ((int []){ 'a' })); + ut_asserteq(3, gs.index); + ut_assertnonnull(gs.arg); + ut_asserteq_str("foo", gs.arg); + + test_getopt("a::b:c", + ((char *[]){ "program", "-bfoo", 0 }), + ((int []){ 'b' })); + ut_asserteq(2, gs.index); + ut_assertnonnull(gs.arg); + ut_asserteq_str("foo", gs.arg); + + test_getopt("a::b:c", + ((char *[]){ "program", "-b", "foo", 0 }), + ((int []){ 'b' })); + ut_asserteq(3, gs.index); + ut_assertnonnull(gs.arg); + ut_asserteq_str("foo", gs.arg); + + return 0; +} +LIB_TEST(lib_test_getopt, 0); From patchwork Sat Oct 17 18:07:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1383758 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=qq+qf7hh; 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 4CDB3R1FRDz9sSs for ; Sun, 18 Oct 2020 05:13:39 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BEE16824BC; Sat, 17 Oct 2020 20:08:55 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=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="qq+qf7hh"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A800382477; Sat, 17 Oct 2020 20:08:33 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x131.google.com (mail-il1-x131.google.com [IPv6:2607:f8b0:4864:20::131]) (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 68FD882479 for ; Sat, 17 Oct 2020 20:08:24 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-il1-x131.google.com with SMTP id p9so6293094ilr.1 for ; Sat, 17 Oct 2020 11:08:24 -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=hi+dxyWE6EHRb5Sg2bBXIX0hUBatIEXQwD64eyJorXY=; b=qq+qf7hhJqlyclKi5nzOC6oCzFpsubjjtPoSAUeIVdQu6z21eP4OkOVI+D3bcFcnHN euSmdlnSjVWVajmBpPshbd3hVVxpF0p36yN3xUPwa4lvO6y4zr1PbCCSxoyLW/z5L8Gm YEJRcOCyl2q5uu+QC/Ao7x5nuhCs7Dt8AzpvHyoOTwaFIFTHQSeZlUxOV1YiTBXnQMuY GJOkI6W6dvbLVKuTOW/SFn2GckybbMAwA8wOddHOc3S1rQ5aYJDPP0c0BONpVCuk5PZy DcQS2LnQ+HF7al8HxImc/nomVGbSkQW3bK697Y8OHO4bK/R6dTgO135u6Fg3sNqzxyRK vHzA== 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=hi+dxyWE6EHRb5Sg2bBXIX0hUBatIEXQwD64eyJorXY=; b=FLuxVkhng1Mv6iI0gGwKu9oL3HIiVH2aEAlepNTR4pnwHyEJAtt7HPclYkkULXJr5y 10oMVIYx27Z9OZIGBk8Dbr0YvnCkIOvJIGlrVWZEJjJI6b9LD3XeZiie/+42nFl8ocBW C4jUjP2ZVZO464+nC+l7/sSeCobPo78uKzHs8WEj0lWRMCpl7P90mt7M/Y0y/h50JbGB GXY8h+deIyrfCa+E+jwG62/vBC0q5Hj9PE+lkM51FuEr0hC3uqEgKfWJdW0Jfhr4B9h1 c24j8MH0kHpy1ZRB3EvMmmbv1bHZcEXMAKj2G2DVE54EVgLQvHgakGRz+r1rsnq3lIxT CUng== X-Gm-Message-State: AOAM5336jBZ4ThehzDjwLojrQdq/Kh+V8eSQv+oqrv1O94te/ZL8S5Yz 2XeSfa2XW9jPorpX2iMVON91HkDHinZglA== X-Google-Smtp-Source: ABdhPJxxi2hhkbM6+jmPsjcXuRd7bS0Q4KCKhlgxjJ9fGGrBYJCedx9ZUOnmVDYKezS3MVicqyJD3g== X-Received: by 2002:a92:da0e:: with SMTP id z14mr6327466ilm.151.1602958097916; Sat, 17 Oct 2020 11:08: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 k7sm5337730iog.26.2020.10.17.11.08.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Oct 2020 11:08:17 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Simon Glass , Heinrich Schuchardt , Tom Rini , Sean Anderson Subject: [PATCH v3 20/23] cmd: log: Add commands to manipulate filters Date: Sat, 17 Oct 2020 14:07:45 -0400 Message-Id: <20201017180749.119271-21-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201017180749.119271-1-seanga2@gmail.com> References: <20201017180749.119271-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 --- (no changes since v2) Changes in v2: - Add option to remove all filters to filter-remove - Clarify filter-* help text cmd/Kconfig | 1 + cmd/log.c | 240 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 241 insertions(+) diff --git a/cmd/Kconfig b/cmd/Kconfig index a3166e4f31..768ac541b2 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -2218,6 +2218,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..6190a274e4 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,220 @@ static int do_log_drivers(struct cmd_tbl *cmdtp, int flag, int argc, return CMD_RET_SUCCESS; } +static int do_log_filter_list(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + int opt; + const char *drv_name = "console"; + struct getopt_state gs; + struct log_filter *filt; + struct log_device *ldev; + + getopt_init_state(&gs); + while ((opt = getopt(&gs, argc, argv, "d:")) > 0) { + switch (opt) { + case 'd': + drv_name = gs.arg; + break; + default: + return CMD_RET_USAGE; + } + } + + if (gs.index != argc) + return CMD_RET_USAGE; + + ldev = log_device_find_by_name(drv_name); + if (!ldev) { + printf("Could not find log device for \"%s\"\n", drv_name); + return CMD_RET_FAILURE; + } + + printf("num policy level categories files\n"); + list_for_each_entry(filt, &ldev->filter_head, sibling_node) { + printf("%3d %6.6s %s%-7.7s ", filt->filter_num, + filt->flags & LOGFF_DENY ? "deny" : "allow", + filt->flags & LOGFF_LEVEL_MIN ? ">=" : "<=", + log_get_level_name(filt->level)); + + if (filt->flags & LOGFF_HAS_CAT) { + int i; + + if (filt->cat_list[0] != LOGC_END) + printf("%16.16s %s\n", + log_get_cat_name(filt->cat_list[0]), + filt->file_list ? filt->file_list : ""); + + for (i = 1; i < LOGF_MAX_CATEGORIES && + filt->cat_list[i] != LOGC_END; i++) + printf("%20c %16.16s\n", ' ', + log_get_cat_name(filt->cat_list[i])); + } else { + printf("%16c %s\n", ' ', + filt->file_list ? filt->file_list : ""); + } + } + + return CMD_RET_SUCCESS; +} + +static int do_log_filter_add(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + bool level_set = false; + bool print_num = false; + bool type_set = false; + char *file_list = NULL; + const char *drv_name = "console"; + int opt, err; + int cat_count = 0; + int flags = 0; + enum log_category_t cat_list[LOGF_MAX_CATEGORIES + 1]; + enum log_level_t level = LOGL_MAX; + struct getopt_state gs; + + getopt_init_state(&gs); + while ((opt = getopt(&gs, argc, argv, "Ac:d:Df:l:L:p")) > 0) { + switch (opt) { + case 'A': +#define do_type() do { \ + if (type_set) { \ + printf("Allow or deny set twice\n"); \ + return CMD_RET_USAGE; \ + } \ + type_set = true; \ +} while (0) + do_type(); + break; + case 'c': { + enum log_category_t cat; + + if (cat_count >= LOGF_MAX_CATEGORIES) { + printf("Too many categories\n"); + return CMD_RET_FAILURE; + } + + cat = log_get_cat_by_name(gs.arg); + if (cat == LOGC_NONE) { + printf("Unknown category \"%s\"\n", gs.arg); + return CMD_RET_FAILURE; + } + + cat_list[cat_count++] = cat; + break; + } + case 'd': + drv_name = gs.arg; + break; + case 'D': + do_type(); + flags |= LOGFF_DENY; + break; + case 'f': + file_list = gs.arg; + break; + case 'l': +#define do_level() do { \ + if (level_set) { \ + printf("Log level set twice\n"); \ + return CMD_RET_USAGE; \ + } \ + level = parse_log_level(gs.arg); \ + if (level == LOGL_NONE) \ + return CMD_RET_FAILURE; \ + level_set = true; \ +} while (0) + do_level(); + break; + case 'L': + do_level(); + flags |= LOGFF_LEVEL_MIN; + break; + case 'p': + print_num = true; + break; + default: + return CMD_RET_USAGE; + } + } + + if (gs.index != argc) + return CMD_RET_USAGE; + + cat_list[cat_count] = LOGC_END; + err = log_add_filter_flags(drv_name, cat_count ? cat_list : NULL, level, + file_list, flags); + if (err < 0) { + printf("Could not add filter (err = %d)\n", err); + return CMD_RET_FAILURE; + } else if (print_num) { + printf("%d\n", err); + } + + return CMD_RET_SUCCESS; +} + +static int do_log_filter_remove(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + bool all = false; + int opt, err; + ulong filter_num; + const char *drv_name = "console"; + struct getopt_state gs; + + getopt_init_state(&gs); + while ((opt = getopt(&gs, argc, argv, "ad:")) > 0) { + switch (opt) { + case 'a': + all = true; + break; + case 'd': + drv_name = gs.arg; + break; + default: + return CMD_RET_USAGE; + } + } + + if (all) { + struct log_filter *filt, *tmp_filt; + struct log_device *ldev; + + if (gs.index != argc) + return CMD_RET_USAGE; + + ldev = log_device_find_by_name(drv_name); + if (!ldev) { + printf("Could not find log device for \"%s\"\n", + drv_name); + return CMD_RET_FAILURE; + } + + list_for_each_entry_safe(filt, tmp_filt, &ldev->filter_head, + sibling_node) { + list_del(&filt->sibling_node); + free(filt); + } + } else { + if (gs.index + 1 != argc) + return CMD_RET_USAGE; + + if (strict_strtoul(argv[gs.index], 10, &filter_num)) { + printf("Invalid filter number \"%s\"\n", argv[gs.index]); + return CMD_RET_FAILURE; + } + + err = log_remove_filter(drv_name, filter_num); + if (err) { + printf("Could not remove filter (err = %d)\n", err); + return CMD_RET_FAILURE; + } + } + + return CMD_RET_SUCCESS; +} + static int do_log_format(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { @@ -162,6 +378,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 +411,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 Sat Oct 17 18:07:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1383755 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=nIULc7Pw; 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 4CDB2w4jJHz9sSs for ; Sun, 18 Oct 2020 05:13:12 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0705C824A8; Sat, 17 Oct 2020 20:08:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="nIULc7Pw"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4F29482477; Sat, 17 Oct 2020 20:08:23 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd43.google.com (mail-io1-xd43.google.com [IPv6:2607:f8b0:4864:20::d43]) (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 81A2882457 for ; Sat, 17 Oct 2020 20:08:20 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-io1-xd43.google.com with SMTP id n6so7946919ioc.12 for ; Sat, 17 Oct 2020 11:08: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=ROyi9l3swOUIyQPlkAx9vdcEhwqbSBMe8NyFSUAdqOE=; b=nIULc7PwTdzeNNBMbS1PgF6iJtDa5qfdwDcIPpeHARYmzA0YKb4+Rg8WX6KJ+0dS3Q Jxx6Mliw+/cPkYsh/j9XgiEaFEdNbZ7DbM/Ojj2qVUzISrdlugIV/jqdqPHZ5UH87KGP VBqLwnisFd408dkpx2oX8ZcMzAq8iInZAF1ONEeqLMPf5liiWiJftop8ejHA5d7EDwQH wM7dozi6JebNh7o1PqK6829oisL39guYR/JQTNS6CnM7anqqXTh2jTcK9A5PtLbz8Lbb h9sg3fZWE/Gf/uLrAIfWgk6PUqmg5p3zZXF6WZgqoqhS7vv3uG4gCKjgVJHpdJ68e1h0 6pSA== 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=ROyi9l3swOUIyQPlkAx9vdcEhwqbSBMe8NyFSUAdqOE=; b=FjPCHZN5EJI2Ff4MwtSybXiq163fAAJksG8DZ8ksY59Yo2wOpGj+JdDc4SXcVFWcF3 /NLzrNNROoaSGjClH8xN7pEMCgAmrAJLICEgGxxcR0B3OnY0H5vxvLT8UJd2AAOWvkzo NocdjXMjXTK3cZfYFG4cMcChoVdjOfZRO6kOJN9fMz4oHnsnseeiNl9+XN291bdKuKqD eSWmX/8F4DX7o8QeM86Ww5iIcCPtYuHYRFE1nvfc4XPzWbrWa62sgY2NrHgssLFpXIWw OPFvFHHE9xsx63BhUClrApivk4YBwlb6j+seFqGIo1ouDAi+bQ3PInpEn3oBgJMP4pO4 Yq0Q== X-Gm-Message-State: AOAM532Oh6i5CqZajzADAY8gXDu0bzlMSmlT5PxC0saaqS8hJ+OAp4F5 HjE9F6gjrX6pAhI1NqY/M0XpUMUyEdX+2g== X-Google-Smtp-Source: ABdhPJwGpJIoWiINM+iPJJox3A2Xd3bowzhUTfQzRpg4/HbySeqSyEuXtS6JD8C5N/uNPsr8nxXqlA== X-Received: by 2002:a6b:c9c9:: with SMTP id z192mr6082578iof.175.1602958099191; Sat, 17 Oct 2020 11:08:19 -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 k7sm5337730iog.26.2020.10.17.11.08.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Oct 2020 11:08:18 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Simon Glass , Heinrich Schuchardt , Tom Rini , Sean Anderson Subject: [PATCH v3 21/23] test: Add a test for log filter-* Date: Sat, 17 Oct 2020 14:07:46 -0400 Message-Id: <20201017180749.119271-22-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201017180749.119271-1-seanga2@gmail.com> References: <20201017180749.119271-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 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..e27229dbd9 --- /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, + UCLASS_MMC)); + ut_asserteq(true, log_has_cat(filt->cat_list, + UCLASS_SPI)); + ut_asserteq(LOGL_WARNING, filt->level); + ut_asserteq_str("file", filt->file_list); + } + } + ut_asserteq(true, filt1_found); + ut_asserteq(true, filt2_found); + +#define remove_filter(filter_num) do { \ + ut_assertok(console_record_reset_enable()); \ + snprintf(cmd, sizeof(cmd), "log filter-remove %lu", filter_num); \ + ut_assertok(run_command(cmd, 0)); \ + ut_assert_console_end(); \ +} while (0) + + remove_filter(filt1); + remove_filter(filt2); + + filt1_found = false; + filt2_found = false; + list_for_each_entry(filt, &ldev->filter_head, sibling_node) { + if (filt->filter_num == filt1) + filt1_found = true; + else if (filt->filter_num == filt2) + filt2_found = true; + } + ut_asserteq(false, filt1_found); + ut_asserteq(false, filt2_found); + + create_filter("", filt1); + create_filter("", filt2); + + ut_assertok(console_record_reset_enable()); + ut_assertok(run_command("log filter-remove -a", 0)); + ut_assert_console_end(); + + list_for_each_entry(filt, &ldev->filter_head, sibling_node) + any_found = true; + ut_asserteq(false, any_found); + + return 0; +} +LOG_TEST_FLAGS(log_test_filter, UT_TESTF_CONSOLE_REC); From patchwork Sat Oct 17 18:07:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1383757 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=j6Oe8bJp; 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 4CDB3G2rC8z9sSs for ; Sun, 18 Oct 2020 05:13:30 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D499A824B7; Sat, 17 Oct 2020 20:08:54 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=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="j6Oe8bJp"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4227A8248B; Sat, 17 Oct 2020 20:08:32 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd30.google.com (mail-io1-xd30.google.com [IPv6:2607:f8b0:4864:20::d30]) (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 0B5A88246B for ; Sat, 17 Oct 2020 20:08:22 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-io1-xd30.google.com with SMTP id m17so8087893ioo.1 for ; Sat, 17 Oct 2020 11:08:21 -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=UZNJ46zKjDjrgGxH7cMULF4OBzaoSexkcBn0pn9Vc7k=; b=j6Oe8bJphwUZP+X2+wQ2nDH6vM0cPXkBTY/2pTM65gXSc/SFtZrDDilM3GWsRO37YU q8S4GFVort+dlQsBsZeoC9YRn/OLzVeMVDJGYNh8ydNcOA6aWxI81SaF8E3RdRehqJ/q hYhbGfuHdgdGSy2UT8+lQb6RLdISDDqNysATv/NuFg3efGOLPZ4cwVSsZEFm9OGkXSql bvvn/CdD97JOWubzrC+1ZBZ3vQ4K5HndPLUpoGLDgYF7kC2wTSNg00dd3yhlghyjjWr7 76kfKtSNq1/umMgWv8I+DEHYDfi3z0JbKm/XqOO2DzYEsTb8Rd1N7w8uNw8+3kYWkYy3 PqwQ== 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=UZNJ46zKjDjrgGxH7cMULF4OBzaoSexkcBn0pn9Vc7k=; b=P5WIMTeEYos/dukwWawX/d076B5bY6wh/xu5VRwUap2ui1l77Y7CYYKrz3zwl0obeu XBSstTUcXNxwN/ZRxKUHg5rcL4N6VjcKZQFkVUV/Haz42zUCvc2+CZtnOZ4PlpIalFwD Dxvfl44EiohijLBNHxsRwymkyZEwZ4vy1IDhB/zFN1cnGNjwqwuZe7U7vF7H6t6JzPu7 vhRr6Yb3peFvXbjMzR8X3rigHKYj+veC9k2rTZgfSyqdhS3A2N2rKxA+M5Nlcvy4oeh1 YP6N0/A/wYIwC03hmigu8bRwxQvk48fNZTYIm8ZlwxypNdDCJfJY5DueUEmdhNGDh1HC pcgQ== X-Gm-Message-State: AOAM533D+DtHETVoqz6rCFQlaMXzYILZtSDAzvg5EkNQnsCcL90BeqaS 9X1pRYMbhVOwY/9bDB8HOBL6l0F6t/yGng== X-Google-Smtp-Source: ABdhPJz2huBTRi76XPeC8ZhTaBMHdww8hL5Or+XlszLvkb0e2O90uBMddRpJjVLM17v2D/mEceRpQw== X-Received: by 2002:a02:3b54:: with SMTP id i20mr2704068jaf.94.1602958100481; Sat, 17 Oct 2020 11:08:20 -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 k7sm5337730iog.26.2020.10.17.11.08.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Oct 2020 11:08:19 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Simon Glass , Heinrich Schuchardt , Tom Rini , Sean Anderson Subject: [PATCH v3 22/23] doc: Add log kerneldocs to documentation Date: Sat, 17 Oct 2020 14:07:47 -0400 Message-Id: <20201017180749.119271-23-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201017180749.119271-1-seanga2@gmail.com> References: <20201017180749.119271-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 7ce8482ab6..6a22062073 100644 --- a/doc/develop/logging.rst +++ b/doc/develop/logging.rst @@ -288,3 +288,8 @@ information Add a command to add new log records and delete existing records. Provide additional log() functions - e.g. logc() to specify the category + +Logging API +----------- +.. kernel-doc:: include/log.h + :internal: diff --git a/include/log.h b/include/log.h index 9f57957aae..639f9e1199 100644 --- a/include/log.h +++ b/include/log.h @@ -17,52 +17,86 @@ 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. */ 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 */ @@ -81,7 +115,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, ...) @@ -236,7 +270,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); \ @@ -320,8 +354,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. @@ -378,11 +413,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 @@ -407,7 +442,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 '<'. */ @@ -417,7 +452,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); @@ -425,7 +460,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); @@ -433,7 +468,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); @@ -441,7 +476,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); @@ -489,15 +524,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, @@ -509,13 +545,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[], @@ -532,8 +569,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); @@ -554,7 +592,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 @@ -568,7 +606,7 @@ static inline int log_init(void) * log_get_default_format() - get default log format * * The default log format is configurable via - * CONFIG_LOGF_FILE, CONFIG_LOGF_LINE, CONFIG_LOGF_FUNC. + * %CONFIG_LOGF_FILE, %CONFIG_LOGF_LINE, and %CONFIG_LOGF_FUNC. * * Return: default log format */ From patchwork Sat Oct 17 18:07:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1383756 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=lxVifI33; 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 4CDB354W86z9sTD for ; Sun, 18 Oct 2020 05:13:21 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id F00BF824B2; Sat, 17 Oct 2020 20:08:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="lxVifI33"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 915A182478; Sat, 17 Oct 2020 20:08:29 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x129.google.com (mail-il1-x129.google.com [IPv6:2607:f8b0:4864:20::129]) (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 5AD3282457 for ; Sat, 17 Oct 2020 20:08:23 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-il1-x129.google.com with SMTP id j17so6274470ilr.2 for ; Sat, 17 Oct 2020 11:08:23 -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=IIhwdHzEVkqHrOlcopKSSuhxovNPsue9BEiqwyFxvFY=; b=lxVifI33OyS6e3KJSYRwpJt0V19QL46G0exIiL0sqMHcRJBlEVcV3/JdnmwfJpMyHa iAeLT08bAHtbinAQ63PBTtvUKeLxPBRGKM+TDB43Ls09+ZqAT7tkW+rY6HMM8EcDFwb+ pfmhIz+a2dx8HJbpFg3CAMjjfASqRIkVcbOW6b32g4tq9QqX6pkHDYFHo1VSa0ON/wTI MMyj22xPevRjn94pyJNfctpYtGI4HScmKsjwDpGT/7Oe73Agy60t2afclAIBe8htQlNk BcpjkShKkaVp9JBOWoxK0OJ3q32yRUyGHkjIOpYowoelfrtDUVbqU/N5/VCE6s74BiD1 YXlA== 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=IIhwdHzEVkqHrOlcopKSSuhxovNPsue9BEiqwyFxvFY=; b=gw1ktUPaxnyaIBlW217D1eWyFiUBydrauGShvA+w+sM0R3hLxPJKyLB6ckrlhi3vzF cFpqEzFHuswh5Yrnc+I1fzUXwlxOsHmFUxf5Uf9+AkMKfpWhSbvxz92fCepe94SIj6tU ASjD3yWo+BxQexB0+6VoHu8f+i67OZeZcSEyQV3VjQWcYWwvC/DMyVqoZWiPJ33Ftpkc wdRodMM8Hj5UAKCjcXauD76RdqQbe/xkx8bLDL8s4n9wqF/QnlaM/25AfVmZAkGVcp2B ePOMc4zWX3OQeRkVNInzWb3d411zvFHCNAe3PbddA9G8CKaXeCHWJydYlF7f+lseqrBr Imwg== X-Gm-Message-State: AOAM531ski24sHaPK4L8zNSvUjRxJcZ7Cm4HD/fQSsui2/ZvNgCHzAYX bc6zV0IJDln2F0mEFRh5JalOjdnP9wuSEA== X-Google-Smtp-Source: ABdhPJxpc/8zHwL1srmMIHIU4SBUk6uX7B6GjYfRk+7ScpIg0rgowrUrc17JE740TlajLcdW9Ut5Vw== X-Received: by 2002:a92:cb0c:: with SMTP id s12mr5953529ilo.215.1602958101770; Sat, 17 Oct 2020 11:08:21 -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 k7sm5337730iog.26.2020.10.17.11.08.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Oct 2020 11:08:21 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de Cc: Simon Glass , Heinrich Schuchardt , Tom Rini , Sean Anderson Subject: [PATCH v3 23/23] doc: Update logging documentation Date: Sat, 17 Oct 2020 14:07:48 -0400 Message-Id: <20201017180749.119271-24-seanga2@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201017180749.119271-1-seanga2@gmail.com> References: <20201017180749.119271-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 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 | 242 +++++++++++++++++++--------------------- 1 file changed, 115 insertions(+), 127 deletions(-) diff --git a/doc/develop/logging.rst b/doc/develop/logging.rst index 6a22062073..2b87bc2b4f 100644 --- a/doc/develop/logging.rst +++ b/doc/develop/logging.rst @@ -21,23 +21,13 @@ is visible from the basic console output. U-Boot's logging feature aims to satisfy this goal for both users and developers. - Logging levels -------------- -There are a number logging levels available, in increasing order of verbosity: - -* LOGL_EMERG - Printed before U-Boot halts -* LOGL_ALERT - Indicates action must be taken immediate or U-Boot will crash -* LOGL_CRIT - Indicates a critical error that will cause boot failure -* LOGL_ERR - Indicates an error that may cause boot failure -* LOGL_WARNING - Warning about an unexpected condition -* LOGL_NOTE - Important information about progress -* LOGL_INFO - Information about normal boot progress -* LOGL_DEBUG - Debug information (useful for debugging a driver or subsystem) -* LOGL_DEBUG_CONTENT - Debug message showing full message content -* LOGL_DEBUG_IO - Debug message showing hardware I/O access +There are a number logging levels available. +.. kernel-doc:: include/log.h + :identifiers: log_level_t Logging category ---------------- @@ -46,16 +36,8 @@ Logging can come from a wide variety of places within U-Boot. Each log message has a category which is intended to allow messages to be filtered according to their source. -The following main categories are defined: - -* LOGC_NONE - Unknown category (e.g. a debug() statement) -* UCLASS\_... - Related to a particular uclass (e.g. UCLASS_USB) -* LOGC_ARCH - Related to architecture-specific code -* LOGC_BOARD - Related to board-specific code -* LOGC_CORE - Related to core driver-model support -* LOGC_DT - Related to device tree control -* LOGC_EFI - Related to EFI implementation - +.. kernel-doc:: include/log.h + :identifiers: log_category_t Enabling logging ---------------- @@ -72,7 +54,6 @@ If CONFIG_LOG is not set, then no logging will be available. The above have SPL and TPL versions also, e.g. CONFIG_SPL_LOG_MAX_LEVEL and CONFIG_TPL_LOG_MAX_LEVEL. - Temporary logging within a single file -------------------------------------- @@ -86,46 +67,8 @@ to enable building in of all logging statements in a single file. Put it at the top of the file, before any #includes. To actually get U-Boot to output this you need to also set the default logging -level - e.g. set CONFIG_LOG_DEFAULT_LEVEL to 7 (LOGL_DEBUG) or more. Otherwise -debug output is suppressed and will not be generated. - - -Convenience functions ---------------------- - -A number of convenience functions are available to shorten the code needed -for logging: - -* log_err(_fmt...) -* log_warning(_fmt...) -* log_notice(_fmt...) -* log_info(_fmt...) -* log_debug(_fmt...) -* log_content(_fmt...) -* log_io(_fmt...) - -With these the log level is implicit in the name. The category is set by -LOG_CATEGORY, which you can only define once per file, above all #includes, e.g. - -.. code-block:: c - - #define LOG_CATEGORY LOGC_ALLOC - -Remember that all uclasses IDs are log categories too. - - -Log command ------------ - -The 'log' command provides access to several features: - -* level - access the default log level -* format - access the console log format -* rec - output a log record -* test - run tests - -Type 'help log' for details. - +level - e.g. set CONFIG_LOG_DEFAULT_LEVEL to 7 (:c:type:`LOGL_DEBUG`) or more. +Otherwise debug output is suppressed and will not be generated. Using DEBUG ----------- @@ -142,51 +85,6 @@ at the top of a file, then it takes precedence. This means that debug() statements will result in output to the console and this output will not be logged. - -Logging destinations --------------------- - -If logging information goes nowhere then it serves no purpose. U-Boot provides -several possible determinations for logging information, all of which can be -enabled or disabled independently: - -* console - goes to stdout -* syslog - broadcast RFC 3164 messages to syslog servers on UDP port 514 - -The syslog driver sends the value of environmental variable 'log_hostname' as -HOSTNAME if available. - - -Log format ----------- - -You can control the log format using the 'log format' command. The basic -format is:: - - LEVEL.category,file.c:123-func() message - -In the above, file.c:123 is the filename where the log record was generated and -func() is the function name. By default ('log format default') only the -function name and message are displayed on the console. You can control which -fields are present, but not the field order. - - -Filters -------- - -Filters are attached to log drivers to control what those drivers emit. Only -records that pass through the filter make it to the driver. - -Filters can be based on several criteria: - -* maximum log level -* in a set of categories -* in a set of files - -If no filters are attached to a driver then a default filter is used, which -limits output to records with a level less than CONFIG_MAX_LOG_LEVEL. - - Logging statements ------------------ @@ -210,6 +108,112 @@ can be used whenever your function returns an error value: This will write a log record when an error code is detected (a value < 0). This can make it easier to trace errors that are generated deep in the call stack. +Convenience functions +~~~~~~~~~~~~~~~~~~~~~ + +A number of convenience functions are available to shorten the code needed +for logging: + +* log_err(_fmt...) +* log_warning(_fmt...) +* log_notice(_fmt...) +* log_info(_fmt...) +* log_debug(_fmt...) +* log_content(_fmt...) +* log_io(_fmt...) + +With these the log level is implicit in the name. The category is set by +LOG_CATEGORY, which you can only define once per file, above all #includes, e.g. + +.. code-block:: c + + #define LOG_CATEGORY LOGC_ALLOC + +Remember that all uclasses IDs are log categories too. + +Logging destinations +-------------------- + +If logging information goes nowhere then it serves no purpose. U-Boot provides +several possible determinations for logging information, all of which can be +enabled or disabled independently: + +* console - goes to stdout +* syslog - broadcast RFC 3164 messages to syslog servers on UDP port 514 + +The syslog driver sends the value of environmental variable 'log_hostname' as +HOSTNAME if available. + +Filters +------- + +Filters are attached to log drivers to control what those drivers emit. FIlters +can either allow or deny a log message when they match it. Only records which +are allowed by a filter make it to the driver. + +Filters can be based on several criteria: + +* minimum or maximum log level +* in a set of categories +* in a set of files + +If no filters are attached to a driver then a default filter is used, which +limits output to records with a level less than CONFIG_MAX_LOG_LEVEL. + +Log command +----------- + +The 'log' command provides access to several features: + +* level - get/set the log level +* categories - list log categories +* drivers - list log drivers +* filter-list - list filters +* filter-add - add a new filter +* filter-remove - remove filters +* format - access the console log format +* rec - output a log record + +Type 'help log' for details. + +Log format +~~~~~~~~~~ + +You can control the log format using the 'log format' command. The basic +format is:: + + LEVEL.category,file.c:123-func() message + +In the above, file.c:123 is the filename where the log record was generated and +func() is the function name. By default ('log format default') only the message +is displayed on the console. You can control which fields are present, but not +the field order. + +Adding Filters +~~~~~~~~~~~~~~ + +To add new filters at runtime, use the 'log filter-add' command. For example, to +suppress messages from the SPI subsystem, run:: + + log filter-add -D -c spi + +You will also need to add another filter to allow other messages (because the +default filter no longer applies):: + + log filter-add -A -l debug + +To view active filters, use the 'log filter-list' command. Some example output +is:: + + => log filter-list + num policy level categories files + 0 deny <=IO spi + 1 allow <=DEBUG + +Note that filters are processed in-order from top to bottom, not in the order of +their filter number. Filters are added to the top of the list if they deny when +they match, and to the bottom if they allow when they match. For more +information, consult the usage of the 'log' command, by running 'help log'. Code size --------- @@ -226,12 +230,11 @@ 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 Convenience functions to support setting the category: @@ -253,25 +256,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 @@ -282,12 +275,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 -----------