Re: [PATCH v6 9/9] drm/selftests: Add tests for drm_internal_framebuffer_create

2018-10-30 Thread Daniel Vetter
On Mon, Oct 29, 2018 at 05:14:44PM +, Alexandru-Cosmin Gheorghe wrote:
> Add tests that verify that drm_internal_framebuffer_create creates
> buffers correctly by creating a dummy drm_device with a mock function
> for the fb_create callback.
> 
> To decide if a buffer has been created or not it just checks if
> fb_create callback has been called for the particular drm_mode_fb_cmd2
> that's being tested.
> 
> Signed-off-by: Alexandru Gheorghe 

Again adding Brendan as fyi, lots of use-cases for the mocking
infrastructure from kunit in these unit tests here (greg for
buffer_created).

> ---
>  drivers/gpu/drm/selftests/Makefile|   2 +-
>  .../gpu/drm/selftests/drm_modeset_selftests.h |   1 +
>  .../gpu/drm/selftests/test-drm_framebuffer.c  | 344 ++
>  .../drm/selftests/test-drm_modeset_common.h   |   1 +
>  4 files changed, 347 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/gpu/drm/selftests/test-drm_framebuffer.c
> 
> diff --git a/drivers/gpu/drm/selftests/Makefile 
> b/drivers/gpu/drm/selftests/Makefile
> index 07b4f88b422a..383d8d6c5847 100644
> --- a/drivers/gpu/drm/selftests/Makefile
> +++ b/drivers/gpu/drm/selftests/Makefile
> @@ -1,4 +1,4 @@
>  test-drm_modeset-y := test-drm_modeset_common.o test-drm_plane_helper.o \
> -  test-drm_format.o
> +  test-drm_format.o test-drm_framebuffer.o
>  
>  obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o test-drm_modeset.o
> diff --git a/drivers/gpu/drm/selftests/drm_modeset_selftests.h 
> b/drivers/gpu/drm/selftests/drm_modeset_selftests.h
> index 4e203ac8c134..92601defd8f6 100644
> --- a/drivers/gpu/drm/selftests/drm_modeset_selftests.h
> +++ b/drivers/gpu/drm/selftests/drm_modeset_selftests.h
> @@ -10,3 +10,4 @@ selftest(check_plane_state, igt_check_plane_state)
>  selftest(check_drm_format_block_width, igt_check_drm_format_block_width)
>  selftest(check_drm_format_block_height, igt_check_drm_format_block_height)
>  selftest(check_drm_format_min_pitch, igt_check_drm_format_min_pitch)
> +selftest(check_drm_framebuffer_create, igt_check_drm_framebuffer_create)
> diff --git a/drivers/gpu/drm/selftests/test-drm_framebuffer.c 
> b/drivers/gpu/drm/selftests/test-drm_framebuffer.c
> new file mode 100644
> index ..3098435678af
> --- /dev/null
> +++ b/drivers/gpu/drm/selftests/test-drm_framebuffer.c
> @@ -0,0 +1,344 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Test cases for the drm_framebuffer functions
> + */
> +
> +#include 
> +#include "../drm_crtc_internal.h"
> +
> +#include "test-drm_modeset_common.h"
> +
> +#define MIN_WIDTH 4
> +#define MAX_WIDTH 4096
> +#define MIN_HEIGHT 4
> +#define MAX_HEIGHT 4096
> +
> +struct drm_framebuffer_test {
> + int buffer_created;
> + struct drm_mode_fb_cmd2 cmd;
> + const char *name;
> +};
> +
> +static struct drm_framebuffer_test createbuffer_tests[] = {
> +{ .buffer_created = 1, .name = "ABGR normal sizes",
> + .cmd = { .width = 600, .height = 600, .pixel_format = 
> DRM_FORMAT_ABGR,
> +  .handles = { 1, 0, 0 }, .pitches = { 4 * 600, 0, 0 },
> + }
> +},
> +{ .buffer_created = 1, .name = "ABGR max sizes",
> + .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = 
> DRM_FORMAT_ABGR,
> +  .handles = { 1, 0, 0 }, .pitches = { 4 * MAX_WIDTH, 0, 0 },
> + }
> +},
> +{ .buffer_created = 1, .name = "ABGR pitch greater than min required",
> + .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = 
> DRM_FORMAT_ABGR,
> +  .handles = { 1, 0, 0 }, .pitches = { 4 * MAX_WIDTH + 1, 0, 0 },
> + }
> +},
> +{ .buffer_created = 0, .name = "ABGR pitch less than min required",
> + .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = 
> DRM_FORMAT_ABGR,
> +  .handles = { 1, 0, 0 }, .pitches = { 4 * MAX_WIDTH - 1, 0, 0 },
> + }
> +},
> +{ .buffer_created = 0, .name = "ABGR Invalid width",
> + .cmd = { .width = MAX_WIDTH + 1, .height = MAX_HEIGHT, .pixel_format = 
> DRM_FORMAT_ABGR,
> +  .handles = { 1, 0, 0 }, .pitches = { 4 * (MAX_WIDTH + 1), 0, 0 
> },
> + }
> +},
> +{ .buffer_created = 0, .name = "ABGR Invalid buffer handle",
> + .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = 
> DRM_FORMAT_ABGR,
> +  .handles = { 0, 0, 0 }, .pitches = { 4 * MAX_WIDTH, 0, 0 },
> + }
> +},
> +{ .buffer_created = 0, .name = "No pixel format",
> + .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = 0,
> +  .handles = { 1, 0, 0 }, .pitches = { 4 * MAX_WIDTH, 0, 0 },
> + }
> +},
> +{ .buffer_created = 0, .name = "ABGR Width 0",
> + .cmd = { .width = 0, .height = MAX_HEIGHT, .pixel_format = 
> DRM_FORMAT_ABGR,
> +  .handles = { 1, 0, 0 }, .pitches = { 4 * MAX_WIDTH, 0, 0 },
> + }
> +},
> +{ .buffer_created = 0, .name = "ABGR Height 0",
> + .cmd = { .width = 

[PATCH v6 9/9] drm/selftests: Add tests for drm_internal_framebuffer_create

2018-10-29 Thread Alexandru-Cosmin Gheorghe
Add tests that verify that drm_internal_framebuffer_create creates
buffers correctly by creating a dummy drm_device with a mock function
for the fb_create callback.

To decide if a buffer has been created or not it just checks if
fb_create callback has been called for the particular drm_mode_fb_cmd2
that's being tested.

Signed-off-by: Alexandru Gheorghe 
---
 drivers/gpu/drm/selftests/Makefile|   2 +-
 .../gpu/drm/selftests/drm_modeset_selftests.h |   1 +
 .../gpu/drm/selftests/test-drm_framebuffer.c  | 344 ++
 .../drm/selftests/test-drm_modeset_common.h   |   1 +
 4 files changed, 347 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/selftests/test-drm_framebuffer.c

diff --git a/drivers/gpu/drm/selftests/Makefile 
b/drivers/gpu/drm/selftests/Makefile
index 07b4f88b422a..383d8d6c5847 100644
--- a/drivers/gpu/drm/selftests/Makefile
+++ b/drivers/gpu/drm/selftests/Makefile
@@ -1,4 +1,4 @@
 test-drm_modeset-y := test-drm_modeset_common.o test-drm_plane_helper.o \
-  test-drm_format.o
+  test-drm_format.o test-drm_framebuffer.o
 
 obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o test-drm_modeset.o
diff --git a/drivers/gpu/drm/selftests/drm_modeset_selftests.h 
b/drivers/gpu/drm/selftests/drm_modeset_selftests.h
index 4e203ac8c134..92601defd8f6 100644
--- a/drivers/gpu/drm/selftests/drm_modeset_selftests.h
+++ b/drivers/gpu/drm/selftests/drm_modeset_selftests.h
@@ -10,3 +10,4 @@ selftest(check_plane_state, igt_check_plane_state)
 selftest(check_drm_format_block_width, igt_check_drm_format_block_width)
 selftest(check_drm_format_block_height, igt_check_drm_format_block_height)
 selftest(check_drm_format_min_pitch, igt_check_drm_format_min_pitch)
+selftest(check_drm_framebuffer_create, igt_check_drm_framebuffer_create)
diff --git a/drivers/gpu/drm/selftests/test-drm_framebuffer.c 
b/drivers/gpu/drm/selftests/test-drm_framebuffer.c
new file mode 100644
index ..3098435678af
--- /dev/null
+++ b/drivers/gpu/drm/selftests/test-drm_framebuffer.c
@@ -0,0 +1,344 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Test cases for the drm_framebuffer functions
+ */
+
+#include 
+#include "../drm_crtc_internal.h"
+
+#include "test-drm_modeset_common.h"
+
+#define MIN_WIDTH 4
+#define MAX_WIDTH 4096
+#define MIN_HEIGHT 4
+#define MAX_HEIGHT 4096
+
+struct drm_framebuffer_test {
+   int buffer_created;
+   struct drm_mode_fb_cmd2 cmd;
+   const char *name;
+};
+
+static struct drm_framebuffer_test createbuffer_tests[] = {
+{ .buffer_created = 1, .name = "ABGR normal sizes",
+   .cmd = { .width = 600, .height = 600, .pixel_format = 
DRM_FORMAT_ABGR,
+.handles = { 1, 0, 0 }, .pitches = { 4 * 600, 0, 0 },
+   }
+},
+{ .buffer_created = 1, .name = "ABGR max sizes",
+   .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = 
DRM_FORMAT_ABGR,
+.handles = { 1, 0, 0 }, .pitches = { 4 * MAX_WIDTH, 0, 0 },
+   }
+},
+{ .buffer_created = 1, .name = "ABGR pitch greater than min required",
+   .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = 
DRM_FORMAT_ABGR,
+.handles = { 1, 0, 0 }, .pitches = { 4 * MAX_WIDTH + 1, 0, 0 },
+   }
+},
+{ .buffer_created = 0, .name = "ABGR pitch less than min required",
+   .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = 
DRM_FORMAT_ABGR,
+.handles = { 1, 0, 0 }, .pitches = { 4 * MAX_WIDTH - 1, 0, 0 },
+   }
+},
+{ .buffer_created = 0, .name = "ABGR Invalid width",
+   .cmd = { .width = MAX_WIDTH + 1, .height = MAX_HEIGHT, .pixel_format = 
DRM_FORMAT_ABGR,
+.handles = { 1, 0, 0 }, .pitches = { 4 * (MAX_WIDTH + 1), 0, 0 
},
+   }
+},
+{ .buffer_created = 0, .name = "ABGR Invalid buffer handle",
+   .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = 
DRM_FORMAT_ABGR,
+.handles = { 0, 0, 0 }, .pitches = { 4 * MAX_WIDTH, 0, 0 },
+   }
+},
+{ .buffer_created = 0, .name = "No pixel format",
+   .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = 0,
+.handles = { 1, 0, 0 }, .pitches = { 4 * MAX_WIDTH, 0, 0 },
+   }
+},
+{ .buffer_created = 0, .name = "ABGR Width 0",
+   .cmd = { .width = 0, .height = MAX_HEIGHT, .pixel_format = 
DRM_FORMAT_ABGR,
+.handles = { 1, 0, 0 }, .pitches = { 4 * MAX_WIDTH, 0, 0 },
+   }
+},
+{ .buffer_created = 0, .name = "ABGR Height 0",
+   .cmd = { .width = MAX_WIDTH, .height = 0, .pixel_format = 
DRM_FORMAT_ABGR,
+.handles = { 1, 0, 0 }, .pitches = { 4 * MAX_WIDTH, 0, 0 },
+   }
+},
+{ .buffer_created = 0, .name = "ABGR Out of bound height * pitch 
combination",
+   .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = 
DRM_FORMAT_ABGR,
+.handles = { 1, 0, 0 }, .offsets = { UINT_MAX - 1,