OSDN Git Service

Move mmfs ioctls into the DRM. Untested.
[android-x86/external-libdrm.git] / tests / mm_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_unref(int fd)
40 {
41         struct drm_mm_unreference_args unref;
42         int ret;
43
44         printf("Testing error return on bad unreference ioctl.\n");
45
46         unref.handle = 0x10101010;
47         ret = ioctl(fd, DRM_IOCTL_MM_UNREFERENCE, &unref);
48
49         assert(ret == -1 && errno == EINVAL);
50 }
51
52 static void
53 test_alloc_unref(int fd)
54 {
55         struct drm_mm_alloc_args alloc;
56         struct drm_mm_unreference_args unref;
57         int ret;
58
59         printf("Testing allocating and unreferencing an object.\n");
60
61         memset(&alloc, 0, sizeof(alloc));
62         alloc.size = 16 * 1024;
63         ret = ioctl(fd, DRM_IOCTL_MM_ALLOC, &alloc);
64         assert(ret == 0);
65
66         unref.handle = alloc.handle;
67         ret = ioctl(fd, DRM_IOCTL_MM_UNREFERENCE, &unref);
68 }
69
70 static void
71 test_alloc_close(int fd)
72 {
73         struct drm_mm_alloc_args alloc;
74         int ret;
75
76         printf("Testing closing with an object allocated.\n");
77
78         memset(&alloc, 0, sizeof(alloc));
79         alloc.size = 16 * 1024;
80         ret = ioctl(fd, DRM_IOCTL_MM_ALLOC, &alloc);
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_unref(fd);
93         test_alloc_unref(fd);
94         test_alloc_close(fd);
95
96         close(fd);
97
98         return 0;
99 }