From patchwork Mon Mar 8 00:35:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1448800 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; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=PUe56IXh; 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 4Dtzyq46rXz9sSC for ; Mon, 8 Mar 2021 11:40:35 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 604D98291D; Mon, 8 Mar 2021 01:38:28 +0100 (CET) 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="PUe56IXh"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7470A828B6; Mon, 8 Mar 2021 01:36:19 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) (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 1480B825F4 for ; Mon, 8 Mar 2021 01:35:43 +0100 (CET) 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-ot1-x329.google.com with SMTP id r24so533135otq.13 for ; Sun, 07 Mar 2021 16:35:42 -0800 (PST) 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=tgcX9ymSRmM4w/DMJ5iV3lBWNzqorxMMWWyBip5DiHQ=; b=PUe56IXhwdUA2YFBpBtm96/ZTiASnDoOQ5Z+HZFtMfPd8NKfv68z7nB5Iw4x/bGWMU lkyIVjdb3+NtraJ3Uec1gBKZHu5k7rArQJtJnhBXmUlFmU/HxeHZqUrWKwqpgelaMyUP k/3W8cscJQcTXWQRQecee44xSsm0PMrSMLLQ0= 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=tgcX9ymSRmM4w/DMJ5iV3lBWNzqorxMMWWyBip5DiHQ=; b=t9udD/In4HRiLxZAj2wDSwn7j91F1A+HMRreE5cOTAwOvNuGtTMPq04kizpCfQy5+y 6Pdcb1NknaNoj+BBokRrYxkMfoY/oyTixLszd+7XmDm9YHmMMhFlg81nAJl5T5HQtvRu S0qpbk/+vNLY05MqcV5Y5vVuX663oPiIzy9zPlLbSKYHYuNHN3V7lPlBkkqOzOk2/uhj AIgv7jmp/GinKAS8P2YkSdpMeEwdLKBlKi2yaA1bkakB+7H3SFwGlb4Oe24BUdpuZQPo sozjyQa45t5uLEf1apq2wVux5pIiafJnA7UbUPM7LxZHhYIW9mDeBbMQqqP4qJNXwFYT Fi0g== X-Gm-Message-State: AOAM531rrk5L1yli8TKKxrm2i14SMtReFSWazcDRSph6tCFL36ZM0fZn WnStDvmWdNkkDHlHc8bBhekBDsBjaBtVG0fm X-Google-Smtp-Source: ABdhPJx4NPeBXVfHWFzEbN5ZHFqPqWjWvNIrZKiBBK/RFB7ydCsDRjdeWUyoVDolKv4yb68p2NYLmQ== X-Received: by 2002:a9d:340b:: with SMTP id v11mr17724870otb.284.1615163741516; Sun, 07 Mar 2021 16:35:41 -0800 (PST) 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 a7sm2078112oon.8.2021.03.07.16.35.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Mar 2021 16:35:41 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Heinrich Schuchardt , Tom Rini , Stephen Warren , Stephen Warren , Simon Glass Subject: [PATCH v5 24/41] test: Move test running into a separate function Date: Sun, 7 Mar 2021 17:35:00 -0700 Message-Id: <20210308003517.1574569-24-sjg@chromium.org> X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog In-Reply-To: <20210308003517.1574569-1-sjg@chromium.org> References: <20210308003517.1574569-1-sjg@chromium.org> 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.4 at phobos.denx.de X-Virus-Status: Clean Add a function to handle the preparation for running a test and the post-test clean-up. Signed-off-by: Simon Glass --- (no changes since v1) include/test/ut.h | 16 ++++++++++++++++ test/test-main.c | 32 +++++++++++++++++++++++--------- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/include/test/ut.h b/include/test/ut.h index 4e0aba9f700..98f699cbba2 100644 --- a/include/test/ut.h +++ b/include/test/ut.h @@ -387,6 +387,22 @@ int test_pre_run(struct unit_test_state *uts, struct unit_test *test); */ int test_post_run(struct unit_test_state *uts, struct unit_test *test); +/** + * ut_run_test() - Run a single test + * + * This runs the test, handling any preparation and clean-up needed. It prints + * the name of each test before running it. + * + * @uts: Test state to update. The caller should ensure that this is zeroed for + * the first call to this function. On exit, @uts->fail_count is + * incremented by the number of failures (0, one hopes) + * @test: Test to run + * @name: Name of test, possibly skipping a prefix that should not be displayed + * @return 0 if all tests passed, -EAGAIN if the test should be skipped, -1 if + * any failed + */ +int ut_run_test(struct unit_test_state *uts, struct unit_test *test, + const char *name); /** * ut_run_tests() - Run a set of tests diff --git a/test/test-main.c b/test/test-main.c index 3806c2ad89c..dee28d35d82 100644 --- a/test/test-main.c +++ b/test/test-main.c @@ -121,6 +121,28 @@ int test_post_run(struct unit_test_state *uts, struct unit_test *test) return 0; } +int ut_run_test(struct unit_test_state *uts, struct unit_test *test, + const char *test_name) +{ + int ret; + + printf("Test: %s\n", test_name); + + ret = test_pre_run(uts, test); + if (ret == -EAGAIN) + return -EAGAIN; + if (ret) + return ret; + + test->func(uts); + + ret = test_post_run(uts, test); + if (ret) + return ret; + + return 0; +} + int ut_run_tests(struct unit_test_state *uts, const char *prefix, struct unit_test *tests, int count, const char *select_name) { @@ -138,20 +160,12 @@ int ut_run_tests(struct unit_test_state *uts, const char *prefix, if (select_name && strcmp(select_name, test_name)) continue; - printf("Test: %s\n", test_name); + ret = ut_run_test(uts, test, test_name); found++; - - ret = test_pre_run(uts, test); if (ret == -EAGAIN) continue; if (ret) return ret; - - test->func(uts); - - ret = test_post_run(uts, test); - if (ret) - return ret; } if (select_name && !found) return -ENOENT;