]>
Commit | Line | Data |
---|---|---|
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 | 14 | * You should have received a copy of the GNU Lesser General Public |
dea2dfee | 15 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
976ea8c3 LDM |
16 | */ |
17 | ||
976ea8c3 | 18 | #include <errno.h> |
976ea8c3 | 19 | #include <inttypes.h> |
c2e4286b LDM |
20 | #include <stddef.h> |
21 | #include <stdio.h> | |
22 | #include <stdlib.h> | |
976ea8c3 | 23 | #include <string.h> |
c2e4286b | 24 | #include <unistd.h> |
976ea8c3 LDM |
25 | |
26 | #include "testsuite.h" | |
27 | ||
d96ca9c4 | 28 | static noreturn int modprobe_show_depends(const struct test *t) |
976ea8c3 | 29 | { |
b6adccd6 | 30 | const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; |
976ea8c3 LDM |
31 | const char *const args[] = { |
32 | progname, | |
eeb62700 | 33 | "--show-depends", "mod-loop-a", |
976ea8c3 LDM |
34 | NULL, |
35 | }; | |
36 | ||
37 | test_spawn_prog(progname, args); | |
38 | exit(EXIT_FAILURE); | |
39 | } | |
f1155c15 | 40 | DEFINE_TEST(modprobe_show_depends, |
976ea8c3 LDM |
41 | .description = "check if output for modprobe --show-depends is correct for loaded modules", |
42 | .config = { | |
43 | [TC_UNAME_R] = "4.4.4", | |
44 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/show-depends", | |
45 | }, | |
46 | .output = { | |
bd4e7340 | 47 | .out = TESTSUITE_ROOTFS "test-modprobe/show-depends/correct.txt", |
976ea8c3 LDM |
48 | }); |
49 | ||
d96ca9c4 | 50 | static noreturn int modprobe_show_depends2(const struct test *t) |
976ea8c3 | 51 | { |
b6adccd6 | 52 | const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; |
976ea8c3 LDM |
53 | const char *const args[] = { |
54 | progname, | |
eeb62700 | 55 | "--show-depends", "mod-simple", |
976ea8c3 LDM |
56 | NULL, |
57 | }; | |
58 | ||
59 | test_spawn_prog(progname, args); | |
60 | exit(EXIT_FAILURE); | |
61 | } | |
f1155c15 | 62 | DEFINE_TEST(modprobe_show_depends2, |
976ea8c3 LDM |
63 | .description = "check if output for modprobe --show-depends is correct", |
64 | .config = { | |
65 | [TC_UNAME_R] = "4.4.4", | |
66 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/show-depends", | |
67 | }, | |
68 | .output = { | |
eeb62700 | 69 | .out = TESTSUITE_ROOTFS "test-modprobe/show-depends/correct-mod-simple.txt", |
976ea8c3 | 70 | }); |
a7f5300d | 71 | |
5278396d | 72 | |
d96ca9c4 | 73 | static noreturn int modprobe_show_alias_to_none(const struct test *t) |
5278396d | 74 | { |
b6adccd6 | 75 | const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; |
5278396d LDM |
76 | const char *const args[] = { |
77 | progname, | |
bf0b87f4 | 78 | "--show-depends", "--ignore-install", "--quiet", "mod-simple", |
5278396d LDM |
79 | NULL, |
80 | }; | |
81 | ||
82 | test_spawn_prog(progname, args); | |
83 | exit(EXIT_FAILURE); | |
84 | } | |
f1155c15 | 85 | DEFINE_TEST(modprobe_show_alias_to_none, |
5278396d | 86 | .description = "check if modprobe --show-depends doesn't explode with an alias to nothing", |
5278396d LDM |
87 | .config = { |
88 | [TC_UNAME_R] = "4.4.4", | |
89 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/alias-to-none", | |
90 | }, | |
91 | .output = { | |
bf0b87f4 | 92 | .out = TESTSUITE_ROOTFS "test-modprobe/alias-to-none/correct.txt", |
88ac4084 MM |
93 | }, |
94 | .modules_loaded = "", | |
95 | ); | |
5278396d LDM |
96 | |
97 | ||
068729e3 LDM |
98 | static noreturn int modprobe_show_exports(const struct test *t) |
99 | { | |
100 | const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; | |
101 | const char *const args[] = { | |
102 | progname, | |
103 | "--show-exports", "--quiet", "/mod-loop-a.ko", | |
104 | NULL, | |
105 | }; | |
106 | ||
107 | test_spawn_prog(progname, args); | |
108 | exit(EXIT_FAILURE); | |
109 | } | |
110 | DEFINE_TEST(modprobe_show_exports, | |
111 | .description = "check if modprobe --show-depends doesn't explode with an alias to nothing", | |
112 | .config = { | |
113 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/show-exports", | |
114 | }, | |
115 | .output = { | |
116 | .out = TESTSUITE_ROOTFS "test-modprobe/show-exports/correct.txt", | |
eb862179 | 117 | .regex = true, |
068729e3 LDM |
118 | }); |
119 | ||
120 | ||
d96ca9c4 | 121 | static noreturn int modprobe_builtin(const struct test *t) |
a7f5300d | 122 | { |
b6adccd6 | 123 | const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; |
a7f5300d LDM |
124 | const char *const args[] = { |
125 | progname, | |
126 | "unix", | |
127 | NULL, | |
128 | }; | |
129 | ||
130 | test_spawn_prog(progname, args); | |
131 | exit(EXIT_FAILURE); | |
132 | } | |
f1155c15 | 133 | DEFINE_TEST(modprobe_builtin, |
a7f5300d | 134 | .description = "check if modprobe return 0 for builtin", |
a7f5300d LDM |
135 | .config = { |
136 | [TC_UNAME_R] = "4.4.4", | |
137 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/builtin", | |
138 | }); | |
139 | ||
ade6b25c LDM |
140 | static noreturn int modprobe_builtin_lookup_only(const struct test *t) |
141 | { | |
142 | const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; | |
143 | const char *const args[] = { | |
144 | progname, | |
145 | "-R", "unix", | |
146 | NULL, | |
147 | }; | |
148 | ||
149 | test_spawn_prog(progname, args); | |
150 | exit(EXIT_FAILURE); | |
151 | } | |
152 | DEFINE_TEST(modprobe_builtin_lookup_only, | |
153 | .description = "check if modprobe -R correctly returns the builtin module", | |
154 | .config = { | |
155 | [TC_UNAME_R] = "4.4.4", | |
156 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/builtin", | |
157 | }, | |
158 | .output = { | |
159 | .out = TESTSUITE_ROOTFS "test-modprobe/builtin/correct.txt", | |
160 | }); | |
161 | ||
d96ca9c4 | 162 | static noreturn int modprobe_softdep_loop(const struct test *t) |
a6976f8b | 163 | { |
b6adccd6 | 164 | const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; |
a6976f8b LDM |
165 | const char *const args[] = { |
166 | progname, | |
1e128242 | 167 | "mod-loop-b", |
a6976f8b LDM |
168 | NULL, |
169 | }; | |
170 | ||
171 | test_spawn_prog(progname, args); | |
172 | exit(EXIT_FAILURE); | |
173 | } | |
f1155c15 | 174 | DEFINE_TEST(modprobe_softdep_loop, |
a6976f8b LDM |
175 | .description = "check if modprobe breaks softdep loop", |
176 | .config = { | |
177 | [TC_UNAME_R] = "4.4.4", | |
178 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/softdep-loop", | |
179 | [TC_INIT_MODULE_RETCODES] = "", | |
88ac4084 | 180 | }, |
1e128242 | 181 | .modules_loaded = "mod-loop-a,mod-loop-b", |
88ac4084 | 182 | ); |
a6976f8b | 183 | |
d96ca9c4 | 184 | static noreturn int modprobe_install_cmd_loop(const struct test *t) |
01d9ee64 | 185 | { |
b6adccd6 | 186 | const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; |
01d9ee64 LDM |
187 | const char *const args[] = { |
188 | progname, | |
621ac887 | 189 | "mod-loop-a", |
01d9ee64 LDM |
190 | NULL, |
191 | }; | |
192 | ||
193 | test_spawn_prog(progname, args); | |
194 | exit(EXIT_FAILURE); | |
195 | } | |
f1155c15 | 196 | DEFINE_TEST(modprobe_install_cmd_loop, |
9b01fd2e | 197 | .description = "check if modprobe breaks install-commands loop", |
01d9ee64 LDM |
198 | .config = { |
199 | [TC_UNAME_R] = "4.4.4", | |
200 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/install-cmd-loop", | |
201 | [TC_INIT_MODULE_RETCODES] = "", | |
202 | }, | |
203 | .env_vars = (const struct keyval[]) { | |
b6adccd6 | 204 | { "MODPROBE", ABS_TOP_BUILDDIR "/tools/modprobe" }, |
01d9ee64 LDM |
205 | { } |
206 | }, | |
621ac887 | 207 | .modules_loaded = "mod-loop-b,mod-loop-a", |
01d9ee64 LDM |
208 | ); |
209 | ||
d8b31c34 | 210 | static noreturn int modprobe_param_kcmdline_show_deps(const struct test *t) |
ea225b98 LDM |
211 | { |
212 | const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; | |
213 | const char *const args[] = { | |
214 | progname, | |
246d67d4 | 215 | "--show-depends", "mod-simple", |
ea225b98 LDM |
216 | NULL, |
217 | }; | |
218 | ||
219 | test_spawn_prog(progname, args); | |
220 | exit(EXIT_FAILURE); | |
221 | } | |
d8b31c34 | 222 | DEFINE_TEST(modprobe_param_kcmdline_show_deps, |
55f8286f | 223 | .description = "check if params from kcmdline are passed to (f)init_module call", |
ea225b98 LDM |
224 | .config = { |
225 | [TC_UNAME_R] = "4.4.4", | |
226 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline", | |
227 | }, | |
228 | .output = { | |
bd4e7340 | 229 | .out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline/correct.txt", |
88ac4084 MM |
230 | }, |
231 | .modules_loaded = "", | |
232 | ); | |
ea225b98 | 233 | |
d8b31c34 | 234 | static noreturn int modprobe_param_kcmdline(const struct test *t) |
55bcc4a5 LDM |
235 | { |
236 | const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; | |
237 | const char *const args[] = { | |
238 | progname, | |
239 | "-c", | |
240 | NULL, | |
241 | }; | |
242 | ||
243 | test_spawn_prog(progname, args); | |
244 | exit(EXIT_FAILURE); | |
245 | } | |
d8b31c34 | 246 | DEFINE_TEST_WITH_FUNC(modprobe_param_kcmdline2, modprobe_param_kcmdline, |
55bcc4a5 LDM |
247 | .description = "check if params with no value are parsed correctly from kcmdline", |
248 | .config = { | |
249 | [TC_UNAME_R] = "4.4.4", | |
250 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline2", | |
251 | }, | |
252 | .output = { | |
253 | .out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline2/correct.txt", | |
254 | }, | |
255 | .modules_loaded = "", | |
256 | ); | |
257 | ||
d8b31c34 | 258 | DEFINE_TEST_WITH_FUNC(modprobe_param_kcmdline3, modprobe_param_kcmdline, |
42149024 LDM |
259 | .description = "check if unrelated strings in kcmdline are correctly ignored", |
260 | .config = { | |
261 | [TC_UNAME_R] = "4.4.4", | |
262 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline3", | |
263 | }, | |
264 | .output = { | |
265 | .out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline3/correct.txt", | |
266 | }, | |
267 | .modules_loaded = "", | |
268 | ); | |
269 | ||
d8b31c34 | 270 | DEFINE_TEST_WITH_FUNC(modprobe_param_kcmdline4, modprobe_param_kcmdline, |
49776627 LDM |
271 | .description = "check if unrelated strings in kcmdline are correctly ignored", |
272 | .config = { | |
273 | [TC_UNAME_R] = "4.4.4", | |
274 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline4", | |
275 | }, | |
276 | .output = { | |
277 | .out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline4/correct.txt", | |
278 | }, | |
279 | .modules_loaded = "", | |
280 | ); | |
281 | ||
d8b31c34 | 282 | DEFINE_TEST_WITH_FUNC(modprobe_param_kcmdline5, modprobe_param_kcmdline, |
ded0bebc LDM |
283 | .description = "check if params with spaces are parsed correctly from kcmdline", |
284 | .config = { | |
285 | [TC_UNAME_R] = "4.4.4", | |
286 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline5", | |
287 | }, | |
288 | .output = { | |
289 | .out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline5/correct.txt", | |
290 | }, | |
291 | .modules_loaded = "", | |
292 | ); | |
293 | ||
d8b31c34 | 294 | DEFINE_TEST_WITH_FUNC(modprobe_param_kcmdline6, modprobe_param_kcmdline, |
3c1073e1 LDM |
295 | .description = "check if dots on other parts of kcmdline don't confuse our parser", |
296 | .config = { | |
297 | [TC_UNAME_R] = "4.4.4", | |
298 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline6", | |
299 | }, | |
300 | .output = { | |
301 | .out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline6/correct.txt", | |
302 | }, | |
303 | .modules_loaded = "", | |
304 | ); | |
305 | ||
d8b31c34 | 306 | DEFINE_TEST_WITH_FUNC(modprobe_param_kcmdline7, modprobe_param_kcmdline, |
d3a1fe67 LDM |
307 | .description = "check if dots on other parts of kcmdline don't confuse our parser", |
308 | .config = { | |
309 | [TC_UNAME_R] = "4.4.4", | |
310 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline7", | |
311 | }, | |
312 | .output = { | |
313 | .out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline7/correct.txt", | |
314 | }, | |
315 | .modules_loaded = "", | |
316 | ); | |
317 | ||
d8b31c34 | 318 | DEFINE_TEST_WITH_FUNC(modprobe_param_kcmdline8, modprobe_param_kcmdline, |
d3a1fe67 LDM |
319 | .description = "check if dots on other parts of kcmdline don't confuse our parser", |
320 | .config = { | |
321 | [TC_UNAME_R] = "4.4.4", | |
322 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline8", | |
323 | }, | |
324 | .output = { | |
325 | .out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline8/correct.txt", | |
326 | }, | |
327 | .modules_loaded = "", | |
328 | ); | |
329 | ||
330 | ||
2ce5de0a MM |
331 | static noreturn int modprobe_force(const struct test *t) |
332 | { | |
333 | const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; | |
334 | const char *const args[] = { | |
335 | progname, | |
a1a13690 | 336 | "--force", "mod-simple", |
2ce5de0a MM |
337 | NULL, |
338 | }; | |
339 | ||
340 | test_spawn_prog(progname, args); | |
341 | exit(EXIT_FAILURE); | |
342 | } | |
f1155c15 | 343 | DEFINE_TEST(modprobe_force, |
2ce5de0a MM |
344 | .description = "check modprobe --force", |
345 | .config = { | |
346 | [TC_UNAME_R] = "4.4.4", | |
347 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/force", | |
348 | [TC_INIT_MODULE_RETCODES] = "", | |
349 | }, | |
a1a13690 | 350 | .modules_loaded = "mod-simple", |
2ce5de0a MM |
351 | ); |
352 | ||
be29c40e MM |
353 | static noreturn int modprobe_oldkernel(const struct test *t) |
354 | { | |
355 | const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; | |
356 | const char *const args[] = { | |
357 | progname, | |
33c11852 | 358 | "mod-simple", |
be29c40e MM |
359 | NULL, |
360 | }; | |
361 | ||
362 | test_spawn_prog(progname, args); | |
363 | exit(EXIT_FAILURE); | |
364 | } | |
f1155c15 | 365 | DEFINE_TEST(modprobe_oldkernel, |
33c11852 | 366 | .description = "check modprobe with kernel without finit_module()", |
be29c40e MM |
367 | .config = { |
368 | [TC_UNAME_R] = "3.3.3", | |
369 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/oldkernel", | |
370 | [TC_INIT_MODULE_RETCODES] = "", | |
371 | }, | |
33c11852 | 372 | .modules_loaded = "mod-simple", |
be29c40e MM |
373 | ); |
374 | ||
375 | static noreturn int modprobe_oldkernel_force(const struct test *t) | |
376 | { | |
377 | const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; | |
378 | const char *const args[] = { | |
379 | progname, | |
33c11852 | 380 | "--force", "mod-simple", |
be29c40e MM |
381 | NULL, |
382 | }; | |
383 | ||
384 | test_spawn_prog(progname, args); | |
385 | exit(EXIT_FAILURE); | |
386 | } | |
f1155c15 | 387 | DEFINE_TEST(modprobe_oldkernel_force, |
33c11852 | 388 | .description = "check modprobe --force with kernel without finit_module()", |
be29c40e MM |
389 | .config = { |
390 | [TC_UNAME_R] = "3.3.3", | |
391 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/oldkernel-force", | |
392 | [TC_INIT_MODULE_RETCODES] = "", | |
393 | }, | |
33c11852 | 394 | .modules_loaded = "mod-simple", |
be29c40e MM |
395 | ); |
396 | ||
df492f5c YK |
397 | static noreturn int modprobe_external(const struct test *t) |
398 | { | |
399 | const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; | |
400 | const char *const args[] = { | |
401 | progname, | |
402 | "mod-simple", | |
403 | NULL, | |
404 | }; | |
405 | ||
406 | test_spawn_prog(progname, args); | |
407 | exit(EXIT_FAILURE); | |
408 | } | |
409 | DEFINE_TEST(modprobe_external, | |
410 | .description = "check modprobe able to load external module", | |
411 | .config = { | |
412 | [TC_UNAME_R] = "4.4.4", | |
413 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/external", | |
414 | [TC_INIT_MODULE_RETCODES] = "", | |
415 | }, | |
416 | .modules_loaded = "mod-simple", | |
417 | ); | |
418 | ||
883d931d GS |
419 | static noreturn int modprobe_module_from_abspath(const struct test *t) |
420 | { | |
421 | const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; | |
422 | const char *const args[] = { | |
423 | progname, | |
424 | "/home/foo/mod-simple.ko", | |
425 | NULL, | |
426 | }; | |
427 | ||
428 | test_spawn_prog(progname, args); | |
429 | exit(EXIT_FAILURE); | |
430 | } | |
431 | DEFINE_TEST(modprobe_module_from_abspath, | |
432 | .description = "check modprobe able to load module given as an absolute path", | |
433 | .config = { | |
434 | [TC_UNAME_R] = "4.4.4", | |
435 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-from-abspath", | |
436 | [TC_INIT_MODULE_RETCODES] = "", | |
437 | }, | |
438 | .modules_loaded = "mod-simple", | |
439 | ); | |
440 | ||
441 | static noreturn int modprobe_module_from_relpath(const struct test *t) | |
442 | { | |
443 | const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; | |
444 | const char *const args[] = { | |
445 | progname, | |
446 | "./mod-simple.ko", | |
447 | NULL, | |
448 | }; | |
449 | ||
450 | if (chdir("/home/foo") != 0) { | |
451 | perror("failed to change into /home/foo"); | |
452 | exit(EXIT_FAILURE); | |
453 | } | |
454 | ||
455 | test_spawn_prog(progname, args); | |
456 | exit(EXIT_FAILURE); | |
457 | } | |
458 | DEFINE_TEST(modprobe_module_from_relpath, | |
459 | .description = "check modprobe able to load module given as a relative path", | |
460 | .config = { | |
461 | [TC_UNAME_R] = "4.4.4", | |
462 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-from-relpath", | |
463 | [TC_INIT_MODULE_RETCODES] = "", | |
464 | }, | |
465 | .need_spawn = true, | |
466 | .modules_loaded = "mod-simple", | |
467 | ); | |
468 | ||
43289820 | 469 | TESTSUITE_MAIN(); |