[igt-dev] [PATCH i-g-t 5/5] tests/panfrost: Add initial tests for panfrost

Tomeu Vizoso tomeu.vizoso at collabora.com
Wed Apr 24 15:25:11 UTC 2019


Signed-off-by: Tomeu Vizoso <tomeu.vizoso at collabora.com>
---
 tests/meson.build          |   4 +
 tests/panfrost_gem_new.c   |  90 ++++++++++++++++++++
 tests/panfrost_get_param.c |  73 +++++++++++++++++
 tests/panfrost_prime.c     |  79 ++++++++++++++++++
 tests/panfrost_submit.c    | 163 +++++++++++++++++++++++++++++++++++++
 5 files changed, 409 insertions(+)
 create mode 100644 tests/panfrost_gem_new.c
 create mode 100644 tests/panfrost_get_param.c
 create mode 100644 tests/panfrost_prime.c
 create mode 100644 tests/panfrost_submit.c

diff --git a/tests/meson.build b/tests/meson.build
index e3c8b07fe28e..50933170cf78 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -63,6 +63,10 @@ test_progs = [
 	'kms_vblank',
 	'kms_vrr',
 	'meta_test',
+	'panfrost_get_param',
+	'panfrost_gem_new',
+	'panfrost_prime',
+	'panfrost_submit',
 	'perf',
 	'prime_busy',
 	'prime_mmap',
diff --git a/tests/panfrost_gem_new.c b/tests/panfrost_gem_new.c
new file mode 100644
index 000000000000..940525ff1b34
--- /dev/null
+++ b/tests/panfrost_gem_new.c
@@ -0,0 +1,90 @@
+/*
+ * Copyright © 2016 Broadcom
+ * Copyright © 2019 Collabora, Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "igt.h"
+#include "igt_panfrost.h"
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include "panfrost_drm.h"
+
+igt_main
+{
+	int fd;
+
+	igt_fixture {
+		fd = drm_open_driver(DRIVER_PANFROST);
+	}
+
+	igt_subtest("gem-new-4096") {
+		struct panfrost_bo *bo = igt_panfrost_gem_new(fd, 4096);
+		igt_panfrost_free_bo(fd, bo);
+	}
+
+	igt_subtest("gem-new-0") {
+		struct drm_panfrost_create_bo arg = {
+			.size = 0,
+		};
+		do_ioctl_err(fd, DRM_IOCTL_PANFROST_CREATE_BO, &arg, EINVAL);
+	}
+
+	igt_subtest("gem-new-zeroed") {
+		int fd2 = drm_open_driver(DRIVER_PANFROST);
+		struct panfrost_bo *bo;
+		uint32_t *map;
+		/* A size different from any used in our other tests, to try
+		 * to convince it to land as the only one of its size in the
+		 * kernel BO cache
+		 */
+		size_t size = 3 * 4096, i;
+
+		/* Make a BO and free it on our main fd. */
+		bo = igt_panfrost_gem_new(fd, size);
+		map = igt_panfrost_mmap_bo(fd, bo->handle, size, PROT_READ | PROT_WRITE);
+		memset(map, 0xd0, size);
+		munmap(map, size);
+		igt_panfrost_free_bo(fd, bo);
+
+		/* Now, allocate a BO on the other fd and make sure it doesn't
+		 * have the old contents.
+		 */
+		bo = igt_panfrost_gem_new(fd2, size);
+		map = igt_panfrost_mmap_bo(fd2, bo->handle, size, PROT_READ | PROT_WRITE);
+		for (i = 0; i < size / 4; i++)
+			igt_assert_eq_u32(map[i], 0x0);
+		munmap(map, size);
+		igt_panfrost_free_bo(fd2, bo);
+
+		close(fd2);
+	}
+
+	igt_fixture
+		close(fd);
+}
diff --git a/tests/panfrost_get_param.c b/tests/panfrost_get_param.c
new file mode 100644
index 000000000000..413b48121688
--- /dev/null
+++ b/tests/panfrost_get_param.c
@@ -0,0 +1,73 @@
+/*
+ * Copyright © 2017 Broadcom
+ * Copyright © 2019 Collabora, Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "igt.h"
+#include "igt_panfrost.h"
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <poll.h>
+#include "panfrost_drm.h"
+
+igt_main
+{
+	int fd;
+
+	igt_fixture
+		fd = drm_open_driver(DRIVER_PANFROST);
+
+	igt_subtest("base-params") {
+		int last_base_param = DRM_PANFROST_PARAM_GPU_PROD_ID;
+		uint32_t results[last_base_param];
+
+		for (int i = 0; i < ARRAY_SIZE(results); i++)
+			results[i] = igt_panfrost_get_param(fd, i + 1);
+
+		igt_assert(results[DRM_PANFROST_PARAM_GPU_PROD_ID - 1]);
+	}
+
+	igt_subtest("get-bad-param") {
+		struct drm_panfrost_get_param get = {
+			.param = 0xd0d0d0d0,
+		};
+		do_ioctl_err(fd, DRM_IOCTL_PANFROST_GET_PARAM, &get, EINVAL);
+	}
+
+	igt_subtest("get-bad-flags") {
+		struct drm_panfrost_get_param get = {
+			.param = DRM_PANFROST_PARAM_GPU_PROD_ID,
+			.pad = 1,
+		};
+		do_ioctl_err(fd, DRM_IOCTL_PANFROST_GET_PARAM, &get, EINVAL);
+	}
+
+	igt_fixture
+		close(fd);
+}
diff --git a/tests/panfrost_prime.c b/tests/panfrost_prime.c
new file mode 100644
index 000000000000..351d46f2f7e6
--- /dev/null
+++ b/tests/panfrost_prime.c
@@ -0,0 +1,79 @@
+/*
+ * Copyright © 2016 Broadcom
+ * Copyright © 2019 Collabora, Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "igt.h"
+#include "igt_panfrost.h"
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include "panfrost_drm.h"
+
+igt_main
+{
+	int fd, kms_fd;
+
+	igt_fixture {
+		kms_fd = drm_open_driver_master(DRIVER_ANY);
+		fd = drm_open_driver(DRIVER_PANFROST);
+	}
+
+	igt_subtest("gem-prime-import") {
+		struct panfrost_bo *bo;
+		uint32_t handle, dumb_handle;
+	        struct drm_panfrost_get_bo_offset get_bo_offset = {0,};
+		int dmabuf_fd;
+
+		/* Just to be sure that when we import the dumb buffer it has
+		 * a non-NULL address.
+		 */
+		bo = igt_panfrost_gem_new(fd, 1024);
+
+		dumb_handle = kmstest_dumb_create(kms_fd, 1024, 1024, 32, NULL, NULL);
+
+		dmabuf_fd = prime_handle_to_fd(kms_fd, dumb_handle);
+
+		handle = prime_fd_to_handle(fd, dmabuf_fd);
+
+		get_bo_offset.handle = handle;
+		do_ioctl(fd, DRM_IOCTL_PANFROST_GET_BO_OFFSET, &get_bo_offset);
+		igt_assert(get_bo_offset.offset);
+
+		gem_close(fd, handle);
+
+		kmstest_dumb_destroy(kms_fd, dumb_handle);
+
+		igt_panfrost_free_bo(fd, bo);
+	}
+
+	igt_fixture {
+		close(fd);
+		close(kms_fd);
+	}
+}
diff --git a/tests/panfrost_submit.c b/tests/panfrost_submit.c
new file mode 100644
index 000000000000..5770dc24a42b
--- /dev/null
+++ b/tests/panfrost_submit.c
@@ -0,0 +1,163 @@
+/*
+ * Copyright © 2016 Broadcom
+ * Copyright © 2019 Collabora, Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "igt.h"
+#include "igt_panfrost.h"
+#include "igt_syncobj.h"
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include "panfrost_drm.h"
+
+#define WIDTH          1366
+#define HEIGHT         768
+#define CLEAR_COLOR    0xff7f7f7f
+
+/* One tenth of a second */
+#define SHORT_TIME_NSEC 100000000ull
+
+/* Add the time that the bad job takes to timeout (sched->timeout) and the time that a reset can take */
+#define BAD_JOB_TIME_NSEC (SHORT_TIME_NSEC + 500000000ull + 100000000ull)
+
+#define NSECS_PER_SEC 1000000000ull
+
+static uint64_t
+abs_timeout(uint64_t duration)
+{
+        struct timespec current;
+        clock_gettime(CLOCK_MONOTONIC, &current);
+        return (uint64_t)current.tv_sec * NSECS_PER_SEC + current.tv_nsec + duration;
+}
+
+static void check_fb(int fd, struct panfrost_bo *bo)
+{
+        __uint32_t *fbo;
+        int i;
+
+        fbo = bo->map;
+        for (i = 0; i < ALIGN(WIDTH, 16) * HEIGHT; i++)
+                igt_assert_eq_u32(fbo[i], CLEAR_COLOR);
+}
+
+igt_main
+{
+        int fd;
+
+        igt_fixture {
+                fd = drm_open_driver(DRIVER_PANFROST);
+        }
+
+        igt_subtest("pan-submit") {
+                struct panfrost_submit *submit;
+
+                submit = igt_panfrost_trivial_job(fd, false, WIDTH, HEIGHT,
+                                                  CLEAR_COLOR);
+
+                igt_panfrost_bo_mmap(fd, submit->fbo);
+                do_ioctl(fd, DRM_IOCTL_PANFROST_SUBMIT, submit->args);
+                igt_assert(syncobj_wait(fd, &submit->args->out_sync, 1,
+                                        abs_timeout(SHORT_TIME_NSEC), 0, NULL));
+                check_fb(fd, submit->fbo);
+                igt_panfrost_free_job(fd, submit);
+        }
+
+        igt_subtest("pan-submit-error-no-jc") {
+                struct drm_panfrost_submit submit = {.jc = 0,};
+                do_ioctl_err(fd, DRM_IOCTL_PANFROST_SUBMIT, &submit, EINVAL);
+        }
+
+        igt_subtest("pan-submit-error-bad-in-syncs") {
+                struct panfrost_submit *submit;
+
+                submit = igt_panfrost_trivial_job(fd, false, WIDTH, HEIGHT,
+                                                  CLEAR_COLOR);
+                submit->args->in_syncs = 0ULL;
+                submit->args->in_sync_count = 1;
+
+                do_ioctl_err(fd, DRM_IOCTL_PANFROST_SUBMIT, submit->args, EFAULT);
+        }
+
+        igt_subtest("pan-submit-error-bad-bo-handles") {
+                struct panfrost_submit *submit;
+
+                submit = igt_panfrost_trivial_job(fd, false, WIDTH, HEIGHT,
+                                                  CLEAR_COLOR);
+                submit->args->bo_handles = 0ULL;
+                submit->args->bo_handle_count = 1;
+
+                do_ioctl_err(fd, DRM_IOCTL_PANFROST_SUBMIT, submit->args, EFAULT);
+        }
+
+        igt_subtest("pan-submit-error-bad-requirements") {
+                struct panfrost_submit *submit;
+
+                submit = igt_panfrost_trivial_job(fd, false, WIDTH, HEIGHT,
+                                                  CLEAR_COLOR);
+                submit->args->requirements = 2;
+
+                do_ioctl_err(fd, DRM_IOCTL_PANFROST_SUBMIT, submit->args, EINVAL);
+        }
+
+        igt_subtest("pan-submit-error-bad-out-sync") {
+                struct panfrost_submit *submit;
+
+                submit = igt_panfrost_trivial_job(fd, false, WIDTH, HEIGHT,
+                                                  CLEAR_COLOR);
+                submit->args->out_sync = -1;
+
+                do_ioctl_err(fd, DRM_IOCTL_PANFROST_SUBMIT, submit->args, ENODEV);
+        }
+
+        igt_subtest("pan-reset") {
+                struct panfrost_submit *submit;
+
+                submit = igt_panfrost_trivial_job(fd, true, WIDTH, HEIGHT,
+                                                  CLEAR_COLOR);
+                do_ioctl(fd, DRM_IOCTL_PANFROST_SUBMIT, submit->args);
+                /* Expect for this job to timeout */
+                igt_assert(!syncobj_wait(fd, &submit->args->out_sync, 1,
+                                         abs_timeout(SHORT_TIME_NSEC), 0, NULL));
+                igt_panfrost_free_job(fd, submit);
+
+                submit = igt_panfrost_trivial_job(fd, false, WIDTH, HEIGHT,
+                                                  CLEAR_COLOR);
+                igt_panfrost_bo_mmap(fd, submit->fbo);
+                do_ioctl(fd, DRM_IOCTL_PANFROST_SUBMIT, submit->args);
+                /* This one should work */
+                igt_assert(syncobj_wait(fd, &submit->args->out_sync, 1,
+                                        abs_timeout(BAD_JOB_TIME_NSEC), 0, NULL));
+                check_fb(fd, submit->fbo);
+                igt_panfrost_free_job(fd, submit);
+        }
+
+        igt_fixture {
+                close(fd);
+        }
+}
-- 
2.20.1



More information about the igt-dev mailing list