]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (C) 2012-2013 ProFUSION embedded systems | |
3 | * | |
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. | |
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 | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | * Lesser General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU Lesser General Public | |
15 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. | |
16 | */ | |
17 | ||
18 | #include <errno.h> | |
19 | #include <inttypes.h> | |
20 | #include <stddef.h> | |
21 | #include <stdio.h> | |
22 | #include <stdlib.h> | |
23 | #include <string.h> | |
24 | #include <unistd.h> | |
25 | ||
26 | #include "testsuite.h" | |
27 | ||
28 | static noreturn int modprobe_show_depends(const struct test *t) | |
29 | { | |
30 | const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; | |
31 | const char *const args[] = { | |
32 | progname, | |
33 | "--show-depends", "mod-loop-a", | |
34 | NULL, | |
35 | }; | |
36 | ||
37 | test_spawn_prog(progname, args); | |
38 | exit(EXIT_FAILURE); | |
39 | } | |
40 | DEFINE_TEST(modprobe_show_depends, | |
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 = { | |
47 | .out = TESTSUITE_ROOTFS "test-modprobe/show-depends/correct.txt", | |
48 | }); | |
49 | ||
50 | static noreturn int modprobe_show_depends2(const struct test *t) | |
51 | { | |
52 | const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; | |
53 | const char *const args[] = { | |
54 | progname, | |
55 | "--show-depends", "mod-simple", | |
56 | NULL, | |
57 | }; | |
58 | ||
59 | test_spawn_prog(progname, args); | |
60 | exit(EXIT_FAILURE); | |
61 | } | |
62 | DEFINE_TEST(modprobe_show_depends2, | |
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 = { | |
69 | .out = TESTSUITE_ROOTFS "test-modprobe/show-depends/correct-mod-simple.txt", | |
70 | }); | |
71 | ||
72 | ||
73 | static noreturn int modprobe_show_alias_to_none(const struct test *t) | |
74 | { | |
75 | const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; | |
76 | const char *const args[] = { | |
77 | progname, | |
78 | "--show-depends", "--ignore-install", "--quiet", "mod-simple", | |
79 | NULL, | |
80 | }; | |
81 | ||
82 | test_spawn_prog(progname, args); | |
83 | exit(EXIT_FAILURE); | |
84 | } | |
85 | DEFINE_TEST(modprobe_show_alias_to_none, | |
86 | .description = "check if modprobe --show-depends doesn't explode with an alias to nothing", | |
87 | .config = { | |
88 | [TC_UNAME_R] = "4.4.4", | |
89 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/alias-to-none", | |
90 | }, | |
91 | .output = { | |
92 | .out = TESTSUITE_ROOTFS "test-modprobe/alias-to-none/correct.txt", | |
93 | }, | |
94 | .modules_loaded = "", | |
95 | ); | |
96 | ||
97 | ||
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", | |
117 | .regex = true, | |
118 | }); | |
119 | ||
120 | ||
121 | static noreturn int modprobe_builtin(const struct test *t) | |
122 | { | |
123 | const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; | |
124 | const char *const args[] = { | |
125 | progname, | |
126 | "unix", | |
127 | NULL, | |
128 | }; | |
129 | ||
130 | test_spawn_prog(progname, args); | |
131 | exit(EXIT_FAILURE); | |
132 | } | |
133 | DEFINE_TEST(modprobe_builtin, | |
134 | .description = "check if modprobe return 0 for builtin", | |
135 | .config = { | |
136 | [TC_UNAME_R] = "4.4.4", | |
137 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/builtin", | |
138 | }); | |
139 | ||
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 | ||
162 | static noreturn int modprobe_softdep_loop(const struct test *t) | |
163 | { | |
164 | const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; | |
165 | const char *const args[] = { | |
166 | progname, | |
167 | "mod-loop-b", | |
168 | NULL, | |
169 | }; | |
170 | ||
171 | test_spawn_prog(progname, args); | |
172 | exit(EXIT_FAILURE); | |
173 | } | |
174 | DEFINE_TEST(modprobe_softdep_loop, | |
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] = "", | |
180 | }, | |
181 | .modules_loaded = "mod-loop-a,mod-loop-b", | |
182 | ); | |
183 | ||
184 | static noreturn int modprobe_install_cmd_loop(const struct test *t) | |
185 | { | |
186 | const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; | |
187 | const char *const args[] = { | |
188 | progname, | |
189 | "mod-loop-a", | |
190 | NULL, | |
191 | }; | |
192 | ||
193 | test_spawn_prog(progname, args); | |
194 | exit(EXIT_FAILURE); | |
195 | } | |
196 | DEFINE_TEST(modprobe_install_cmd_loop, | |
197 | .description = "check if modprobe breaks install-commands loop", | |
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[]) { | |
204 | { "MODPROBE", ABS_TOP_BUILDDIR "/tools/modprobe" }, | |
205 | { } | |
206 | }, | |
207 | .modules_loaded = "mod-loop-b,mod-loop-a", | |
208 | ); | |
209 | ||
210 | static noreturn int modprobe_param_kcmdline_show_deps(const struct test *t) | |
211 | { | |
212 | const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; | |
213 | const char *const args[] = { | |
214 | progname, | |
215 | "--show-depends", "mod-simple", | |
216 | NULL, | |
217 | }; | |
218 | ||
219 | test_spawn_prog(progname, args); | |
220 | exit(EXIT_FAILURE); | |
221 | } | |
222 | DEFINE_TEST(modprobe_param_kcmdline_show_deps, | |
223 | .description = "check if params from kcmdline are passed to (f)init_module call", | |
224 | .config = { | |
225 | [TC_UNAME_R] = "4.4.4", | |
226 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline", | |
227 | }, | |
228 | .output = { | |
229 | .out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline/correct.txt", | |
230 | }, | |
231 | .modules_loaded = "", | |
232 | ); | |
233 | ||
234 | static noreturn int modprobe_param_kcmdline(const struct test *t) | |
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 | } | |
246 | DEFINE_TEST_WITH_FUNC(modprobe_param_kcmdline2, modprobe_param_kcmdline, | |
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 | ||
258 | DEFINE_TEST_WITH_FUNC(modprobe_param_kcmdline3, modprobe_param_kcmdline, | |
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 | ||
270 | DEFINE_TEST_WITH_FUNC(modprobe_param_kcmdline4, modprobe_param_kcmdline, | |
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 | ||
282 | DEFINE_TEST_WITH_FUNC(modprobe_param_kcmdline5, modprobe_param_kcmdline, | |
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 | ||
294 | DEFINE_TEST_WITH_FUNC(modprobe_param_kcmdline6, modprobe_param_kcmdline, | |
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 | ||
306 | DEFINE_TEST_WITH_FUNC(modprobe_param_kcmdline7, modprobe_param_kcmdline, | |
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 | ||
318 | DEFINE_TEST_WITH_FUNC(modprobe_param_kcmdline8, modprobe_param_kcmdline, | |
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 | ||
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, | |
336 | "--force", "mod-simple", | |
337 | NULL, | |
338 | }; | |
339 | ||
340 | test_spawn_prog(progname, args); | |
341 | exit(EXIT_FAILURE); | |
342 | } | |
343 | DEFINE_TEST(modprobe_force, | |
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 | }, | |
350 | .modules_loaded = "mod-simple", | |
351 | ); | |
352 | ||
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, | |
358 | "mod-simple", | |
359 | NULL, | |
360 | }; | |
361 | ||
362 | test_spawn_prog(progname, args); | |
363 | exit(EXIT_FAILURE); | |
364 | } | |
365 | DEFINE_TEST(modprobe_oldkernel, | |
366 | .description = "check modprobe with kernel without finit_module()", | |
367 | .config = { | |
368 | [TC_UNAME_R] = "3.3.3", | |
369 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/oldkernel", | |
370 | [TC_INIT_MODULE_RETCODES] = "", | |
371 | }, | |
372 | .modules_loaded = "mod-simple", | |
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, | |
380 | "--force", "mod-simple", | |
381 | NULL, | |
382 | }; | |
383 | ||
384 | test_spawn_prog(progname, args); | |
385 | exit(EXIT_FAILURE); | |
386 | } | |
387 | DEFINE_TEST(modprobe_oldkernel_force, | |
388 | .description = "check modprobe --force with kernel without finit_module()", | |
389 | .config = { | |
390 | [TC_UNAME_R] = "3.3.3", | |
391 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/oldkernel-force", | |
392 | [TC_INIT_MODULE_RETCODES] = "", | |
393 | }, | |
394 | .modules_loaded = "mod-simple", | |
395 | ); | |
396 | ||
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 | ||
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 | ||
469 | TESTSUITE_MAIN(); |