From patchwork Mon Dec 11 22:09:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Winiarski?= X-Patchwork-Id: 13488145 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1D743C35273 for ; Mon, 11 Dec 2023 22:10:08 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D5C2C10E51F; Mon, 11 Dec 2023 22:10:01 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) by gabe.freedesktop.org (Postfix) with ESMTPS id E6E9B10E51B; Mon, 11 Dec 2023 22:09:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702332598; x=1733868598; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=/ymKimFLSiDeo/NVNz3x/mTKycmLWMpbqiCB7S8EMV4=; b=nQ9GdlqSNENy44DXGszQFxQUs3zVsiotGlcV0k6h+71ay2t5CsE26cEt fRAt9PbAZmAOMde8Fe08NXnVBaZLtXG4hePV71EeqocplC/QBOhyUilxK DjRVrNEZytXXI3MXYPnK8+7Tk7Q/3cmxiEvR9vaQP/so9NOFMCGPH4/7T gaaCSEFuIJeXC0DfUPUfGH0Z7CDBmdLZpN2mrb426fgzDM+ZIGvEIFold +ibNq/rMAoK/HQWwxpuqPd3R1DyihWUi4VVbALoFjOqrvpGnRuj256aqR kxQ5aF2fifaOBnJ5y8Y1J3n7MyH4+BmlAS+tL8uWdOrVrUkhqCejvT2uZ g==; X-IronPort-AV: E=McAfee;i="6600,9927,10921"; a="1865670" X-IronPort-AV: E=Sophos;i="6.04,268,1695711600"; d="scan'208";a="1865670" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Dec 2023 14:09:57 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10921"; a="776826861" X-IronPort-AV: E=Sophos;i="6.04,268,1695711600"; d="scan'208";a="776826861" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by fmsmga007.fm.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 11 Dec 2023 14:09:57 -0800 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Mon, 11 Dec 2023 14:09:56 -0800 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35 via Frontend Transport; Mon, 11 Dec 2023 14:09:56 -0800 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (104.47.66.40) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Mon, 11 Dec 2023 14:09:55 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EJ/nY9hnunXtpr8ubuVx9bVJuIi9WawXztpr+5UfYBSZeurAuESDT6c2rz+nFWFiLdCHrG0BJ/spsmiJ+6GP1TPWBQ7k0nMYW424RAJKipEbWThbZLBrL4B4UJ3cW0FBt63tRiTBcxyNNiUXsmHealOaNGBlzS8uLHIHtVzGGvUlK68ruUGU/qStPux8ejSaWa/kiTwteqolBCzZBfbPO3u9Q/PrQ84hOdnKiFeZ12osnHmirIy0fsU8i4Hu7s1UlSlv2uWxtVA+vlVUdVEFrSgmrxFsWTp2uc5vDocqIVVWFJ6VCEb1pijoNNDpJuYq0e1k0pBf3dKC69aZ03RQVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=sIOvHiNhB1GGERAGve4YMpEIaydyZIfnAdB2dNv3AxQ=; b=Lf9Sj3f8dl2VJmEGz02T+dHWn9VjQYQfmo8okE8i5yGj51xlYjlXSxRiVlE14QHh1h6lu2giuVGnz/qB88gf/WYtqteZEr3fNeLlNpwgzkfqN8Psjma3xeikV6gapDGQJsuF5FdQLLL8nD7V0gx/dzjxViDFLBMfuU/6VKwweD493zpy2zTXygfUo/W1BJWsXeyZ+r1lVV+pbcmlpUd0sUye9PPMDnDeXqUvBm9hJYCSAeOVjq4JFFwkLDzDfAFqM7cwpQWVfe8qcUEu2E/VDXdpMIcoEGveiKG+0KtdoXciT5R7a1JvlJ0mYxJfoYV9coqt2EmhG0/mJh82Do6xtg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) by DS0PR11MB8134.namprd11.prod.outlook.com (2603:10b6:8:15a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.32; Mon, 11 Dec 2023 22:09:53 +0000 Received: from DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::f105:47dd:6794:6821]) by DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::f105:47dd:6794:6821%4]) with mapi id 15.20.7068.031; Mon, 11 Dec 2023 22:09:53 +0000 From: =?utf-8?q?Micha=C5=82_Winiarski?= To: , , Subject: [PATCH v3 2/3] drm/tests: managed: Extract device initialization into test init Date: Mon, 11 Dec 2023 23:09:38 +0100 Message-ID: <20231211220939.215024-3-michal.winiarski@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231211220939.215024-1-michal.winiarski@intel.com> References: <20231211220939.215024-1-michal.winiarski@intel.com> X-ClientProxiedBy: WA2P291CA0012.POLP291.PROD.OUTLOOK.COM (2603:10a6:1d0:1e::27) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR11MB5373:EE_|DS0PR11MB8134:EE_ X-MS-Office365-Filtering-Correlation-Id: e981944c-6e56-45c4-ff60-08dbfa95e6ad X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7uWAfarzlT3S+r/04m6MoQ2mhzGCFa9SoqfR897pWTdwjfnn8PRYqnLL9knPbqyG9pg6ODbg82osRRuxDtbkcNsghScf70dKIQBrYNjFHibRv7jzkj91TadyjODzuoAriopivLoyDBRR9G9+Rmf1E1FUiEaxh8HsuFVUvE4XON2AliAM1o2N5i1dNoWvSX/Ot9cXqQciJDLKGBbCnv0X91mFYwi8sv/vFQImKYl8rMZR0pirVIBfc38M3kvwRXHznrQd3RuRTWfBBUCwFdH93k2ABRgp0poJ1tM5M79kBSTih+8VbridGA6LBiiXfIkL9UW91vbMXQBBOBiwcrmvg4oSvJqhShbvzHbcygHnof4MyG0IUU3SN3Hq78WZ1Zo2qpJUpBMeJSauNKRRNzmFiV1Ms1/kR6gTGyaiWjKHDQpyFrgB+pb28jJIwn+D34f/V2K8KmGk6EUUQceZsPO64Q3mX0iQSaiTjy5z412dkhVdtZ6SrzAORvHfNXdtJYUrFjuJI4cgKiAJxbY2xw0AB8QWcwP9EkhTh8yPe51Z3JfMv+2mubpcfc1j/DVdsRWd X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM4PR11MB5373.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(136003)(346002)(376002)(39860400002)(396003)(366004)(230922051799003)(186009)(451199024)(1800799012)(64100799003)(41300700001)(1076003)(26005)(83380400001)(2616005)(82960400001)(86362001)(36756003)(38100700002)(5660300002)(316002)(8936002)(8676002)(4326008)(2906002)(7416002)(6666004)(6512007)(6506007)(66476007)(54906003)(66946007)(66556008)(478600001)(6486002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?U9PE9grlV/dj4PE5JoYJZjWTHoSO?= =?utf-8?q?DsMczOKO+grzMRWf7CauxdEpJkgNkbeJICJqfD+I/KfI/Wam9nCVLLK1Quow2SNHk?= =?utf-8?q?hIiO7utLAH3R831brb80+DoXHUzQHgWJMN16qVSc1pG2dzpvGYp1MN+Dk6PWVodg+?= =?utf-8?q?IBU6MpQDA9qjdFU4SJgvtkn96x3sYIQ+2kNPBQ0fMBAtJjyfJbZlC3NLg24FzglKM?= =?utf-8?q?zRLAZrHHgqohhMxswNySLF/G3eym8QJwrY1P2a/hghW+DUNzkhY7pWeUvf0FSJm1O?= =?utf-8?q?7PbXr4ohozJHAJN3sXARwmHwBZuN2HZkN7muhcquiuoDTFGiVyJPFT+dSwnyZiEti?= =?utf-8?q?NYs/AKXfbG0AAHT9EerLbB4l001IAM6yyRdfEssn2fRZNqCQmbTUCDCkyMw2J4JvQ?= =?utf-8?q?cdjHuKcOp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mJK/rT6uD2EmwcE6LPCn90APU82mKK3GnIr2I5GQ1kbrRA?= =?utf-8?q?Vxr1ZzH/j+5B3N+p1Bsp7WuOYzbiQAaQ+2xKmml91sw0KzVX85FBDMLdo2yd9/li3?= =?utf-8?q?Srwy2l97nIcGlx2ji3rOMmt0EItSydAagCkC15i1k/cClzfG6xT0pDrdbKQC3T7/J?= =?utf-8?q?xhpnIg5k5hL/SsFefpFdJw4L4eZmpBSHMwV6Wv48n1tYUVP4p7uLl0RBVj5chsP4B?= =?utf-8?q?G0ZP7VS0Mzs6B9Ou+o6YVpV6vUSTgQRxpA=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: e981944c-6e56-45c4-ff60-08dbfa95e6ad X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5373.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2023 22:09:53.1685 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: mz27213IHC/FUoaZn7qkFuf1FvZNassZft3qMa/OMmnfuz9I2GU29Zi5BkjFHK1wMzU5JepUjbSI4NOVIgL1uGf64P/2H0voVWqu1r62giE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR11MB8134 X-OriginatorOrg: intel.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Micha=C5=82_Winiarski?= , =?utf-8?q?Ma=C3=ADra_Canal?= , Javier Martinez Canillas , Maxime Ripard , Thomas Zimmermann , Rodrigo Vivi , Michal Wajdeczko Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" It simplifies the process of extending the test suite with additional test cases without unnecessary duplication. Signed-off-by: MichaƂ Winiarski --- drivers/gpu/drm/tests/drm_managed_test.c | 51 +++++++++++++++++------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/drivers/gpu/drm/tests/drm_managed_test.c b/drivers/gpu/drm/tests/drm_managed_test.c index 1652dca11d30c..15bd2474440b5 100644 --- a/drivers/gpu/drm/tests/drm_managed_test.c +++ b/drivers/gpu/drm/tests/drm_managed_test.c @@ -12,6 +12,7 @@ #define TEST_TIMEOUT_MS 100 struct managed_test_priv { + struct drm_device *drm; bool action_done; wait_queue_head_t action_wq; }; @@ -24,35 +25,54 @@ static void drm_action(struct drm_device *drm, void *ptr) wake_up_interruptible(&priv->action_wq); } +/* + * The test verifies that the release action is called automatically when the + * device is released. + */ static void drm_test_managed_run_action(struct kunit *test) +{ + struct managed_test_priv *priv = test->priv; + int ret; + + ret = drmm_add_action_or_reset(priv->drm, drm_action, priv); + KUNIT_EXPECT_EQ(test, ret, 0); + + ret = drm_dev_register(priv->drm, 0); + KUNIT_ASSERT_EQ(test, ret, 0); + + drm_dev_unregister(priv->drm); + drm_kunit_helper_free_device(test, priv->drm->dev); + + ret = wait_event_interruptible_timeout(priv->action_wq, priv->action_done, + msecs_to_jiffies(TEST_TIMEOUT_MS)); + KUNIT_EXPECT_GT_MSG(test, ret, 0, "Release action was not called"); +} + +static int drm_managed_test_init(struct kunit *test) { struct managed_test_priv *priv; - struct drm_device *drm; struct device *dev; - int ret; priv = kunit_kzalloc(test, sizeof(*priv), GFP_KERNEL); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv); - init_waitqueue_head(&priv->action_wq); dev = drm_kunit_helper_alloc_device(test); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev); - drm = __drm_kunit_helper_alloc_drm_device(test, dev, sizeof(*drm), 0, DRIVER_MODESET); - KUNIT_ASSERT_NOT_ERR_OR_NULL(test, drm); + /* + * DRM device can't be embedded in priv, since priv->action_done needs + * to remain allocated beyond both parent device and drm_device + * lifetime. + */ + priv->drm = __drm_kunit_helper_alloc_drm_device(test, dev, sizeof(*priv->drm), 0, + DRIVER_MODESET); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv->drm); - ret = drmm_add_action_or_reset(drm, drm_action, priv); - KUNIT_EXPECT_EQ(test, ret, 0); - - ret = drm_dev_register(drm, 0); - KUNIT_ASSERT_EQ(test, ret, 0); + init_waitqueue_head(&priv->action_wq); - drm_dev_unregister(drm); - drm_kunit_helper_free_device(test, dev); + test->priv = priv; - ret = wait_event_interruptible_timeout(priv->action_wq, priv->action_done, - msecs_to_jiffies(TEST_TIMEOUT_MS)); - KUNIT_EXPECT_GT(test, ret, 0); + return 0; } static struct kunit_case drm_managed_tests[] = { @@ -62,6 +82,7 @@ static struct kunit_case drm_managed_tests[] = { static struct kunit_suite drm_managed_test_suite = { .name = "drm-test-managed", + .init = drm_managed_test_init, .test_cases = drm_managed_tests };