[Intel-gfx] [PATCH 5/5] contexts: basic context test

Ben Widawsky ben at bwidawsk.net
Mon Jan 16 03:21:26 CET 2012


This serves as an example of how to use the new gem_stress library
functions, but shouldn't actually build until we get the libdrm updated
functions in place.

Cc: Daniel Vetter <daniel.vetter at ffwll.ch>
Signed-off-by: Ben Widawsky <ben at bwidawsk.net>
---
 tests/Makefile.am     |    1 +
 tests/gem_ctx_basic.c |  121 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 122 insertions(+), 0 deletions(-)
 create mode 100644 tests/gem_ctx_basic.c

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6fdc96f..15299a1 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -55,6 +55,7 @@ TESTS_progs = \
 	drm_vma_limiter_cpu \
 	drm_vma_limiter_gtt \
 	drm_vma_limiter_cached \
+	gem_ctx_basic \
 	$(NULL)
 
 # IMPORTANT: The ZZ_ tests need to be run last!
diff --git a/tests/gem_ctx_basic.c b/tests/gem_ctx_basic.c
new file mode 100644
index 0000000..90fbce6
--- /dev/null
+++ b/tests/gem_ctx_basic.c
@@ -0,0 +1,121 @@
+/*
+ * 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 at bwidawsk.net>
+ *
+ * gem_stress library has a hard dependence on batch. So we use forking instead
+ * of pthreads.
+ */
+
+#include <pthread.h>
+#include "gem_stress.h"
+
+#define CONTEXT_COUNT 3
+#define ITER 1000
+
+struct option_struct options;
+
+struct intel_batchbuffer *batch;
+drm_intel_bufmgr *bufmgr;
+pid_t pids[CONTEXT_COUNT];
+int devid;
+int fd;
+
+static void work(void)
+{
+	drm_intel_context *context;
+	int i;
+
+	bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
+	batch = intel_batchbuffer_alloc(bufmgr, devid);
+	context = drm_intel_gem_context_create(bufmgr);
+	for (i = 0; i < ITER; i++) {
+#ifndef REALLY_BASIC_CONTEXT_TEST
+		struct scratch_buf src, dst;
+		int ret;
+
+		init_buffer(&src, options.scratch_buf_size);
+		init_buffer(&dst, options.scratch_buf_size);
+
+		gen6_render_copyfunc(&src, 0, 0, &dst, 0, 0, 0);
+
+		ret = drm_intel_bo_subdata(batch->bo, 0, 4096, batch->buffer);
+		assert(ret == 0);
+
+		batch->context = context;
+		intel_batchbuffer_flush_with_context(batch);
+		intel_batchbuffer_reset(batch);
+#else
+		BEGIN_BATCH(8);
+		OUT_BATCH(MI_NOOP);
+		OUT_BATCH(MI_NOOP);
+		OUT_BATCH(MI_NOOP);
+		OUT_BATCH(MI_NOOP);
+		OUT_BATCH(MI_NOOP);
+		OUT_BATCH(MI_NOOP);
+		OUT_BATCH(MI_NOOP);
+		OUT_BATCH(MI_NOOP);
+		ADVANCE_BATCH();
+#endif
+	}
+	drm_intel_gem_context_destroy(context);
+	intel_batchbuffer_free(batch);
+	drm_intel_bufmgr_destroy(bufmgr);
+	close(fd);
+	exit(EXIT_SUCCESS);
+}
+
+int main(int argc, char **argv)
+{
+	int i;
+
+	fd = drm_open_any();
+	devid = intel_get_drm_devid(fd);
+
+	parse_options(argc, argv, devid);
+
+	if (!IS_GEN6(devid)) {
+		fprintf(stderr, "Sorry, only gen6 supported\n");
+		exit(EXIT_FAILURE);
+	}
+
+	if (!strncmp("doit", argv[0], strlen("doit"))) {
+		work();
+		assert(1);
+	}
+
+	for (i = 0; i < CONTEXT_COUNT; i++) {
+		pids[i] = fork();
+		if (pids[i] == -1) {
+			fprintf(stderr, "fork bad %d\n", errno);
+			exit(EXIT_FAILURE);
+		}
+		if (pids[i] == 0) {
+			execl(argv[0], "doit", NULL);
+		}
+	}
+
+	close(fd);
+
+	exit(EXIT_SUCCESS);
+}
-- 
1.7.8.3




More information about the Intel-gfx mailing list