From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.domeneshop.no (smtp.domeneshop.no [194.63.252.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AFBFA7B for ; Mon, 26 Sep 2022 12:16:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tronnes.org ; s=ds202112; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:From: References:Cc:To:Subject:MIME-Version:Date:Message-ID:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=VqqSqbLQ5CcNULSIxBrajieA3dWYiSKrZmW1RRtf2jA=; b=FMxfkov+yeLnAgQjafE8g9To1P clmuv1NwmM/GT/7KQvLpa2fgLvgElGaDMSjVapH/NX57xOh5Cfd1Tsa2tvazzp1xbT34/sWFZSsxf G+33Mez91WAezNG7jxhrzQJi1HJ4RMSbrEt/NhffiULFzLJkf0DT+Dy3y/PhaE6Mj51uSvpE8Q02X +Wg8OyhF/H9EumsY/eHK7iQo7QkDFQZMEHfp3Lnk5V1ZMMtekj/ajQLAvH6ws+wESFiM4pzDtspPW +H7msO0IVHArxJVz7tWFGwWvpRY3610HctqslpxOAPUco0dGkVPpdoTrG4RbBtVSg5vlQAtpJbMBK a6MHbVJw==; Received: from [2a01:799:961:d200:3946:6b45:3eef:d112] (port=65380) by smtp.domeneshop.no with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ocn1g-0001Me-Bi; Mon, 26 Sep 2022 14:15:56 +0200 Message-ID: <8eab2fc7-92de-fcc9-150b-ac3e7f293267@tronnes.org> Date: Mon, 26 Sep 2022 14:15:48 +0200 Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.13.1 Subject: Re: [PATCH v2 02/33] drm/tests: Add Kunit Helpers To: Maxime Ripard Cc: Jernej Skrabec , Rodrigo Vivi , Ben Skeggs , David Airlie , Joonas Lahtinen , Emma Anholt , Karol Herbst , Samuel Holland , Jani Nikula , Thomas Zimmermann , Daniel Vetter , Lyude Paul , Maarten Lankhorst , Tvrtko Ursulin , Chen-Yu Tsai , Hans de Goede , nouveau@lists.freedesktop.org, Geert Uytterhoeven , Dave Stevenson , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Phil Elwell , intel-gfx@lists.freedesktop.org, Dom Cobley , linux-sunxi@lists.linux.dev, Mateusz Kwiatkowski , dri-devel@lists.freedesktop.org, =?UTF-8?Q?Noralf_Tr=c3=b8nnes?= References: <20220728-rpi-analog-tv-properties-v2-0-f733a0ed9f90@cerno.tech> <20220728-rpi-analog-tv-properties-v2-2-f733a0ed9f90@cerno.tech> <3f7000ab-b845-a7e8-f215-02121da779b7@tronnes.org> <20220926093612.wvbou2srbo3uinar@houat> From: =?UTF-8?Q?Noralf_Tr=c3=b8nnes?= In-Reply-To: <20220926093612.wvbou2srbo3uinar@houat> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Den 26.09.2022 11.36, skrev Maxime Ripard: > Hi Noralf, > > On Sat, Sep 24, 2022 at 08:06:17PM +0200, Noralf Trønnes wrote: >> Den 24.09.2022 19.56, skrev Noralf Trønnes: >>> >>> >>> Den 22.09.2022 16.25, skrev Maxime Ripard: >>>> As the number of kunit tests in KMS grows further, we start to have >>>> multiple test suites that, for example, need to register a mock DRM >>>> driver to interact with the KMS function they are supposed to test. >>>> >>>> Let's add a file meant to provide those kind of helpers to avoid >>>> duplication. >>>> >>>> Signed-off-by: Maxime Ripard >>>> >>>> diff --git a/drivers/gpu/drm/tests/Makefile b/drivers/gpu/drm/tests/Makefile >>>> index 2d9f49b62ecb..b29ef1085cad 100644 >>>> --- a/drivers/gpu/drm/tests/Makefile >>>> +++ b/drivers/gpu/drm/tests/Makefile >>>> @@ -8,6 +8,7 @@ obj-$(CONFIG_DRM_KUNIT_TEST) += \ >>>> drm_format_helper_test.o \ >>>> drm_format_test.o \ >>>> drm_framebuffer_test.o \ >>>> + drm_kunit_helpers.o \ >>>> drm_mm_test.o \ >>>> drm_plane_helper_test.o \ >>>> drm_rect_test.o >>>> diff --git a/drivers/gpu/drm/tests/drm_kunit_helpers.c b/drivers/gpu/drm/tests/drm_kunit_helpers.c >>>> new file mode 100644 >>>> index 000000000000..7ebd620481c1 >>>> --- /dev/null >>>> +++ b/drivers/gpu/drm/tests/drm_kunit_helpers.c >>>> @@ -0,0 +1,54 @@ >>>> +#include >>>> +#include >>>> + >>>> +#include >>>> + >>>> +static const struct drm_mode_config_funcs drm_mode_config_funcs = { >>>> +}; >>>> + >>>> +static const struct drm_driver drm_mode_driver = { >>>> +}; >>>> + >>>> +static void drm_kunit_free_device(struct drm_device *drm, void *ptr) >>>> +{ >>>> + struct device *dev = ptr; >>>> + >>>> + root_device_unregister(dev); >>>> +} >>>> + >>>> +struct drm_device *drm_kunit_device_init(const char *name) >>>> +{ >>>> + struct drm_device *drm; >>>> + struct device *dev; >>>> + int ret; >>>> + >>>> + dev = root_device_register(name); >>>> + if (IS_ERR(dev)) >>>> + return ERR_CAST(dev); >>>> + >>>> + drm = drm_dev_alloc(&drm_mode_driver, dev); >>> >>> I can't find drm being freed anywhere? >>> Maybe you could assign it to drm->managed.final_kfree. > > There's a drm_dev_put in the test_exit hook which should free it. > I see now, there's a drmm_add_final_kfree() in drm_dev_alloc(). Noralf. >> Perhaps a better solution would be to use devm_drm_dev_alloc() and >> unregister the root device on exit. That avoids reaching into the drm >> managed internals and it looks more like a regular driver. > > But yeah, this is a good idea, I'll do it. > > Maxime