summaryrefslogtreecommitdiff
path: root/tests/core_auth.c
diff options
context:
space:
mode:
authorDaniel Vetter <daniel.vetter@ffwll.ch>2019-01-23 12:31:08 +0100
committerDaniel Vetter <daniel.vetter@ffwll.ch>2019-01-29 11:01:00 +0100
commitbd796ece3e35f0dd5f17ab1c4ca615e81faa312a (patch)
treeb6a818f3715971ab9dc12b4ea9574a1e98a1b47d /tests/core_auth.c
parent9e01bb1b82cc66c0daddb4a252c6db62e0d2ca66 (diff)
tests/core_auth: Merge getclient subtests
Emil has another auth test which could use the check_auth function, so best to merge them all. We need a subtest group and put the tests which need to fully control who's master and how many open drm fd there are first. Cc: Emil Velikov <emil.l.velikov@gmail.com> Acked-by: Emil Velikov <emil.velikov@collabora.com> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Diffstat (limited to 'tests/core_auth.c')
-rw-r--r--tests/core_auth.c75
1 files changed, 68 insertions, 7 deletions
diff --git a/tests/core_auth.c b/tests/core_auth.c
index cedcff92..0c016a37 100644
--- a/tests/core_auth.c
+++ b/tests/core_auth.c
@@ -42,8 +42,44 @@
#include <sys/resource.h>
#include "drm.h"
+#ifdef __linux__
+# include <sys/syscall.h>
+#else
+# include <pthread.h>
+#endif
+
IGT_TEST_DESCRIPTION("Call drmGetMagic() and drmAuthMagic() and see if it behaves.");
+static bool
+is_local_tid(pid_t tid)
+{
+#ifndef __linux__
+ return pthread_self() == tid;
+#else
+ /* On Linux systems, drmGetClient() would return the thread ID
+ instead of the actual process ID */
+ return syscall(SYS_gettid) == tid;
+#endif
+}
+
+
+static bool check_auth(int fd)
+{
+ pid_t client_pid;
+ int i, auth, pid, uid;
+ unsigned long magic, iocs;
+ bool is_authenticated = false;
+
+ client_pid = getpid();
+ for (i = 0; !is_authenticated; i++) {
+ if (drmGetClient(fd, i, &auth, &pid, &uid, &magic, &iocs) != 0)
+ break;
+ is_authenticated = auth && (pid == client_pid || is_local_tid(pid));
+ }
+ return is_authenticated;
+}
+
+
static int magic_cmp(const void *p1, const void *p2)
{
return *(const drm_magic_t*)p1 < *(const drm_magic_t*)p2;
@@ -158,13 +194,38 @@ igt_main
{
int master;
- igt_fixture
- master = drm_open_driver_master(DRIVER_ANY);
+ /* root (which we run igt as) should always be authenticated */
+ igt_subtest("getclient-simple") {
+ int fd = drm_open_driver(DRIVER_ANY);
- igt_subtest("basic-auth")
- test_basic_auth(master);
+ igt_assert(check_auth(fd) == true);
- /* this must be last, we adjust the rlimit */
- igt_subtest("many-magics")
- test_many_magics(master);
+ close(fd);
+ }
+
+ igt_subtest("getclient-master-drop") {
+ int fd = drm_open_driver(DRIVER_ANY);
+ int fd2 = drm_open_driver(DRIVER_ANY);
+
+ igt_assert(check_auth(fd2) == true);
+
+ close(fd);
+
+ igt_assert(check_auth(fd2) == true);
+
+ close(fd2);
+ }
+
+ /* above tests require that no drm fd is open */
+ igt_subtest_group {
+ igt_fixture
+ master = drm_open_driver_master(DRIVER_ANY);
+
+ igt_subtest("basic-auth")
+ test_basic_auth(master);
+
+ /* this must be last, we adjust the rlimit */
+ igt_subtest("many-magics")
+ test_many_magics(master);
+ }
}