intel-gfx.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel.vetter@ffwll.ch>
To: Intel Graphics Development <intel-gfx@lists.freedesktop.org>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>,
	Daniel Vetter <daniel.vetter@intel.com>
Subject: [PATCH i-g-t 10/17] tests: Add gem_ctx_param_basic
Date: Tue, 10 Feb 2015 19:05:53 +0100	[thread overview]
Message-ID: <1423591560-9471-10-git-send-email-daniel.vetter@ffwll.ch> (raw)
In-Reply-To: <1423591560-9471-1-git-send-email-daniel.vetter@ffwll.ch>

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>
---
 tests/.gitignore            |   1 +
 tests/Makefile.sources      |   1 +
 tests/gem_ctx_exec.c        |   3 +-
 tests/gem_ctx_param_basic.  | 172 ++++++++++++++++++++++++++++++++++++++++++++
 tests/gem_ctx_param_basic.c | 137 +++++++++++++++++++++++++++++++++++
 5 files changed, 313 insertions(+), 1 deletion(-)
 create mode 100644 tests/gem_ctx_param_basic.
 create mode 100644 tests/gem_ctx_param_basic.c

diff --git a/tests/.gitignore b/tests/.gitignore
index 88a6405394b2..7b4dd94722a2 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 74deec3127fb..51e8376b24e6 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 ca5bf640adaf..ead3d463003a 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 000000000000..2d866b3eee26
--- /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 000000000000..8a2534cd64ee
--- /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);
+}
-- 
2.1.4

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2015-02-10 18:04 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-10 18:05 [PATCH i-g-t 01/17] lib/gt: api polish for igt_can_hang_ring Daniel Vetter
2015-02-10 18:05 ` [PATCH i-g-t 02/17] lib/ioctl: api polish for gem_context_has_param Daniel Vetter
2015-02-10 18:05 ` [PATCH i-g-t 03/17] lib/ioctl: gem_ prefix for igt_require_mmap_wc Daniel Vetter
2015-02-10 21:58   ` Chris Wilson
2015-02-11  8:37     ` Daniel Vetter
2015-02-10 18:05 ` [PATCH i-g-t 04/17] igt/ioctls: doc for gem_mmap Daniel Vetter
2015-02-10 18:05 ` [PATCH i-g-t 05/17] lib/ioctls: make gem_context_set/get_param infallible Daniel Vetter
2015-02-10 21:54   ` Chris Wilson
2015-02-11  8:42     ` Daniel Vetter
2015-02-10 18:05 ` [PATCH i-g-t 06/17] lib/ioctl: Add gem_context_destroy helpers Daniel Vetter
2015-02-10 18:05 ` [PATCH i-g-t 07/17] tests/gem_ctx_*: Use helpers Daniel Vetter
2015-02-10 18:05 ` [PATCH i-g-t 08/17] tests/gem_reset_stat: Use new ctx helpers Daniel Vetter
2015-02-10 18:05 ` [PATCH i-g-t 09/17] lib/ioctl: Document ctx param functions Daniel Vetter
2015-02-10 18:05 ` Daniel Vetter [this message]
2015-02-10 18:05 ` [PATCH i-g-t 11/17] tests: Add invalid pad tests for ctx create/destroy Daniel Vetter
2015-02-10 18:05 ` [PATCH i-g-t 12/17] tests/gem_ppgtt: Start rcs before bcs for context tests Daniel Vetter
2015-02-10 18:05 ` [PATCH i-g-t 13/17] tests: Align subtest with naming convention Daniel Vetter
2015-02-10 21:53   ` Chris Wilson
2015-02-11  8:44     ` Daniel Vetter
2015-02-10 18:05 ` [PATCH i-g-t 14/17] lib/igt_aux: s/swap/igt_swap/ Daniel Vetter
2015-02-10 18:05 ` [PATCH i-g-t 15/17] tests/gem_wait: Adjust makefile Daniel Vetter
2015-02-10 18:05 ` [PATCH i-g-t 16/17] doc: Consolidate naming conventions into docbook Daniel Vetter
2015-02-10 18:06 ` [PATCH i-g-t 17/17] lib/igt_gt: Document and consolidate Daniel Vetter
2015-02-10 21:36 ` [PATCH i-g-t 01/17] lib/gt: api polish for igt_can_hang_ring Chris Wilson
2015-02-10 21:56   ` Daniel Vetter
2015-02-10 21:59   ` [PATCH i-g-t] lib/chipset: Cache devid Daniel Vetter
2015-02-10 22:28     ` Chris Wilson
2015-02-10 22:37       ` Daniel Vetter
2015-02-10 22:39         ` Daniel Vetter
2015-02-10 22:45           ` Daniel Vetter
2015-02-10 22:50             ` Chris Wilson
2015-02-11  8:49               ` Daniel Vetter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1423591560-9471-10-git-send-email-daniel.vetter@ffwll.ch \
    --to=daniel.vetter@ffwll.ch \
    --cc=daniel.vetter@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).