Back to index

libdrm  2.4.37
gem_basic.c
Go to the documentation of this file.
00001 /*
00002  * Copyright © 2008 Intel Corporation
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a
00005  * copy of this software and associated documentation files (the "Software"),
00006  * to deal in the Software without restriction, including without limitation
00007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008  * and/or sell copies of the Software, and to permit persons to whom the
00009  * Software is furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice (including the next
00012  * paragraph) shall be included in all copies or substantial portions of the
00013  * Software.
00014  *
00015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
00018  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00020  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
00021  * IN THE SOFTWARE.
00022  *
00023  * Authors:
00024  *    Eric Anholt <eric@anholt.net>
00025  *
00026  */
00027 
00028 #include <stdlib.h>
00029 #include <stdio.h>
00030 #include <string.h>
00031 #include <assert.h>
00032 #include <fcntl.h>
00033 #include <inttypes.h>
00034 #include <errno.h>
00035 #include <sys/stat.h>
00036 #include "drm.h"
00037 #include "i915_drm.h"
00038 
00039 static void
00040 test_bad_close(int fd)
00041 {
00042        struct drm_gem_close close;
00043        int ret;
00044 
00045        printf("Testing error return on bad close ioctl.\n");
00046 
00047        close.handle = 0x10101010;
00048        ret = ioctl(fd, DRM_IOCTL_GEM_CLOSE, &close);
00049 
00050        assert(ret == -1 && errno == EINVAL);
00051 }
00052 
00053 static void
00054 test_create_close(int fd)
00055 {
00056        struct drm_i915_gem_create create;
00057        struct drm_gem_close close;
00058        int ret;
00059 
00060        printf("Testing creating and closing an object.\n");
00061 
00062        memset(&create, 0, sizeof(create));
00063        create.size = 16 * 1024;
00064        ret = ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create);
00065        assert(ret == 0);
00066 
00067        close.handle = create.handle;
00068        ret = ioctl(fd, DRM_IOCTL_GEM_CLOSE, &close);
00069 }
00070 
00071 static void
00072 test_create_fd_close(int fd)
00073 {
00074        struct drm_i915_gem_create create;
00075        int ret;
00076 
00077        printf("Testing closing with an object allocated.\n");
00078 
00079        memset(&create, 0, sizeof(create));
00080        create.size = 16 * 1024;
00081        ret = ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create);
00082        assert(ret == 0);
00083 
00084        close(fd);
00085 }
00086 
00087 int main(int argc, char **argv)
00088 {
00089        int fd;
00090 
00091        fd = drm_open_matching("8086:*", 0);
00092        if (fd < 0) {
00093               fprintf(stderr, "failed to open intel drm device\n");
00094               return 0;
00095        }
00096 
00097        test_bad_close(fd);
00098        test_create_close(fd);
00099        test_create_fd_close(fd);
00100 
00101        return 0;
00102 }