Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp153116rdb; Thu, 30 Nov 2023 00:38:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IEmJaOqJchc9JDcLN/5826/U2cOb1aA0Lb1PeO/zs6POaSWu1o/Y6RlH4h2yjGticu+v1Pg X-Received: by 2002:a17:902:720c:b0:1cf:d2c5:ae87 with SMTP id ba12-20020a170902720c00b001cfd2c5ae87mr11534034plb.11.1701333529727; Thu, 30 Nov 2023 00:38:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701333529; cv=none; d=google.com; s=arc-20160816; b=U/oSsPZSya1ImvpfQRNieckZgRpqxyq0Nky9ifP+MZg5wnqG/ero447I9pCuIn6pa8 qXUaUOdBAOa+WbFSmqu4nGS6eXab881zsgs1XefF/8s60Vc8Scbof7BkzKoSWd2lSFA2 6g/F7WfD6jVOFS5fYCg5naVt35R25rKMZI89OPomyitoqe/ET2PzcyYyxp/qZl52nVA3 HfQjA0ljZDzXnWyrVqruC6Y3ZkNau41a0wMUZ+jDISaQ2KZG+zPqxxTDJsIJM5VNyzkU Dx9ZgT7LELWbyYxguoJ+PXljajQrcj4Ztvh9j65+JHXcli409QMdUY8vBOMLHwuVDi9G zaHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=sVA52N6Tv2s684/l6ma5Nvp7JTXlrCDR7am1ZOKoNTE=; fh=Tg+iK/mtBMU5WI6r3+3lxZk/Qs91S9FQJyDwmQJPOUs=; b=Ajbv2GRLc04Anyyqo+Z6cyxu3w1EdNotaGgBf0qoeWv1UpOra1PCo7tfT/jU6dV25P 5mBXJ+KRImblynN6BEA7s3pyVngWYb4BMcQaXL7QGeDbfTLQO2hgY9d+CkN93w+YTCpX Hrn/0pCwKnrK1nUVgP0TPB1h3bODCPqkY/MwlYHkmXXYawyC9uUpRxrZ5gcrRIxw2/9s Ey/0UaHioj3YnioFSrHWJBZskMWJEbOc7XVtvMo3Pf49r51reoRCoHsZ5FGkmtsOsoc1 tCA+1E+PzaLijw5cHfd4Dd2oZh72IBgeA/cEbfpvuqMD434nmccmgJDRoIC9XWxvgebf zesQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jgFgs5aV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id e6-20020a17090301c600b001ce16902d3dsi777396plh.430.2023.11.30.00.38.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 00:38:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jgFgs5aV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 1E479802AF2F; Thu, 30 Nov 2023 00:38:48 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344967AbjK3Iif (ORCPT + 99 others); Thu, 30 Nov 2023 03:38:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344980AbjK3Iic (ORCPT ); Thu, 30 Nov 2023 03:38:32 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 429C610DB for ; Thu, 30 Nov 2023 00:38:38 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 91EB2C433D9; Thu, 30 Nov 2023 08:38:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701333517; bh=3f4PCKBuYDS/P+l0eRzusj//XC10y90AiINJ1mwoS5k=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=jgFgs5aVUNhfK5jkDO9qxnDY8SRhyumOnhAACdENGLLOYbGJQPVRyOmnK/ZGTJh7N e1TWBDOH78S7vCbQIuej8kLVz/UnZ86ksZaKP8ELS9Z3/kPjPl9zsGRtuiq6bXNw2H 1HOD4a0EoBB0VfDeTFq7WySrabzTPiZEIbZeAaXRBP7s56ZJJw77fvOCjjTgRNwsDs zMCYch69i3eu/l34rjgX8C42XoEEvkP+kNrBav+g4Vs5yfI0TEbKmrTsfsXsehYOkF Y1MLo/ca0CZ5EpM+87EOkEngCeR/qvlmPv2rG4WxaZahjMaOnBxZg1YsbeFWJn7yat hgxIC+mDareKQ== Date: Thu, 30 Nov 2023 09:38:35 +0100 From: Maxime Ripard To: =?utf-8?Q?Micha=C5=82?= Winiarski Cc: intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Rodrigo Vivi , Michal Wajdeczko , Maarten Lankhorst , Thomas Zimmermann , David Airlie , Daniel Vetter , Javier Martinez Canillas , =?utf-8?B?TWHDrXJh?= Canal Subject: Re: [PATCH 2/2] drm/tests: managed: Add a simple test for drmm_managed_release Message-ID: <3sio7356dxi5nbld2eupih3rzazvef4ebusrpdrhabnpg7pns4@5zxfnd4az4li> References: <20231129221412.1180549-1-michal.winiarski@intel.com> <20231129221412.1180549-3-michal.winiarski@intel.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="nal4dtzzote2yu2x" Content-Disposition: inline In-Reply-To: <20231129221412.1180549-3-michal.winiarski@intel.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 30 Nov 2023 00:38:48 -0800 (PST) --nal4dtzzote2yu2x Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi, Thanks for creating a test for that, that's really appreciated :) On Wed, Nov 29, 2023 at 11:14:12PM +0100, Micha=C5=82 Winiarski wrote: > Add a simple test that checks whether the action is indeed called right > away and that it is not called on the final drm_dev_put(). >=20 > Signed-off-by: Micha=C5=82 Winiarski > --- > drivers/gpu/drm/tests/drm_managed_test.c | 65 ++++++++++++++++++------ > 1 file changed, 50 insertions(+), 15 deletions(-) >=20 > diff --git a/drivers/gpu/drm/tests/drm_managed_test.c b/drivers/gpu/drm/t= ests/drm_managed_test.c > index 1652dca11d30c..a645ea42aee56 100644 > --- a/drivers/gpu/drm/tests/drm_managed_test.c > +++ b/drivers/gpu/drm/tests/drm_managed_test.c > @@ -12,6 +12,8 @@ > #define TEST_TIMEOUT_MS 100 > =20 > struct managed_test_priv { > + struct drm_device *drm; > + struct device *dev; > bool action_done; > wait_queue_head_t action_wq; > }; > @@ -26,42 +28,75 @@ static void drm_action(struct drm_device *drm, void *= ptr) > =20 > static void drm_test_managed_run_action(struct kunit *test) > { > - struct managed_test_priv *priv; > - struct drm_device *drm; > - struct device *dev; > + struct managed_test_priv *priv =3D test->priv; > int ret; > =20 > - priv =3D kunit_kzalloc(test, sizeof(*priv), GFP_KERNEL); > - KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv); > - init_waitqueue_head(&priv->action_wq); > + ret =3D drmm_add_action_or_reset(priv->drm, drm_action, priv); > + KUNIT_EXPECT_EQ(test, ret, 0); > =20 > - dev =3D drm_kunit_helper_alloc_device(test); > - KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev); > + ret =3D drm_dev_register(priv->drm, 0); > + KUNIT_ASSERT_EQ(test, ret, 0); > + > + drm_dev_unregister(priv->drm); > + drm_kunit_helper_free_device(test, priv->dev); I think we'll need two patches here, one to convert to having an init function, and one to actually add the new test, it's pretty confusing as it is. > =20 > - drm =3D __drm_kunit_helper_alloc_drm_device(test, dev, sizeof(*drm), 0,= DRIVER_MODESET); > - KUNIT_ASSERT_NOT_ERR_OR_NULL(test, drm); > + ret =3D wait_event_interruptible_timeout(priv->action_wq, priv->action_= done, > + msecs_to_jiffies(TEST_TIMEOUT_MS)); > + KUNIT_EXPECT_GT(test, ret, 0); > +} > =20 > - ret =3D drmm_add_action_or_reset(drm, drm_action, priv); > +static void drm_test_managed_release_action(struct kunit *test) > +{ > + struct managed_test_priv *priv =3D test->priv; > + int ret; > + > + ret =3D drmm_add_action_or_reset(priv->drm, drm_action, priv); > KUNIT_EXPECT_EQ(test, ret, 0); > =20 > - ret =3D drm_dev_register(drm, 0); > + ret =3D drm_dev_register(priv->drm, 0); > KUNIT_ASSERT_EQ(test, ret, 0); > =20 > - drm_dev_unregister(drm); > - drm_kunit_helper_free_device(test, dev); > + drmm_release_action(priv->drm, drm_action, priv); > + KUNIT_EXPECT_TRUE(test, priv->action_done); > + priv->action_done =3D false; > + > + drm_dev_unregister(priv->drm); > + drm_kunit_helper_free_device(test, priv->dev); > =20 > ret =3D wait_event_interruptible_timeout(priv->action_wq, priv->action_= done, > msecs_to_jiffies(TEST_TIMEOUT_MS)); > - KUNIT_EXPECT_GT(test, ret, 0); > + KUNIT_EXPECT_EQ(test, ret, 0); > +} > + > +static int drm_managed_test_init(struct kunit *test) > +{ > + struct managed_test_priv *priv; > + > + priv =3D kunit_kzalloc(test, sizeof(*priv), GFP_KERNEL); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv); > + init_waitqueue_head(&priv->action_wq); Also, I know that it was there before, but I'm not sure it's valid from a lifetime point of view. Or at least, we have to think hard enough about it to just remove that construct > + priv->dev =3D drm_kunit_helper_alloc_device(test); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv->dev); > + > + priv->drm =3D __drm_kunit_helper_alloc_drm_device(test, priv->dev, size= of(*priv->drm), > + 0, DRIVER_MODESET); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv->drm); For example by storing the drm_device struct in the priv structure directly, and thus everything will just work out. Maxime --nal4dtzzote2yu2x Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQRcEzekXsqa64kGDp7j7w1vZxhRxQUCZWhKCgAKCRDj7w1vZxhR xb1nAQDoFA7eK6k4vMebPc69Mn8c5dpfEOdMUwahXkSWMEL/vQD/WmVgGnKC+weA C/jQ19tn3571o1sQ/8HEgSUsEmQh3w0= =L/hk -----END PGP SIGNATURE----- --nal4dtzzote2yu2x--