• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
modprobe_show_depends(const struct test * t)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 
modprobe_show_depends2(const struct test * t)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 
modprobe_show_alias_to_none(const struct test * t)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 #if defined(KMOD_SYSCONFDIR_NOT_ETC)
87         .skip = true,
88 #endif
89 	.description = "check if modprobe --show-depends doesn't explode with an alias to nothing",
90 	.config = {
91 		[TC_UNAME_R] = "4.4.4",
92 		[TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/alias-to-none",
93 	},
94 	.output = {
95 		.out = TESTSUITE_ROOTFS "test-modprobe/alias-to-none/correct.txt",
96 	},
97 	.modules_loaded = "",
98 	);
99 
100 
modprobe_show_exports(const struct test * t)101 static noreturn int modprobe_show_exports(const struct test *t)
102 {
103 	const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
104 	const char *const args[] = {
105 		progname,
106 		"--show-exports", "--quiet", "/mod-loop-a.ko",
107 		NULL,
108 	};
109 
110 	test_spawn_prog(progname, args);
111 	exit(EXIT_FAILURE);
112 }
113 DEFINE_TEST(modprobe_show_exports,
114 	.description = "check if modprobe --show-depends doesn't explode with an alias to nothing",
115 	.config = {
116 		[TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/show-exports",
117 	},
118 	.output = {
119 		.out = TESTSUITE_ROOTFS "test-modprobe/show-exports/correct.txt",
120 		.regex = true,
121 	});
122 
123 
modprobe_builtin(const struct test * t)124 static noreturn int modprobe_builtin(const struct test *t)
125 {
126 	const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
127 	const char *const args[] = {
128 		progname,
129 		"unix",
130 		NULL,
131 	};
132 
133 	test_spawn_prog(progname, args);
134 	exit(EXIT_FAILURE);
135 }
136 DEFINE_TEST(modprobe_builtin,
137 	.description = "check if modprobe return 0 for builtin",
138 	.config = {
139 		[TC_UNAME_R] = "4.4.4",
140 		[TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/builtin",
141 	});
142 
modprobe_builtin_lookup_only(const struct test * t)143 static noreturn int modprobe_builtin_lookup_only(const struct test *t)
144 {
145 	const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
146 	const char *const args[] = {
147 		progname,
148 		"-R", "unix",
149 		NULL,
150 	};
151 
152 	test_spawn_prog(progname, args);
153 	exit(EXIT_FAILURE);
154 }
155 DEFINE_TEST(modprobe_builtin_lookup_only,
156 	.description = "check if modprobe -R correctly returns the builtin module",
157 	.config = {
158 		[TC_UNAME_R] = "4.4.4",
159 		[TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/builtin",
160 	},
161 	.output = {
162 		.out = TESTSUITE_ROOTFS "test-modprobe/builtin/correct.txt",
163 	});
164 
modprobe_softdep_loop(const struct test * t)165 static noreturn int modprobe_softdep_loop(const struct test *t)
166 {
167 	const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
168 	const char *const args[] = {
169 		progname,
170 		"mod-loop-b",
171 		NULL,
172 	};
173 
174 	test_spawn_prog(progname, args);
175 	exit(EXIT_FAILURE);
176 }
177 DEFINE_TEST(modprobe_softdep_loop,
178 #if defined(KMOD_SYSCONFDIR_NOT_ETC)
179         .skip = true,
180 #endif
181 	.description = "check if modprobe breaks softdep loop",
182 	.config = {
183 		[TC_UNAME_R] = "4.4.4",
184 		[TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/softdep-loop",
185 		[TC_INIT_MODULE_RETCODES] = "",
186 	},
187 	.modules_loaded = "mod-loop-a,mod-loop-b",
188 	);
189 
modprobe_install_cmd_loop(const struct test * t)190 static noreturn int modprobe_install_cmd_loop(const struct test *t)
191 {
192 	const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
193 	const char *const args[] = {
194 		progname,
195 		"mod-loop-a",
196 		NULL,
197 	};
198 
199 	test_spawn_prog(progname, args);
200 	exit(EXIT_FAILURE);
201 }
202 DEFINE_TEST(modprobe_install_cmd_loop,
203 	.description = "check if modprobe breaks install-commands loop",
204 	.config = {
205 		[TC_UNAME_R] = "4.4.4",
206 		[TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/install-cmd-loop",
207 		[TC_INIT_MODULE_RETCODES] = "",
208 	},
209 	.env_vars = (const struct keyval[]) {
210 		{ "MODPROBE", ABS_TOP_BUILDDIR "/tools/modprobe" },
211 		{ }
212 		},
213 	.modules_loaded = "mod-loop-b,mod-loop-a",
214 	);
215 
modprobe_param_kcmdline_show_deps(const struct test * t)216 static noreturn int modprobe_param_kcmdline_show_deps(const struct test *t)
217 {
218 	const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
219 	const char *const args[] = {
220 		progname,
221 		"--show-depends", "mod-simple",
222 		NULL,
223 	};
224 
225 	test_spawn_prog(progname, args);
226 	exit(EXIT_FAILURE);
227 }
228 DEFINE_TEST(modprobe_param_kcmdline_show_deps,
229 	.description = "check if params from kcmdline are passed to (f)init_module call",
230 	.config = {
231 		[TC_UNAME_R] = "4.4.4",
232 		[TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline",
233 	},
234 	.output = {
235 		.out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline/correct.txt",
236 	},
237 	.modules_loaded = "",
238 	);
239 
modprobe_param_kcmdline(const struct test * t)240 static noreturn int modprobe_param_kcmdline(const struct test *t)
241 {
242 	const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
243 	const char *const args[] = {
244 		progname,
245 		"-c",
246 		NULL,
247 	};
248 
249 	test_spawn_prog(progname, args);
250 	exit(EXIT_FAILURE);
251 }
252 DEFINE_TEST_WITH_FUNC(modprobe_param_kcmdline2, modprobe_param_kcmdline,
253 	.description = "check if params with no value are parsed correctly from kcmdline",
254 	.config = {
255 		[TC_UNAME_R] = "4.4.4",
256 		[TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline2",
257 	},
258 	.output = {
259 		.out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline2/correct.txt",
260 	},
261 	.modules_loaded = "",
262 	);
263 
264 DEFINE_TEST_WITH_FUNC(modprobe_param_kcmdline3, modprobe_param_kcmdline,
265 	.description = "check if unrelated strings in kcmdline are correctly ignored",
266 	.config = {
267 		[TC_UNAME_R] = "4.4.4",
268 		[TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline3",
269 	},
270 	.output = {
271 		.out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline3/correct.txt",
272 	},
273 	.modules_loaded = "",
274 	);
275 
276 DEFINE_TEST_WITH_FUNC(modprobe_param_kcmdline4, modprobe_param_kcmdline,
277 	.description = "check if unrelated strings in kcmdline are correctly ignored",
278 	.config = {
279 		[TC_UNAME_R] = "4.4.4",
280 		[TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline4",
281 	},
282 	.output = {
283 		.out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline4/correct.txt",
284 	},
285 	.modules_loaded = "",
286 	);
287 
288 DEFINE_TEST_WITH_FUNC(modprobe_param_kcmdline5, modprobe_param_kcmdline,
289 	.description = "check if params with spaces are parsed correctly from kcmdline",
290 	.config = {
291 		[TC_UNAME_R] = "4.4.4",
292 		[TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline5",
293 	},
294 	.output = {
295 		.out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline5/correct.txt",
296 	},
297 	.modules_loaded = "",
298 	);
299 
300 DEFINE_TEST_WITH_FUNC(modprobe_param_kcmdline6, modprobe_param_kcmdline,
301 	.description = "check if dots on other parts of kcmdline don't confuse our parser",
302 	.config = {
303 		[TC_UNAME_R] = "4.4.4",
304 		[TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline6",
305 	},
306 	.output = {
307 		.out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline6/correct.txt",
308 	},
309 	.modules_loaded = "",
310 	);
311 
312 DEFINE_TEST_WITH_FUNC(modprobe_param_kcmdline7, modprobe_param_kcmdline,
313 	.description = "check if dots on other parts of kcmdline don't confuse our parser",
314 	.config = {
315 		[TC_UNAME_R] = "4.4.4",
316 		[TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline7",
317 	},
318 	.output = {
319 		.out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline7/correct.txt",
320 	},
321 	.modules_loaded = "",
322 	);
323 
324 DEFINE_TEST_WITH_FUNC(modprobe_param_kcmdline8, modprobe_param_kcmdline,
325 	.description = "check if dots on other parts of kcmdline don't confuse our parser",
326 	.config = {
327 		[TC_UNAME_R] = "4.4.4",
328 		[TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline8",
329 	},
330 	.output = {
331 		.out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline8/correct.txt",
332 	},
333 	.modules_loaded = "",
334 	);
335 
336 
modprobe_force(const struct test * t)337 static noreturn int modprobe_force(const struct test *t)
338 {
339 	const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
340 	const char *const args[] = {
341 		progname,
342 		"--force", "mod-simple",
343 		NULL,
344 	};
345 
346 	test_spawn_prog(progname, args);
347 	exit(EXIT_FAILURE);
348 }
349 DEFINE_TEST(modprobe_force,
350 	.description = "check modprobe --force",
351 	.config = {
352 		[TC_UNAME_R] = "4.4.4",
353 		[TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/force",
354 		[TC_INIT_MODULE_RETCODES] = "",
355 	},
356 	.modules_loaded = "mod-simple",
357 	);
358 
modprobe_oldkernel(const struct test * t)359 static noreturn int modprobe_oldkernel(const struct test *t)
360 {
361 	const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
362 	const char *const args[] = {
363 		progname,
364 		"mod-simple",
365 		NULL,
366 	};
367 
368 	test_spawn_prog(progname, args);
369 	exit(EXIT_FAILURE);
370 }
371 DEFINE_TEST(modprobe_oldkernel,
372 	.description = "check modprobe with kernel without finit_module()",
373 	.config = {
374 		[TC_UNAME_R] = "3.3.3",
375 		[TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/oldkernel",
376 		[TC_INIT_MODULE_RETCODES] = "",
377 	},
378 	.modules_loaded = "mod-simple",
379 	);
380 
modprobe_oldkernel_force(const struct test * t)381 static noreturn int modprobe_oldkernel_force(const struct test *t)
382 {
383 	const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
384 	const char *const args[] = {
385 		progname,
386 		"--force", "mod-simple",
387 		NULL,
388 	};
389 
390 	test_spawn_prog(progname, args);
391 	exit(EXIT_FAILURE);
392 }
393 DEFINE_TEST(modprobe_oldkernel_force,
394 	.description = "check modprobe --force with kernel without finit_module()",
395 	.config = {
396 		[TC_UNAME_R] = "3.3.3",
397 		[TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/oldkernel-force",
398 		[TC_INIT_MODULE_RETCODES] = "",
399 	},
400 	.modules_loaded = "mod-simple",
401 	);
402 
modprobe_external(const struct test * t)403 static noreturn int modprobe_external(const struct test *t)
404 {
405 	const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
406 	const char *const args[] = {
407 		progname,
408 		"mod-simple",
409 		NULL,
410 	};
411 
412 	test_spawn_prog(progname, args);
413 	exit(EXIT_FAILURE);
414 }
415 DEFINE_TEST(modprobe_external,
416 	.description = "check modprobe able to load external module",
417 	.config = {
418 		[TC_UNAME_R] = "4.4.4",
419 		[TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/external",
420 		[TC_INIT_MODULE_RETCODES] = "",
421 	},
422 	.modules_loaded = "mod-simple",
423 	);
424 
425 TESTSUITE_MAIN();
426