~ubuntu-branches/ubuntu/trusty/intel-gpu-tools/trusty-proposed

« back to all changes in this revision

Viewing changes to tests/gem_ctx_bad_exec.c

  • Committer: Package Import Robot
  • Author(s): Timo Aaltonen
  • Date: 2012-09-07 09:30:07 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20120907093007-kmupkih9ch31lo5i
Tags: 1.3-0ubuntu1
Sync from unreleased debian git.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2012 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
 *    Ben Widawsky <ben@bwidawsk.net>
 
25
 *
 
26
 */
 
27
 
 
28
/*
 
29
 * Negative test cases:
 
30
 *  test we can't submit contexts to unsupported rings
 
31
 */
 
32
 
 
33
#include <unistd.h>
 
34
#include <stdlib.h>
 
35
#include <stdint.h>
 
36
#include <stdio.h>
 
37
#include <string.h>
 
38
#include <assert.h>
 
39
#include <fcntl.h>
 
40
#include <inttypes.h>
 
41
#include <errno.h>
 
42
#include <sys/stat.h>
 
43
#include <sys/ioctl.h>
 
44
#include <sys/mman.h>
 
45
#include <sys/time.h>
 
46
#include "drm.h"
 
47
#include "i915_drm.h"
 
48
#include "drmtest.h"
 
49
 
 
50
struct local_drm_i915_gem_context_create {
 
51
        __u32 ctx_id;
 
52
        __u32 pad;
 
53
};
 
54
 
 
55
#define CONTEXT_CREATE_IOCTL DRM_IOWR(DRM_COMMAND_BASE + 0x2d, struct local_drm_i915_gem_context_create)
 
56
 
 
57
static uint32_t context_create(int fd)
 
58
{
 
59
        struct local_drm_i915_gem_context_create create;
 
60
        int ret;
 
61
 
 
62
        ret = drmIoctl(fd, CONTEXT_CREATE_IOCTL, &create);
 
63
        if (ret == -1 && (errno == ENODEV || errno == EINVAL)) {
 
64
                exit(77);
 
65
        } else if (ret) {
 
66
                abort();
 
67
        }
 
68
 
 
69
        return create.ctx_id;
 
70
}
 
71
 
 
72
/* Copied from gem_exec_nop.c */
 
73
static int exec(int fd, uint32_t handle, int ring, int ctx_id)
 
74
{
 
75
        struct drm_i915_gem_execbuffer2 execbuf;
 
76
        struct drm_i915_gem_exec_object2 gem_exec;
 
77
        int ret = 0;
 
78
 
 
79
        gem_exec.handle = handle;
 
80
        gem_exec.relocation_count = 0;
 
81
        gem_exec.relocs_ptr = 0;
 
82
        gem_exec.alignment = 0;
 
83
        gem_exec.offset = 0;
 
84
        gem_exec.flags = 0;
 
85
        gem_exec.rsvd1 = 0;
 
86
        gem_exec.rsvd2 = 0;
 
87
 
 
88
        execbuf.buffers_ptr = (uintptr_t)&gem_exec;
 
89
        execbuf.buffer_count = 1;
 
90
        execbuf.batch_start_offset = 0;
 
91
        execbuf.batch_len = 8;
 
92
        execbuf.cliprects_ptr = 0;
 
93
        execbuf.num_cliprects = 0;
 
94
        execbuf.DR1 = 0;
 
95
        execbuf.DR4 = 0;
 
96
        execbuf.flags = ring;
 
97
        i915_execbuffer2_set_context_id(execbuf, ctx_id);
 
98
        execbuf.rsvd2 = 0;
 
99
 
 
100
        ret = drmIoctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2,
 
101
                        &execbuf);
 
102
        gem_sync(fd, handle);
 
103
 
 
104
        return ret;
 
105
}
 
106
 
 
107
#define MI_BATCH_BUFFER_END     (0xA<<23)
 
108
int main(int argc, char *argv[])
 
109
{
 
110
        uint32_t handle;
 
111
        uint32_t batch[2] = {MI_BATCH_BUFFER_END};
 
112
        uint32_t ctx_id;
 
113
        int fd;
 
114
        fd = drm_open_any();
 
115
 
 
116
        ctx_id = context_create(fd);
 
117
 
 
118
        handle = gem_create(fd, 4096);
 
119
        gem_write(fd, handle, 0, batch, sizeof(batch));
 
120
        assert(exec(fd, handle, I915_EXEC_RENDER, ctx_id) == 0);
 
121
        assert(exec(fd, handle, I915_EXEC_BSD, ctx_id) != 0);
 
122
        assert(exec(fd, handle, I915_EXEC_BLT, ctx_id) != 0);
 
123
 
 
124
        exit(EXIT_SUCCESS);
 
125
}