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);