OSDN Git Service

[GEM] Update testcases for new API.
[android-x86/external-libdrm.git] / tests / gem_basic.c
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
38 static void
39 test_bad_close(int fd)
40 {
41         struct drm_gem_close close;
42         int ret;
43
44         printf("Testing error return on bad close ioctl.\n");
45
46         close.handle = 0x10101010;
47         ret = ioctl(fd, DRM_IOCTL_GEM_CLOSE, &close);
48
49         assert(ret == -1 && errno == EINVAL);
50 }
51
52 static void
53 test_create_close(int fd)
54 {
55         struct drm_gem_create create;
56         struct drm_gem_close close;
57         int ret;
58
59         printf("Testing creating and closing an object.\n");
60
61         memset(&create, 0, sizeof(create));
62         create.size = 16 * 1024;
63         ret = ioctl(fd, DRM_IOCTL_GEM_CREATE, &create);
64         assert(ret == 0);
65
66         close.handle = create.handle;
67         ret = ioctl(fd, DRM_IOCTL_GEM_CLOSE, &close);
68 }
69
70 static void
71 test_create_fd_close(int fd)
72 {
73         struct drm_gem_create create;
74         int ret;
75
76         printf("Testing closing with an object allocated.\n");
77
78         memset(&create, 0, sizeof(create));
79         create.size = 16 * 1024;
80         ret = ioctl(fd, DRM_IOCTL_GEM_CREATE, &create);
81         assert(ret == 0);
82
83         close(fd);
84 }
85
86 int main(int argc, char **argv)
87 {
88         int fd;
89
90         fd = drm_open_any();
91
92         test_bad_close(fd);
93         test_create_close(fd);
94         test_create_fd_close(fd);
95
96         return 0;
97 }