2008-04-22 17:08:23 -06:00
|
|
|
/*
|
|
|
|
* Copyright © 2008 Intel Corporation
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
* IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Eric Anholt <eric@anholt.net>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2008-04-23 12:32:31 -06:00
|
|
|
#include <string.h>
|
2008-04-22 17:08:23 -06:00
|
|
|
#include <assert.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <inttypes.h>
|
2008-04-23 12:32:31 -06:00
|
|
|
#include <errno.h>
|
2008-04-22 17:08:23 -06:00
|
|
|
#include <sys/stat.h>
|
2008-04-29 14:45:43 -06:00
|
|
|
#include "drm.h"
|
2008-06-11 15:42:40 -06:00
|
|
|
#include "i915_drm.h"
|
2008-04-22 17:08:23 -06:00
|
|
|
|
2008-04-23 12:32:31 -06:00
|
|
|
static void
|
2008-05-12 16:42:20 -06:00
|
|
|
test_bad_close(int fd)
|
2008-04-23 12:32:31 -06:00
|
|
|
{
|
2008-05-12 16:42:20 -06:00
|
|
|
struct drm_gem_close close;
|
2008-04-23 12:32:31 -06:00
|
|
|
int ret;
|
|
|
|
|
2008-05-12 16:42:20 -06:00
|
|
|
printf("Testing error return on bad close ioctl.\n");
|
2008-04-23 12:32:31 -06:00
|
|
|
|
2008-05-12 16:42:20 -06:00
|
|
|
close.handle = 0x10101010;
|
|
|
|
ret = ioctl(fd, DRM_IOCTL_GEM_CLOSE, &close);
|
2008-04-23 12:32:31 -06:00
|
|
|
|
|
|
|
assert(ret == -1 && errno == EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-05-12 16:42:20 -06:00
|
|
|
test_create_close(int fd)
|
2008-04-23 12:32:31 -06:00
|
|
|
{
|
2008-06-11 15:42:40 -06:00
|
|
|
struct drm_i915_gem_create create;
|
2008-05-12 16:42:20 -06:00
|
|
|
struct drm_gem_close close;
|
2008-04-23 12:32:31 -06:00
|
|
|
int ret;
|
|
|
|
|
2008-05-12 16:42:20 -06:00
|
|
|
printf("Testing creating and closing an object.\n");
|
2008-04-23 12:32:31 -06:00
|
|
|
|
2008-05-12 16:42:20 -06:00
|
|
|
memset(&create, 0, sizeof(create));
|
|
|
|
create.size = 16 * 1024;
|
2008-06-11 15:42:40 -06:00
|
|
|
ret = ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create);
|
2008-04-23 12:32:31 -06:00
|
|
|
assert(ret == 0);
|
|
|
|
|
2008-05-12 16:42:20 -06:00
|
|
|
close.handle = create.handle;
|
|
|
|
ret = ioctl(fd, DRM_IOCTL_GEM_CLOSE, &close);
|
2008-04-23 12:32:31 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-05-12 16:42:20 -06:00
|
|
|
test_create_fd_close(int fd)
|
2008-04-23 12:32:31 -06:00
|
|
|
{
|
2008-06-11 15:42:40 -06:00
|
|
|
struct drm_i915_gem_create create;
|
2008-04-23 12:32:31 -06:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
printf("Testing closing with an object allocated.\n");
|
|
|
|
|
2008-05-12 16:42:20 -06:00
|
|
|
memset(&create, 0, sizeof(create));
|
|
|
|
create.size = 16 * 1024;
|
2008-06-11 15:42:40 -06:00
|
|
|
ret = ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create);
|
2008-04-23 12:32:31 -06:00
|
|
|
assert(ret == 0);
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
}
|
2008-04-22 17:08:23 -06:00
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
|
2009-04-06 15:13:01 -06:00
|
|
|
fd = drm_open_matching("8086:*", 0);
|
|
|
|
if (fd < 0) {
|
|
|
|
fprintf(stderr, "failed to open intel drm device\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2008-04-22 17:08:23 -06:00
|
|
|
|
2008-05-12 16:42:20 -06:00
|
|
|
test_bad_close(fd);
|
|
|
|
test_create_close(fd);
|
|
|
|
test_create_fd_close(fd);
|
2008-04-22 17:08:23 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|