aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore4
-rw-r--r--tests/Makefile.am9
-rw-r--r--tests/gem_basic.c102
-rw-r--r--tests/gem_flink.c137
-rw-r--r--tests/gem_mmap.c136
-rw-r--r--tests/gem_readwrite.c139
6 files changed, 0 insertions, 527 deletions
diff --git a/.gitignore b/.gitignore
index 3596a4a8..06cc9283 100644
--- a/.gitignore
+++ b/.gitignore
@@ -79,10 +79,6 @@ tests/getclient
79tests/getstats 79tests/getstats
80tests/getversion 80tests/getversion
81tests/lock 81tests/lock
82tests/gem_basic
83tests/gem_flink
84tests/gem_mmap
85tests/gem_readwrite
86tests/openclose 82tests/openclose
87tests/setversion 83tests/setversion
88tests/updatedraw 84tests/updatedraw
diff --git a/tests/Makefile.am b/tests/Makefile.am
index e7ec4fa5..37b8d3a1 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -58,15 +58,6 @@ TESTS = \
58 58
59SUBDIRS += vbltest $(NULL) 59SUBDIRS += vbltest $(NULL)
60 60
61if HAVE_INTEL
62TESTS += \
63 gem_basic \
64 gem_flink \
65 gem_readwrite \
66 gem_mmap \
67 $(NULL)
68endif
69
70check_PROGRAMS += $(TESTS) 61check_PROGRAMS += $(TESTS)
71 62
72endif 63endif
diff --git a/tests/gem_basic.c b/tests/gem_basic.c
deleted file mode 100644
index 4e4b6cbd..00000000
--- a/tests/gem_basic.c
+++ /dev/null
@@ -1,102 +0,0 @@
1/*
2 * Copyright © 2008 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 *
26 */
27
28#include <stdlib.h>
29#include <stdio.h>
30#include <string.h>
31#include <assert.h>
32#include <fcntl.h>
33#include <inttypes.h>
34#include <errno.h>
35#include <sys/stat.h>
36#include "drm.h"
37#include "i915_drm.h"
38
39static void
40test_bad_close(int fd)
41{
42 struct drm_gem_close close;
43 int ret;
44
45 printf("Testing error return on bad close ioctl.\n");
46
47 close.handle = 0x10101010;
48 ret = ioctl(fd, DRM_IOCTL_GEM_CLOSE, &close);
49
50 assert(ret == -1 && errno == EINVAL);
51}
52
53static void
54test_create_close(int fd)
55{
56 struct drm_i915_gem_create create;
57 struct drm_gem_close close;
58 int ret;
59
60 printf("Testing creating and closing an object.\n");
61
62 memset(&create, 0, sizeof(create));
63 create.size = 16 * 1024;
64 ret = ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create);
65 assert(ret == 0);
66
67 close.handle = create.handle;
68 ret = ioctl(fd, DRM_IOCTL_GEM_CLOSE, &close);
69}
70
71static void
72test_create_fd_close(int fd)
73{
74 struct drm_i915_gem_create create;
75 int ret;
76
77 printf("Testing closing with an object allocated.\n");
78
79 memset(&create, 0, sizeof(create));
80 create.size = 16 * 1024;
81 ret = ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create);
82 assert(ret == 0);
83
84 close(fd);
85}
86
87int main(int argc, char **argv)
88{
89 int fd;
90
91 fd = drm_open_matching("8086:*", 0);
92 if (fd < 0) {
93 fprintf(stderr, "failed to open intel drm device\n");
94 return 0;
95 }
96
97 test_bad_close(fd);
98 test_create_close(fd);
99 test_create_fd_close(fd);
100
101 return 0;
102}
diff --git a/tests/gem_flink.c b/tests/gem_flink.c
deleted file mode 100644
index ce43e422..00000000
--- a/tests/gem_flink.c
+++ /dev/null
@@ -1,137 +0,0 @@
1/*
2 * Copyright © 2008 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 *
26 */
27
28#include <stdlib.h>
29#include <stdio.h>
30#include <string.h>
31#include <assert.h>
32#include <fcntl.h>
33#include <inttypes.h>
34#include <errno.h>
35#include <sys/stat.h>
36#include "drm.h"
37#include "i915_drm.h"
38
39static void
40test_flink(int fd)
41{
42 struct drm_i915_gem_create create;
43 struct drm_gem_flink flink;
44 struct drm_gem_open open;
45 int ret;
46
47 printf("Testing flink and open.\n");
48
49 memset(&create, 0, sizeof(create));
50 create.size = 16 * 1024;
51 ret = ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create);
52 assert(ret == 0);
53
54 flink.handle = create.handle;
55 ret = ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink);
56 assert(ret == 0);
57
58 open.name = flink.name;
59 ret = ioctl(fd, DRM_IOCTL_GEM_OPEN, &open);
60 assert(ret == 0);
61 assert(open.handle != 0);
62}
63
64static void
65test_double_flink(int fd)
66{
67 struct drm_i915_gem_create create;
68 struct drm_gem_flink flink;
69 struct drm_gem_flink flink2;
70 int ret;
71
72 printf("Testing repeated flink.\n");
73
74 memset(&create, 0, sizeof(create));
75 create.size = 16 * 1024;
76 ret = ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create);
77 assert(ret == 0);
78
79 flink.handle = create.handle;
80 ret = ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink);
81 assert(ret == 0);
82
83 flink2.handle = create.handle;
84 ret = ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink2);
85 assert(ret == 0);
86 assert(flink2.name == flink.name);
87}
88
89static void
90test_bad_flink(int fd)
91{
92 struct drm_gem_flink flink;
93 int ret;
94
95 printf("Testing error return on bad flink ioctl.\n");
96
97 flink.handle = 0x10101010;
98 ret = ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink);
99 assert(ret == -1 && errno == ENOENT);
100}
101
102static void
103test_bad_open(int fd)
104{
105 struct drm_gem_open open;
106 int ret;
107
108 printf("Testing error return on bad open ioctl.\n");
109
110 open.name = 0x10101010;
111 ret = ioctl(fd, DRM_IOCTL_GEM_OPEN, &open);
112
113 assert(ret == -1 && errno == ENOENT);
114}
115
116int main(int argc, char **argv)
117{
118 int fd;
119
120 if (geteuid()) {
121 fprintf(stderr, "requires root privileges, skipping\n");
122 return 77;
123 }
124
125 fd = drm_open_matching("8086:*", 0);
126 if (fd < 0) {
127 fprintf(stderr, "failed to open intel drm device, skipping\n");
128 return 77;
129 }
130
131 test_flink(fd);
132 test_double_flink(fd);
133 test_bad_flink(fd);
134 test_bad_open(fd);
135
136 return 0;
137}
diff --git a/tests/gem_mmap.c b/tests/gem_mmap.c
deleted file mode 100644
index 2239789f..00000000
--- a/tests/gem_mmap.c
+++ /dev/null
@@ -1,136 +0,0 @@
1/*
2 * Copyright © 2008 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 *
26 */
27
28#include <stdlib.h>
29#include <stdio.h>
30#include <string.h>
31#include <assert.h>
32#include <fcntl.h>
33#include <inttypes.h>
34#include <errno.h>
35#include <sys/stat.h>
36#include "drm.h"
37#include "i915_drm.h"
38
39#define OBJECT_SIZE 16384
40
41int do_read(int fd, int handle, void *buf, int offset, int size)
42{
43 struct drm_i915_gem_pread read;
44
45 /* Ensure that we don't have any convenient data in buf in case
46 * we fail.
47 */
48 memset(buf, 0xd0, size);
49
50 memset(&read, 0, sizeof(read));
51 read.handle = handle;
52 read.data_ptr = (uintptr_t)buf;
53 read.size = size;
54 read.offset = offset;
55
56 return ioctl(fd, DRM_IOCTL_I915_GEM_PREAD, &read);
57}
58
59int do_write(int fd, int handle, void *buf, int offset, int size)
60{
61 struct drm_i915_gem_pwrite write;
62
63 memset(&write, 0, sizeof(write));
64 write.handle = handle;
65 write.data_ptr = (uintptr_t)buf;
66 write.size = size;
67 write.offset = offset;
68
69 return ioctl(fd, DRM_IOCTL_I915_GEM_PWRITE, &write);
70}
71
72int main(int argc, char **argv)
73{
74 int fd;
75 struct drm_i915_gem_create create;
76 struct drm_i915_gem_mmap mmap;
77 struct drm_gem_close unref;
78 uint8_t expected[OBJECT_SIZE];
79 uint8_t buf[OBJECT_SIZE];
80 uint8_t *addr;
81 int ret;
82 int handle;
83
84 fd = drm_open_matching("8086:*", 0);
85 if (fd < 0) {
86 fprintf(stderr, "failed to open intel drm device, skipping\n");
87 return 0;
88 }
89
90 memset(&mmap, 0, sizeof(mmap));
91 mmap.handle = 0x10101010;
92 mmap.offset = 0;
93 mmap.size = 4096;
94 printf("Testing mmaping of bad object.\n");
95 ret = ioctl(fd, DRM_IOCTL_I915_GEM_MMAP, &mmap);
96 assert(ret == -1 && errno == ENOENT);
97
98 memset(&create, 0, sizeof(create));
99 create.size = OBJECT_SIZE;
100 ret = ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create);
101 assert(ret == 0);
102 handle = create.handle;
103
104 printf("Testing mmaping of newly created object.\n");
105 mmap.handle = handle;
106 mmap.offset = 0;
107 mmap.size = OBJECT_SIZE;
108 ret = ioctl(fd, DRM_IOCTL_I915_GEM_MMAP, &mmap);
109 assert(ret == 0);
110 addr = (uint8_t *)(uintptr_t)mmap.addr_ptr;
111
112 printf("Testing contents of newly created object.\n");
113 memset(expected, 0, sizeof(expected));
114 assert(memcmp(addr, expected, sizeof(expected)) == 0);
115
116 printf("Testing coherency of writes and mmap reads.\n");
117 memset(buf, 0, sizeof(buf));
118 memset(buf + 1024, 0x01, 1024);
119 memset(expected + 1024, 0x01, 1024);
120 ret = do_write(fd, handle, buf, 0, OBJECT_SIZE);
121 assert(ret == 0);
122 assert(memcmp(buf, addr, sizeof(buf)) == 0);
123
124 printf("Testing that mapping stays after close\n");
125 unref.handle = handle;
126 ret = ioctl(fd, DRM_IOCTL_GEM_CLOSE, &unref);
127 assert(ret == 0);
128 assert(memcmp(buf, addr, sizeof(buf)) == 0);
129
130 printf("Testing unmapping\n");
131 munmap(addr, OBJECT_SIZE);
132
133 close(fd);
134
135 return 0;
136}
diff --git a/tests/gem_readwrite.c b/tests/gem_readwrite.c
deleted file mode 100644
index 07dc853a..00000000
--- a/tests/gem_readwrite.c
+++ /dev/null
@@ -1,139 +0,0 @@
1/*
2 * Copyright © 2008 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 *
26 */
27
28#include <stdlib.h>
29#include <stdio.h>
30#include <string.h>
31#include <assert.h>
32#include <fcntl.h>
33#include <inttypes.h>
34#include <errno.h>
35#include <sys/stat.h>
36#include "drm.h"
37#include "i915_drm.h"
38
39#define OBJECT_SIZE 16384
40
41int do_read(int fd, int handle, void *buf, int offset, int size)
42{
43 struct drm_i915_gem_pread read;
44
45 /* Ensure that we don't have any convenient data in buf in case
46 * we fail.
47 */
48 memset(buf, 0xd0, size);
49
50 memset(&read, 0, sizeof(read));
51 read.handle = handle;
52 read.data_ptr = (uintptr_t)buf;
53 read.size = size;
54 read.offset = offset;
55
56 return ioctl(fd, DRM_IOCTL_I915_GEM_PREAD, &read);
57}
58
59int do_write(int fd, int handle, void *buf, int offset, int size)
60{
61 struct drm_i915_gem_pwrite write;
62
63 memset(&write, 0, sizeof(write));
64 write.handle = handle;
65 write.data_ptr = (uintptr_t)buf;
66 write.size = size;
67 write.offset = offset;
68
69 return ioctl(fd, DRM_IOCTL_I915_GEM_PWRITE, &write);
70}
71
72int main(int argc, char **argv)
73{
74 int fd;
75 struct drm_i915_gem_create create;
76 uint8_t expected[OBJECT_SIZE];
77 uint8_t buf[OBJECT_SIZE];
78 int ret;
79 int handle;
80
81 fd = drm_open_matching("8086:*", 0);
82 if (fd < 0) {
83 fprintf(stderr, "failed to open intel drm device, skipping\n");
84 return 0;
85 }
86
87 memset(&create, 0, sizeof(create));
88 create.size = OBJECT_SIZE;
89 ret = ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create);
90 assert(ret == 0);
91 handle = create.handle;
92
93 printf("Testing contents of newly created object.\n");
94 ret = do_read(fd, handle, buf, 0, OBJECT_SIZE);
95 assert(ret == 0);
96 memset(&expected, 0, sizeof(expected));
97 assert(memcmp(expected, buf, sizeof(expected)) == 0);
98
99 printf("Testing read beyond end of buffer.\n");
100 ret = do_read(fd, handle, buf, OBJECT_SIZE / 2, OBJECT_SIZE);
101 printf("%d %d\n", ret, errno);
102 assert(ret == -1 && errno == EINVAL);
103
104 printf("Testing full write of buffer\n");
105 memset(buf, 0, sizeof(buf));
106 memset(buf + 1024, 0x01, 1024);
107 memset(expected + 1024, 0x01, 1024);
108 ret = do_write(fd, handle, buf, 0, OBJECT_SIZE);
109 assert(ret == 0);
110 ret = do_read(fd, handle, buf, 0, OBJECT_SIZE);
111 assert(ret == 0);
112 assert(memcmp(buf, expected, sizeof(buf)) == 0);
113
114 printf("Testing partial write of buffer\n");
115 memset(buf + 4096, 0x02, 1024);
116 memset(expected + 4096, 0x02, 1024);
117 ret = do_write(fd, handle, buf + 4096, 4096, 1024);
118 assert(ret == 0);
119 ret = do_read(fd, handle, buf, 0, OBJECT_SIZE);
120 assert(ret == 0);
121 assert(memcmp(buf, expected, sizeof(buf)) == 0);
122
123 printf("Testing partial read of buffer\n");
124 ret = do_read(fd, handle, buf, 512, 1024);
125 assert(ret == 0);
126 assert(memcmp(buf, expected + 512, 1024) == 0);
127
128 printf("Testing read of bad buffer handle\n");
129 ret = do_read(fd, 1234, buf, 0, 1024);
130 assert(ret == -1 && errno == ENOENT);
131
132 printf("Testing write of bad buffer handle\n");
133 ret = do_write(fd, 1234, buf, 0, 1024);
134 assert(ret == -1 && errno == ENOENT);
135
136 close(fd);
137
138 return 0;
139}