From patchwork Wed Nov 23 15:25:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 13053844 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 EA563C433FE for ; Wed, 23 Nov 2022 15:29:01 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2BF0510E578; Wed, 23 Nov 2022 15:29:00 +0000 (UTC) Received: from wnew2-smtp.messagingengine.com (wnew2-smtp.messagingengine.com [64.147.123.27]) by gabe.freedesktop.org (Postfix) with ESMTPS id B342110E578 for ; Wed, 23 Nov 2022 15:28:52 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailnew.west.internal (Postfix) with ESMTP id 931592B069AE; Wed, 23 Nov 2022 10:28:49 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Wed, 23 Nov 2022 10:28:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cerno.tech; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm2; t=1669217329; x= 1669224529; bh=7JDQwbQ4e5e4kxrps/6I/UtgQ5oCSdXQgO2nu4ENguA=; b=D G9d+VqcAtmqLWgWkoNX9A4ZOdaJSiBXTATnchS5w+7l1ubvMRaVjVla8gcjaK3iy CiaDPPPKjIAEJxGYMGPYZS+wGl0KYr4OhIRjhuSAR9d3qVpaXwyjFLdpGms66UUM 4YwkJsf2MK6HgCcwECD89ZWN9C6E+f3c/u8qOXH/32H1SCxIVqpvtSWhByIQLQT6 zKr329q9V2jqTAYPG41gfUYOovgF9miuLpanexnM/VjANjbW8tFXaaJ8lq8dVDSC Tcqo/p38byR8fSsrF6eJ6NVJEYvsAwPdReQw3d5x9tU6C2sjMMVQ9CBErkpSFkZF TztaTV3zYD0SW2PNm7ajw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1669217329; x= 1669224529; bh=7JDQwbQ4e5e4kxrps/6I/UtgQ5oCSdXQgO2nu4ENguA=; b=w QcmYSzl4NmlEPIKvho8Ytc4wGAv8JmDflJlLo0C+/i6nZT/pqpjuAnJ3wq8Y7u30 89jJsB+SORHXE1QAoQu6PR1pYzS5y8OCfOd7QIYo2Sf5Ex3+KdAchS6y+sxsMtiR 362zox/BaBprGBIoaakyOIxJkEjwsC5yXrO6mqAFbp0Xj9ZCvy75o0K8rvIeLkgn vKNQbwod/0q3qKVstOG3NNlSpjc8cuCJuVAJZEjegkaeTqyJNkIAu6yvkL5kjn/m 3cttgWMtcDty+fcXlAWEmlsDCXgdKA9F0v9kl22qirg/ukQm7Mk9DgiZbAiwBZ1k rhYma+1unMpLvZquHE24Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvgedriedugdejgecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhfffugggtgffkfhgjvfevofesthekredtredtjeenucfhrhhomhepofgrgihi mhgvucftihhprghrugcuoehmrgigihhmvgestggvrhhnohdrthgvtghhqeenucggtffrrg htthgvrhhnpeduudduhfevjeetfeegvdffvdevvdejudegudekjeehtdelhfffveethfej ledtveenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe hmrgigihhmvgestggvrhhnohdrthgvtghh X-ME-Proxy: Feedback-ID: i8771445c:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 23 Nov 2022 10:28:47 -0500 (EST) From: Maxime Ripard Date: Wed, 23 Nov 2022 16:25:45 +0100 Subject: [PATCH 03/24] drm/tests: helpers: Create the device in another function MIME-Version: 1.0 Message-Id: <20221123-rpi-kunit-tests-v1-3-051a0bb60a16@cerno.tech> References: <20221123-rpi-kunit-tests-v1-0-051a0bb60a16@cerno.tech> In-Reply-To: <20221123-rpi-kunit-tests-v1-0-051a0bb60a16@cerno.tech> To: Maxime Ripard , Maarten Lankhorst , Daniel Vetter , David Airlie , Thomas Zimmermann X-Mailer: b4 0.11.0-dev-d416f X-Developer-Signature: v=1; a=openpgp-sha256; l=4269; i=maxime@cerno.tech; h=from:subject:message-id; bh=Oe4YemANeM13u35azFRZAL2Ko/LAeQk6CaEWXQ6B8jI=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDMl11tWzFNg0jFL5JK80JSfV/RErXag72eI9k/q5ZVaxNU/O N7h1lLIwiHExyIopssQImy+JOzXrdScb3zyYOaxMIEMYuDgFYCJzWhn+R941aXcVj2yxd5N7VMejvE ts95X96SeWJ19gyMwJ4v6xkZFh8W2j1M+6wT9vSSxhe+gRsuFZNsvZt/UuB4xW9v83+HCPCQA= X-Developer-Key: i=maxime@cerno.tech; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D 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: =?unknown-8bit?q?David_Gow_=3Cdavidgow=40google=2Ecom=3E=2C_Brendan_Higg?= =?unknown-8bit?q?ins_=3Cbrendan=2Ehiggins=40linux=2Edev=3E=2C_Greg_Kroah-Ha?= =?unknown-8bit?q?rtman_=3Cgregkh=40linuxfoundation=2Eorg=3E=2C_Dave_Stevens?= =?unknown-8bit?q?on_=3Cdave=2Estevenson=40raspberrypi=2Ecom=3E=2C_Javier_Ma?= =?unknown-8bit?q?rtinez_Canillas_=3Cjavierm=40redhat=2Ecom=3E=2C_dri-devel?= =?unknown-8bit?q?=40lists=2Efreedesktop=2Eorg=2C_linux-kernel=40vger=2Ekern?= =?unknown-8bit?q?el=2Eorg=2C_linaro-mm-sig=40lists=2Elinaro=2Eorg=2C_Ma=C3?= =?unknown-8bit?q?=ADra_Canal_=3Cmairacanal=40riseup=2Enet=3E=2C_Maxime_Ripa?= =?unknown-8bit?q?rd_=3Cmaxime=40cerno=2Etech=3E=2C_linux-kselftest=40vger?= =?unknown-8bit?q?=2Ekernel=2Eorg=2C_kunit-dev=40googlegroups=2Ecom=2C_linux?= =?unknown-8bit?q?-media=40vger=2Ekernel=2Eorg?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" We'll need in some tests to control when the device needs to be added and removed, so let's split the device creation from the DRM device creation function. Signed-off-by: Maxime Ripard Reviewed-by: Javier Martinez Canillas --- drivers/gpu/drm/tests/drm_client_modeset_test.c | 14 +++++++++++++- drivers/gpu/drm/tests/drm_kunit_helpers.c | 23 ++++------------------- drivers/gpu/drm/tests/drm_kunit_helpers.h | 5 ++++- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/tests/drm_client_modeset_test.c b/drivers/gpu/drm/tests/drm_client_modeset_test.c index 6920c3ffdfdf..fe95fda350ae 100644 --- a/drivers/gpu/drm/tests/drm_client_modeset_test.c +++ b/drivers/gpu/drm/tests/drm_client_modeset_test.c @@ -16,6 +16,7 @@ struct drm_client_modeset_test_priv { struct drm_device *drm; + struct device *dev; struct drm_connector connector; }; @@ -41,7 +42,10 @@ static int drm_client_modeset_test_init(struct kunit *test) test->priv = priv; - priv->drm = drm_kunit_helper_alloc_drm_device(test, DRIVER_MODESET); + priv->dev = drm_kunit_helper_alloc_device(test); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv->dev); + + priv->drm = drm_kunit_helper_alloc_drm_device(test, priv->dev, DRIVER_MODESET); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv->drm); ret = drmm_connector_init(priv->drm, &priv->connector, @@ -55,6 +59,13 @@ static int drm_client_modeset_test_init(struct kunit *test) return 0; } +static void drm_client_modeset_test_exit(struct kunit *test) +{ + struct drm_client_modeset_test_priv *priv = test->priv; + + drm_kunit_helper_free_device(test, priv->dev); +} + static void drm_test_pick_cmdline_res_1920_1080_60(struct kunit *test) { struct drm_client_modeset_test_priv *priv = test->priv; @@ -92,6 +103,7 @@ static struct kunit_case drm_test_pick_cmdline_tests[] = { static struct kunit_suite drm_test_pick_cmdline_test_suite = { .name = "drm_test_pick_cmdline", .init = drm_client_modeset_test_init, + .exit = drm_client_modeset_test_exit, .test_cases = drm_test_pick_cmdline_tests }; diff --git a/drivers/gpu/drm/tests/drm_kunit_helpers.c b/drivers/gpu/drm/tests/drm_kunit_helpers.c index 7f69f56f5892..2f974f45c5b4 100644 --- a/drivers/gpu/drm/tests/drm_kunit_helpers.c +++ b/drivers/gpu/drm/tests/drm_kunit_helpers.c @@ -18,40 +18,25 @@ struct kunit_dev { static const struct drm_mode_config_funcs drm_mode_config_funcs = { }; -static int dev_init(struct kunit_resource *res, void *ptr) +struct device *drm_kunit_helper_alloc_device(struct kunit *test) { - char *name = ptr; - struct device *dev; - - dev = root_device_register(name); - if (IS_ERR(dev)) - return PTR_ERR(dev); - - res->data = dev; - return 0; + return root_device_register(FAKE_DEVICE_NAME); } -static void dev_free(struct kunit_resource *res) +void drm_kunit_helper_free_device(struct kunit *test, struct device *dev) { - struct device *dev = res->data; - root_device_unregister(dev); } struct drm_device * -drm_kunit_helper_alloc_drm_device(struct kunit *test, +drm_kunit_helper_alloc_drm_device(struct kunit *test, struct device *dev, u32 features) { struct kunit_dev *kdev; struct drm_device *drm; struct drm_driver *driver; - struct device *dev; int ret; - dev = kunit_alloc_resource(test, dev_init, dev_free, GFP_KERNEL, FAKE_DEVICE_NAME); - if (!dev) - return ERR_PTR(-ENOMEM); - driver = kunit_kzalloc(test, sizeof(*driver), GFP_KERNEL); if (!driver) return ERR_PTR(-ENOMEM); diff --git a/drivers/gpu/drm/tests/drm_kunit_helpers.h b/drivers/gpu/drm/tests/drm_kunit_helpers.h index 6c12b1426ba0..b4277fe92c38 100644 --- a/drivers/gpu/drm/tests/drm_kunit_helpers.h +++ b/drivers/gpu/drm/tests/drm_kunit_helpers.h @@ -6,8 +6,11 @@ struct drm_device; struct kunit; +struct device *drm_kunit_helper_alloc_device(struct kunit *test); +void drm_kunit_helper_free_device(struct kunit *test, struct device *dev); + struct drm_device * -drm_kunit_helper_alloc_drm_device(struct kunit *test, +drm_kunit_helper_alloc_drm_device(struct kunit *test, struct device *dev, u32 features); #endif // DRM_KUNIT_HELPERS_H_