diff mbox series

drm: Fix oops in damage self-tests by mocking damage property

Message ID 20210730095251.4343-1-daniel.vetter@ffwll.ch (mailing list archive)
State New, archived
Headers show
Series drm: Fix oops in damage self-tests by mocking damage property | expand

Commit Message

Daniel Vetter July 30, 2021, 9:52 a.m. UTC
I've added a new check to make sure that drivers which insepct the
damage property have it set up correctly, but somehow missed that this
borke the damage selftest in the CI result noise.

Fix it up by mocking enough of drm_device and drm_plane so we can call
drm_plane_enable_fb_damage_clips() to make the new check happy.

Since there's a lot of duplicated mock code already copy-pasted into
each test I've also refactored this a bit to trim it down.

Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Fixes: c7fcbf251397 ("drm/plane: check that fb_damage is set up when used")
Cc: José Roberto de Souza <jose.souza@intel.com> (v1)
Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Cc: Gwan-gyeong Mun <gwan-gyeong.mun@intel.com>
Cc: José Roberto de Souza <jose.souza@intel.com>
Cc: Hans de Goede <hdegoede@redhat.com>
Cc: Daniel Vetter <daniel.vetter@intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
---
 .../drm/selftests/test-drm_damage_helper.c    | 287 +++++-------------
 1 file changed, 71 insertions(+), 216 deletions(-)

Comments

kernel test robot July 30, 2021, 2:19 p.m. UTC | #1
Hi Daniel,

I love your patch! Perhaps something to improve:

[auto build test WARNING on drm-tip/drm-tip]
[also build test WARNING on drm-intel/for-linux-next drm-exynos/exynos-drm-next tegra-drm/drm/tegra/for-next linus/master v5.14-rc3 next-20210729]
[cannot apply to drm/drm-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Daniel-Vetter/drm-Fix-oops-in-damage-self-tests-by-mocking-damage-property/20210730-175415
base:   git://anongit.freedesktop.org/drm/drm-tip drm-tip
config: i386-randconfig-s001-20210730 (attached as .config)
compiler: gcc-10 (Ubuntu 10.3.0-1ubuntu1~20.04) 10.3.0
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.3-341-g8af24329-dirty
        # https://github.com/0day-ci/linux/commit/cfe1add77c3c78aec60eb1645950c6aa2daf8b4d
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Daniel-Vetter/drm-Fix-oops-in-damage-self-tests-by-mocking-damage-property/20210730-175415
        git checkout cfe1add77c3c78aec60eb1645950c6aa2daf8b4d
        # save the attached .config to linux build tree
        make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=i386 SHELL=/bin/bash drivers/gpu/drm/selftests/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>


sparse warnings: (new ones prefixed by >>)
>> drivers/gpu/drm/selftests/test-drm_damage_helper.c:15:19: sparse: sparse: symbol 'mock_device' was not declared. Should it be static?
>> drivers/gpu/drm/selftests/test-drm_damage_helper.c:16:30: sparse: sparse: symbol 'mock_obj_props' was not declared. Should it be static?
>> drivers/gpu/drm/selftests/test-drm_damage_helper.c:17:18: sparse: sparse: symbol 'mock_plane' was not declared. Should it be static?
>> drivers/gpu/drm/selftests/test-drm_damage_helper.c:18:21: sparse: sparse: symbol 'mock_prop' was not declared. Should it be static?
   drivers/gpu/drm/selftests/test-drm_damage_helper.c:101:30: sparse: sparse: symbol 'fb' was not declared. Should it be static?
   drivers/gpu/drm/selftests/test-drm_damage_helper.c:259:23: sparse: sparse: Using plain integer as NULL pointer

Please review and possibly fold the followup patch.

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Maarten Lankhorst Aug. 2, 2021, 9:10 a.m. UTC | #2
Op 30-07-2021 om 11:52 schreef Daniel Vetter:
> I've added a new check to make sure that drivers which insepct the
> damage property have it set up correctly, but somehow missed that this
> borke the damage selftest in the CI result noise.
>
> Fix it up by mocking enough of drm_device and drm_plane so we can call
> drm_plane_enable_fb_damage_clips() to make the new check happy.
>
> Since there's a lot of duplicated mock code already copy-pasted into
> each test I've also refactored this a bit to trim it down.
>
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> Fixes: c7fcbf251397 ("drm/plane: check that fb_damage is set up when used")
> Cc: José Roberto de Souza <jose.souza@intel.com> (v1)
> Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
> Cc: Gwan-gyeong Mun <gwan-gyeong.mun@intel.com>
> Cc: José Roberto de Souza <jose.souza@intel.com>
> Cc: Hans de Goede <hdegoede@redhat.com>
> Cc: Daniel Vetter <daniel.vetter@intel.com>
> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> Cc: Maxime Ripard <mripard@kernel.org>
> Cc: Thomas Zimmermann <tzimmermann@suse.de>
> ---
>  .../drm/selftests/test-drm_damage_helper.c    | 287 +++++-------------
>  1 file changed, 71 insertions(+), 216 deletions(-)
>
> diff --git a/drivers/gpu/drm/selftests/test-drm_damage_helper.c b/drivers/gpu/drm/selftests/test-drm_damage_helper.c
> index 9d2bcdf8bc29..1b585c13e042 100644
> --- a/drivers/gpu/drm/selftests/test-drm_damage_helper.c
> +++ b/drivers/gpu/drm/selftests/test-drm_damage_helper.c
> @@ -6,9 +6,37 @@
>  #define pr_fmt(fmt) "drm_damage_helper: " fmt
>  
>  #include <drm/drm_damage_helper.h>
> +#include <drm/drm_plane.h>
> +#include <drm/drm_drv.h>
>  
>  #include "test-drm_modeset_common.h"
>  
> +struct drm_driver mock_driver;
> +struct drm_device mock_device;
> +struct drm_object_properties mock_obj_props;
> +struct drm_plane mock_plane;
> +struct drm_property mock_prop;
> +
> +static void mock_setup(struct drm_plane_state *state)
> +{
> +	static bool setup_done = false;
> +
> +	state->plane = &mock_plane;
> +
> +	if (setup_done)
> +		return;
> +
> +	/* just enough so that drm_plane_enable_fb_damage_clips() works */
> +	mock_device.driver = &mock_driver;
> +	mock_device.mode_config.prop_fb_damage_clips = &mock_prop;
> +	mock_plane.dev = &mock_device;
> +	mock_plane.base.properties = &mock_obj_props;
> +	mock_prop.base.id = 1; /* 0 is an invalid id */
> +	mock_prop.dev = &mock_device;
> +
> +	drm_plane_enable_fb_damage_clips(&mock_plane);
> +}
> +
>  static void set_plane_src(struct drm_plane_state *state, int x1, int y1, int x2,
>  			  int y2)
>  {
> @@ -70,23 +98,29 @@ static bool check_damage_clip(struct drm_plane_state *state, struct drm_rect *r,
>  	return true;
>  }
>  
> +const struct drm_framebuffer fb = {
> +	.width = 2048,
> +	.height = 2048
> +};
> +
> +/* common mocked structs many tests need */
> +#define MOCK_VARIABLES() \
> +	struct drm_plane_state old_state; \
> +	struct drm_plane_state state = { \
> +		.crtc = ZERO_SIZE_PTR, \
> +		.fb = (struct drm_framebuffer *) &fb, \
> +		.visible = true, \
> +	}; \
> +	mock_setup(&old_state); \
> +	mock_setup(&state);
> +
>  int igt_damage_iter_no_damage(void *ignored)
>  {
>  	struct drm_atomic_helper_damage_iter iter;
> -	struct drm_plane_state old_state;
>  	struct drm_rect clip;
>  	uint32_t num_hits = 0;
>  
> -	struct drm_framebuffer fb = {
> -		.width = 2048,
> -		.height = 2048
> -	};
> -
> -	struct drm_plane_state state = {
> -		.crtc = ZERO_SIZE_PTR,
> -		.fb = &fb,
> -		.visible = true,
> -	};
> +	MOCK_VARIABLES();
>  
>  	/* Plane src same as fb size. */
>  	set_plane_src(&old_state, 0, 0, fb.width << 16, fb.height << 16);
> @@ -104,20 +138,10 @@ int igt_damage_iter_no_damage(void *ignored)
>  int igt_damage_iter_no_damage_fractional_src(void *ignored)
>  {
>  	struct drm_atomic_helper_damage_iter iter;
> -	struct drm_plane_state old_state;
>  	struct drm_rect clip;
>  	uint32_t num_hits = 0;
>  
> -	struct drm_framebuffer fb = {
> -		.width = 2048,
> -		.height = 2048
> -	};
> -
> -	struct drm_plane_state state = {
> -		.crtc = ZERO_SIZE_PTR,
> -		.fb = &fb,
> -		.visible = true,
> -	};
> +	MOCK_VARIABLES();
>  
>  	/* Plane src has fractional part. */
>  	set_plane_src(&old_state, 0x3fffe, 0x3fffe,
> @@ -137,20 +161,10 @@ int igt_damage_iter_no_damage_fractional_src(void *ignored)
>  int igt_damage_iter_no_damage_src_moved(void *ignored)
>  {
>  	struct drm_atomic_helper_damage_iter iter;
> -	struct drm_plane_state old_state;
>  	struct drm_rect clip;
>  	uint32_t num_hits = 0;
>  
> -	struct drm_framebuffer fb = {
> -		.width = 2048,
> -		.height = 2048
> -	};
> -
> -	struct drm_plane_state state = {
> -		.crtc = ZERO_SIZE_PTR,
> -		.fb = &fb,
> -		.visible = true,
> -	};
> +	MOCK_VARIABLES();
>  
>  	/* Plane src moved since old plane state. */
>  	set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16);
> @@ -169,20 +183,10 @@ int igt_damage_iter_no_damage_src_moved(void *ignored)
>  int igt_damage_iter_no_damage_fractional_src_moved(void *ignored)
>  {
>  	struct drm_atomic_helper_damage_iter iter;
> -	struct drm_plane_state old_state;
>  	struct drm_rect clip;
>  	uint32_t num_hits = 0;
>  
> -	struct drm_framebuffer fb = {
> -		.width = 2048,
> -		.height = 2048
> -	};
> -
> -	struct drm_plane_state state = {
> -		.crtc = ZERO_SIZE_PTR,
> -		.fb = &fb,
> -		.visible = true,
> -	};
> +	MOCK_VARIABLES();
>  
>  	/* Plane src has fractional part and it moved since old plane state. */
>  	set_plane_src(&old_state, 0x3fffe, 0x3fffe,
> @@ -202,20 +206,14 @@ int igt_damage_iter_no_damage_fractional_src_moved(void *ignored)
>  int igt_damage_iter_no_damage_not_visible(void *ignored)
>  {
>  	struct drm_atomic_helper_damage_iter iter;
> -	struct drm_plane_state old_state;
>  	struct drm_rect clip;
>  	uint32_t num_hits = 0;
>  
> -	struct drm_framebuffer fb = {
> -		.width = 2048,
> -		.height = 2048
> -	};
> +	MOCK_VARIABLES();
>  
> -	struct drm_plane_state state = {
> -		.crtc = ZERO_SIZE_PTR,
> -		.fb = &fb,
> -		.visible = false,
> -	};
> +	state.visible = false;
> +
> +	mock_setup(&old_state);
>  
>  	set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16);
>  	set_plane_src(&state, 0, 0, 1024 << 16, 768 << 16);
> @@ -231,19 +229,12 @@ int igt_damage_iter_no_damage_not_visible(void *ignored)
>  int igt_damage_iter_no_damage_no_crtc(void *ignored)
>  {
>  	struct drm_atomic_helper_damage_iter iter;
> -	struct drm_plane_state old_state;
>  	struct drm_rect clip;
>  	uint32_t num_hits = 0;
>  
> -	struct drm_framebuffer fb = {
> -		.width = 2048,
> -		.height = 2048
> -	};
> +	MOCK_VARIABLES();
>  
> -	struct drm_plane_state state = {
> -		.crtc = 0,
> -		.fb = &fb,
> -	};
> +	state.crtc = NULL;
>  
>  	set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16);
>  	set_plane_src(&state, 0, 0, 1024 << 16, 768 << 16);
> @@ -268,6 +259,8 @@ int igt_damage_iter_no_damage_no_fb(void *ignored)
>  		.fb = 0,
>  	};
>  
> +	mock_setup(&old_state);
> +
>  	set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16);
>  	set_plane_src(&state, 0, 0, 1024 << 16, 768 << 16);
>  	drm_atomic_helper_damage_iter_init(&iter, &old_state, &state);
> @@ -282,22 +275,12 @@ int igt_damage_iter_no_damage_no_fb(void *ignored)
>  int igt_damage_iter_simple_damage(void *ignored)
>  {
>  	struct drm_atomic_helper_damage_iter iter;
> -	struct drm_plane_state old_state;
>  	struct drm_property_blob damage_blob;
>  	struct drm_mode_rect damage;
>  	struct drm_rect clip;
>  	uint32_t num_hits = 0;
>  
> -	struct drm_framebuffer fb = {
> -		.width = 2048,
> -		.height = 2048
> -	};
> -
> -	struct drm_plane_state state = {
> -		.crtc = ZERO_SIZE_PTR,
> -		.fb = &fb,
> -		.visible = true,
> -	};
> +	MOCK_VARIABLES();
>  
>  	set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16);
>  	set_plane_src(&state, 0, 0, 1024 << 16, 768 << 16);
> @@ -318,22 +301,12 @@ int igt_damage_iter_simple_damage(void *ignored)
>  int igt_damage_iter_single_damage(void *ignored)
>  {
>  	struct drm_atomic_helper_damage_iter iter;
> -	struct drm_plane_state old_state;
>  	struct drm_property_blob damage_blob;
>  	struct drm_mode_rect damage;
>  	struct drm_rect clip;
>  	uint32_t num_hits = 0;
>  
> -	struct drm_framebuffer fb = {
> -		.width = 2048,
> -		.height = 2048
> -	};
> -
> -	struct drm_plane_state state = {
> -		.crtc = ZERO_SIZE_PTR,
> -		.fb = &fb,
> -		.visible = true,
> -	};
> +	MOCK_VARIABLES();
>  
>  	set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16);
>  	set_plane_src(&state, 0, 0, 1024 << 16, 768 << 16);
> @@ -353,22 +326,12 @@ int igt_damage_iter_single_damage(void *ignored)
>  int igt_damage_iter_single_damage_intersect_src(void *ignored)
>  {
>  	struct drm_atomic_helper_damage_iter iter;
> -	struct drm_plane_state old_state;
>  	struct drm_property_blob damage_blob;
>  	struct drm_mode_rect damage;
>  	struct drm_rect clip;
>  	uint32_t num_hits = 0;
>  
> -	struct drm_framebuffer fb = {
> -		.width = 2048,
> -		.height = 2048
> -	};
> -
> -	struct drm_plane_state state = {
> -		.crtc = ZERO_SIZE_PTR,
> -		.fb = &fb,
> -		.visible = true,
> -	};
> +	MOCK_VARIABLES();
>  
>  	set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16);
>  	set_plane_src(&state, 0, 0, 1024 << 16, 768 << 16);
> @@ -389,22 +352,12 @@ int igt_damage_iter_single_damage_intersect_src(void *ignored)
>  int igt_damage_iter_single_damage_outside_src(void *ignored)
>  {
>  	struct drm_atomic_helper_damage_iter iter;
> -	struct drm_plane_state old_state;
>  	struct drm_property_blob damage_blob;
>  	struct drm_mode_rect damage;
>  	struct drm_rect clip;
>  	uint32_t num_hits = 0;
>  
> -	struct drm_framebuffer fb = {
> -		.width = 2048,
> -		.height = 2048
> -	};
> -
> -	struct drm_plane_state state = {
> -		.crtc = ZERO_SIZE_PTR,
> -		.fb = &fb,
> -		.visible = true,
> -	};
> +	MOCK_VARIABLES();
>  
>  	set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16);
>  	set_plane_src(&state, 0, 0, 1024 << 16, 768 << 16);
> @@ -424,22 +377,12 @@ int igt_damage_iter_single_damage_outside_src(void *ignored)
>  int igt_damage_iter_single_damage_fractional_src(void *ignored)
>  {
>  	struct drm_atomic_helper_damage_iter iter;
> -	struct drm_plane_state old_state;
>  	struct drm_property_blob damage_blob;
>  	struct drm_mode_rect damage;
>  	struct drm_rect clip;
>  	uint32_t num_hits = 0;
>  
> -	struct drm_framebuffer fb = {
> -		.width = 2048,
> -		.height = 2048
> -	};
> -
> -	struct drm_plane_state state = {
> -		.crtc = ZERO_SIZE_PTR,
> -		.fb = &fb,
> -		.visible = true,
> -	};
> +	MOCK_VARIABLES();
>  
>  	/* Plane src has fractional part. */
>  	set_plane_src(&old_state, 0x40002, 0x40002,
> @@ -462,22 +405,12 @@ int igt_damage_iter_single_damage_fractional_src(void *ignored)
>  int igt_damage_iter_single_damage_intersect_fractional_src(void *ignored)
>  {
>  	struct drm_atomic_helper_damage_iter iter;
> -	struct drm_plane_state old_state;
>  	struct drm_property_blob damage_blob;
>  	struct drm_mode_rect damage;
>  	struct drm_rect clip;
>  	uint32_t num_hits = 0;
>  
> -	struct drm_framebuffer fb = {
> -		.width = 2048,
> -		.height = 2048
> -	};
> -
> -	struct drm_plane_state state = {
> -		.crtc = ZERO_SIZE_PTR,
> -		.fb = &fb,
> -		.visible = true,
> -	};
> +	MOCK_VARIABLES();
>  
>  	/* Plane src has fractional part. */
>  	set_plane_src(&old_state, 0x40002, 0x40002,
> @@ -501,22 +434,12 @@ int igt_damage_iter_single_damage_intersect_fractional_src(void *ignored)
>  int igt_damage_iter_single_damage_outside_fractional_src(void *ignored)
>  {
>  	struct drm_atomic_helper_damage_iter iter;
> -	struct drm_plane_state old_state;
>  	struct drm_property_blob damage_blob;
>  	struct drm_mode_rect damage;
>  	struct drm_rect clip;
>  	uint32_t num_hits = 0;
>  
> -	struct drm_framebuffer fb = {
> -		.width = 2048,
> -		.height = 2048
> -	};
> -
> -	struct drm_plane_state state = {
> -		.crtc = ZERO_SIZE_PTR,
> -		.fb = &fb,
> -		.visible = true,
> -	};
> +	MOCK_VARIABLES();
>  
>  	/* Plane src has fractional part. */
>  	set_plane_src(&old_state, 0x40002, 0x40002,
> @@ -539,22 +462,12 @@ int igt_damage_iter_single_damage_outside_fractional_src(void *ignored)
>  int igt_damage_iter_single_damage_src_moved(void *ignored)
>  {
>  	struct drm_atomic_helper_damage_iter iter;
> -	struct drm_plane_state old_state;
>  	struct drm_property_blob damage_blob;
>  	struct drm_mode_rect damage;
>  	struct drm_rect clip;
>  	uint32_t num_hits = 0;
>  
> -	struct drm_framebuffer fb = {
> -		.width = 2048,
> -		.height = 2048
> -	};
> -
> -	struct drm_plane_state state = {
> -		.crtc = ZERO_SIZE_PTR,
> -		.fb = &fb,
> -		.visible = true,
> -	};
> +	MOCK_VARIABLES();
>  
>  	/* Plane src moved since old plane state. */
>  	set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16);
> @@ -576,22 +489,12 @@ int igt_damage_iter_single_damage_src_moved(void *ignored)
>  int igt_damage_iter_single_damage_fractional_src_moved(void *ignored)
>  {
>  	struct drm_atomic_helper_damage_iter iter;
> -	struct drm_plane_state old_state;
>  	struct drm_property_blob damage_blob;
>  	struct drm_mode_rect damage;
>  	struct drm_rect clip;
>  	uint32_t num_hits = 0;
>  
> -	struct drm_framebuffer fb = {
> -		.width = 2048,
> -		.height = 2048
> -	};
> -
> -	struct drm_plane_state state = {
> -		.crtc = ZERO_SIZE_PTR,
> -		.fb = &fb,
> -		.visible = true,
> -	};
> +	MOCK_VARIABLES();
>  
>  	/* Plane src with fractional part moved since old plane state. */
>  	set_plane_src(&old_state, 0x3fffe, 0x3fffe,
> @@ -615,22 +518,12 @@ int igt_damage_iter_single_damage_fractional_src_moved(void *ignored)
>  int igt_damage_iter_damage(void *ignored)
>  {
>  	struct drm_atomic_helper_damage_iter iter;
> -	struct drm_plane_state old_state;
>  	struct drm_property_blob damage_blob;
>  	struct drm_mode_rect damage[2];
>  	struct drm_rect clip;
>  	uint32_t num_hits = 0;
>  
> -	struct drm_framebuffer fb = {
> -		.width = 2048,
> -		.height = 2048
> -	};
> -
> -	struct drm_plane_state state = {
> -		.crtc = ZERO_SIZE_PTR,
> -		.fb = &fb,
> -		.visible = true,
> -	};
> +	MOCK_VARIABLES();
>  
>  	set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16);
>  	set_plane_src(&state, 0, 0, 1024 << 16, 768 << 16);
> @@ -656,22 +549,12 @@ int igt_damage_iter_damage(void *ignored)
>  int igt_damage_iter_damage_one_intersect(void *ignored)
>  {
>  	struct drm_atomic_helper_damage_iter iter;
> -	struct drm_plane_state old_state;
>  	struct drm_property_blob damage_blob;
>  	struct drm_mode_rect damage[2];
>  	struct drm_rect clip;
>  	uint32_t num_hits = 0;
>  
> -	struct drm_framebuffer fb = {
> -		.width = 2048,
> -		.height = 2048
> -	};
> -
> -	struct drm_plane_state state = {
> -		.crtc = ZERO_SIZE_PTR,
> -		.fb = &fb,
> -		.visible = true,
> -	};
> +	MOCK_VARIABLES();
>  
>  	set_plane_src(&old_state, 0x40002, 0x40002,
>  		      0x40002 + (1024 << 16), 0x40002 + (768 << 16));
> @@ -699,22 +582,12 @@ int igt_damage_iter_damage_one_intersect(void *ignored)
>  int igt_damage_iter_damage_one_outside(void *ignored)
>  {
>  	struct drm_atomic_helper_damage_iter iter;
> -	struct drm_plane_state old_state;
>  	struct drm_property_blob damage_blob;
>  	struct drm_mode_rect damage[2];
>  	struct drm_rect clip;
>  	uint32_t num_hits = 0;
>  
> -	struct drm_framebuffer fb = {
> -		.width = 2048,
> -		.height = 2048
> -	};
> -
> -	struct drm_plane_state state = {
> -		.crtc = ZERO_SIZE_PTR,
> -		.fb = &fb,
> -		.visible = true,
> -	};
> +	MOCK_VARIABLES();
>  
>  	set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16);
>  	set_plane_src(&state, 0, 0, 1024 << 16, 768 << 16);
> @@ -736,22 +609,12 @@ int igt_damage_iter_damage_one_outside(void *ignored)
>  int igt_damage_iter_damage_src_moved(void *ignored)
>  {
>  	struct drm_atomic_helper_damage_iter iter;
> -	struct drm_plane_state old_state;
>  	struct drm_property_blob damage_blob;
>  	struct drm_mode_rect damage[2];
>  	struct drm_rect clip;
>  	uint32_t num_hits = 0;
>  
> -	struct drm_framebuffer fb = {
> -		.width = 2048,
> -		.height = 2048
> -	};
> -
> -	struct drm_plane_state state = {
> -		.crtc = ZERO_SIZE_PTR,
> -		.fb = &fb,
> -		.visible = true,
> -	};
> +	MOCK_VARIABLES();
>  
>  	set_plane_src(&old_state, 0x40002, 0x40002,
>  		      0x40002 + (1024 << 16), 0x40002 + (768 << 16));
> @@ -775,22 +638,14 @@ int igt_damage_iter_damage_src_moved(void *ignored)
>  int igt_damage_iter_damage_not_visible(void *ignored)
>  {
>  	struct drm_atomic_helper_damage_iter iter;
> -	struct drm_plane_state old_state;
>  	struct drm_property_blob damage_blob;
>  	struct drm_mode_rect damage[2];
>  	struct drm_rect clip;
>  	uint32_t num_hits = 0;
>  
> -	struct drm_framebuffer fb = {
> -		.width = 2048,
> -		.height = 2048
> -	};
> +	MOCK_VARIABLES();
>  
> -	struct drm_plane_state state = {
> -		.crtc = ZERO_SIZE_PTR,
> -		.fb = &fb,
> -		.visible = false,
> -	};
> +	state.visible = false;
>  
>  	set_plane_src(&old_state, 0x40002, 0x40002,
>  		      0x40002 + (1024 << 16), 0x40002 + (768 << 16));

Reviewed-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/selftests/test-drm_damage_helper.c b/drivers/gpu/drm/selftests/test-drm_damage_helper.c
index 9d2bcdf8bc29..1b585c13e042 100644
--- a/drivers/gpu/drm/selftests/test-drm_damage_helper.c
+++ b/drivers/gpu/drm/selftests/test-drm_damage_helper.c
@@ -6,9 +6,37 @@ 
 #define pr_fmt(fmt) "drm_damage_helper: " fmt
 
 #include <drm/drm_damage_helper.h>
+#include <drm/drm_plane.h>
+#include <drm/drm_drv.h>
 
 #include "test-drm_modeset_common.h"
 
+struct drm_driver mock_driver;
+struct drm_device mock_device;
+struct drm_object_properties mock_obj_props;
+struct drm_plane mock_plane;
+struct drm_property mock_prop;
+
+static void mock_setup(struct drm_plane_state *state)
+{
+	static bool setup_done = false;
+
+	state->plane = &mock_plane;
+
+	if (setup_done)
+		return;
+
+	/* just enough so that drm_plane_enable_fb_damage_clips() works */
+	mock_device.driver = &mock_driver;
+	mock_device.mode_config.prop_fb_damage_clips = &mock_prop;
+	mock_plane.dev = &mock_device;
+	mock_plane.base.properties = &mock_obj_props;
+	mock_prop.base.id = 1; /* 0 is an invalid id */
+	mock_prop.dev = &mock_device;
+
+	drm_plane_enable_fb_damage_clips(&mock_plane);
+}
+
 static void set_plane_src(struct drm_plane_state *state, int x1, int y1, int x2,
 			  int y2)
 {
@@ -70,23 +98,29 @@  static bool check_damage_clip(struct drm_plane_state *state, struct drm_rect *r,
 	return true;
 }
 
+const struct drm_framebuffer fb = {
+	.width = 2048,
+	.height = 2048
+};
+
+/* common mocked structs many tests need */
+#define MOCK_VARIABLES() \
+	struct drm_plane_state old_state; \
+	struct drm_plane_state state = { \
+		.crtc = ZERO_SIZE_PTR, \
+		.fb = (struct drm_framebuffer *) &fb, \
+		.visible = true, \
+	}; \
+	mock_setup(&old_state); \
+	mock_setup(&state);
+
 int igt_damage_iter_no_damage(void *ignored)
 {
 	struct drm_atomic_helper_damage_iter iter;
-	struct drm_plane_state old_state;
 	struct drm_rect clip;
 	uint32_t num_hits = 0;
 
-	struct drm_framebuffer fb = {
-		.width = 2048,
-		.height = 2048
-	};
-
-	struct drm_plane_state state = {
-		.crtc = ZERO_SIZE_PTR,
-		.fb = &fb,
-		.visible = true,
-	};
+	MOCK_VARIABLES();
 
 	/* Plane src same as fb size. */
 	set_plane_src(&old_state, 0, 0, fb.width << 16, fb.height << 16);
@@ -104,20 +138,10 @@  int igt_damage_iter_no_damage(void *ignored)
 int igt_damage_iter_no_damage_fractional_src(void *ignored)
 {
 	struct drm_atomic_helper_damage_iter iter;
-	struct drm_plane_state old_state;
 	struct drm_rect clip;
 	uint32_t num_hits = 0;
 
-	struct drm_framebuffer fb = {
-		.width = 2048,
-		.height = 2048
-	};
-
-	struct drm_plane_state state = {
-		.crtc = ZERO_SIZE_PTR,
-		.fb = &fb,
-		.visible = true,
-	};
+	MOCK_VARIABLES();
 
 	/* Plane src has fractional part. */
 	set_plane_src(&old_state, 0x3fffe, 0x3fffe,
@@ -137,20 +161,10 @@  int igt_damage_iter_no_damage_fractional_src(void *ignored)
 int igt_damage_iter_no_damage_src_moved(void *ignored)
 {
 	struct drm_atomic_helper_damage_iter iter;
-	struct drm_plane_state old_state;
 	struct drm_rect clip;
 	uint32_t num_hits = 0;
 
-	struct drm_framebuffer fb = {
-		.width = 2048,
-		.height = 2048
-	};
-
-	struct drm_plane_state state = {
-		.crtc = ZERO_SIZE_PTR,
-		.fb = &fb,
-		.visible = true,
-	};
+	MOCK_VARIABLES();
 
 	/* Plane src moved since old plane state. */
 	set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16);
@@ -169,20 +183,10 @@  int igt_damage_iter_no_damage_src_moved(void *ignored)
 int igt_damage_iter_no_damage_fractional_src_moved(void *ignored)
 {
 	struct drm_atomic_helper_damage_iter iter;
-	struct drm_plane_state old_state;
 	struct drm_rect clip;
 	uint32_t num_hits = 0;
 
-	struct drm_framebuffer fb = {
-		.width = 2048,
-		.height = 2048
-	};
-
-	struct drm_plane_state state = {
-		.crtc = ZERO_SIZE_PTR,
-		.fb = &fb,
-		.visible = true,
-	};
+	MOCK_VARIABLES();
 
 	/* Plane src has fractional part and it moved since old plane state. */
 	set_plane_src(&old_state, 0x3fffe, 0x3fffe,
@@ -202,20 +206,14 @@  int igt_damage_iter_no_damage_fractional_src_moved(void *ignored)
 int igt_damage_iter_no_damage_not_visible(void *ignored)
 {
 	struct drm_atomic_helper_damage_iter iter;
-	struct drm_plane_state old_state;
 	struct drm_rect clip;
 	uint32_t num_hits = 0;
 
-	struct drm_framebuffer fb = {
-		.width = 2048,
-		.height = 2048
-	};
+	MOCK_VARIABLES();
 
-	struct drm_plane_state state = {
-		.crtc = ZERO_SIZE_PTR,
-		.fb = &fb,
-		.visible = false,
-	};
+	state.visible = false;
+
+	mock_setup(&old_state);
 
 	set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16);
 	set_plane_src(&state, 0, 0, 1024 << 16, 768 << 16);
@@ -231,19 +229,12 @@  int igt_damage_iter_no_damage_not_visible(void *ignored)
 int igt_damage_iter_no_damage_no_crtc(void *ignored)
 {
 	struct drm_atomic_helper_damage_iter iter;
-	struct drm_plane_state old_state;
 	struct drm_rect clip;
 	uint32_t num_hits = 0;
 
-	struct drm_framebuffer fb = {
-		.width = 2048,
-		.height = 2048
-	};
+	MOCK_VARIABLES();
 
-	struct drm_plane_state state = {
-		.crtc = 0,
-		.fb = &fb,
-	};
+	state.crtc = NULL;
 
 	set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16);
 	set_plane_src(&state, 0, 0, 1024 << 16, 768 << 16);
@@ -268,6 +259,8 @@  int igt_damage_iter_no_damage_no_fb(void *ignored)
 		.fb = 0,
 	};
 
+	mock_setup(&old_state);
+
 	set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16);
 	set_plane_src(&state, 0, 0, 1024 << 16, 768 << 16);
 	drm_atomic_helper_damage_iter_init(&iter, &old_state, &state);
@@ -282,22 +275,12 @@  int igt_damage_iter_no_damage_no_fb(void *ignored)
 int igt_damage_iter_simple_damage(void *ignored)
 {
 	struct drm_atomic_helper_damage_iter iter;
-	struct drm_plane_state old_state;
 	struct drm_property_blob damage_blob;
 	struct drm_mode_rect damage;
 	struct drm_rect clip;
 	uint32_t num_hits = 0;
 
-	struct drm_framebuffer fb = {
-		.width = 2048,
-		.height = 2048
-	};
-
-	struct drm_plane_state state = {
-		.crtc = ZERO_SIZE_PTR,
-		.fb = &fb,
-		.visible = true,
-	};
+	MOCK_VARIABLES();
 
 	set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16);
 	set_plane_src(&state, 0, 0, 1024 << 16, 768 << 16);
@@ -318,22 +301,12 @@  int igt_damage_iter_simple_damage(void *ignored)
 int igt_damage_iter_single_damage(void *ignored)
 {
 	struct drm_atomic_helper_damage_iter iter;
-	struct drm_plane_state old_state;
 	struct drm_property_blob damage_blob;
 	struct drm_mode_rect damage;
 	struct drm_rect clip;
 	uint32_t num_hits = 0;
 
-	struct drm_framebuffer fb = {
-		.width = 2048,
-		.height = 2048
-	};
-
-	struct drm_plane_state state = {
-		.crtc = ZERO_SIZE_PTR,
-		.fb = &fb,
-		.visible = true,
-	};
+	MOCK_VARIABLES();
 
 	set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16);
 	set_plane_src(&state, 0, 0, 1024 << 16, 768 << 16);
@@ -353,22 +326,12 @@  int igt_damage_iter_single_damage(void *ignored)
 int igt_damage_iter_single_damage_intersect_src(void *ignored)
 {
 	struct drm_atomic_helper_damage_iter iter;
-	struct drm_plane_state old_state;
 	struct drm_property_blob damage_blob;
 	struct drm_mode_rect damage;
 	struct drm_rect clip;
 	uint32_t num_hits = 0;
 
-	struct drm_framebuffer fb = {
-		.width = 2048,
-		.height = 2048
-	};
-
-	struct drm_plane_state state = {
-		.crtc = ZERO_SIZE_PTR,
-		.fb = &fb,
-		.visible = true,
-	};
+	MOCK_VARIABLES();
 
 	set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16);
 	set_plane_src(&state, 0, 0, 1024 << 16, 768 << 16);
@@ -389,22 +352,12 @@  int igt_damage_iter_single_damage_intersect_src(void *ignored)
 int igt_damage_iter_single_damage_outside_src(void *ignored)
 {
 	struct drm_atomic_helper_damage_iter iter;
-	struct drm_plane_state old_state;
 	struct drm_property_blob damage_blob;
 	struct drm_mode_rect damage;
 	struct drm_rect clip;
 	uint32_t num_hits = 0;
 
-	struct drm_framebuffer fb = {
-		.width = 2048,
-		.height = 2048
-	};
-
-	struct drm_plane_state state = {
-		.crtc = ZERO_SIZE_PTR,
-		.fb = &fb,
-		.visible = true,
-	};
+	MOCK_VARIABLES();
 
 	set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16);
 	set_plane_src(&state, 0, 0, 1024 << 16, 768 << 16);
@@ -424,22 +377,12 @@  int igt_damage_iter_single_damage_outside_src(void *ignored)
 int igt_damage_iter_single_damage_fractional_src(void *ignored)
 {
 	struct drm_atomic_helper_damage_iter iter;
-	struct drm_plane_state old_state;
 	struct drm_property_blob damage_blob;
 	struct drm_mode_rect damage;
 	struct drm_rect clip;
 	uint32_t num_hits = 0;
 
-	struct drm_framebuffer fb = {
-		.width = 2048,
-		.height = 2048
-	};
-
-	struct drm_plane_state state = {
-		.crtc = ZERO_SIZE_PTR,
-		.fb = &fb,
-		.visible = true,
-	};
+	MOCK_VARIABLES();
 
 	/* Plane src has fractional part. */
 	set_plane_src(&old_state, 0x40002, 0x40002,
@@ -462,22 +405,12 @@  int igt_damage_iter_single_damage_fractional_src(void *ignored)
 int igt_damage_iter_single_damage_intersect_fractional_src(void *ignored)
 {
 	struct drm_atomic_helper_damage_iter iter;
-	struct drm_plane_state old_state;
 	struct drm_property_blob damage_blob;
 	struct drm_mode_rect damage;
 	struct drm_rect clip;
 	uint32_t num_hits = 0;
 
-	struct drm_framebuffer fb = {
-		.width = 2048,
-		.height = 2048
-	};
-
-	struct drm_plane_state state = {
-		.crtc = ZERO_SIZE_PTR,
-		.fb = &fb,
-		.visible = true,
-	};
+	MOCK_VARIABLES();
 
 	/* Plane src has fractional part. */
 	set_plane_src(&old_state, 0x40002, 0x40002,
@@ -501,22 +434,12 @@  int igt_damage_iter_single_damage_intersect_fractional_src(void *ignored)
 int igt_damage_iter_single_damage_outside_fractional_src(void *ignored)
 {
 	struct drm_atomic_helper_damage_iter iter;
-	struct drm_plane_state old_state;
 	struct drm_property_blob damage_blob;
 	struct drm_mode_rect damage;
 	struct drm_rect clip;
 	uint32_t num_hits = 0;
 
-	struct drm_framebuffer fb = {
-		.width = 2048,
-		.height = 2048
-	};
-
-	struct drm_plane_state state = {
-		.crtc = ZERO_SIZE_PTR,
-		.fb = &fb,
-		.visible = true,
-	};
+	MOCK_VARIABLES();
 
 	/* Plane src has fractional part. */
 	set_plane_src(&old_state, 0x40002, 0x40002,
@@ -539,22 +462,12 @@  int igt_damage_iter_single_damage_outside_fractional_src(void *ignored)
 int igt_damage_iter_single_damage_src_moved(void *ignored)
 {
 	struct drm_atomic_helper_damage_iter iter;
-	struct drm_plane_state old_state;
 	struct drm_property_blob damage_blob;
 	struct drm_mode_rect damage;
 	struct drm_rect clip;
 	uint32_t num_hits = 0;
 
-	struct drm_framebuffer fb = {
-		.width = 2048,
-		.height = 2048
-	};
-
-	struct drm_plane_state state = {
-		.crtc = ZERO_SIZE_PTR,
-		.fb = &fb,
-		.visible = true,
-	};
+	MOCK_VARIABLES();
 
 	/* Plane src moved since old plane state. */
 	set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16);
@@ -576,22 +489,12 @@  int igt_damage_iter_single_damage_src_moved(void *ignored)
 int igt_damage_iter_single_damage_fractional_src_moved(void *ignored)
 {
 	struct drm_atomic_helper_damage_iter iter;
-	struct drm_plane_state old_state;
 	struct drm_property_blob damage_blob;
 	struct drm_mode_rect damage;
 	struct drm_rect clip;
 	uint32_t num_hits = 0;
 
-	struct drm_framebuffer fb = {
-		.width = 2048,
-		.height = 2048
-	};
-
-	struct drm_plane_state state = {
-		.crtc = ZERO_SIZE_PTR,
-		.fb = &fb,
-		.visible = true,
-	};
+	MOCK_VARIABLES();
 
 	/* Plane src with fractional part moved since old plane state. */
 	set_plane_src(&old_state, 0x3fffe, 0x3fffe,
@@ -615,22 +518,12 @@  int igt_damage_iter_single_damage_fractional_src_moved(void *ignored)
 int igt_damage_iter_damage(void *ignored)
 {
 	struct drm_atomic_helper_damage_iter iter;
-	struct drm_plane_state old_state;
 	struct drm_property_blob damage_blob;
 	struct drm_mode_rect damage[2];
 	struct drm_rect clip;
 	uint32_t num_hits = 0;
 
-	struct drm_framebuffer fb = {
-		.width = 2048,
-		.height = 2048
-	};
-
-	struct drm_plane_state state = {
-		.crtc = ZERO_SIZE_PTR,
-		.fb = &fb,
-		.visible = true,
-	};
+	MOCK_VARIABLES();
 
 	set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16);
 	set_plane_src(&state, 0, 0, 1024 << 16, 768 << 16);
@@ -656,22 +549,12 @@  int igt_damage_iter_damage(void *ignored)
 int igt_damage_iter_damage_one_intersect(void *ignored)
 {
 	struct drm_atomic_helper_damage_iter iter;
-	struct drm_plane_state old_state;
 	struct drm_property_blob damage_blob;
 	struct drm_mode_rect damage[2];
 	struct drm_rect clip;
 	uint32_t num_hits = 0;
 
-	struct drm_framebuffer fb = {
-		.width = 2048,
-		.height = 2048
-	};
-
-	struct drm_plane_state state = {
-		.crtc = ZERO_SIZE_PTR,
-		.fb = &fb,
-		.visible = true,
-	};
+	MOCK_VARIABLES();
 
 	set_plane_src(&old_state, 0x40002, 0x40002,
 		      0x40002 + (1024 << 16), 0x40002 + (768 << 16));
@@ -699,22 +582,12 @@  int igt_damage_iter_damage_one_intersect(void *ignored)
 int igt_damage_iter_damage_one_outside(void *ignored)
 {
 	struct drm_atomic_helper_damage_iter iter;
-	struct drm_plane_state old_state;
 	struct drm_property_blob damage_blob;
 	struct drm_mode_rect damage[2];
 	struct drm_rect clip;
 	uint32_t num_hits = 0;
 
-	struct drm_framebuffer fb = {
-		.width = 2048,
-		.height = 2048
-	};
-
-	struct drm_plane_state state = {
-		.crtc = ZERO_SIZE_PTR,
-		.fb = &fb,
-		.visible = true,
-	};
+	MOCK_VARIABLES();
 
 	set_plane_src(&old_state, 0, 0, 1024 << 16, 768 << 16);
 	set_plane_src(&state, 0, 0, 1024 << 16, 768 << 16);
@@ -736,22 +609,12 @@  int igt_damage_iter_damage_one_outside(void *ignored)
 int igt_damage_iter_damage_src_moved(void *ignored)
 {
 	struct drm_atomic_helper_damage_iter iter;
-	struct drm_plane_state old_state;
 	struct drm_property_blob damage_blob;
 	struct drm_mode_rect damage[2];
 	struct drm_rect clip;
 	uint32_t num_hits = 0;
 
-	struct drm_framebuffer fb = {
-		.width = 2048,
-		.height = 2048
-	};
-
-	struct drm_plane_state state = {
-		.crtc = ZERO_SIZE_PTR,
-		.fb = &fb,
-		.visible = true,
-	};
+	MOCK_VARIABLES();
 
 	set_plane_src(&old_state, 0x40002, 0x40002,
 		      0x40002 + (1024 << 16), 0x40002 + (768 << 16));
@@ -775,22 +638,14 @@  int igt_damage_iter_damage_src_moved(void *ignored)
 int igt_damage_iter_damage_not_visible(void *ignored)
 {
 	struct drm_atomic_helper_damage_iter iter;
-	struct drm_plane_state old_state;
 	struct drm_property_blob damage_blob;
 	struct drm_mode_rect damage[2];
 	struct drm_rect clip;
 	uint32_t num_hits = 0;
 
-	struct drm_framebuffer fb = {
-		.width = 2048,
-		.height = 2048
-	};
+	MOCK_VARIABLES();
 
-	struct drm_plane_state state = {
-		.crtc = ZERO_SIZE_PTR,
-		.fb = &fb,
-		.visible = false,
-	};
+	state.visible = false;
 
 	set_plane_src(&old_state, 0x40002, 0x40002,
 		      0x40002 + (1024 << 16), 0x40002 + (768 << 16));