2 * Copyright © 2012,2013 Intel Corporation
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:
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
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
24 * Daniel Vetter <daniel.vetter@ffwll.ch>
26 * Based upon code from libva/va/drm/va_drm_auth.c:
30 * Testcase: Check that the hollowed-out get_client ioctl still works for libva
32 * Oh dear, libva, why do you do such funny things?
40 # include <sys/syscall.h>
43 #include "ioctl_wrappers.h"
46 /* Checks whether the thread id is the current thread */
48 is_local_tid(pid_t tid)
51 /* On Linux systems, drmGetClient() would return the thread ID
52 instead of the actual process ID */
53 return syscall(SYS_gettid) == tid;
55 return gettid() == tid;
60 static bool check_auth(int fd)
63 int i, auth, pid, uid;
64 unsigned long magic, iocs;
65 bool is_authenticated = false;
67 client_pid = getpid();
68 for (i = 0; !is_authenticated; i++) {
69 if (drmGetClient(fd, i, &auth, &pid, &uid, &magic, &iocs) != 0)
71 is_authenticated = auth && (pid == client_pid || is_local_tid(pid));
73 return is_authenticated;
79 /* root (which we run igt as) should always be authenticated */
80 igt_subtest("simple") {
81 int fd = drm_open_any();
83 igt_assert(check_auth(fd) == true);
88 igt_subtest("master-drop") {
89 int fd = drm_open_any();
90 int fd2 = drm_open_any();
92 igt_assert(check_auth(fd2) == true);
96 igt_assert(check_auth(fd2) == true);