]> git.ipfire.org Git - thirdparty/kmod.git/blame - testsuite/test-modprobe.c
testsuite: add support for testing output against regex
[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 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 28static 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 40DEFINE_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 50static 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 62DEFINE_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 73static 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 85DEFINE_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
98static 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}
110DEFINE_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 });
118
119
d96ca9c4 120static noreturn int modprobe_builtin(const struct test *t)
a7f5300d 121{
b6adccd6 122 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
a7f5300d
LDM
123 const char *const args[] = {
124 progname,
125 "unix",
126 NULL,
127 };
128
129 test_spawn_prog(progname, args);
130 exit(EXIT_FAILURE);
131}
f1155c15 132DEFINE_TEST(modprobe_builtin,
a7f5300d 133 .description = "check if modprobe return 0 for builtin",
a7f5300d
LDM
134 .config = {
135 [TC_UNAME_R] = "4.4.4",
136 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/builtin",
137 });
138
ade6b25c
LDM
139static noreturn int modprobe_builtin_lookup_only(const struct test *t)
140{
141 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
142 const char *const args[] = {
143 progname,
144 "-R", "unix",
145 NULL,
146 };
147
148 test_spawn_prog(progname, args);
149 exit(EXIT_FAILURE);
150}
151DEFINE_TEST(modprobe_builtin_lookup_only,
152 .description = "check if modprobe -R correctly returns the builtin module",
153 .config = {
154 [TC_UNAME_R] = "4.4.4",
155 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/builtin",
156 },
157 .output = {
158 .out = TESTSUITE_ROOTFS "test-modprobe/builtin/correct.txt",
159 });
160
d96ca9c4 161static noreturn int modprobe_softdep_loop(const struct test *t)
a6976f8b 162{
b6adccd6 163 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
a6976f8b
LDM
164 const char *const args[] = {
165 progname,
1e128242 166 "mod-loop-b",
a6976f8b
LDM
167 NULL,
168 };
169
170 test_spawn_prog(progname, args);
171 exit(EXIT_FAILURE);
172}
f1155c15 173DEFINE_TEST(modprobe_softdep_loop,
a6976f8b
LDM
174 .description = "check if modprobe breaks softdep loop",
175 .config = {
176 [TC_UNAME_R] = "4.4.4",
177 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/softdep-loop",
178 [TC_INIT_MODULE_RETCODES] = "",
88ac4084 179 },
1e128242 180 .modules_loaded = "mod-loop-a,mod-loop-b",
88ac4084 181 );
a6976f8b 182
d96ca9c4 183static noreturn int modprobe_install_cmd_loop(const struct test *t)
01d9ee64 184{
b6adccd6 185 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
01d9ee64
LDM
186 const char *const args[] = {
187 progname,
621ac887 188 "mod-loop-a",
01d9ee64
LDM
189 NULL,
190 };
191
192 test_spawn_prog(progname, args);
193 exit(EXIT_FAILURE);
194}
f1155c15 195DEFINE_TEST(modprobe_install_cmd_loop,
9b01fd2e 196 .description = "check if modprobe breaks install-commands loop",
01d9ee64
LDM
197 .config = {
198 [TC_UNAME_R] = "4.4.4",
199 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/install-cmd-loop",
200 [TC_INIT_MODULE_RETCODES] = "",
201 },
202 .env_vars = (const struct keyval[]) {
b6adccd6 203 { "MODPROBE", ABS_TOP_BUILDDIR "/tools/modprobe" },
01d9ee64
LDM
204 { }
205 },
621ac887 206 .modules_loaded = "mod-loop-b,mod-loop-a",
01d9ee64
LDM
207 );
208
d96ca9c4 209static noreturn int modprobe_param_kcmdline(const struct test *t)
ea225b98
LDM
210{
211 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
212 const char *const args[] = {
213 progname,
246d67d4 214 "--show-depends", "mod-simple",
ea225b98
LDM
215 NULL,
216 };
217
218 test_spawn_prog(progname, args);
219 exit(EXIT_FAILURE);
220}
f1155c15 221DEFINE_TEST(modprobe_param_kcmdline,
55f8286f 222 .description = "check if params from kcmdline are passed to (f)init_module call",
ea225b98
LDM
223 .config = {
224 [TC_UNAME_R] = "4.4.4",
225 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline",
226 },
227 .output = {
bd4e7340 228 .out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline/correct.txt",
88ac4084
MM
229 },
230 .modules_loaded = "",
231 );
ea225b98 232
55bcc4a5
LDM
233static noreturn int modprobe_param_kcmdline2(const struct test *t)
234{
235 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
236 const char *const args[] = {
237 progname,
238 "-c",
239 NULL,
240 };
241
242 test_spawn_prog(progname, args);
243 exit(EXIT_FAILURE);
244}
f1155c15 245DEFINE_TEST(modprobe_param_kcmdline2,
55bcc4a5
LDM
246 .description = "check if params with no value are parsed correctly from kcmdline",
247 .config = {
248 [TC_UNAME_R] = "4.4.4",
249 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline2",
250 },
251 .output = {
252 .out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline2/correct.txt",
253 },
254 .modules_loaded = "",
255 );
256
42149024
LDM
257static noreturn int modprobe_param_kcmdline3(const struct test *t)
258{
259 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
260 const char *const args[] = {
261 progname,
262 "-c",
263 NULL,
264 };
265
266 test_spawn_prog(progname, args);
267 exit(EXIT_FAILURE);
268}
f1155c15 269DEFINE_TEST(modprobe_param_kcmdline3,
42149024
LDM
270 .description = "check if unrelated strings in kcmdline are correctly ignored",
271 .config = {
272 [TC_UNAME_R] = "4.4.4",
273 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline3",
274 },
275 .output = {
276 .out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline3/correct.txt",
277 },
278 .modules_loaded = "",
279 );
280
49776627
LDM
281static noreturn int modprobe_param_kcmdline4(const struct test *t)
282{
283 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
284 const char *const args[] = {
285 progname,
286 "-c",
287 NULL,
288 };
289
290 test_spawn_prog(progname, args);
291 exit(EXIT_FAILURE);
292}
f1155c15 293DEFINE_TEST(modprobe_param_kcmdline4,
49776627
LDM
294 .description = "check if unrelated strings in kcmdline are correctly ignored",
295 .config = {
296 [TC_UNAME_R] = "4.4.4",
297 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline4",
298 },
299 .output = {
300 .out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline4/correct.txt",
301 },
302 .modules_loaded = "",
303 );
304
ded0bebc
LDM
305static noreturn int modprobe_param_kcmdline5(const struct test *t)
306{
307 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
308 const char *const args[] = {
309 progname,
310 "-c",
311 NULL,
312 };
313
314 test_spawn_prog(progname, args);
315 exit(EXIT_FAILURE);
316}
317DEFINE_TEST(modprobe_param_kcmdline5,
318 .description = "check if params with spaces are parsed correctly from kcmdline",
319 .config = {
320 [TC_UNAME_R] = "4.4.4",
321 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline5",
322 },
323 .output = {
324 .out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline5/correct.txt",
325 },
326 .modules_loaded = "",
327 );
328
329
2ce5de0a
MM
330static noreturn int modprobe_force(const struct test *t)
331{
332 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
333 const char *const args[] = {
334 progname,
a1a13690 335 "--force", "mod-simple",
2ce5de0a
MM
336 NULL,
337 };
338
339 test_spawn_prog(progname, args);
340 exit(EXIT_FAILURE);
341}
f1155c15 342DEFINE_TEST(modprobe_force,
2ce5de0a
MM
343 .description = "check modprobe --force",
344 .config = {
345 [TC_UNAME_R] = "4.4.4",
346 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/force",
347 [TC_INIT_MODULE_RETCODES] = "",
348 },
a1a13690 349 .modules_loaded = "mod-simple",
2ce5de0a
MM
350 );
351
be29c40e
MM
352static noreturn int modprobe_oldkernel(const struct test *t)
353{
354 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
355 const char *const args[] = {
356 progname,
33c11852 357 "mod-simple",
be29c40e
MM
358 NULL,
359 };
360
361 test_spawn_prog(progname, args);
362 exit(EXIT_FAILURE);
363}
f1155c15 364DEFINE_TEST(modprobe_oldkernel,
33c11852 365 .description = "check modprobe with kernel without finit_module()",
be29c40e
MM
366 .config = {
367 [TC_UNAME_R] = "3.3.3",
368 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/oldkernel",
369 [TC_INIT_MODULE_RETCODES] = "",
370 },
33c11852 371 .modules_loaded = "mod-simple",
be29c40e
MM
372 );
373
374static noreturn int modprobe_oldkernel_force(const struct test *t)
375{
376 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
377 const char *const args[] = {
378 progname,
33c11852 379 "--force", "mod-simple",
be29c40e
MM
380 NULL,
381 };
382
383 test_spawn_prog(progname, args);
384 exit(EXIT_FAILURE);
385}
f1155c15 386DEFINE_TEST(modprobe_oldkernel_force,
33c11852 387 .description = "check modprobe --force with kernel without finit_module()",
be29c40e
MM
388 .config = {
389 [TC_UNAME_R] = "3.3.3",
390 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/oldkernel-force",
391 [TC_INIT_MODULE_RETCODES] = "",
392 },
33c11852 393 .modules_loaded = "mod-simple",
be29c40e
MM
394 );
395
df492f5c
YK
396static noreturn int modprobe_external(const struct test *t)
397{
398 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
399 const char *const args[] = {
400 progname,
401 "mod-simple",
402 NULL,
403 };
404
405 test_spawn_prog(progname, args);
406 exit(EXIT_FAILURE);
407}
408DEFINE_TEST(modprobe_external,
409 .description = "check modprobe able to load external module",
410 .config = {
411 [TC_UNAME_R] = "4.4.4",
412 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/external",
413 [TC_INIT_MODULE_RETCODES] = "",
414 },
415 .modules_loaded = "mod-simple",
416 );
417
43289820 418TESTSUITE_MAIN();