summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Vetter <daniel.vetter@ffwll.ch>2015-02-06 17:54:46 +0100
committerDaniel Vetter <daniel.vetter@ffwll.ch>2015-02-13 09:35:36 +0100
commit6f582f70e1b344c6d0e20f312f376892553af55e (patch)
tree186b6c8aa8fd35f3a781c98dc62265ceece2321d
parent75c075cb263bf33259d26692b4f093f84276915c (diff)
tests: Add gem_ctx_param_basic
Boring ioctl validation. Luckily no gaps found while doing it. v2: git add ftw! v3: Fixes: - args->size is an outparam for get, adjust test. - Pick an invalid param, not an invalid ioctl number ... tsk. Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/Makefile.sources1
-rw-r--r--tests/gem_ctx_exec.c3
-rw-r--r--tests/gem_ctx_param_basic.172
-rw-r--r--tests/gem_ctx_param_basic.c137
5 files changed, 313 insertions, 1 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
index 88a64053..7b4dd947 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -30,6 +30,7 @@ gem_ctx_basic
gem_ctx_create
gem_ctx_exec
gem_ctx_thrash
+gem_ctx_param_basic
gem_double_irq_loop
gem_dummy_reloc_loop
gem_evict_alignment
diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index 74deec31..51e8376b 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -23,6 +23,7 @@ TESTS_progs_M = \
gem_close_race \
gem_concurrent_blit \
gem_cs_tlb \
+ gem_ctx_param_basic \
gem_ctx_bad_exec \
gem_ctx_exec \
gem_dummy_reloc_loop \
diff --git a/tests/gem_ctx_exec.c b/tests/gem_ctx_exec.c
index ca5bf640..ead3d463 100644
--- a/tests/gem_ctx_exec.c
+++ b/tests/gem_ctx_exec.c
@@ -161,7 +161,8 @@ int fd;
igt_main
{
igt_skip_on_simulation();
- igt_fixture {
+
+ igt_fixture {
fd = drm_open_any_render();
handle = gem_create(fd, 4096);
diff --git a/tests/gem_ctx_param_basic. b/tests/gem_ctx_param_basic.
new file mode 100644
index 00000000..2d866b3e
--- /dev/null
+++ b/tests/gem_ctx_param_basic.
@@ -0,0 +1,172 @@
+/*
+ * Copyright © 2011 Intel Corporation
+ *
+ * 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.
+ *
+ * Authors:
+ * Ben Widawsky <ben@bwidawsk.net>
+ *
+ */
+
+/*
+ * This test is useful for finding memory and refcount leaks.
+ */
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include "drm.h"
+#include "ioctl_wrappers.h"
+#include "drmtest.h"
+#include "intel_bufmgr.h"
+#include "intel_batchbuffer.h"
+#include "intel_io.h"
+#include "intel_chipset.h"
+
+IGT_TEST_DESCRIPTION("Basic test for memory and refcount leaks.");
+
+/* options */
+int num_contexts = 10;
+int uncontexted = 0; /* test only context create/destroy */
+int multiple_fds = 1;
+int iter = 10000;
+
+/* globals */
+pthread_t *threads;
+int devid;
+int fd;
+
+static void init_buffer(drm_intel_bufmgr *bufmgr,
+ struct igt_buf *buf,
+ uint32_t size)
+{
+ buf->bo = drm_intel_bo_alloc(bufmgr, "", size, 4096);
+ buf->size = size;
+ igt_assert(buf->bo);
+ buf->tiling = I915_TILING_NONE;
+ buf->stride = 4096;
+}
+
+static void *work(void *arg)
+{
+ struct intel_batchbuffer *batch;
+ igt_render_copyfunc_t rendercopy = igt_get_render_copyfunc(devid);
+ drm_intel_context *context;
+ drm_intel_bufmgr *bufmgr;
+ int td_fd;
+ int i;
+
+ if (multiple_fds)
+ td_fd = fd = drm_open_any_render();
+ else
+ td_fd = fd;
+
+ igt_assert(td_fd >= 0);
+
+ bufmgr = drm_intel_bufmgr_gem_init(td_fd, 4096);
+ batch = intel_batchbuffer_alloc(bufmgr, devid);
+ context = drm_intel_gem_context_create(bufmgr);
+ igt_require(context);
+
+ for (i = 0; i < iter; i++) {
+ struct igt_buf src, dst;
+
+ init_buffer(bufmgr, &src, 4096);
+ init_buffer(bufmgr, &dst, 4096);
+
+
+ if (uncontexted) {
+ igt_assert(rendercopy);
+ rendercopy(batch, NULL, &src, 0, 0, 0, 0, &dst, 0, 0);
+ } else {
+ int ret;
+ ret = drm_intel_bo_subdata(batch->bo, 0, 4096, batch->buffer);
+ igt_assert(ret == 0);
+ intel_batchbuffer_flush_with_context(batch, context);
+ }
+ }
+
+ drm_intel_gem_context_destroy(context);
+ intel_batchbuffer_free(batch);
+ drm_intel_bufmgr_destroy(bufmgr);
+
+ if (multiple_fds)
+ close(td_fd);
+
+ pthread_exit(NULL);
+}
+
+static int opt_handler(int opt, int opt_index)
+{
+ switch (opt) {
+ case 'i':
+ iter = atoi(optarg);
+ break;
+ case 'c':
+ num_contexts = atoi(optarg);
+ break;
+ case 'm':
+ multiple_fds = 1;
+ break;
+ case 'u':
+ uncontexted = 1;
+ break;
+ }
+
+ return 0;
+}
+
+int main(int argc, char *argv[])
+{
+ int i;
+
+ igt_simple_init_parse_opts(argc, argv, "i:c:n:mu", NULL, NULL,
+ opt_handler);
+
+ fd = drm_open_any_render();
+ devid = intel_get_drm_devid(fd);
+
+ if (igt_run_in_simulation()) {
+ num_contexts = 2;
+ iter = 4;
+ }
+
+ threads = calloc(num_contexts, sizeof(*threads));
+
+ for (i = 0; i < num_contexts; i++)
+ pthread_create(&threads[i], NULL, work, &i);
+
+ for (i = 0; i < num_contexts; i++) {
+ void *retval;
+ igt_assert(pthread_join(threads[i], &retval) == 0);
+ }
+
+ free(threads);
+ close(fd);
+
+ igt_exit();
+}
diff --git a/tests/gem_ctx_param_basic.c b/tests/gem_ctx_param_basic.c
new file mode 100644
index 00000000..8a2534cd
--- /dev/null
+++ b/tests/gem_ctx_param_basic.c
@@ -0,0 +1,137 @@
+/*
+ * Copyright © 2015 Intel Corporation
+ *
+ * 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.
+ *
+ * Authors:
+ * Daniel Vetter <daniel.vetter@ffwll.ch>
+ */
+
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <stdio.h>
+#include "ioctl_wrappers.h"
+#include "drmtest.h"
+#include "igt_aux.c"
+
+IGT_TEST_DESCRIPTION("Basic test for context set/get param input validation.");
+
+int fd;
+int32_t ctx;
+
+#define LOCAL_I915_GEM_CONTEXT_GETPARAM 0x34
+#define LOCAL_I915_GEM_CONTEXT_SETPARAM 0x35
+#define LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM DRM_IOWR (DRM_COMMAND_BASE + LOCAL_I915_GEM_CONTEXT_GETPARAM, struct local_i915_gem_context_param)
+#define LOCAL_IOCTL_I915_GEM_CONTEXT_SETPARAM DRM_IOWR (DRM_COMMAND_BASE + LOCAL_I915_GEM_CONTEXT_SETPARAM, struct local_i915_gem_context_param)
+
+#define TEST_SUCCESS(ioc) \
+ igt_assert(drmIoctl(fd, (ioc), &ctx_param) == 0);
+#define TEST_FAIL(ioc, exp_errno) \
+ igt_assert(drmIoctl(fd, (ioc), &ctx_param) < 0 && errno == exp_errno);
+
+igt_main
+{
+ struct local_i915_gem_context_param ctx_param;
+
+ memset(&ctx_param, 0, sizeof(ctx_param));
+
+ igt_fixture {
+ fd = drm_open_any_render();
+ ctx = gem_context_create(fd);
+ }
+
+ ctx_param.param = LOCAL_CONTEXT_PARAM_BAN_PERIOD;
+
+ igt_subtest("basic") {
+ ctx_param.context = ctx;
+ TEST_SUCCESS(LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM);
+ TEST_SUCCESS(LOCAL_IOCTL_I915_GEM_CONTEXT_SETPARAM);
+ }
+
+ igt_subtest("basic-default") {
+ ctx_param.context = 0;
+ TEST_SUCCESS(LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM);
+ TEST_SUCCESS(LOCAL_IOCTL_I915_GEM_CONTEXT_SETPARAM);
+ }
+
+ igt_subtest("invalid-ctx-get") {
+ ctx_param.context = 2;
+ TEST_FAIL(LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, ENOENT);
+ }
+
+ igt_subtest("invalid-ctx-set") {
+ ctx_param.context = ctx;
+ TEST_SUCCESS(LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM);
+ ctx_param.context = 2;
+ TEST_FAIL(LOCAL_IOCTL_I915_GEM_CONTEXT_SETPARAM, ENOENT);
+ }
+
+ igt_subtest("invalid-size-get") {
+ ctx_param.context = ctx;
+ ctx_param.size = 8;
+ TEST_SUCCESS(LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM);
+ igt_assert(ctx_param.size == 0);
+ }
+
+ igt_subtest("invalid-size-set") {
+ ctx_param.context = ctx;
+ TEST_SUCCESS(LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM);
+ ctx_param.size = 8;
+ TEST_FAIL(LOCAL_IOCTL_I915_GEM_CONTEXT_SETPARAM, EINVAL);
+ ctx_param.size = 0;
+ }
+
+ ctx_param.param = LOCAL_CONTEXT_PARAM_BAN_PERIOD + 1;
+
+ igt_subtest("invalid-param-get") {
+ ctx_param.context = ctx;
+ TEST_FAIL(LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, EINVAL);
+ }
+
+ igt_subtest("invalid-param-set") {
+ ctx_param.context = ctx;
+ TEST_FAIL(LOCAL_IOCTL_I915_GEM_CONTEXT_SETPARAM, EINVAL);
+ }
+
+ ctx_param.param = LOCAL_CONTEXT_PARAM_BAN_PERIOD;
+
+ igt_subtest("non-root-set") {
+ igt_fork(child, 1) {
+ igt_drop_root();
+
+ ctx_param.context = ctx;
+ TEST_SUCCESS(LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM);
+ ctx_param.value--;
+ TEST_FAIL(LOCAL_IOCTL_I915_GEM_CONTEXT_SETPARAM, EPERM);
+ }
+
+ igt_waitchildren();
+ }
+
+ igt_subtest("root-set") {
+ ctx_param.context = ctx;
+ TEST_SUCCESS(LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM);
+ ctx_param.value--;
+ TEST_SUCCESS(LOCAL_IOCTL_I915_GEM_CONTEXT_SETPARAM);
+ }
+
+ igt_fixture
+ close(fd);
+}