Lucas De Marchi | 976ea8c | 2012-02-08 01:40:00 -0200 | [diff] [blame] | 1 | /* |
Lucas De Marchi | e6b0e49 | 2013-01-16 11:27:21 -0200 | [diff] [blame] | 2 | * Copyright (C) 2012-2013 ProFUSION embedded systems |
Lucas De Marchi | 976ea8c | 2012-02-08 01:40:00 -0200 | [diff] [blame] | 3 | * |
Lucas De Marchi | e1b1ab2 | 2012-07-10 09:42:24 -0300 | [diff] [blame] | 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. |
Lucas De Marchi | 976ea8c | 2012-02-08 01:40:00 -0200 | [diff] [blame] | 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 |
Lucas De Marchi | e1b1ab2 | 2012-07-10 09:42:24 -0300 | [diff] [blame] | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Lesser General Public License for more details. |
Lucas De Marchi | 976ea8c | 2012-02-08 01:40:00 -0200 | [diff] [blame] | 13 | * |
Lucas De Marchi | e1b1ab2 | 2012-07-10 09:42:24 -0300 | [diff] [blame] | 14 | * You should have received a copy of the GNU Lesser General Public |
| 15 | * License along with this library; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Lucas De Marchi | 976ea8c | 2012-02-08 01:40:00 -0200 | [diff] [blame] | 17 | */ |
| 18 | |
Lucas De Marchi | c2e4286 | 2014-10-03 01:41:42 -0300 | [diff] [blame] | 19 | #include <errno.h> |
| 20 | #include <inttypes.h> |
| 21 | #include <stddef.h> |
Lucas De Marchi | 976ea8c | 2012-02-08 01:40:00 -0200 | [diff] [blame] | 22 | #include <stdio.h> |
| 23 | #include <stdlib.h> |
Lucas De Marchi | 976ea8c | 2012-02-08 01:40:00 -0200 | [diff] [blame] | 24 | #include <string.h> |
Lucas De Marchi | c2e4286 | 2014-10-03 01:41:42 -0300 | [diff] [blame] | 25 | #include <unistd.h> |
Lucas De Marchi | 976ea8c | 2012-02-08 01:40:00 -0200 | [diff] [blame] | 26 | |
| 27 | #include "testsuite.h" |
| 28 | |
Lucas De Marchi | d96ca9c | 2013-12-17 19:10:16 -0200 | [diff] [blame] | 29 | static noreturn int modprobe_show_depends(const struct test *t) |
Lucas De Marchi | 976ea8c | 2012-02-08 01:40:00 -0200 | [diff] [blame] | 30 | { |
Lucas De Marchi | b6adccd | 2013-07-04 16:01:55 -0300 | [diff] [blame] | 31 | const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; |
Lucas De Marchi | 976ea8c | 2012-02-08 01:40:00 -0200 | [diff] [blame] | 32 | const char *const args[] = { |
| 33 | progname, |
| 34 | "--show-depends", "btusb", |
| 35 | NULL, |
| 36 | }; |
| 37 | |
| 38 | test_spawn_prog(progname, args); |
| 39 | exit(EXIT_FAILURE); |
| 40 | } |
| 41 | static DEFINE_TEST(modprobe_show_depends, |
| 42 | .description = "check if output for modprobe --show-depends is correct for loaded modules", |
| 43 | .config = { |
| 44 | [TC_UNAME_R] = "4.4.4", |
| 45 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/show-depends", |
| 46 | }, |
| 47 | .output = { |
John Spencer | bd4e734 | 2013-08-27 01:38:11 +0200 | [diff] [blame] | 48 | .out = TESTSUITE_ROOTFS "test-modprobe/show-depends/correct.txt", |
Lucas De Marchi | 976ea8c | 2012-02-08 01:40:00 -0200 | [diff] [blame] | 49 | }); |
| 50 | |
Lucas De Marchi | d96ca9c | 2013-12-17 19:10:16 -0200 | [diff] [blame] | 51 | static noreturn int modprobe_show_depends2(const struct test *t) |
Lucas De Marchi | 976ea8c | 2012-02-08 01:40:00 -0200 | [diff] [blame] | 52 | { |
Lucas De Marchi | b6adccd | 2013-07-04 16:01:55 -0300 | [diff] [blame] | 53 | const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; |
Lucas De Marchi | 976ea8c | 2012-02-08 01:40:00 -0200 | [diff] [blame] | 54 | const char *const args[] = { |
| 55 | progname, |
| 56 | "--show-depends", "psmouse", |
| 57 | NULL, |
| 58 | }; |
| 59 | |
| 60 | test_spawn_prog(progname, args); |
| 61 | exit(EXIT_FAILURE); |
| 62 | } |
| 63 | static DEFINE_TEST(modprobe_show_depends2, |
| 64 | .description = "check if output for modprobe --show-depends is correct", |
| 65 | .config = { |
| 66 | [TC_UNAME_R] = "4.4.4", |
| 67 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/show-depends", |
| 68 | }, |
| 69 | .output = { |
John Spencer | bd4e734 | 2013-08-27 01:38:11 +0200 | [diff] [blame] | 70 | .out = TESTSUITE_ROOTFS "test-modprobe/show-depends/correct-psmouse.txt", |
Lucas De Marchi | 976ea8c | 2012-02-08 01:40:00 -0200 | [diff] [blame] | 71 | }); |
Lucas De Marchi | a7f5300 | 2012-02-16 21:04:24 -0200 | [diff] [blame] | 72 | |
Lucas De Marchi | 5278396 | 2013-03-21 02:24:07 -0300 | [diff] [blame] | 73 | |
Lucas De Marchi | d96ca9c | 2013-12-17 19:10:16 -0200 | [diff] [blame] | 74 | static noreturn int modprobe_show_alias_to_none(const struct test *t) |
Lucas De Marchi | 5278396 | 2013-03-21 02:24:07 -0300 | [diff] [blame] | 75 | { |
Lucas De Marchi | b6adccd | 2013-07-04 16:01:55 -0300 | [diff] [blame] | 76 | const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; |
Lucas De Marchi | 5278396 | 2013-03-21 02:24:07 -0300 | [diff] [blame] | 77 | const char *const args[] = { |
| 78 | progname, |
| 79 | "--show-depends", "--ignore-install", "--quiet", "psmouse", |
| 80 | NULL, |
| 81 | }; |
| 82 | |
| 83 | test_spawn_prog(progname, args); |
| 84 | exit(EXIT_FAILURE); |
| 85 | } |
| 86 | static DEFINE_TEST(modprobe_show_alias_to_none, |
| 87 | .description = "check if modprobe --show-depends doesn't explode with an alias to nothing", |
Lucas De Marchi | 5278396 | 2013-03-21 02:24:07 -0300 | [diff] [blame] | 88 | .config = { |
| 89 | [TC_UNAME_R] = "4.4.4", |
| 90 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/alias-to-none", |
| 91 | }, |
| 92 | .output = { |
John Spencer | bd4e734 | 2013-08-27 01:38:11 +0200 | [diff] [blame] | 93 | .out = TESTSUITE_ROOTFS "test-modprobe/show-depends/correct-psmouse.txt", |
Michal Marek | 88ac408 | 2014-02-28 13:05:28 +0100 | [diff] [blame] | 94 | }, |
| 95 | .modules_loaded = "", |
| 96 | ); |
Lucas De Marchi | 5278396 | 2013-03-21 02:24:07 -0300 | [diff] [blame] | 97 | |
| 98 | |
Lucas De Marchi | d96ca9c | 2013-12-17 19:10:16 -0200 | [diff] [blame] | 99 | static noreturn int modprobe_builtin(const struct test *t) |
Lucas De Marchi | a7f5300 | 2012-02-16 21:04:24 -0200 | [diff] [blame] | 100 | { |
Lucas De Marchi | b6adccd | 2013-07-04 16:01:55 -0300 | [diff] [blame] | 101 | const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; |
Lucas De Marchi | a7f5300 | 2012-02-16 21:04:24 -0200 | [diff] [blame] | 102 | const char *const args[] = { |
| 103 | progname, |
| 104 | "unix", |
| 105 | NULL, |
| 106 | }; |
| 107 | |
| 108 | test_spawn_prog(progname, args); |
| 109 | exit(EXIT_FAILURE); |
| 110 | } |
| 111 | static DEFINE_TEST(modprobe_builtin, |
| 112 | .description = "check if modprobe return 0 for builtin", |
Lucas De Marchi | a7f5300 | 2012-02-16 21:04:24 -0200 | [diff] [blame] | 113 | .config = { |
| 114 | [TC_UNAME_R] = "4.4.4", |
| 115 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/builtin", |
| 116 | }); |
| 117 | |
Lucas De Marchi | d96ca9c | 2013-12-17 19:10:16 -0200 | [diff] [blame] | 118 | static noreturn int modprobe_softdep_loop(const struct test *t) |
Lucas De Marchi | a6976f8 | 2012-06-04 20:45:24 -0300 | [diff] [blame] | 119 | { |
Lucas De Marchi | b6adccd | 2013-07-04 16:01:55 -0300 | [diff] [blame] | 120 | const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; |
Lucas De Marchi | a6976f8 | 2012-06-04 20:45:24 -0300 | [diff] [blame] | 121 | const char *const args[] = { |
| 122 | progname, |
| 123 | "bluetooth", |
| 124 | NULL, |
| 125 | }; |
| 126 | |
| 127 | test_spawn_prog(progname, args); |
| 128 | exit(EXIT_FAILURE); |
| 129 | } |
| 130 | static DEFINE_TEST(modprobe_softdep_loop, |
| 131 | .description = "check if modprobe breaks softdep loop", |
| 132 | .config = { |
| 133 | [TC_UNAME_R] = "4.4.4", |
| 134 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/softdep-loop", |
| 135 | [TC_INIT_MODULE_RETCODES] = "", |
Michal Marek | 88ac408 | 2014-02-28 13:05:28 +0100 | [diff] [blame] | 136 | }, |
| 137 | .modules_loaded = "btusb,bluetooth", |
| 138 | ); |
Lucas De Marchi | a6976f8 | 2012-06-04 20:45:24 -0300 | [diff] [blame] | 139 | |
Lucas De Marchi | d96ca9c | 2013-12-17 19:10:16 -0200 | [diff] [blame] | 140 | static noreturn int modprobe_install_cmd_loop(const struct test *t) |
Lucas De Marchi | 01d9ee6 | 2012-06-06 01:44:23 -0300 | [diff] [blame] | 141 | { |
Lucas De Marchi | b6adccd | 2013-07-04 16:01:55 -0300 | [diff] [blame] | 142 | const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; |
Lucas De Marchi | 01d9ee6 | 2012-06-06 01:44:23 -0300 | [diff] [blame] | 143 | const char *const args[] = { |
| 144 | progname, |
| 145 | "snd-pcm", |
| 146 | NULL, |
| 147 | }; |
| 148 | |
| 149 | test_spawn_prog(progname, args); |
| 150 | exit(EXIT_FAILURE); |
| 151 | } |
| 152 | static DEFINE_TEST(modprobe_install_cmd_loop, |
Lucas De Marchi | 9b01fd2 | 2012-06-06 10:49:04 -0300 | [diff] [blame] | 153 | .description = "check if modprobe breaks install-commands loop", |
Lucas De Marchi | 01d9ee6 | 2012-06-06 01:44:23 -0300 | [diff] [blame] | 154 | .config = { |
| 155 | [TC_UNAME_R] = "4.4.4", |
| 156 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/install-cmd-loop", |
| 157 | [TC_INIT_MODULE_RETCODES] = "", |
| 158 | }, |
| 159 | .env_vars = (const struct keyval[]) { |
Lucas De Marchi | b6adccd | 2013-07-04 16:01:55 -0300 | [diff] [blame] | 160 | { "MODPROBE", ABS_TOP_BUILDDIR "/tools/modprobe" }, |
Lucas De Marchi | 01d9ee6 | 2012-06-06 01:44:23 -0300 | [diff] [blame] | 161 | { } |
| 162 | }, |
Michal Marek | 88ac408 | 2014-02-28 13:05:28 +0100 | [diff] [blame] | 163 | .modules_loaded = "snd,snd-pcm", |
Lucas De Marchi | 01d9ee6 | 2012-06-06 01:44:23 -0300 | [diff] [blame] | 164 | ); |
| 165 | |
Lucas De Marchi | d96ca9c | 2013-12-17 19:10:16 -0200 | [diff] [blame] | 166 | static noreturn int modprobe_param_kcmdline(const struct test *t) |
Lucas De Marchi | ea225b9 | 2013-08-13 22:03:26 -0300 | [diff] [blame] | 167 | { |
| 168 | const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; |
| 169 | const char *const args[] = { |
| 170 | progname, |
| 171 | "--show-depends", "psmouse", |
| 172 | NULL, |
| 173 | }; |
| 174 | |
| 175 | test_spawn_prog(progname, args); |
| 176 | exit(EXIT_FAILURE); |
| 177 | } |
| 178 | static DEFINE_TEST(modprobe_param_kcmdline, |
Lucas De Marchi | bad84a9 | 2014-03-06 01:14:12 -0300 | [diff] [blame] | 179 | .description = "check if params from kcmdline are passed in fact passed to (f)init_module call", |
Lucas De Marchi | ea225b9 | 2013-08-13 22:03:26 -0300 | [diff] [blame] | 180 | .config = { |
| 181 | [TC_UNAME_R] = "4.4.4", |
| 182 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline", |
| 183 | }, |
| 184 | .output = { |
John Spencer | bd4e734 | 2013-08-27 01:38:11 +0200 | [diff] [blame] | 185 | .out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline/correct.txt", |
Michal Marek | 88ac408 | 2014-02-28 13:05:28 +0100 | [diff] [blame] | 186 | }, |
| 187 | .modules_loaded = "", |
| 188 | ); |
Lucas De Marchi | ea225b9 | 2013-08-13 22:03:26 -0300 | [diff] [blame] | 189 | |
Lucas De Marchi | 55bcc4a | 2014-03-06 01:09:30 -0300 | [diff] [blame] | 190 | static noreturn int modprobe_param_kcmdline2(const struct test *t) |
| 191 | { |
| 192 | const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; |
| 193 | const char *const args[] = { |
| 194 | progname, |
| 195 | "-c", |
| 196 | NULL, |
| 197 | }; |
| 198 | |
| 199 | test_spawn_prog(progname, args); |
| 200 | exit(EXIT_FAILURE); |
| 201 | } |
| 202 | static DEFINE_TEST(modprobe_param_kcmdline2, |
| 203 | .description = "check if params with no value are parsed correctly from kcmdline", |
| 204 | .config = { |
| 205 | [TC_UNAME_R] = "4.4.4", |
| 206 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline2", |
| 207 | }, |
| 208 | .output = { |
| 209 | .out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline2/correct.txt", |
| 210 | }, |
| 211 | .modules_loaded = "", |
| 212 | ); |
| 213 | |
Lucas De Marchi | 4214902 | 2014-03-06 01:24:32 -0300 | [diff] [blame] | 214 | static noreturn int modprobe_param_kcmdline3(const struct test *t) |
| 215 | { |
| 216 | const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; |
| 217 | const char *const args[] = { |
| 218 | progname, |
| 219 | "-c", |
| 220 | NULL, |
| 221 | }; |
| 222 | |
| 223 | test_spawn_prog(progname, args); |
| 224 | exit(EXIT_FAILURE); |
| 225 | } |
| 226 | static DEFINE_TEST(modprobe_param_kcmdline3, |
| 227 | .description = "check if unrelated strings in kcmdline are correctly ignored", |
| 228 | .config = { |
| 229 | [TC_UNAME_R] = "4.4.4", |
| 230 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline3", |
| 231 | }, |
| 232 | .output = { |
| 233 | .out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline3/correct.txt", |
| 234 | }, |
| 235 | .modules_loaded = "", |
| 236 | ); |
| 237 | |
Lucas De Marchi | 4977662 | 2014-03-06 01:36:02 -0300 | [diff] [blame] | 238 | static noreturn int modprobe_param_kcmdline4(const struct test *t) |
| 239 | { |
| 240 | const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; |
| 241 | const char *const args[] = { |
| 242 | progname, |
| 243 | "-c", |
| 244 | NULL, |
| 245 | }; |
| 246 | |
| 247 | test_spawn_prog(progname, args); |
| 248 | exit(EXIT_FAILURE); |
| 249 | } |
| 250 | static DEFINE_TEST(modprobe_param_kcmdline4, |
| 251 | .description = "check if unrelated strings in kcmdline are correctly ignored", |
| 252 | .config = { |
| 253 | [TC_UNAME_R] = "4.4.4", |
| 254 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline4", |
| 255 | }, |
| 256 | .output = { |
| 257 | .out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline4/correct.txt", |
| 258 | }, |
| 259 | .modules_loaded = "", |
| 260 | ); |
| 261 | |
Michal Marek | 2ce5de0 | 2014-02-28 13:05:29 +0100 | [diff] [blame] | 262 | static noreturn int modprobe_force(const struct test *t) |
| 263 | { |
| 264 | const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; |
| 265 | const char *const args[] = { |
| 266 | progname, |
| 267 | "--force", "psmouse", |
| 268 | NULL, |
| 269 | }; |
| 270 | |
| 271 | test_spawn_prog(progname, args); |
| 272 | exit(EXIT_FAILURE); |
| 273 | } |
| 274 | static DEFINE_TEST(modprobe_force, |
| 275 | .description = "check modprobe --force", |
| 276 | .config = { |
| 277 | [TC_UNAME_R] = "4.4.4", |
| 278 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/force", |
| 279 | [TC_INIT_MODULE_RETCODES] = "", |
| 280 | }, |
| 281 | .modules_loaded = "psmouse", |
| 282 | ); |
| 283 | |
Michal Marek | be29c40 | 2014-02-28 13:05:31 +0100 | [diff] [blame] | 284 | static noreturn int modprobe_oldkernel(const struct test *t) |
| 285 | { |
| 286 | const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; |
| 287 | const char *const args[] = { |
| 288 | progname, |
| 289 | "psmouse", |
| 290 | NULL, |
| 291 | }; |
| 292 | |
| 293 | test_spawn_prog(progname, args); |
| 294 | exit(EXIT_FAILURE); |
| 295 | } |
| 296 | static DEFINE_TEST(modprobe_oldkernel, |
| 297 | .description = "check modprobe --force", |
| 298 | .config = { |
| 299 | [TC_UNAME_R] = "3.3.3", |
| 300 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/oldkernel", |
| 301 | [TC_INIT_MODULE_RETCODES] = "", |
| 302 | }, |
| 303 | .modules_loaded = "psmouse", |
| 304 | ); |
| 305 | |
| 306 | static noreturn int modprobe_oldkernel_force(const struct test *t) |
| 307 | { |
| 308 | const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; |
| 309 | const char *const args[] = { |
| 310 | progname, |
| 311 | "--force", "psmouse", |
| 312 | NULL, |
| 313 | }; |
| 314 | |
| 315 | test_spawn_prog(progname, args); |
| 316 | exit(EXIT_FAILURE); |
| 317 | } |
| 318 | static DEFINE_TEST(modprobe_oldkernel_force, |
| 319 | .description = "check modprobe --force", |
| 320 | .config = { |
| 321 | [TC_UNAME_R] = "3.3.3", |
| 322 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/oldkernel-force", |
| 323 | [TC_INIT_MODULE_RETCODES] = "", |
| 324 | }, |
| 325 | .modules_loaded = "psmouse", |
| 326 | ); |
| 327 | |
Lucas De Marchi | 5278396 | 2013-03-21 02:24:07 -0300 | [diff] [blame] | 328 | |
Lucas De Marchi | 976ea8c | 2012-02-08 01:40:00 -0200 | [diff] [blame] | 329 | static const struct test *tests[] = { |
| 330 | &smodprobe_show_depends, |
| 331 | &smodprobe_show_depends2, |
Lucas De Marchi | 5278396 | 2013-03-21 02:24:07 -0300 | [diff] [blame] | 332 | &smodprobe_show_alias_to_none, |
Lucas De Marchi | a7f5300 | 2012-02-16 21:04:24 -0200 | [diff] [blame] | 333 | &smodprobe_builtin, |
Lucas De Marchi | a6976f8 | 2012-06-04 20:45:24 -0300 | [diff] [blame] | 334 | &smodprobe_softdep_loop, |
Lucas De Marchi | 01d9ee6 | 2012-06-06 01:44:23 -0300 | [diff] [blame] | 335 | &smodprobe_install_cmd_loop, |
Lucas De Marchi | ea225b9 | 2013-08-13 22:03:26 -0300 | [diff] [blame] | 336 | &smodprobe_param_kcmdline, |
Lucas De Marchi | 55bcc4a | 2014-03-06 01:09:30 -0300 | [diff] [blame] | 337 | &smodprobe_param_kcmdline2, |
Lucas De Marchi | 4214902 | 2014-03-06 01:24:32 -0300 | [diff] [blame] | 338 | &smodprobe_param_kcmdline3, |
Lucas De Marchi | 4977662 | 2014-03-06 01:36:02 -0300 | [diff] [blame] | 339 | &smodprobe_param_kcmdline4, |
Michal Marek | 2ce5de0 | 2014-02-28 13:05:29 +0100 | [diff] [blame] | 340 | &smodprobe_force, |
Michal Marek | be29c40 | 2014-02-28 13:05:31 +0100 | [diff] [blame] | 341 | &smodprobe_oldkernel, |
| 342 | &smodprobe_oldkernel_force, |
Lucas De Marchi | 976ea8c | 2012-02-08 01:40:00 -0200 | [diff] [blame] | 343 | NULL, |
| 344 | }; |
| 345 | |
| 346 | TESTSUITE_MAIN(tests); |