kms_rotation_crc: Allow the sprite test to run even without universal planes
[platform/upstream/intel-gpu-tools.git] / tests / core_get_client_auth.c
1 /*
2  * Copyright © 2012,2013 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  *    Daniel Vetter <daniel.vetter@ffwll.ch>
25  *
26  * Based upon code from libva/va/drm/va_drm_auth.c:
27  */
28
29 /*
30  * Testcase: Check that the hollowed-out get_client ioctl still works for libva
31  *
32  * Oh dear, libva, why do you do such funny things?
33  */
34
35 #define _GNU_SOURCE
36 #include <unistd.h>
37 #include <stdlib.h>
38 #include <stdio.h>
39 #include <string.h>
40 # include <sys/syscall.h>
41
42 #include "drm.h"
43 #include "ioctl_wrappers.h"
44 #include "drmtest.h"
45
46 /* Checks whether the thread id is the current thread */
47 static bool
48 is_local_tid(pid_t tid)
49 {
50 #ifndef ANDROID
51         /* On Linux systems, drmGetClient() would return the thread ID
52            instead of the actual process ID */
53         return syscall(SYS_gettid) == tid;
54 #else
55         return gettid() == tid;
56 #endif
57 }
58
59
60 static bool check_auth(int fd)
61 {
62         pid_t client_pid;
63         int i, auth, pid, uid;
64         unsigned long magic, iocs;
65         bool is_authenticated = false;
66
67         client_pid = getpid();
68         for (i = 0; !is_authenticated; i++) {
69                 if (drmGetClient(fd, i, &auth, &pid, &uid, &magic, &iocs) != 0)
70                         break;
71                 is_authenticated = auth && (pid == client_pid || is_local_tid(pid));
72         }
73         return is_authenticated;
74 }
75
76
77 igt_main
78 {
79         /* root (which we run igt as) should always be authenticated */
80         igt_subtest("simple") {
81                 int fd = drm_open_any();
82
83                 igt_assert(check_auth(fd) == true);
84
85                 close(fd);
86         }
87
88         igt_subtest("master-drop") {
89                 int fd = drm_open_any();
90                 int fd2 = drm_open_any();
91
92                 igt_assert(check_auth(fd2) == true);
93
94                 close(fd);
95
96                 igt_assert(check_auth(fd2) == true);
97
98                 close(fd2);
99         }
100 }