Back to index

libdrm  2.4.37
setversion.c
Go to the documentation of this file.
00001 /*
00002  * Copyright © 2007 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 <limits.h>
00029 #include "drmtest.h"
00030 
00038 int main(int argc, char **argv)
00039 {
00040        int fd, ret;
00041        drm_set_version_t sv, version;
00042 
00043        if (getuid() != 0) {
00044               fprintf(stderr, "setversion test requires root, skipping\n");
00045               return 0;
00046        }
00047 
00048        fd = drm_open_any_master();
00049 
00050        /* First, check that we can get the DD/DI versions. */
00051        memset(&version, 0, sizeof(version));
00052        version.drm_di_major = -1;
00053        version.drm_di_minor = -1;
00054        version.drm_dd_major = -1;
00055        version.drm_dd_minor = -1;
00056        ret = ioctl(fd, DRM_IOCTL_SET_VERSION, &version);
00057        assert(ret == 0);
00058        assert(version.drm_di_major != -1);
00059        assert(version.drm_di_minor != -1);
00060        assert(version.drm_dd_major != -1);
00061        assert(version.drm_dd_minor != -1);
00062 
00063        /* Check that an invalid DI major fails */
00064        sv = version;
00065        sv.drm_di_major++;
00066        ret = ioctl(fd, DRM_IOCTL_SET_VERSION, &sv);
00067        assert(ret == -1 && errno == EINVAL);
00068 
00069        /* Check that an invalid DI minor fails */
00070        sv = version;
00071        sv.drm_di_major++;
00072        ret = ioctl(fd, DRM_IOCTL_SET_VERSION, &sv);
00073        assert(ret == -1 && errno == EINVAL);
00074 
00075        /* Check that an invalid DD major fails */
00076        sv = version;
00077        sv.drm_dd_major++;
00078        ret = ioctl(fd, DRM_IOCTL_SET_VERSION, &sv);
00079        assert(ret == -1 && errno == EINVAL);
00080 
00081        /* Check that an invalid DD minor fails */
00082        sv = version;
00083        sv.drm_dd_minor++;
00084        ret = ioctl(fd, DRM_IOCTL_SET_VERSION, &sv);
00085        assert(ret == -1 && errno == EINVAL);
00086 
00087        close(fd);
00088        return 0;
00089 }