From patchwork Thu Mar 4 13:50:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1447341 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=JDJcE4UU; 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 4Drsq13ypMz9sRf for ; Fri, 5 Mar 2021 00:56:29 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B8FD382893; Thu, 4 Mar 2021 14:53:15 +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="JDJcE4UU"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BD75482804; Thu, 4 Mar 2021 14:52:18 +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.0 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-oi1-x22f.google.com (mail-oi1-x22f.google.com [IPv6:2607:f8b0:4864:20::22f]) (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 808498276B for ; Thu, 4 Mar 2021 14:52:04 +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-oi1-x22f.google.com with SMTP id o3so30132457oic.8 for ; Thu, 04 Mar 2021 05:52:04 -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=BVmvpFDVTCSE0+gHFuqCnD7fHdI4Kl+yneAiKQvGPdg=; b=JDJcE4UUyMKhimC6r5zc1MxTzp5EkCchI90Ftm0xizvmxDpoMQi13KHcVDOZu7OuOj 5b4/fjHJzF1z3KwRyjvB37GRJSSzNAxylri6MYX8cBOeGMT3feuhLBRgd5+NQIi9bPRj x+aZqHQE23SSnme3L7dmNte6i0NrlSp2p9Ezg= 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=BVmvpFDVTCSE0+gHFuqCnD7fHdI4Kl+yneAiKQvGPdg=; b=CnhXMnWH4IvaUxFGLX0FRIm6YmQ39qwtVRqI79WMvxLOX+vLcz/kojy977ZAYKW/Gh +of6eVXRjStDe8X7x5ANH141e5MmeHzH/QVKX2j6ZWGELVAC7O1PRo8oIKD2h6YwZc7z 71p9VuoCblzzfx1IoitcqgTuzXyDgeF7D4dqzJcVKv1Cjzm4M34OREc6QpggUa9jzvqD UYnjmUDtat+Kt41z7NxouDtacIbzF7o13V+35rxFCShzvjwF3cY8yk9uPU3Fb4R+piAJ OaLfnCDGT6+2e27FNfUjbimnNYtfKNsj5dlNfXoPbAUYi8frJ1s8AG4EnYz/d7vq+BL1 NzHg== X-Gm-Message-State: AOAM532lRXPivpS0dX1Qee71B1YdGQtr3s1F5UO/2XLRVv5tOi3HZKog hOGqYdaKpSBy+I8IlP/pxk0CzBP2ZQZwgic7 X-Google-Smtp-Source: ABdhPJx0UB/2ngIowqbI7v2AsHuqiCfYEviqN2H0xc3honAIJ4c5+HVgs3/7ruQtmjGRprzFFjKWBA== X-Received: by 2002:a05:6808:105:: with SMTP id b5mr2991372oie.53.1614865922838; Thu, 04 Mar 2021 05:52:02 -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 x10sm4029465otp.19.2021.03.04.05.52.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Mar 2021 05:52:02 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Heinrich Schuchardt , Stephen Warren , Stephen Warren , Simon Glass Subject: [PATCH v4 21/42] test: Drop struct dm_test_state Date: Thu, 4 Mar 2021 06:50:57 -0700 Message-Id: <20210304135118.643277-21-sjg@chromium.org> X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog In-Reply-To: <20210304135118.643277-1-sjg@chromium.org> References: <20210304135118.643277-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 Driver model is a core part of U-Boot. We don't really need to have a separate test structure for the driver model tests and it makes it harder to write a test if you have to think about which type of test it is. Subsume the fields from struct dm_test_state into struct unit_test_state and delete the former. Signed-off-by: Simon Glass --- Changes in v4: - Rebase on master include/dm/test.h | 17 ------------- include/test/test.h | 10 ++++++-- test/dm/core.c | 58 ++++++++++++++++++------------------------- test/dm/test-dm.c | 10 ++++---- test/dm/test-driver.c | 4 +-- test/dm/test-uclass.c | 3 +-- 6 files changed, 39 insertions(+), 63 deletions(-) diff --git a/include/dm/test.h b/include/dm/test.h index c0b463cc0f1..fe1cc2e278c 100644 --- a/include/dm/test.h +++ b/include/dm/test.h @@ -125,23 +125,6 @@ extern int dm_testdrv_op_count[DM_TEST_OP_COUNT]; extern struct unit_test_state global_dm_test_state; -/* - * struct dm_test_state - Entire state of dm test system - * - * This is often abreviated to dms. - * - * @root: Root device - * @testdev: Test device - * @force_fail_alloc: Force all memory allocs to fail - * @skip_post_probe: Skip uclass post-probe processing - */ -struct dm_test_state { - struct udevice *root; - struct udevice *testdev; - int force_fail_alloc; - int skip_post_probe; -}; - /* Declare a new driver model test */ #define DM_TEST(_name, _flags) \ UNIT_TEST(_name, UT_TESTF_DM | UT_TESTF_CONSOLE_REC | (_flags), dm_test) diff --git a/include/test/test.h b/include/test/test.h index 6997568cc07..5eeec35f525 100644 --- a/include/test/test.h +++ b/include/test/test.h @@ -14,18 +14,24 @@ * * @fail_count: Number of tests that failed * @start: Store the starting mallinfo when doing leak test - * @priv: A pointer to some other info some suites want to track * @of_live: true to use livetree if available, false to use flattree * @of_root: Record of the livetree root node (used for setting up tests) + * @root: Root device + * @testdev: Test device + * @force_fail_alloc: Force all memory allocs to fail + * @skip_post_probe: Skip uclass post-probe processing * @expect_str: Temporary string used to hold expected string value * @actual_str: Temporary string used to hold actual string value */ struct unit_test_state { int fail_count; struct mallinfo start; - void *priv; struct device_node *of_root; bool of_live; + struct udevice *root; + struct udevice *testdev; + int force_fail_alloc; + int skip_post_probe; char expect_str[256]; char actual_str[256]; }; diff --git a/test/dm/core.c b/test/dm/core.c index 35ca689d646..2210345dd14 100644 --- a/test/dm/core.c +++ b/test/dm/core.c @@ -117,14 +117,13 @@ int dm_leak_check_end(struct unit_test_state *uts) /* Test that binding with plat occurs correctly */ static int dm_test_autobind(struct unit_test_state *uts) { - struct dm_test_state *dms = uts->priv; struct udevice *dev; /* * We should have a single class (UCLASS_ROOT) and a single root * device with no children. */ - ut_assert(dms->root); + ut_assert(uts->root); ut_asserteq(1, list_count_items(gd->uclass_root)); ut_asserteq(0, list_count_items(&gd->dm_root->child_head)); ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_POST_BIND]); @@ -207,7 +206,6 @@ DM_TEST(dm_test_autobind_uclass_pdata_valid, UT_TESTF_SCAN_PDATA); /* Test that autoprobe finds all the expected devices */ static int dm_test_autoprobe(struct unit_test_state *uts) { - struct dm_test_state *dms = uts->priv; int expected_base_add; struct udevice *dev; struct uclass *uc; @@ -221,7 +219,7 @@ static int dm_test_autoprobe(struct unit_test_state *uts) ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_POST_PROBE]); /* The root device should not be activated until needed */ - ut_assert(dev_get_flags(dms->root) & DM_FLAG_ACTIVATED); + ut_assert(dev_get_flags(uts->root) & DM_FLAG_ACTIVATED); /* * We should be able to find the three test devices, and they should @@ -241,7 +239,7 @@ static int dm_test_autoprobe(struct unit_test_state *uts) /* Activating a device should activate the root device */ if (!i) - ut_assert(dev_get_flags(dms->root) & DM_FLAG_ACTIVATED); + ut_assert(dev_get_flags(uts->root) & DM_FLAG_ACTIVATED); } /* @@ -293,7 +291,6 @@ DM_TEST(dm_test_plat, UT_TESTF_SCAN_PDATA); /* Test that we can bind, probe, remove, unbind a driver */ static int dm_test_lifecycle(struct unit_test_state *uts) { - struct dm_test_state *dms = uts->priv; int op_count[DM_TEST_OP_COUNT]; struct udevice *dev, *test_dev; int pingret; @@ -301,7 +298,7 @@ static int dm_test_lifecycle(struct unit_test_state *uts) memcpy(op_count, dm_testdrv_op_count, sizeof(op_count)); - ut_assertok(device_bind_by_name(dms->root, false, &driver_info_manual, + ut_assertok(device_bind_by_name(uts->root, false, &driver_info_manual, &dev)); ut_assert(dev); ut_assert(dm_testdrv_op_count[DM_TEST_OP_BIND] @@ -309,7 +306,7 @@ static int dm_test_lifecycle(struct unit_test_state *uts) ut_assert(!dev_get_priv(dev)); /* Probe the device - it should fail allocating private data */ - dms->force_fail_alloc = 1; + uts->force_fail_alloc = 1; ret = device_probe(dev); ut_assert(ret == -ENOMEM); ut_assert(dm_testdrv_op_count[DM_TEST_OP_PROBE] @@ -317,7 +314,7 @@ static int dm_test_lifecycle(struct unit_test_state *uts) ut_assert(!dev_get_priv(dev)); /* Try again without the alloc failure */ - dms->force_fail_alloc = 0; + uts->force_fail_alloc = 0; ut_assertok(device_probe(dev)); ut_assert(dm_testdrv_op_count[DM_TEST_OP_PROBE] == op_count[DM_TEST_OP_PROBE] + 2); @@ -349,19 +346,18 @@ DM_TEST(dm_test_lifecycle, UT_TESTF_SCAN_PDATA | UT_TESTF_PROBE_TEST); /* Test that we can bind/unbind and the lists update correctly */ static int dm_test_ordering(struct unit_test_state *uts) { - struct dm_test_state *dms = uts->priv; struct udevice *dev, *dev_penultimate, *dev_last, *test_dev; int pingret; - ut_assertok(device_bind_by_name(dms->root, false, &driver_info_manual, + ut_assertok(device_bind_by_name(uts->root, false, &driver_info_manual, &dev)); ut_assert(dev); /* Bind two new devices (numbers 4 and 5) */ - ut_assertok(device_bind_by_name(dms->root, false, &driver_info_manual, + ut_assertok(device_bind_by_name(uts->root, false, &driver_info_manual, &dev_penultimate)); ut_assert(dev_penultimate); - ut_assertok(device_bind_by_name(dms->root, false, &driver_info_manual, + ut_assertok(device_bind_by_name(uts->root, false, &driver_info_manual, &dev_last)); ut_assert(dev_last); @@ -376,7 +372,7 @@ static int dm_test_ordering(struct unit_test_state *uts) ut_assert(dev_last == test_dev); /* Add back the original device 3, now in position 5 */ - ut_assertok(device_bind_by_name(dms->root, false, &driver_info_manual, + ut_assertok(device_bind_by_name(uts->root, false, &driver_info_manual, &dev)); ut_assert(dev); @@ -568,7 +564,6 @@ static int create_children(struct unit_test_state *uts, struct udevice *parent, static int dm_test_children(struct unit_test_state *uts) { - struct dm_test_state *dms = uts->priv; struct udevice *top[NODE_COUNT]; struct udevice *child[NODE_COUNT]; struct udevice *grandchild[NODE_COUNT]; @@ -578,12 +573,12 @@ static int dm_test_children(struct unit_test_state *uts) int i; /* We don't care about the numbering for this test */ - dms->skip_post_probe = 1; + uts->skip_post_probe = 1; ut_assert(NODE_COUNT > 5); /* First create 10 top-level children */ - ut_assertok(create_children(uts, dms->root, NODE_COUNT, 0, top)); + ut_assertok(create_children(uts, uts->root, NODE_COUNT, 0, top)); /* Now a few have their own children */ ut_assertok(create_children(uts, top[2], NODE_COUNT, 2, NULL)); @@ -654,7 +649,6 @@ DM_TEST(dm_test_children, 0); static int dm_test_device_reparent(struct unit_test_state *uts) { - struct dm_test_state *dms = uts->priv; struct udevice *top[NODE_COUNT]; struct udevice *child[NODE_COUNT]; struct udevice *grandchild[NODE_COUNT]; @@ -664,12 +658,12 @@ static int dm_test_device_reparent(struct unit_test_state *uts) int i; /* We don't care about the numbering for this test */ - dms->skip_post_probe = 1; + uts->skip_post_probe = 1; ut_assert(NODE_COUNT > 5); /* First create 10 top-level children */ - ut_assertok(create_children(uts, dms->root, NODE_COUNT, 0, top)); + ut_assertok(create_children(uts, uts->root, NODE_COUNT, 0, top)); /* Now a few have their own children */ ut_assertok(create_children(uts, top[2], NODE_COUNT, 2, NULL)); @@ -815,15 +809,14 @@ DM_TEST(dm_test_device_reparent, 0); /* Test that pre-relocation devices work as expected */ static int dm_test_pre_reloc(struct unit_test_state *uts) { - struct dm_test_state *dms = uts->priv; struct udevice *dev; /* The normal driver should refuse to bind before relocation */ - ut_asserteq(-EPERM, device_bind_by_name(dms->root, true, + ut_asserteq(-EPERM, device_bind_by_name(uts->root, true, &driver_info_manual, &dev)); /* But this one is marked pre-reloc */ - ut_assertok(device_bind_by_name(dms->root, true, + ut_assertok(device_bind_by_name(uts->root, true, &driver_info_pre_reloc, &dev)); return 0; @@ -836,10 +829,9 @@ DM_TEST(dm_test_pre_reloc, 0); */ static int dm_test_remove_active_dma(struct unit_test_state *uts) { - struct dm_test_state *dms = uts->priv; struct udevice *dev; - ut_assertok(device_bind_by_name(dms->root, false, &driver_info_act_dma, + ut_assertok(device_bind_by_name(uts->root, false, &driver_info_act_dma, &dev)); ut_assert(dev); @@ -872,7 +864,7 @@ static int dm_test_remove_active_dma(struct unit_test_state *uts) * the active DMA remove call */ ut_assertok(device_unbind(dev)); - ut_assertok(device_bind_by_name(dms->root, false, &driver_info_manual, + ut_assertok(device_bind_by_name(uts->root, false, &driver_info_manual, &dev)); ut_assert(dev); @@ -895,25 +887,24 @@ DM_TEST(dm_test_remove_active_dma, 0); /* Test removal of 'vital' devices */ static int dm_test_remove_vital(struct unit_test_state *uts) { - struct dm_test_state *dms = uts->priv; struct udevice *normal, *dma, *vital, *dma_vital; /* Skip the behaviour in test_post_probe() */ - dms->skip_post_probe = 1; + uts->skip_post_probe = 1; - ut_assertok(device_bind_by_name(dms->root, false, &driver_info_manual, + ut_assertok(device_bind_by_name(uts->root, false, &driver_info_manual, &normal)); ut_assertnonnull(normal); - ut_assertok(device_bind_by_name(dms->root, false, &driver_info_act_dma, + ut_assertok(device_bind_by_name(uts->root, false, &driver_info_act_dma, &dma)); ut_assertnonnull(dma); - ut_assertok(device_bind_by_name(dms->root, false, + ut_assertok(device_bind_by_name(uts->root, false, &driver_info_vital_clk, &vital)); ut_assertnonnull(vital); - ut_assertok(device_bind_by_name(dms->root, false, + ut_assertok(device_bind_by_name(uts->root, false, &driver_info_act_dma_vital_clk, &dma_vital)); ut_assertnonnull(dma_vital); @@ -1133,11 +1124,10 @@ DM_TEST(dm_test_uclass_names, UT_TESTF_SCAN_PDATA); static int dm_test_inactive_child(struct unit_test_state *uts) { - struct dm_test_state *dms = uts->priv; struct udevice *parent, *dev1, *dev2; /* Skip the behaviour in test_post_probe() */ - dms->skip_post_probe = 1; + uts->skip_post_probe = 1; ut_assertok(uclass_first_device_err(UCLASS_TEST, &parent)); diff --git a/test/dm/test-dm.c b/test/dm/test-dm.c index ceeac3fd361..15adc53f533 100644 --- a/test/dm/test-dm.c +++ b/test/dm/test-dm.c @@ -22,14 +22,15 @@ DECLARE_GLOBAL_DATA_PTR; struct unit_test_state global_dm_test_state; -static struct dm_test_state _global_priv_dm_test_state; int dm_test_init(struct unit_test_state *uts) { - struct dm_test_state *dms = uts->priv; bool of_live = uts->of_live; - memset(dms, '\0', sizeof(*dms)); + uts->root = NULL; + uts->testdev = NULL; + uts->force_fail_alloc = false; + uts->skip_post_probe = false; gd->dm_root = NULL; if (!CONFIG_IS_ENABLED(OF_PLATDATA)) memset(dm_testdrv_op_count, '\0', sizeof(dm_testdrv_op_count)); @@ -38,7 +39,7 @@ int dm_test_init(struct unit_test_state *uts) /* Determine whether to make the live tree available */ gd_set_of_root(of_live ? uts->of_root : NULL); ut_assertok(dm_init(of_live)); - dms->root = dm_root(); + uts->root = dm_root(); return 0; } @@ -124,7 +125,6 @@ int dm_test_run(const char *test_name) struct unit_test *test; int found; - uts->priv = &_global_priv_dm_test_state; uts->fail_count = 0; if (!CONFIG_IS_ENABLED(OF_PLATDATA)) { diff --git a/test/dm/test-driver.c b/test/dm/test-driver.c index ca7626a0668..63dc9d335ae 100644 --- a/test/dm/test-driver.c +++ b/test/dm/test-driver.c @@ -116,10 +116,8 @@ static int test_manual_bind(struct udevice *dev) static int test_manual_probe(struct udevice *dev) { - struct dm_test_state *dms = uts->priv; - dm_testdrv_op_count[DM_TEST_OP_PROBE]++; - if (!dms->force_fail_alloc) + if (!uts->force_fail_alloc) dev_set_priv(dev, calloc(1, sizeof(struct dm_test_priv))); if (!dev_get_priv(dev)) return -ENOMEM; diff --git a/test/dm/test-uclass.c b/test/dm/test-uclass.c index f1b7aaa727f..f4b540c9278 100644 --- a/test/dm/test-uclass.c +++ b/test/dm/test-uclass.c @@ -71,13 +71,12 @@ static int test_post_probe(struct udevice *dev) struct dm_test_uclass_perdev_priv *priv = dev_get_uclass_priv(dev); struct uclass *uc = dev->uclass; - struct dm_test_state *dms = uts->priv; dm_testdrv_op_count[DM_TEST_OP_POST_PROBE]++; ut_assert(priv); ut_assert(device_active(dev)); priv->base_add = 0; - if (dms->skip_post_probe) + if (uts->skip_post_probe) return 0; if (&prev->uclass_node != &uc->dev_head) { struct dm_test_uclass_perdev_priv *prev_uc_priv