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 static void
test_bad_close(int fd)40 test_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
53 static void
test_create_close(int fd)54 test_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
71 static void
test_create_fd_close(int fd)72 test_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
main(int argc,char ** argv)87 int 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 }
103