From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2C3BC4338F for ; Thu, 19 Aug 2021 03:42:57 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4437E6109E for ; Thu, 19 Aug 2021 03:42:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4437E6109E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3C6A78312F; Thu, 19 Aug 2021 05:41:41 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="i2STEuxz"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DC7BC82DBC; Thu, 19 Aug 2021 05:41:04 +0200 (CEST) Received: from mail-oi1-x230.google.com (mail-oi1-x230.google.com [IPv6:2607:f8b0:4864:20::230]) (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 6F9F782EA8 for ; Thu, 19 Aug 2021 05:40:52 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-oi1-x230.google.com with SMTP id o185so6598652oih.13 for ; Wed, 18 Aug 2021 20:40:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Z7Rboy5aHimKQmmd59tpW+cawaA8UuuwvMePnolr75c=; b=i2STEuxzAWcTbQWRDK5E7ShzG/ENdeD3KO+fBn5QFwdVS48XEfrpkjGRth6g93OW4Q nDUgMfW3YBMWU+PRwMMOIKbP3zymVc01cFY7pzdmkouhg925gfis5NDNkHCN4jheffnz xKuq5DOK6t4StwIDP+Q0q+FudKlJqs3gq5ArM= 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=Z7Rboy5aHimKQmmd59tpW+cawaA8UuuwvMePnolr75c=; b=mE7IaJO1/WjKDJXxD8jSj5osKb8LBZpwgF57XqX+f+8DiZz7VgsMtZCG6/FVcak0Mh bVny53UnvfYTc+KZOmaucDr7kNw9KX1i882A3SVmw67dOXCRQRSshK/XpgT0YlrHV47v QsKkaCO70m5H1KrmVDemr3znvx1kCQBN5DIUSJYt3LtjnZoZfS11vyCXoBJnBSGj3C2r nBhW3NjgRpaGEB8ppB7fwRfUMKgk2GgaJlKe11FrQLRAGT62nPjXsOkwZ7R8TGZe319E INcqMTtn5J8x5X7JlrnjcLePTcgCqbNC/bBx24LxhMVE/MrlSHP/x+xPO0tpiIbQGS2p f0Fg== X-Gm-Message-State: AOAM532wXtkceXd6OBrLXpoMWcr2w1FxogvnzPMMpCJytIeLldfReeUF IBo76S1gldS7nyUSWHh4Shzjpabc1AALRw== X-Google-Smtp-Source: ABdhPJybadCRS4RH5aB9xf+0vG58tiAKW2iz43d5x+2SEwlfO2xUhZM3r4i8uDfR5rTVRrTyWs6iSw== X-Received: by 2002:a54:4614:: with SMTP id p20mr1174463oip.136.1629344450912; Wed, 18 Aug 2021 20:40:50 -0700 (PDT) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id q27sm415877oof.12.2021.08.18.20.40.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 20:40:50 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass , Heinrich Schuchardt , Sean Anderson Subject: [PATCH 11/11] test: Add a way to skip console checking until a string matches Date: Wed, 18 Aug 2021 21:40:33 -0600 Message-Id: <20210818214022.11.I44fcf34ce986e97cb281a70e4fc04caed4c26045@changeid> X-Mailer: git-send-email 2.33.0.rc1.237.g0d66db33f3-goog In-Reply-To: <20210819034033.1617201-1-sjg@chromium.org> References: <20210819034033.1617201-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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.103.2 at phobos.denx.de X-Virus-Status: Clean Some tests produce a lot of output that does not need to be individually checked by an assertion. Add a macro to handle this. Signed-off-by: Simon Glass --- include/test/ut.h | 24 ++++++++++++++++++++++++ test/ut.c | 26 ++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/include/test/ut.h b/include/test/ut.h index 656e25fe574..fb2e5fcff2c 100644 --- a/include/test/ut.h +++ b/include/test/ut.h @@ -82,6 +82,21 @@ int ut_check_console_linen(struct unit_test_state *uts, const char *fmt, ...) */ int ut_check_skipline(struct unit_test_state *uts); +/** + * ut_check_skip_to_line() - skip output until a line is found + * + * This creates a string and then checks it against the following lines of + * console output obtained with console_record_readline() until it is found. + * + * After the function returns, uts->expect_str holds the expected string and + * uts->actual_str holds the actual string read from the console. + * + * @uts: Test state + * @fmt: printf() format string to look for, followed by args + * @return 0 if OK, -ENOENT if not found, other value on error + */ +int ut_check_skip_to_line(struct unit_test_state *uts, const char *fmt, ...); + /** * ut_check_console_end() - Check there is no more console output * @@ -286,6 +301,15 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes); return CMD_RET_FAILURE; \ } \ +/* Assert that a following console output line matches */ +#define ut_assert_skip_to_line(fmt, args...) \ + if (ut_check_skip_to_line(uts, fmt, ##args)) { \ + ut_failf(uts, __FILE__, __LINE__, __func__, \ + "console", "\nExpected '%s',\n got to '%s'", \ + uts->expect_str, uts->actual_str); \ + return CMD_RET_FAILURE; \ + } \ + /* Assert that there is no more console output */ #define ut_assert_console_end() \ if (ut_check_console_end(uts)) { \ diff --git a/test/ut.c b/test/ut.c index 1eec2a57dff..28da417686e 100644 --- a/test/ut.c +++ b/test/ut.c @@ -121,6 +121,32 @@ int ut_check_skipline(struct unit_test_state *uts) return 0; } +int ut_check_skip_to_line(struct unit_test_state *uts, const char *fmt, ...) +{ + va_list args; + int len; + int ret; + + va_start(args, fmt); + len = vsnprintf(uts->expect_str, sizeof(uts->expect_str), fmt, args); + va_end(args); + if (len >= sizeof(uts->expect_str)) { + ut_fail(uts, __FILE__, __LINE__, __func__, + "unit_test_state->expect_str too small"); + return -EOVERFLOW; + } + while (1) { + if (!console_record_avail()) + return -ENOENT; + ret = readline_check(uts); + if (ret < 0) + return ret; + + if (!strcmp(uts->expect_str, uts->actual_str)) + return 0; + } +} + int ut_check_console_end(struct unit_test_state *uts) { int ret; -- 2.33.0.rc1.237.g0d66db33f3-goog