summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/drmtest.c12
-rw-r--r--lib/drmtest.h2
-rw-r--r--tests/gem_ctx_bad_destroy.c22
-rw-r--r--tests/gem_ctx_bad_exec.c24
-rw-r--r--tests/gem_ctx_exec.c24
5 files changed, 18 insertions, 66 deletions
diff --git a/lib/drmtest.c b/lib/drmtest.c
index 2755ebeb..38d215db 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -526,6 +526,18 @@ int gem_madvise(int fd, uint32_t handle, int state)
return madv.retained;
}
+uint32_t gem_context_create(int fd)
+{
+ struct drm_i915_gem_context_create create;
+ int ret;
+
+ ret = drmIoctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_CREATE, &create);
+ igt_require(ret == 0 || (errno == ENODEV || errno == EINVAL));
+ igt_assert(ret == 0);
+
+ return create.ctx_id;
+}
+
/* prime */
int prime_handle_to_fd(int fd, uint32_t handle)
{
diff --git a/lib/drmtest.h b/lib/drmtest.h
index d2fe2429..3ba3f4f8 100644
--- a/lib/drmtest.h
+++ b/lib/drmtest.h
@@ -77,6 +77,8 @@ uint64_t gem_aperture_size(int fd);
uint64_t gem_mappable_aperture_size(void);
int gem_madvise(int fd, uint32_t handle, int state);
+uint32_t gem_context_create(int fd);
+
/* feature test helpers */
bool gem_uses_aliasing_ppgtt(int fd);
int gem_available_fences(int fd);
diff --git a/tests/gem_ctx_bad_destroy.c b/tests/gem_ctx_bad_destroy.c
index aec27958..78526187 100644
--- a/tests/gem_ctx_bad_destroy.c
+++ b/tests/gem_ctx_bad_destroy.c
@@ -34,33 +34,13 @@
#include "i915_drm.h"
#include "drmtest.h"
-struct local_drm_i915_context_create {
- __u32 ctx_id;
- __u32 pad;
-};
-
struct local_drm_i915_context_destroy {
__u32 ctx_id;
__u32 pad;
};
-#define CONTEXT_CREATE_IOCTL DRM_IOWR(DRM_COMMAND_BASE + 0x2d, struct local_drm_i915_context_create)
#define CONTEXT_DESTROY_IOCTL DRM_IOWR(DRM_COMMAND_BASE + 0x2e, struct local_drm_i915_context_destroy)
-static uint32_t context_create(int fd)
-{
- struct local_drm_i915_context_create create;
- int ret;
-
- ret = drmIoctl(fd, CONTEXT_CREATE_IOCTL, &create);
- if (ret == -1 && (errno == ENODEV || errno == EINVAL))
- igt_skip();
- else if (ret)
- abort();
-
- return create.ctx_id;
-}
-
static void handle_bad(int ret, int lerrno, int expected, const char *desc)
{
if (ret != 0 && lerrno != expected) {
@@ -84,7 +64,7 @@ int main(int argc, char *argv[])
fd = drm_open_any();
- ctx_id = context_create(fd);
+ ctx_id = gem_context_create(fd);
destroy.ctx_id = ctx_id;
/* Make sure a proper destroy works first */
diff --git a/tests/gem_ctx_bad_exec.c b/tests/gem_ctx_bad_exec.c
index 8e80a620..348b2f8f 100644
--- a/tests/gem_ctx_bad_exec.c
+++ b/tests/gem_ctx_bad_exec.c
@@ -46,28 +46,6 @@
#include "i915_drm.h"
#include "drmtest.h"
-struct local_drm_i915_gem_context_create {
- __u32 ctx_id;
- __u32 pad;
-};
-
-#define CONTEXT_CREATE_IOCTL DRM_IOWR(DRM_COMMAND_BASE + 0x2d, struct local_drm_i915_gem_context_create)
-
-static uint32_t context_create(int fd)
-{
- struct local_drm_i915_gem_context_create create;
- int ret;
-
- ret = drmIoctl(fd, CONTEXT_CREATE_IOCTL, &create);
- if (ret == -1 && (errno == ENODEV || errno == EINVAL)) {
- igt_skip();
- } else if (ret) {
- abort();
- }
-
- return create.ctx_id;
-}
-
/* Copied from gem_exec_nop.c */
static int exec(int fd, uint32_t handle, int ring, int ctx_id)
{
@@ -116,7 +94,7 @@ int main(int argc, char *argv[])
igt_fixture {
fd = drm_open_any();
- ctx_id = context_create(fd);
+ ctx_id = gem_context_create(fd);
handle = gem_create(fd, 4096);
gem_write(fd, handle, 0, batch, sizeof(batch));
diff --git a/tests/gem_ctx_exec.c b/tests/gem_ctx_exec.c
index 2d1a7deb..7b5be567 100644
--- a/tests/gem_ctx_exec.c
+++ b/tests/gem_ctx_exec.c
@@ -45,33 +45,13 @@
#include "i915_drm.h"
#include "drmtest.h"
-struct local_drm_i915_gem_context_create {
- __u32 ctx_id;
- __u32 pad;
-};
-
struct local_drm_i915_gem_context_destroy {
__u32 ctx_id;
__u32 pad;
};
-#define CONTEXT_CREATE_IOCTL DRM_IOWR(DRM_COMMAND_BASE + 0x2d, struct local_drm_i915_gem_context_create)
#define CONTEXT_DESTROY_IOCTL DRM_IOWR(DRM_COMMAND_BASE + 0x2e, struct local_drm_i915_gem_context_destroy)
-static uint32_t context_create(int fd)
-{
- struct local_drm_i915_gem_context_create create;
- int ret;
-
- ret = drmIoctl(fd, CONTEXT_CREATE_IOCTL, &create);
- if (ret == -1 && (errno == ENODEV || errno == EINVAL))
- igt_skip();
- else if (ret)
- abort();
-
- return create.ctx_id;
-}
-
static void context_destroy(int fd, uint32_t ctx_id)
{
struct local_drm_i915_gem_context_destroy destroy;
@@ -125,14 +105,14 @@ int main(int argc, char *argv[])
fd = drm_open_any();
- ctx_id = context_create(fd);
+ ctx_id = gem_context_create(fd);
handle = gem_create(fd, 4096);
gem_write(fd, handle, 0, batch, sizeof(batch));
igt_assert(exec(fd, handle, I915_EXEC_RENDER, ctx_id) == 0);
context_destroy(fd, ctx_id);
- ctx_id = context_create(fd);
+ ctx_id = gem_context_create(fd);
igt_assert(exec(fd, handle, I915_EXEC_RENDER, ctx_id) == 0);
context_destroy(fd, ctx_id);