diff options
author | Eric Anholt | 2007-08-13 13:27:46 -0500 |
---|---|---|
committer | Eric Anholt | 2007-08-13 13:27:46 -0500 |
commit | d6a45ebf0ee47c31f560f3072a4b70c4039e454a (patch) | |
tree | 86f284add702a61cac56778af6efcee820945404 /tests | |
parent | 3b07a37a48ca6dc22d538221b59b430dd72c6203 (diff) | |
download | external-libdrm-d6a45ebf0ee47c31f560f3072a4b70c4039e454a.tar.gz external-libdrm-d6a45ebf0ee47c31f560f3072a4b70c4039e454a.tar.xz external-libdrm-d6a45ebf0ee47c31f560f3072a4b70c4039e454a.zip |
Add a regression test for authentication.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 3 | ||||
-rw-r--r-- | tests/auth.c | 137 |
2 files changed, 139 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 38a07a35..e846efbe 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am | |||
@@ -15,7 +15,8 @@ libdrmtest_la_LIBADD = \ | |||
15 | 15 | ||
16 | LDADD = libdrmtest.la | 16 | LDADD = libdrmtest.la |
17 | 17 | ||
18 | TESTS = openclose \ | 18 | TESTS = auth \ |
19 | openclose \ | ||
19 | getversion \ | 20 | getversion \ |
20 | getclient \ | 21 | getclient \ |
21 | updatedraw | 22 | updatedraw |
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 @@ | |||
1 | /* | ||
2 | * Copyright © 2007 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 | * Eric Anholt <eric@anholt.net> | ||
25 | * | ||
26 | */ | ||
27 | |||
28 | #include <limits.h> | ||
29 | #include "drmtest.h" | ||
30 | |||
31 | enum auth_event { | ||
32 | SERVER_READY, | ||
33 | CLIENT_MAGIC, | ||
34 | CLIENT_DONE, | ||
35 | }; | ||
36 | |||
37 | int commfd[2]; | ||
38 | |||
39 | static void wait_event(int pipe, enum auth_event expected_event) | ||
40 | { | ||
41 | int ret; | ||
42 | enum auth_event event; | ||
43 | unsigned char in; | ||
44 | |||
45 | ret = read(commfd[pipe], &in, 1); | ||
46 | if (ret == -1) | ||
47 | err(1, "read error"); | ||
48 | event = in; | ||
49 | |||
50 | if (event != expected_event) | ||
51 | errx(1, "unexpected event: %d\n", event); | ||
52 | } | ||
53 | |||
54 | static void | ||
55 | send_event(int pipe, enum auth_event send_event) | ||
56 | { | ||
57 | int ret; | ||
58 | unsigned char event; | ||
59 | |||
60 | event = send_event; | ||
61 | ret = write(commfd[pipe], &event, 1); | ||
62 | if (ret == -1) | ||
63 | err(1, "failed to send event %d", event); | ||
64 | } | ||
65 | |||
66 | static void client() | ||
67 | { | ||
68 | struct drm_auth auth; | ||
69 | int drmfd, ret; | ||
70 | |||
71 | /* XXX: Should make sure we open the same DRM as the master */ | ||
72 | drmfd = drm_open_any(); | ||
73 | |||
74 | wait_event(0, SERVER_READY); | ||
75 | |||
76 | /* Get a client magic number and pass it to the master for auth. */ | ||
77 | auth.magic = 0; /* Quiet valgrind */ | ||
78 | ret = ioctl(drmfd, DRM_IOCTL_GET_MAGIC, &auth); | ||
79 | if (ret == -1) | ||
80 | err(1, "Couldn't get client magic"); | ||
81 | send_event(0, CLIENT_MAGIC); | ||
82 | ret = write(commfd[0], &auth.magic, sizeof(auth.magic)); | ||
83 | if (ret == -1) | ||
84 | err(1, "Couldn't write auth data"); | ||
85 | |||
86 | /* Signal that the client is completely done. */ | ||
87 | send_event(0, CLIENT_DONE); | ||
88 | } | ||
89 | |||
90 | static void server() | ||
91 | { | ||
92 | int drmfd, ret; | ||
93 | struct drm_auth auth; | ||
94 | |||
95 | drmfd = drm_open_any_master(); | ||
96 | |||
97 | auth.magic = 0xd0d0d0d0; | ||
98 | ret = ioctl(drmfd, DRM_IOCTL_AUTH_MAGIC, &auth); | ||
99 | if (ret != -1 || errno != EINVAL) | ||
100 | errx(1, "Authenticating bad magic succeeded\n"); | ||
101 | |||
102 | send_event(1, SERVER_READY); | ||
103 | |||
104 | wait_event(1, CLIENT_MAGIC); | ||
105 | ret = read(commfd[1], &auth.magic, sizeof(auth.magic)); | ||
106 | if (ret == -1) | ||
107 | err(1, "Failure to read client magic"); | ||
108 | |||
109 | ret = ioctl(drmfd, DRM_IOCTL_AUTH_MAGIC, &auth); | ||
110 | if (ret == -1) | ||
111 | err(1, "Authenticating bad magic succeeded\n"); | ||
112 | |||
113 | wait_event(1, CLIENT_DONE); | ||
114 | } | ||
115 | |||
116 | /** | ||
117 | * Checks DRM authentication mechanisms. | ||
118 | */ | ||
119 | int main(int argc, char **argv) | ||
120 | { | ||
121 | int ret; | ||
122 | |||
123 | ret = pipe(commfd); | ||
124 | if (ret == -1) | ||
125 | err(1, "Couldn't create pipe"); | ||
126 | |||
127 | ret = fork(); | ||
128 | if (ret == -1) | ||
129 | err(1, "failure to fork client"); | ||
130 | if (ret == 0) | ||
131 | client(); | ||
132 | else | ||
133 | server(); | ||
134 | |||
135 | return 0; | ||
136 | } | ||
137 | |||