No empty .Rs/.Re
[netbsd-mini2440.git] / sys / external / bsd / drm / dist / tests / gem_basic.c
blob4e4b6cbdf1a9317c6fad7fc0a3c731ef4c2d9275
1 /*
2 * Copyright © 2008 Intel Corporation
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:
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.
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.
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
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"
39 static void
40 test_bad_close(int fd)
42 struct drm_gem_close close;
43 int ret;
45 printf("Testing error return on bad close ioctl.\n");
47 close.handle = 0x10101010;
48 ret = ioctl(fd, DRM_IOCTL_GEM_CLOSE, &close);
50 assert(ret == -1 && errno == EINVAL);
53 static void
54 test_create_close(int fd)
56 struct drm_i915_gem_create create;
57 struct drm_gem_close close;
58 int ret;
60 printf("Testing creating and closing an object.\n");
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);
67 close.handle = create.handle;
68 ret = ioctl(fd, DRM_IOCTL_GEM_CLOSE, &close);
71 static void
72 test_create_fd_close(int fd)
74 struct drm_i915_gem_create create;
75 int ret;
77 printf("Testing closing with an object allocated.\n");
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);
84 close(fd);
87 int main(int argc, char **argv)
89 int fd;
91 fd = drm_open_matching("8086:*", 0);
92 if (fd < 0) {
93 fprintf(stderr, "failed to open intel drm device\n");
94 return 0;
97 test_bad_close(fd);
98 test_create_close(fd);
99 test_create_fd_close(fd);
101 return 0;