]> git.ipfire.org Git - thirdparty/kmod.git/blame - testsuite/test-modprobe.c
testsuite: add test to ignore unrelated strings in kcmdline
[thirdparty/kmod.git] / testsuite / test-modprobe.c
CommitLineData
976ea8c3 1/*
e6b0e49b 2 * Copyright (C) 2012-2013 ProFUSION embedded systems
976ea8c3 3 *
e1b1ab24
LDM
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
976ea8c3
LDM
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e1b1ab24
LDM
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
976ea8c3 13 *
e1b1ab24
LDM
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
976ea8c3
LDM
17 */
18
19#include <stdio.h>
20#include <stdlib.h>
21#include <stddef.h>
22#include <errno.h>
23#include <unistd.h>
24#include <inttypes.h>
25#include <string.h>
26
27#include "testsuite.h"
28
d96ca9c4 29static noreturn int modprobe_show_depends(const struct test *t)
976ea8c3 30{
b6adccd6 31 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
976ea8c3
LDM
32 const char *const args[] = {
33 progname,
34 "--show-depends", "btusb",
35 NULL,
36 };
37
38 test_spawn_prog(progname, args);
39 exit(EXIT_FAILURE);
40}
41static DEFINE_TEST(modprobe_show_depends,
42 .description = "check if output for modprobe --show-depends is correct for loaded modules",
43 .config = {
44 [TC_UNAME_R] = "4.4.4",
45 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/show-depends",
46 },
47 .output = {
bd4e7340 48 .out = TESTSUITE_ROOTFS "test-modprobe/show-depends/correct.txt",
976ea8c3
LDM
49 });
50
d96ca9c4 51static noreturn int modprobe_show_depends2(const struct test *t)
976ea8c3 52{
b6adccd6 53 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
976ea8c3
LDM
54 const char *const args[] = {
55 progname,
56 "--show-depends", "psmouse",
57 NULL,
58 };
59
60 test_spawn_prog(progname, args);
61 exit(EXIT_FAILURE);
62}
63static DEFINE_TEST(modprobe_show_depends2,
64 .description = "check if output for modprobe --show-depends is correct",
65 .config = {
66 [TC_UNAME_R] = "4.4.4",
67 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/show-depends",
68 },
69 .output = {
bd4e7340 70 .out = TESTSUITE_ROOTFS "test-modprobe/show-depends/correct-psmouse.txt",
976ea8c3 71 });
a7f5300d 72
5278396d 73
d96ca9c4 74static noreturn int modprobe_show_alias_to_none(const struct test *t)
5278396d 75{
b6adccd6 76 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
5278396d
LDM
77 const char *const args[] = {
78 progname,
79 "--show-depends", "--ignore-install", "--quiet", "psmouse",
80 NULL,
81 };
82
83 test_spawn_prog(progname, args);
84 exit(EXIT_FAILURE);
85}
86static DEFINE_TEST(modprobe_show_alias_to_none,
87 .description = "check if modprobe --show-depends doesn't explode with an alias to nothing",
5278396d
LDM
88 .config = {
89 [TC_UNAME_R] = "4.4.4",
90 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/alias-to-none",
91 },
92 .output = {
bd4e7340 93 .out = TESTSUITE_ROOTFS "test-modprobe/show-depends/correct-psmouse.txt",
88ac4084
MM
94 },
95 .modules_loaded = "",
96 );
5278396d
LDM
97
98
d96ca9c4 99static noreturn int modprobe_builtin(const struct test *t)
a7f5300d 100{
b6adccd6 101 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
a7f5300d
LDM
102 const char *const args[] = {
103 progname,
104 "unix",
105 NULL,
106 };
107
108 test_spawn_prog(progname, args);
109 exit(EXIT_FAILURE);
110}
111static DEFINE_TEST(modprobe_builtin,
112 .description = "check if modprobe return 0 for builtin",
a7f5300d
LDM
113 .config = {
114 [TC_UNAME_R] = "4.4.4",
115 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/builtin",
116 });
117
d96ca9c4 118static noreturn int modprobe_softdep_loop(const struct test *t)
a6976f8b 119{
b6adccd6 120 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
a6976f8b
LDM
121 const char *const args[] = {
122 progname,
123 "bluetooth",
124 NULL,
125 };
126
127 test_spawn_prog(progname, args);
128 exit(EXIT_FAILURE);
129}
130static DEFINE_TEST(modprobe_softdep_loop,
131 .description = "check if modprobe breaks softdep loop",
132 .config = {
133 [TC_UNAME_R] = "4.4.4",
134 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/softdep-loop",
135 [TC_INIT_MODULE_RETCODES] = "",
88ac4084
MM
136 },
137 .modules_loaded = "btusb,bluetooth",
138 );
a6976f8b 139
d96ca9c4 140static noreturn int modprobe_install_cmd_loop(const struct test *t)
01d9ee64 141{
b6adccd6 142 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
01d9ee64
LDM
143 const char *const args[] = {
144 progname,
145 "snd-pcm",
146 NULL,
147 };
148
149 test_spawn_prog(progname, args);
150 exit(EXIT_FAILURE);
151}
152static DEFINE_TEST(modprobe_install_cmd_loop,
9b01fd2e 153 .description = "check if modprobe breaks install-commands loop",
01d9ee64
LDM
154 .config = {
155 [TC_UNAME_R] = "4.4.4",
156 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/install-cmd-loop",
157 [TC_INIT_MODULE_RETCODES] = "",
158 },
159 .env_vars = (const struct keyval[]) {
b6adccd6 160 { "MODPROBE", ABS_TOP_BUILDDIR "/tools/modprobe" },
01d9ee64
LDM
161 { }
162 },
88ac4084 163 .modules_loaded = "snd,snd-pcm",
01d9ee64
LDM
164 );
165
d96ca9c4 166static noreturn int modprobe_param_kcmdline(const struct test *t)
ea225b98
LDM
167{
168 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
169 const char *const args[] = {
170 progname,
171 "--show-depends", "psmouse",
172 NULL,
173 };
174
175 test_spawn_prog(progname, args);
176 exit(EXIT_FAILURE);
177}
178static DEFINE_TEST(modprobe_param_kcmdline,
bad84a9e 179 .description = "check if params from kcmdline are passed in fact passed to (f)init_module call",
ea225b98
LDM
180 .config = {
181 [TC_UNAME_R] = "4.4.4",
182 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline",
183 },
184 .output = {
bd4e7340 185 .out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline/correct.txt",
88ac4084
MM
186 },
187 .modules_loaded = "",
188 );
ea225b98 189
55bcc4a5
LDM
190static noreturn int modprobe_param_kcmdline2(const struct test *t)
191{
192 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
193 const char *const args[] = {
194 progname,
195 "-c",
196 NULL,
197 };
198
199 test_spawn_prog(progname, args);
200 exit(EXIT_FAILURE);
201}
202static DEFINE_TEST(modprobe_param_kcmdline2,
203 .description = "check if params with no value are parsed correctly from kcmdline",
204 .config = {
205 [TC_UNAME_R] = "4.4.4",
206 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline2",
207 },
208 .output = {
209 .out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline2/correct.txt",
210 },
211 .modules_loaded = "",
212 );
213
42149024
LDM
214static noreturn int modprobe_param_kcmdline3(const struct test *t)
215{
216 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
217 const char *const args[] = {
218 progname,
219 "-c",
220 NULL,
221 };
222
223 test_spawn_prog(progname, args);
224 exit(EXIT_FAILURE);
225}
226static DEFINE_TEST(modprobe_param_kcmdline3,
227 .description = "check if unrelated strings in kcmdline are correctly ignored",
228 .config = {
229 [TC_UNAME_R] = "4.4.4",
230 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline3",
231 },
232 .output = {
233 .out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline3/correct.txt",
234 },
235 .modules_loaded = "",
236 );
237
2ce5de0a
MM
238static noreturn int modprobe_force(const struct test *t)
239{
240 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
241 const char *const args[] = {
242 progname,
243 "--force", "psmouse",
244 NULL,
245 };
246
247 test_spawn_prog(progname, args);
248 exit(EXIT_FAILURE);
249}
250static DEFINE_TEST(modprobe_force,
251 .description = "check modprobe --force",
252 .config = {
253 [TC_UNAME_R] = "4.4.4",
254 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/force",
255 [TC_INIT_MODULE_RETCODES] = "",
256 },
257 .modules_loaded = "psmouse",
258 );
259
be29c40e
MM
260static noreturn int modprobe_oldkernel(const struct test *t)
261{
262 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
263 const char *const args[] = {
264 progname,
265 "psmouse",
266 NULL,
267 };
268
269 test_spawn_prog(progname, args);
270 exit(EXIT_FAILURE);
271}
272static DEFINE_TEST(modprobe_oldkernel,
273 .description = "check modprobe --force",
274 .config = {
275 [TC_UNAME_R] = "3.3.3",
276 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/oldkernel",
277 [TC_INIT_MODULE_RETCODES] = "",
278 },
279 .modules_loaded = "psmouse",
280 );
281
282static noreturn int modprobe_oldkernel_force(const struct test *t)
283{
284 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
285 const char *const args[] = {
286 progname,
287 "--force", "psmouse",
288 NULL,
289 };
290
291 test_spawn_prog(progname, args);
292 exit(EXIT_FAILURE);
293}
294static DEFINE_TEST(modprobe_oldkernel_force,
295 .description = "check modprobe --force",
296 .config = {
297 [TC_UNAME_R] = "3.3.3",
298 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/oldkernel-force",
299 [TC_INIT_MODULE_RETCODES] = "",
300 },
301 .modules_loaded = "psmouse",
302 );
303
5278396d 304
976ea8c3
LDM
305static const struct test *tests[] = {
306 &smodprobe_show_depends,
307 &smodprobe_show_depends2,
5278396d 308 &smodprobe_show_alias_to_none,
a7f5300d 309 &smodprobe_builtin,
a6976f8b 310 &smodprobe_softdep_loop,
01d9ee64 311 &smodprobe_install_cmd_loop,
ea225b98 312 &smodprobe_param_kcmdline,
55bcc4a5 313 &smodprobe_param_kcmdline2,
42149024 314 &smodprobe_param_kcmdline3,
2ce5de0a 315 &smodprobe_force,
be29c40e
MM
316 &smodprobe_oldkernel,
317 &smodprobe_oldkernel_force,
976ea8c3
LDM
318 NULL,
319};
320
321TESTSUITE_MAIN(tests);