blob: e0dd1992a784aef24560d8504cf2377998b6338e [file] [log] [blame]
Lucas De Marchi976ea8c2012-02-08 01:40:00 -02001/*
Lucas De Marchie6b0e492013-01-16 11:27:21 -02002 * Copyright (C) 2012-2013 ProFUSION embedded systems
Lucas De Marchi976ea8c2012-02-08 01:40:00 -02003 *
Lucas De Marchie1b1ab22012-07-10 09:42:24 -03004 * 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.
Lucas De Marchi976ea8c2012-02-08 01:40:00 -02008 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Lucas De Marchie1b1ab22012-07-10 09:42:24 -030011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
Lucas De Marchi976ea8c2012-02-08 01:40:00 -020013 *
Lucas De Marchie1b1ab22012-07-10 09:42:24 -030014 * You should have received a copy of the GNU Lesser General Public
Lucas De Marchidea2dfe2014-12-25 23:32:03 -020015 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
Lucas De Marchi976ea8c2012-02-08 01:40:00 -020016 */
17
Lucas De Marchic2e42862014-10-03 01:41:42 -030018#include <errno.h>
19#include <inttypes.h>
20#include <stddef.h>
Lucas De Marchi976ea8c2012-02-08 01:40:00 -020021#include <stdio.h>
22#include <stdlib.h>
Lucas De Marchi976ea8c2012-02-08 01:40:00 -020023#include <string.h>
Lucas De Marchic2e42862014-10-03 01:41:42 -030024#include <unistd.h>
Lucas De Marchi976ea8c2012-02-08 01:40:00 -020025
26#include "testsuite.h"
27
Lucas De Marchid96ca9c2013-12-17 19:10:16 -020028static noreturn int modprobe_show_depends(const struct test *t)
Lucas De Marchi976ea8c2012-02-08 01:40:00 -020029{
Lucas De Marchib6adccd2013-07-04 16:01:55 -030030 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
Lucas De Marchi976ea8c2012-02-08 01:40:00 -020031 const char *const args[] = {
32 progname,
Lucas De Marchieeb62702015-02-10 09:30:49 -020033 "--show-depends", "mod-loop-a",
Lucas De Marchi976ea8c2012-02-08 01:40:00 -020034 NULL,
35 };
36
37 test_spawn_prog(progname, args);
38 exit(EXIT_FAILURE);
39}
Lucas De Marchif1155c12014-10-09 13:00:30 -030040DEFINE_TEST(modprobe_show_depends,
Lucas De Marchi976ea8c2012-02-08 01:40:00 -020041 .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 = {
John Spencerbd4e7342013-08-27 01:38:11 +020047 .out = TESTSUITE_ROOTFS "test-modprobe/show-depends/correct.txt",
Lucas De Marchi976ea8c2012-02-08 01:40:00 -020048 });
49
Lucas De Marchid96ca9c2013-12-17 19:10:16 -020050static noreturn int modprobe_show_depends2(const struct test *t)
Lucas De Marchi976ea8c2012-02-08 01:40:00 -020051{
Lucas De Marchib6adccd2013-07-04 16:01:55 -030052 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
Lucas De Marchi976ea8c2012-02-08 01:40:00 -020053 const char *const args[] = {
54 progname,
Lucas De Marchieeb62702015-02-10 09:30:49 -020055 "--show-depends", "mod-simple",
Lucas De Marchi976ea8c2012-02-08 01:40:00 -020056 NULL,
57 };
58
59 test_spawn_prog(progname, args);
60 exit(EXIT_FAILURE);
61}
Lucas De Marchif1155c12014-10-09 13:00:30 -030062DEFINE_TEST(modprobe_show_depends2,
Lucas De Marchi976ea8c2012-02-08 01:40:00 -020063 .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 = {
Lucas De Marchieeb62702015-02-10 09:30:49 -020069 .out = TESTSUITE_ROOTFS "test-modprobe/show-depends/correct-mod-simple.txt",
Lucas De Marchi976ea8c2012-02-08 01:40:00 -020070 });
Lucas De Marchia7f53002012-02-16 21:04:24 -020071
Lucas De Marchi52783962013-03-21 02:24:07 -030072
Lucas De Marchid96ca9c2013-12-17 19:10:16 -020073static noreturn int modprobe_show_alias_to_none(const struct test *t)
Lucas De Marchi52783962013-03-21 02:24:07 -030074{
Lucas De Marchib6adccd2013-07-04 16:01:55 -030075 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
Lucas De Marchi52783962013-03-21 02:24:07 -030076 const char *const args[] = {
77 progname,
Lucas De Marchibf0b87f2015-02-10 22:19:53 -020078 "--show-depends", "--ignore-install", "--quiet", "mod-simple",
Lucas De Marchi52783962013-03-21 02:24:07 -030079 NULL,
80 };
81
82 test_spawn_prog(progname, args);
83 exit(EXIT_FAILURE);
84}
Lucas De Marchif1155c12014-10-09 13:00:30 -030085DEFINE_TEST(modprobe_show_alias_to_none,
Lucas De Marchi52783962013-03-21 02:24:07 -030086 .description = "check if modprobe --show-depends doesn't explode with an alias to nothing",
Lucas De Marchi52783962013-03-21 02:24:07 -030087 .config = {
88 [TC_UNAME_R] = "4.4.4",
89 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/alias-to-none",
90 },
91 .output = {
Lucas De Marchibf0b87f2015-02-10 22:19:53 -020092 .out = TESTSUITE_ROOTFS "test-modprobe/alias-to-none/correct.txt",
Michal Marek88ac4082014-02-28 13:05:28 +010093 },
94 .modules_loaded = "",
95 );
Lucas De Marchi52783962013-03-21 02:24:07 -030096
97
Lucas De Marchid96ca9c2013-12-17 19:10:16 -020098static noreturn int modprobe_builtin(const struct test *t)
Lucas De Marchia7f53002012-02-16 21:04:24 -020099{
Lucas De Marchib6adccd2013-07-04 16:01:55 -0300100 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
Lucas De Marchia7f53002012-02-16 21:04:24 -0200101 const char *const args[] = {
102 progname,
103 "unix",
104 NULL,
105 };
106
107 test_spawn_prog(progname, args);
108 exit(EXIT_FAILURE);
109}
Lucas De Marchif1155c12014-10-09 13:00:30 -0300110DEFINE_TEST(modprobe_builtin,
Lucas De Marchia7f53002012-02-16 21:04:24 -0200111 .description = "check if modprobe return 0 for builtin",
Lucas De Marchia7f53002012-02-16 21:04:24 -0200112 .config = {
113 [TC_UNAME_R] = "4.4.4",
114 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/builtin",
115 });
116
Lucas De Marchiade6b252015-02-27 15:46:24 -0300117static noreturn int modprobe_builtin_lookup_only(const struct test *t)
118{
119 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
120 const char *const args[] = {
121 progname,
122 "-R", "unix",
123 NULL,
124 };
125
126 test_spawn_prog(progname, args);
127 exit(EXIT_FAILURE);
128}
129DEFINE_TEST(modprobe_builtin_lookup_only,
130 .description = "check if modprobe -R correctly returns the builtin module",
131 .config = {
132 [TC_UNAME_R] = "4.4.4",
133 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/builtin",
134 },
135 .output = {
136 .out = TESTSUITE_ROOTFS "test-modprobe/builtin/correct.txt",
137 });
138
Lucas De Marchid96ca9c2013-12-17 19:10:16 -0200139static noreturn int modprobe_softdep_loop(const struct test *t)
Lucas De Marchia6976f82012-06-04 20:45:24 -0300140{
Lucas De Marchib6adccd2013-07-04 16:01:55 -0300141 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
Lucas De Marchia6976f82012-06-04 20:45:24 -0300142 const char *const args[] = {
143 progname,
Lucas De Marchi1e128242015-02-10 21:45:09 -0200144 "mod-loop-b",
Lucas De Marchia6976f82012-06-04 20:45:24 -0300145 NULL,
146 };
147
148 test_spawn_prog(progname, args);
149 exit(EXIT_FAILURE);
150}
Lucas De Marchif1155c12014-10-09 13:00:30 -0300151DEFINE_TEST(modprobe_softdep_loop,
Lucas De Marchia6976f82012-06-04 20:45:24 -0300152 .description = "check if modprobe breaks softdep loop",
153 .config = {
154 [TC_UNAME_R] = "4.4.4",
155 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/softdep-loop",
156 [TC_INIT_MODULE_RETCODES] = "",
Michal Marek88ac4082014-02-28 13:05:28 +0100157 },
Lucas De Marchi1e128242015-02-10 21:45:09 -0200158 .modules_loaded = "mod-loop-a,mod-loop-b",
Michal Marek88ac4082014-02-28 13:05:28 +0100159 );
Lucas De Marchia6976f82012-06-04 20:45:24 -0300160
Lucas De Marchid96ca9c2013-12-17 19:10:16 -0200161static noreturn int modprobe_install_cmd_loop(const struct test *t)
Lucas De Marchi01d9ee62012-06-06 01:44:23 -0300162{
Lucas De Marchib6adccd2013-07-04 16:01:55 -0300163 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
Lucas De Marchi01d9ee62012-06-06 01:44:23 -0300164 const char *const args[] = {
165 progname,
Lucas De Marchi621ac882015-02-11 02:50:06 -0200166 "mod-loop-a",
Lucas De Marchi01d9ee62012-06-06 01:44:23 -0300167 NULL,
168 };
169
170 test_spawn_prog(progname, args);
171 exit(EXIT_FAILURE);
172}
Lucas De Marchif1155c12014-10-09 13:00:30 -0300173DEFINE_TEST(modprobe_install_cmd_loop,
Lucas De Marchi9b01fd22012-06-06 10:49:04 -0300174 .description = "check if modprobe breaks install-commands loop",
Lucas De Marchi01d9ee62012-06-06 01:44:23 -0300175 .config = {
176 [TC_UNAME_R] = "4.4.4",
177 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/install-cmd-loop",
178 [TC_INIT_MODULE_RETCODES] = "",
179 },
180 .env_vars = (const struct keyval[]) {
Lucas De Marchib6adccd2013-07-04 16:01:55 -0300181 { "MODPROBE", ABS_TOP_BUILDDIR "/tools/modprobe" },
Lucas De Marchi01d9ee62012-06-06 01:44:23 -0300182 { }
183 },
Lucas De Marchi621ac882015-02-11 02:50:06 -0200184 .modules_loaded = "mod-loop-b,mod-loop-a",
Lucas De Marchi01d9ee62012-06-06 01:44:23 -0300185 );
186
Lucas De Marchid96ca9c2013-12-17 19:10:16 -0200187static noreturn int modprobe_param_kcmdline(const struct test *t)
Lucas De Marchiea225b92013-08-13 22:03:26 -0300188{
189 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
190 const char *const args[] = {
191 progname,
Lucas De Marchi246d67d2015-02-11 02:59:08 -0200192 "--show-depends", "mod-simple",
Lucas De Marchiea225b92013-08-13 22:03:26 -0300193 NULL,
194 };
195
196 test_spawn_prog(progname, args);
197 exit(EXIT_FAILURE);
198}
Lucas De Marchif1155c12014-10-09 13:00:30 -0300199DEFINE_TEST(modprobe_param_kcmdline,
Lucas De Marchi55f82862017-01-23 11:58:29 -0800200 .description = "check if params from kcmdline are passed to (f)init_module call",
Lucas De Marchiea225b92013-08-13 22:03:26 -0300201 .config = {
202 [TC_UNAME_R] = "4.4.4",
203 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline",
204 },
205 .output = {
John Spencerbd4e7342013-08-27 01:38:11 +0200206 .out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline/correct.txt",
Michal Marek88ac4082014-02-28 13:05:28 +0100207 },
208 .modules_loaded = "",
209 );
Lucas De Marchiea225b92013-08-13 22:03:26 -0300210
Lucas De Marchi55bcc4a2014-03-06 01:09:30 -0300211static noreturn int modprobe_param_kcmdline2(const struct test *t)
212{
213 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
214 const char *const args[] = {
215 progname,
216 "-c",
217 NULL,
218 };
219
220 test_spawn_prog(progname, args);
221 exit(EXIT_FAILURE);
222}
Lucas De Marchif1155c12014-10-09 13:00:30 -0300223DEFINE_TEST(modprobe_param_kcmdline2,
Lucas De Marchi55bcc4a2014-03-06 01:09:30 -0300224 .description = "check if params with no value are parsed correctly from kcmdline",
225 .config = {
226 [TC_UNAME_R] = "4.4.4",
227 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline2",
228 },
229 .output = {
230 .out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline2/correct.txt",
231 },
232 .modules_loaded = "",
233 );
234
Lucas De Marchi42149022014-03-06 01:24:32 -0300235static noreturn int modprobe_param_kcmdline3(const struct test *t)
236{
237 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
238 const char *const args[] = {
239 progname,
240 "-c",
241 NULL,
242 };
243
244 test_spawn_prog(progname, args);
245 exit(EXIT_FAILURE);
246}
Lucas De Marchif1155c12014-10-09 13:00:30 -0300247DEFINE_TEST(modprobe_param_kcmdline3,
Lucas De Marchi42149022014-03-06 01:24:32 -0300248 .description = "check if unrelated strings in kcmdline are correctly ignored",
249 .config = {
250 [TC_UNAME_R] = "4.4.4",
251 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline3",
252 },
253 .output = {
254 .out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline3/correct.txt",
255 },
256 .modules_loaded = "",
257 );
258
Lucas De Marchi49776622014-03-06 01:36:02 -0300259static noreturn int modprobe_param_kcmdline4(const struct test *t)
260{
261 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
262 const char *const args[] = {
263 progname,
264 "-c",
265 NULL,
266 };
267
268 test_spawn_prog(progname, args);
269 exit(EXIT_FAILURE);
270}
Lucas De Marchif1155c12014-10-09 13:00:30 -0300271DEFINE_TEST(modprobe_param_kcmdline4,
Lucas De Marchi49776622014-03-06 01:36:02 -0300272 .description = "check if unrelated strings in kcmdline are correctly ignored",
273 .config = {
274 [TC_UNAME_R] = "4.4.4",
275 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline4",
276 },
277 .output = {
278 .out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline4/correct.txt",
279 },
280 .modules_loaded = "",
281 );
282
Lucas De Marchided0beb2017-01-23 11:59:31 -0800283static noreturn int modprobe_param_kcmdline5(const struct test *t)
284{
285 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
286 const char *const args[] = {
287 progname,
288 "-c",
289 NULL,
290 };
291
292 test_spawn_prog(progname, args);
293 exit(EXIT_FAILURE);
294}
295DEFINE_TEST(modprobe_param_kcmdline5,
296 .description = "check if params with spaces are parsed correctly from kcmdline",
297 .config = {
298 [TC_UNAME_R] = "4.4.4",
299 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline5",
300 },
301 .output = {
302 .out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline5/correct.txt",
303 },
304 .modules_loaded = "",
305 );
306
307
Michal Marek2ce5de02014-02-28 13:05:29 +0100308static noreturn int modprobe_force(const struct test *t)
309{
310 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
311 const char *const args[] = {
312 progname,
Lucas De Marchia1a13692015-02-10 22:01:42 -0200313 "--force", "mod-simple",
Michal Marek2ce5de02014-02-28 13:05:29 +0100314 NULL,
315 };
316
317 test_spawn_prog(progname, args);
318 exit(EXIT_FAILURE);
319}
Lucas De Marchif1155c12014-10-09 13:00:30 -0300320DEFINE_TEST(modprobe_force,
Michal Marek2ce5de02014-02-28 13:05:29 +0100321 .description = "check modprobe --force",
322 .config = {
323 [TC_UNAME_R] = "4.4.4",
324 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/force",
325 [TC_INIT_MODULE_RETCODES] = "",
326 },
Lucas De Marchia1a13692015-02-10 22:01:42 -0200327 .modules_loaded = "mod-simple",
Michal Marek2ce5de02014-02-28 13:05:29 +0100328 );
329
Michal Marekbe29c402014-02-28 13:05:31 +0100330static noreturn int modprobe_oldkernel(const struct test *t)
331{
332 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
333 const char *const args[] = {
334 progname,
Lucas De Marchi33c11852015-02-10 22:11:25 -0200335 "mod-simple",
Michal Marekbe29c402014-02-28 13:05:31 +0100336 NULL,
337 };
338
339 test_spawn_prog(progname, args);
340 exit(EXIT_FAILURE);
341}
Lucas De Marchif1155c12014-10-09 13:00:30 -0300342DEFINE_TEST(modprobe_oldkernel,
Lucas De Marchi33c11852015-02-10 22:11:25 -0200343 .description = "check modprobe with kernel without finit_module()",
Michal Marekbe29c402014-02-28 13:05:31 +0100344 .config = {
345 [TC_UNAME_R] = "3.3.3",
346 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/oldkernel",
347 [TC_INIT_MODULE_RETCODES] = "",
348 },
Lucas De Marchi33c11852015-02-10 22:11:25 -0200349 .modules_loaded = "mod-simple",
Michal Marekbe29c402014-02-28 13:05:31 +0100350 );
351
352static noreturn int modprobe_oldkernel_force(const struct test *t)
353{
354 const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe";
355 const char *const args[] = {
356 progname,
Lucas De Marchi33c11852015-02-10 22:11:25 -0200357 "--force", "mod-simple",
Michal Marekbe29c402014-02-28 13:05:31 +0100358 NULL,
359 };
360
361 test_spawn_prog(progname, args);
362 exit(EXIT_FAILURE);
363}
Lucas De Marchif1155c12014-10-09 13:00:30 -0300364DEFINE_TEST(modprobe_oldkernel_force,
Lucas De Marchi33c11852015-02-10 22:11:25 -0200365 .description = "check modprobe --force with kernel without finit_module()",
Michal Marekbe29c402014-02-28 13:05:31 +0100366 .config = {
367 [TC_UNAME_R] = "3.3.3",
368 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/oldkernel-force",
369 [TC_INIT_MODULE_RETCODES] = "",
370 },
Lucas De Marchi33c11852015-02-10 22:11:25 -0200371 .modules_loaded = "mod-simple",
Michal Marekbe29c402014-02-28 13:05:31 +0100372 );
373
Lucas De Marchi43289822014-10-09 14:29:04 -0300374TESTSUITE_MAIN();