From patchwork Mon Mar 8 00:35:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1448808 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=JazTgYw8; 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 4Dv00c1Gz7z9sSC for ; Mon, 8 Mar 2021 11:42:07 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 659DE82928; Mon, 8 Mar 2021 01:40:10 +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="JazTgYw8"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CBA3F828EA; Mon, 8 Mar 2021 01:36:45 +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-x336.google.com (mail-ot1-x336.google.com [IPv6:2607:f8b0:4864:20::336]) (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 3B2FA828A3 for ; Mon, 8 Mar 2021 01:35:46 +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-x336.google.com with SMTP id v12so7591184ott.10 for ; Sun, 07 Mar 2021 16:35:46 -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=MkjAZbzKwzP0XlGbFhvnFEmOF2nDMrhYmT47BvKz/lQ=; b=JazTgYw8QqROw/fVPLXVWUKiSa1MMd9aG4sSaOWeBEA9bF8XVgWZ3MbmnUbFt4p4r/ kcSmAYaa6ix0JXZW6ikfBqVwQolKvrui/KB+/53cIGLAnGfF588uxsaB+147FUF1trJJ qgVqhaZToEZwSRG7TqHJGufYbwSbeS0JlRXe0= 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=MkjAZbzKwzP0XlGbFhvnFEmOF2nDMrhYmT47BvKz/lQ=; b=X7we+VtPWMZQEiVyHhjNC7NYTfczIk7pCCEb5BupY2WqXmaORYnTV+SrGREzh58o/8 XQRARxUxdCkRtmlSUp6xUZQ4eoS24GSioW9iTHzPitMAARDXand2wtVDVJ9b8j3K1Gu5 D1DrRH01vQ7sX+s+FI8VMTO0rRxGwqE4Ak47kL5YF+UbAZWMI3G1YJRbsR40JHWEFaJt tMQe/kx1pviWavVKehzivHANPIptow+d76B1ozVIIq2wf7QTzLbH7KbDsIZZjeyP/l2c MMBMtMQYkkqsfMSJAFOfuzAuEOIKLJXAReYmu8J8l5KqZUQY3YXZr49st/yzxZ5k60ji 7ZAw== X-Gm-Message-State: AOAM531M7NCq9b/FO/ictdMEiGYZnnK0vOoRQwI5+cZevaqkNyXtweTI I/neIC43Og4lIZsE2a5GYkbbNdwtZtTRyeOb X-Google-Smtp-Source: ABdhPJwIVEj2EpZryFIsQ3xFl1aFTXf7j7P05xCSa/JV/oa529VlHyPqoj86j5SlXvxzan/86Akrcw== X-Received: by 2002:a9d:354:: with SMTP id 78mr17797323otv.123.1615163744836; Sun, 07 Mar 2021 16:35:44 -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.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Mar 2021 16:35:44 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Heinrich Schuchardt , Tom Rini , Stephen Warren , Stephen Warren , Simon Glass Subject: [PATCH v5 28/41] test: Use a local variable for test state Date: Sun, 7 Mar 2021 17:35:04 -0700 Message-Id: <20210308003517.1574569-28-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 At present we use a global test state for all driver-model tests. Make use of a local struct like we do with the other tests. To make this work, add functions to get and set this state. When a test starts, the state is set (so it can be used in the test). When a test finishes, the state is unset, so it cannot be used by mistake. Signed-off-by: Simon Glass --- (no changes since v3) Changes in v3: - Use test_set_state() throughout test-main.c instead of direct assignment include/test/ut.h | 14 ++++++++++++++ test/dm/test-dm.c | 4 +--- test/dm/test-driver.c | 10 +++++++++- test/dm/test-uclass.c | 7 +++++-- test/test-main.c | 18 ++++++++++++++++++ 5 files changed, 47 insertions(+), 6 deletions(-) diff --git a/include/test/ut.h b/include/test/ut.h index d06bc5089be..bed0e6eb5f6 100644 --- a/include/test/ut.h +++ b/include/test/ut.h @@ -367,6 +367,20 @@ void ut_unsilence_console(struct unit_test_state *uts); */ void ut_set_skip_delays(struct unit_test_state *uts, bool skip_delays); +/** + * test_get_state() - Get the active test state + * + * @return the currently active test state, or NULL if none + */ +struct unit_test_state *test_get_state(void); + +/** + * test_set_state() - Set the active test state + * + * @uts: Test state to use as currently active test state, or NULL if none + */ +void test_set_state(struct unit_test_state *uts); + /** * ut_run_test_live_flat() - Run a test with both live and flat tree * diff --git a/test/dm/test-dm.c b/test/dm/test-dm.c index 826b64565e8..cdaf27bf987 100644 --- a/test/dm/test-dm.c +++ b/test/dm/test-dm.c @@ -20,8 +20,6 @@ DECLARE_GLOBAL_DATA_PTR; -struct unit_test_state global_dm_test_state; - static bool test_matches(const char *test_name, const char *find_name) { if (!find_name) @@ -44,7 +42,7 @@ int dm_test_run(const char *test_name) { struct unit_test *tests = ll_entry_start(struct unit_test, dm_test); const int n_ents = ll_entry_count(struct unit_test, dm_test); - struct unit_test_state *uts = &global_dm_test_state; + struct unit_test_state uts_s = { .fail_count = 0 }, *uts = &uts_s; struct unit_test *test; int found; diff --git a/test/dm/test-driver.c b/test/dm/test-driver.c index 63dc9d335ae..02cb974b0f7 100644 --- a/test/dm/test-driver.c +++ b/test/dm/test-driver.c @@ -18,7 +18,6 @@ #include int dm_testdrv_op_count[DM_TEST_OP_COUNT]; -static struct unit_test_state *uts = &global_dm_test_state; static int testdrv_ping(struct udevice *dev, int pingval, int *pingret) { @@ -37,6 +36,8 @@ static const struct test_ops test_ops = { static int test_bind(struct udevice *dev) { + struct unit_test_state *uts = test_get_state(); + /* Private data should not be allocated */ ut_assert(!dev_get_priv(dev)); @@ -46,6 +47,7 @@ static int test_bind(struct udevice *dev) static int test_probe(struct udevice *dev) { + struct unit_test_state *uts = test_get_state(); struct dm_test_priv *priv = dev_get_priv(dev); /* Private data should be allocated */ @@ -58,6 +60,8 @@ static int test_probe(struct udevice *dev) static int test_remove(struct udevice *dev) { + struct unit_test_state *uts = test_get_state(); + /* Private data should still be allocated */ ut_assert(dev_get_priv(dev)); @@ -67,6 +71,8 @@ static int test_remove(struct udevice *dev) static int test_unbind(struct udevice *dev) { + struct unit_test_state *uts = test_get_state(); + /* Private data should not be allocated */ ut_assert(!dev_get_priv(dev)); @@ -116,6 +122,8 @@ static int test_manual_bind(struct udevice *dev) static int test_manual_probe(struct udevice *dev) { + struct unit_test_state *uts = test_get_state(); + dm_testdrv_op_count[DM_TEST_OP_PROBE]++; if (!uts->force_fail_alloc) dev_set_priv(dev, calloc(1, sizeof(struct dm_test_priv))); diff --git a/test/dm/test-uclass.c b/test/dm/test-uclass.c index f4b540c9278..067701734a0 100644 --- a/test/dm/test-uclass.c +++ b/test/dm/test-uclass.c @@ -17,8 +17,6 @@ #include #include -static struct unit_test_state *uts = &global_dm_test_state; - int test_ping(struct udevice *dev, int pingval, int *pingret) { const struct test_ops *ops = device_get_ops(dev); @@ -31,6 +29,7 @@ int test_ping(struct udevice *dev, int pingval, int *pingret) static int test_post_bind(struct udevice *dev) { + struct unit_test_state *uts = test_get_state(); struct dm_test_perdev_uc_pdata *uc_pdata; dm_testdrv_op_count[DM_TEST_OP_POST_BIND]++; @@ -56,6 +55,7 @@ static int test_pre_unbind(struct udevice *dev) static int test_pre_probe(struct udevice *dev) { struct dm_test_uclass_perdev_priv *priv = dev_get_uclass_priv(dev); + struct unit_test_state *uts = test_get_state(); dm_testdrv_op_count[DM_TEST_OP_PRE_PROBE]++; ut_assert(priv); @@ -66,6 +66,7 @@ static int test_pre_probe(struct udevice *dev) static int test_post_probe(struct udevice *dev) { + struct unit_test_state *uts = test_get_state(); struct udevice *prev = list_entry(dev->uclass_node.prev, struct udevice, uclass_node); @@ -100,6 +101,8 @@ static int test_pre_remove(struct udevice *dev) static int test_init(struct uclass *uc) { + struct unit_test_state *uts = test_get_state(); + dm_testdrv_op_count[DM_TEST_OP_INIT]++; ut_assert(uclass_get_priv(uc)); diff --git a/test/test-main.c b/test/test-main.c index 4e17c9edb28..139fc1f6f18 100644 --- a/test/test-main.c +++ b/test/test-main.c @@ -16,6 +16,19 @@ DECLARE_GLOBAL_DATA_PTR; +/* This is valid when a test is running, NULL otherwise */ +static struct unit_test_state *cur_test_state; + +struct unit_test_state *test_get_state(void) +{ + return cur_test_state; +} + +void test_set_state(struct unit_test_state *uts) +{ + cur_test_state = uts; +} + /** * dm_test_pre_run() - Get ready to run a driver model test * @@ -180,6 +193,9 @@ static int ut_run_test(struct unit_test_state *uts, struct unit_test *test, note = " (flat tree)"; printf("Test: %s: %s%s\n", test_name, fname, note); + /* Allow access to test state from drivers */ + test_set_state(uts); + ret = test_pre_run(uts, test); if (ret == -EAGAIN) return -EAGAIN; @@ -192,6 +208,8 @@ static int ut_run_test(struct unit_test_state *uts, struct unit_test *test, if (ret) return ret; + test_set_state( NULL); + return 0; }