OSDN Git Service

drm/selftests: Add tests for drm_format_info* helpers
authorAlexandru Gheorghe <alexandru-cosmin.gheorghe@arm.com>
Thu, 1 Nov 2018 15:11:32 +0000 (15:11 +0000)
committerAlexandru Gheorghe <alexandru-cosmin.gheorghe@arm.com>
Fri, 2 Nov 2018 09:57:58 +0000 (09:57 +0000)
Add selftests for the following newly added functions:
 - drm_format_info_block_width
 - drm_format_info_block_height
 - drm_format_info_min_pitch

Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Alexandru Gheorghe <alexandru-cosmin.gheorghe@arm.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20181101151051.1509-6-alexandru-cosmin.gheorghe@arm.com
drivers/gpu/drm/selftests/Makefile
drivers/gpu/drm/selftests/drm_modeset_selftests.h
drivers/gpu/drm/selftests/test-drm_format.c [new file with mode: 0644]
drivers/gpu/drm/selftests/test-drm_modeset_common.h

index 7e65819..07b4f88 100644 (file)
@@ -1,3 +1,4 @@
-test-drm_modeset-y := test-drm_modeset_common.o test-drm_plane_helper.o
+test-drm_modeset-y := test-drm_modeset_common.o test-drm_plane_helper.o \
+                      test-drm_format.o
 
 obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o test-drm_modeset.o
index 9771290..4e203ac 100644 (file)
@@ -7,3 +7,6 @@
  * Tests are executed in order by igt/drm_selftests_helper
  */
 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)
diff --git a/drivers/gpu/drm/selftests/test-drm_format.c b/drivers/gpu/drm/selftests/test-drm_format.c
new file mode 100644 (file)
index 0000000..c5e212a
--- /dev/null
@@ -0,0 +1,280 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Test cases for the drm_format functions
+ */
+
+#define pr_fmt(fmt) "drm_format: " fmt
+
+#include <linux/errno.h>
+#include <linux/kernel.h>
+
+#include <drm/drm_fourcc.h>
+
+#include "test-drm_modeset_common.h"
+
+int igt_check_drm_format_block_width(void *ignored)
+{
+       const struct drm_format_info *info = NULL;
+
+       /* Test invalid arguments */
+       FAIL_ON(drm_format_info_block_width(info, 0) != 0);
+       FAIL_ON(drm_format_info_block_width(info, -1) != 0);
+       FAIL_ON(drm_format_info_block_width(info, 1) != 0);
+
+       /* Test 1 plane format */
+       info = drm_format_info(DRM_FORMAT_XRGB4444);
+       FAIL_ON(!info);
+       FAIL_ON(drm_format_info_block_width(info, 0) != 1);
+       FAIL_ON(drm_format_info_block_width(info, 1) != 0);
+       FAIL_ON(drm_format_info_block_width(info, -1) != 0);
+
+       /* Test 2 planes format */
+       info = drm_format_info(DRM_FORMAT_NV12);
+       FAIL_ON(!info);
+       FAIL_ON(drm_format_info_block_width(info, 0) != 1);
+       FAIL_ON(drm_format_info_block_width(info, 1) != 1);
+       FAIL_ON(drm_format_info_block_width(info, 2) != 0);
+       FAIL_ON(drm_format_info_block_width(info, -1) != 0);
+
+       /* Test 3 planes format */
+       info = drm_format_info(DRM_FORMAT_YUV422);
+       FAIL_ON(!info);
+       FAIL_ON(drm_format_info_block_width(info, 0) != 1);
+       FAIL_ON(drm_format_info_block_width(info, 1) != 1);
+       FAIL_ON(drm_format_info_block_width(info, 2) != 1);
+       FAIL_ON(drm_format_info_block_width(info, 3) != 0);
+       FAIL_ON(drm_format_info_block_width(info, -1) != 0);
+
+       /* Test a tiled format */
+       info = drm_format_info(DRM_FORMAT_X0L0);
+       FAIL_ON(!info);
+       FAIL_ON(drm_format_info_block_width(info, 0) != 2);
+       FAIL_ON(drm_format_info_block_width(info, 1) != 0);
+       FAIL_ON(drm_format_info_block_width(info, -1) != 0);
+
+       return 0;
+}
+
+int igt_check_drm_format_block_height(void *ignored)
+{
+       const struct drm_format_info *info = NULL;
+
+       /* Test invalid arguments */
+       FAIL_ON(drm_format_info_block_height(info, 0) != 0);
+       FAIL_ON(drm_format_info_block_height(info, -1) != 0);
+       FAIL_ON(drm_format_info_block_height(info, 1) != 0);
+
+       /* Test 1 plane format */
+       info = drm_format_info(DRM_FORMAT_XRGB4444);
+       FAIL_ON(!info);
+       FAIL_ON(drm_format_info_block_height(info, 0) != 1);
+       FAIL_ON(drm_format_info_block_height(info, 1) != 0);
+       FAIL_ON(drm_format_info_block_height(info, -1) != 0);
+
+       /* Test 2 planes format */
+       info = drm_format_info(DRM_FORMAT_NV12);
+       FAIL_ON(!info);
+       FAIL_ON(drm_format_info_block_height(info, 0) != 1);
+       FAIL_ON(drm_format_info_block_height(info, 1) != 1);
+       FAIL_ON(drm_format_info_block_height(info, 2) != 0);
+       FAIL_ON(drm_format_info_block_height(info, -1) != 0);
+
+       /* Test 3 planes format */
+       info = drm_format_info(DRM_FORMAT_YUV422);
+       FAIL_ON(!info);
+       FAIL_ON(drm_format_info_block_height(info, 0) != 1);
+       FAIL_ON(drm_format_info_block_height(info, 1) != 1);
+       FAIL_ON(drm_format_info_block_height(info, 2) != 1);
+       FAIL_ON(drm_format_info_block_height(info, 3) != 0);
+       FAIL_ON(drm_format_info_block_height(info, -1) != 0);
+
+       /* Test a tiled format */
+       info = drm_format_info(DRM_FORMAT_X0L0);
+       FAIL_ON(!info);
+       FAIL_ON(drm_format_info_block_height(info, 0) != 2);
+       FAIL_ON(drm_format_info_block_height(info, 1) != 0);
+       FAIL_ON(drm_format_info_block_height(info, -1) != 0);
+
+       return 0;
+}
+
+int igt_check_drm_format_min_pitch(void *ignored)
+{
+       const struct drm_format_info *info = NULL;
+
+       /* Test invalid arguments */
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 0) != 0);
+       FAIL_ON(drm_format_info_min_pitch(info, -1, 0) != 0);
+       FAIL_ON(drm_format_info_min_pitch(info, 1, 0) != 0);
+
+       /* Test 1 plane 8 bits per pixel format */
+       info = drm_format_info(DRM_FORMAT_RGB332);
+       FAIL_ON(!info);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 0) != 0);
+       FAIL_ON(drm_format_info_min_pitch(info, -1, 0) != 0);
+       FAIL_ON(drm_format_info_min_pitch(info, 1, 0) != 0);
+
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 1) != 1);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 2) != 2);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 640) != 640);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 1024) != 1024);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 1920) != 1920);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 4096) != 4096);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 671) != 671);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX) !=
+                       (uint64_t)UINT_MAX);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, (UINT_MAX - 1)) !=
+                       (uint64_t)(UINT_MAX - 1));
+
+       /* Test 1 plane 16 bits per pixel format */
+       info = drm_format_info(DRM_FORMAT_XRGB4444);
+       FAIL_ON(!info);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 0) != 0);
+       FAIL_ON(drm_format_info_min_pitch(info, -1, 0) != 0);
+       FAIL_ON(drm_format_info_min_pitch(info, 1, 0) != 0);
+
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 1) != 2);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 2) != 4);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 640) != 1280);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 1024) != 2048);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 1920) != 3840);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 4096) != 8192);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 671) != 1342);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX) !=
+                       (uint64_t)UINT_MAX * 2);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, (UINT_MAX - 1)) !=
+                       (uint64_t)(UINT_MAX - 1) * 2);
+
+       /* Test 1 plane 24 bits per pixel format */
+       info = drm_format_info(DRM_FORMAT_RGB888);
+       FAIL_ON(!info);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 0) != 0);
+       FAIL_ON(drm_format_info_min_pitch(info, -1, 0) != 0);
+       FAIL_ON(drm_format_info_min_pitch(info, 1, 0) != 0);
+
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 1) != 3);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 2) != 6);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 640) != 1920);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 1024) != 3072);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 1920) != 5760);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 4096) != 12288);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 671) != 2013);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX) !=
+                       (uint64_t)UINT_MAX * 3);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX - 1) !=
+                       (uint64_t)(UINT_MAX - 1) * 3);
+
+       /* Test 1 plane 32 bits per pixel format */
+       info = drm_format_info(DRM_FORMAT_ABGR8888);
+       FAIL_ON(!info);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 0) != 0);
+       FAIL_ON(drm_format_info_min_pitch(info, -1, 0) != 0);
+       FAIL_ON(drm_format_info_min_pitch(info, 1, 0) != 0);
+
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 1) != 4);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 2) != 8);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 640) != 2560);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 1024) != 4096);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 1920) != 7680);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 4096) != 16384);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 671) != 2684);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX) !=
+                       (uint64_t)UINT_MAX * 4);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX - 1) !=
+                       (uint64_t)(UINT_MAX - 1) * 4);
+
+       /* Test 2 planes format */
+       info = drm_format_info(DRM_FORMAT_NV12);
+       FAIL_ON(!info);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 0) != 0);
+       FAIL_ON(drm_format_info_min_pitch(info, 1, 0) != 0);
+       FAIL_ON(drm_format_info_min_pitch(info, -1, 0) != 0);
+       FAIL_ON(drm_format_info_min_pitch(info, 2, 0) != 0);
+
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 1) != 1);
+       FAIL_ON(drm_format_info_min_pitch(info, 1, 1) != 2);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 2) != 2);
+       FAIL_ON(drm_format_info_min_pitch(info, 1, 1) != 2);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 640) != 640);
+       FAIL_ON(drm_format_info_min_pitch(info, 1, 320) != 640);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 1024) != 1024);
+       FAIL_ON(drm_format_info_min_pitch(info, 1, 512) != 1024);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 1920) != 1920);
+       FAIL_ON(drm_format_info_min_pitch(info, 1, 960) != 1920);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 4096) != 4096);
+       FAIL_ON(drm_format_info_min_pitch(info, 1, 2048) != 4096);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 671) != 671);
+       FAIL_ON(drm_format_info_min_pitch(info, 1, 336) != 672);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX) !=
+                       (uint64_t)UINT_MAX);
+       FAIL_ON(drm_format_info_min_pitch(info, 1, UINT_MAX / 2 + 1) !=
+                       (uint64_t)UINT_MAX + 1);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, (UINT_MAX - 1)) !=
+                       (uint64_t)(UINT_MAX - 1));
+       FAIL_ON(drm_format_info_min_pitch(info, 1, (UINT_MAX - 1) /  2) !=
+                       (uint64_t)(UINT_MAX - 1));
+
+       /* Test 3 planes 8 bits per pixel format */
+       info = drm_format_info(DRM_FORMAT_YUV422);
+       FAIL_ON(!info);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 0) != 0);
+       FAIL_ON(drm_format_info_min_pitch(info, 1, 0) != 0);
+       FAIL_ON(drm_format_info_min_pitch(info, 2, 0) != 0);
+       FAIL_ON(drm_format_info_min_pitch(info, -1, 0) != 0);
+       FAIL_ON(drm_format_info_min_pitch(info, 3, 0) != 0);
+
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 1) != 1);
+       FAIL_ON(drm_format_info_min_pitch(info, 1, 1) != 1);
+       FAIL_ON(drm_format_info_min_pitch(info, 2, 1) != 1);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 2) != 2);
+       FAIL_ON(drm_format_info_min_pitch(info, 1, 2) != 2);
+       FAIL_ON(drm_format_info_min_pitch(info, 2, 2) != 2);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 640) != 640);
+       FAIL_ON(drm_format_info_min_pitch(info, 1, 320) != 320);
+       FAIL_ON(drm_format_info_min_pitch(info, 2, 320) != 320);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 1024) != 1024);
+       FAIL_ON(drm_format_info_min_pitch(info, 1, 512) != 512);
+       FAIL_ON(drm_format_info_min_pitch(info, 2, 512) != 512);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 1920) != 1920);
+       FAIL_ON(drm_format_info_min_pitch(info, 1, 960) != 960);
+       FAIL_ON(drm_format_info_min_pitch(info, 2, 960) != 960);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 4096) != 4096);
+       FAIL_ON(drm_format_info_min_pitch(info, 1, 2048) != 2048);
+       FAIL_ON(drm_format_info_min_pitch(info, 2, 2048) != 2048);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 671) != 671);
+       FAIL_ON(drm_format_info_min_pitch(info, 1, 336) != 336);
+       FAIL_ON(drm_format_info_min_pitch(info, 2, 336) != 336);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX) !=
+                       (uint64_t)UINT_MAX);
+       FAIL_ON(drm_format_info_min_pitch(info, 1, UINT_MAX / 2 + 1) !=
+                       (uint64_t)UINT_MAX / 2 + 1);
+       FAIL_ON(drm_format_info_min_pitch(info, 2, UINT_MAX / 2 + 1) !=
+                       (uint64_t)UINT_MAX / 2 + 1);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, (UINT_MAX - 1) / 2) !=
+                       (uint64_t)(UINT_MAX - 1) / 2);
+       FAIL_ON(drm_format_info_min_pitch(info, 1, (UINT_MAX - 1) / 2) !=
+                       (uint64_t)(UINT_MAX - 1) / 2);
+       FAIL_ON(drm_format_info_min_pitch(info, 2, (UINT_MAX - 1) / 2) !=
+                       (uint64_t)(UINT_MAX - 1) / 2);
+
+       /* Test tiled format */
+       info = drm_format_info(DRM_FORMAT_X0L2);
+       FAIL_ON(!info);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 0) != 0);
+       FAIL_ON(drm_format_info_min_pitch(info, -1, 0) != 0);
+       FAIL_ON(drm_format_info_min_pitch(info, 1, 0) != 0);
+
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 1) != 2);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 2) != 4);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 640) != 1280);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 1024) != 2048);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 1920) != 3840);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 4096) != 8192);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, 671) != 1342);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX) !=
+                       (uint64_t)UINT_MAX * 2);
+       FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX - 1) !=
+                       (uint64_t)(UINT_MAX - 1) * 2);
+
+       return 0;
+}
index b0065a2..592a658 100644 (file)
@@ -14,5 +14,8 @@
 #define FAIL_ON(x) FAIL((x), "%s", "FAIL_ON(" __stringify(x) ")\n")
 
 int igt_check_plane_state(void *ignored);
+int igt_check_drm_format_block_width(void *ignored);
+int igt_check_drm_format_block_height(void *ignored);
+int igt_check_drm_format_min_pitch(void *ignored);
 
 #endif