summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2007-08-16 09:23:09 -0700
committerEric Anholt <eric@anholt.net>2007-08-16 09:23:09 -0700
commit0055fd5c35306a6363b0414f7f2220b3d1c27ecc (patch)
tree40178e87d98efeb4bd9e0030b989a31e2090b9c9 /tests
parent3a0bc518e35c62bb9c64c9105f836584d949653f (diff)
parent02c4e0e757b69cd6ae38b8ab2c078b3f06fea661 (diff)
Merge branch 'master' into bo-set-pin
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am9
-rw-r--r--tests/auth.c137
-rw-r--r--tests/updatedraw.c63
3 files changed, 185 insertions, 24 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3b97fb79..e846efbe 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,5 +1,6 @@
AM_CFLAGS = \
- -I $(top_srcdir)/shared-core
+ -I $(top_srcdir)/shared-core \
+ -I $(top_srcdir)/libdrm
noinst_PROGRAMS = \
dristat \
@@ -14,10 +15,12 @@ libdrmtest_la_LIBADD = \
LDADD = libdrmtest.la
-TESTS = openclose \
+TESTS = auth \
+ openclose \
getversion \
getclient \
updatedraw
EXTRA_PROGRAMS = $(TESTS)
-CLEANFILES = $(EXTRA_PROGRAMS) $(EXTRA_LTLIBRARIES) \ No newline at end of file
+CLEANFILES = $(EXTRA_PROGRAMS) $(EXTRA_LTLIBRARIES)
+
diff --git a/tests/auth.c b/tests/auth.c
new file mode 100644
index 00000000..45265d6c
--- /dev/null
+++ b/tests/auth.c
@@ -0,0 +1,137 @@
+/*
+ * Copyright © 2007 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 <limits.h>
+#include "drmtest.h"
+
+enum auth_event {
+ SERVER_READY,
+ CLIENT_MAGIC,
+ CLIENT_DONE,
+};
+
+int commfd[2];
+
+static void wait_event(int pipe, enum auth_event expected_event)
+{
+ int ret;
+ enum auth_event event;
+ unsigned char in;
+
+ ret = read(commfd[pipe], &in, 1);
+ if (ret == -1)
+ err(1, "read error");
+ event = in;
+
+ if (event != expected_event)
+ errx(1, "unexpected event: %d\n", event);
+}
+
+static void
+send_event(int pipe, enum auth_event send_event)
+{
+ int ret;
+ unsigned char event;
+
+ event = send_event;
+ ret = write(commfd[pipe], &event, 1);
+ if (ret == -1)
+ err(1, "failed to send event %d", event);
+}
+
+static void client()
+{
+ struct drm_auth auth;
+ int drmfd, ret;
+
+ /* XXX: Should make sure we open the same DRM as the master */
+ drmfd = drm_open_any();
+
+ wait_event(0, SERVER_READY);
+
+ /* Get a client magic number and pass it to the master for auth. */
+ auth.magic = 0; /* Quiet valgrind */
+ ret = ioctl(drmfd, DRM_IOCTL_GET_MAGIC, &auth);
+ if (ret == -1)
+ err(1, "Couldn't get client magic");
+ send_event(0, CLIENT_MAGIC);
+ ret = write(commfd[0], &auth.magic, sizeof(auth.magic));
+ if (ret == -1)
+ err(1, "Couldn't write auth data");
+
+ /* Signal that the client is completely done. */
+ send_event(0, CLIENT_DONE);
+}
+
+static void server()
+{
+ int drmfd, ret;
+ struct drm_auth auth;
+
+ drmfd = drm_open_any_master();
+
+ auth.magic = 0xd0d0d0d0;
+ ret = ioctl(drmfd, DRM_IOCTL_AUTH_MAGIC, &auth);
+ if (ret != -1 || errno != EINVAL)
+ errx(1, "Authenticating bad magic succeeded\n");
+
+ send_event(1, SERVER_READY);
+
+ wait_event(1, CLIENT_MAGIC);
+ ret = read(commfd[1], &auth.magic, sizeof(auth.magic));
+ if (ret == -1)
+ err(1, "Failure to read client magic");
+
+ ret = ioctl(drmfd, DRM_IOCTL_AUTH_MAGIC, &auth);
+ if (ret == -1)
+ err(1, "Authenticating bad magic succeeded\n");
+
+ wait_event(1, CLIENT_DONE);
+}
+
+/**
+ * Checks DRM authentication mechanisms.
+ */
+int main(int argc, char **argv)
+{
+ int ret;
+
+ ret = pipe(commfd);
+ if (ret == -1)
+ err(1, "Couldn't create pipe");
+
+ ret = fork();
+ if (ret == -1)
+ err(1, "failure to fork client");
+ if (ret == 0)
+ client();
+ else
+ server();
+
+ return 0;
+}
+
diff --git a/tests/updatedraw.c b/tests/updatedraw.c
index 1186783a..2f22fef2 100644
--- a/tests/updatedraw.c
+++ b/tests/updatedraw.c
@@ -83,16 +83,10 @@ set_draw_cliprects_2(int fd, int drawable)
assert(ret == 0);
}
-/**
- * Tests drawable management: adding, removing, and updating the cliprects of
- * drawables.
- */
-int main(int argc, char **argv)
+static int add_drawable(int fd)
{
drm_draw_t drawarg;
- int fd, ret, drawable;
-
- fd = drm_open_any_master();
+ int ret;
/* Create a drawable.
* IOCTL_ADD_DRAW is RDWR, though it should really just be RD
@@ -100,27 +94,54 @@ int main(int argc, char **argv)
drawarg.handle = 0;
ret = ioctl(fd, DRM_IOCTL_ADD_DRAW, &drawarg);
assert(ret == 0);
- drawable = drawarg.handle;
+ return drawarg.handle;
+}
- /* Do a series of cliprect updates */
- set_draw_cliprects_empty(fd, drawable);
- set_draw_cliprects_2(fd, drawable);
- set_draw_cliprects_empty(fd, drawable);
+static int rm_drawable(int fd, int drawable, int fail)
+{
+ drm_draw_t drawarg;
+ int ret;
- /* Remove our drawable */
+ /* Create a drawable.
+ * IOCTL_ADD_DRAW is RDWR, though it should really just be RD
+ */
drawarg.handle = drawable;
ret = ioctl(fd, DRM_IOCTL_RM_DRAW, &drawarg);
- assert(ret == 0);
- drawable = drawarg.handle;
+ if (!fail)
+ assert(ret == 0);
+ else
+ assert(ret == -1 && errno == EINVAL);
+
+ return drawarg.handle;
+}
+
+/**
+ * Tests drawable management: adding, removing, and updating the cliprects of
+ * drawables.
+ */
+int main(int argc, char **argv)
+{
+ int fd, ret, d1, d2;
+
+ fd = drm_open_any_master();
+
+ d1 = add_drawable(fd);
+ d2 = add_drawable(fd);
+ /* Do a series of cliprect updates */
+ set_draw_cliprects_empty(fd, d1);
+ set_draw_cliprects_empty(fd, d2);
+ set_draw_cliprects_2(fd, d1);
+ set_draw_cliprects_empty(fd, d1);
+
+ /* Remove our drawables */
+ rm_drawable(fd, d1, 0);
+ rm_drawable(fd, d2, 0);
/* Check that removing an unknown drawable returns error */
- drawarg.handle = 0x7fffffff;
- ret = ioctl(fd, DRM_IOCTL_RM_DRAW, &drawarg);
- assert(ret == -1 && errno == EINVAL);
- drawable = drawarg.handle;
+ rm_drawable(fd, 0x7fffffff, 1);
/* Attempt to set cliprects on a nonexistent drawable */
- set_draw_cliprects_empty_fail(fd, drawable);
+ set_draw_cliprects_empty_fail(fd, d1);
close(fd);
return 0;