Skip to content

Commit 542f99c

Browse files
committed
test: add more test cases for proc_cmdline_filter_pid1_args()
1 parent f14f127 commit 542f99c

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

src/test/test-proc-cmdline.c

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,14 +284,47 @@ TEST(proc_cmdline_filter_pid1_args) {
284284
test_proc_cmdline_filter_pid1_args_one("systemd\0",
285285
STRV_MAKE_EMPTY);
286286

287+
/* short option */
287288
test_proc_cmdline_filter_pid1_args_one("systemd\0"
288-
"hoge\0"
289+
"-a\0" /* unknown option */
290+
"-abc\0" /* unknown options */
291+
"-h\0" /* known option */
292+
"-hDbs\0" /* known options */
293+
"-hsx\0" /* mixed (known and unknown) options */
294+
"-z\0drop1\0" /* option with argument */
295+
"-z\0-z\0accept1\0" /* the second -z is handled as argument */
296+
"-az\0drop2\0" /* options with argument */
297+
"-za\0accept2\0" /* options with argument */
298+
"-z\0--\0-x\0", /* "--" is handled as argument */
299+
STRV_MAKE("accept1", "accept2"));
300+
301+
/* long option */
302+
test_proc_cmdline_filter_pid1_args_one("systemd\0"
303+
"--unknown\0accept1\0" /* unknown option */
304+
"--system\0accept2\0" /* no argument */
305+
"--log-level\0drop1\0" /* required argument (separated with space) */
306+
"--log-level=drop2\0accept3\0" /* required argument (concatenated with '=') */
307+
"--log-level\0--log-level\0accept4\0" /* the second "--log-level" is handled as argument */
308+
"--log-level\0--\0-x\0" /* "--" is handled as argument */
309+
"--log-color\0--log-level\0drop3\0" /* optional argument ("--log-level" is handled as another option) */
310+
"--log-color\0accept5\0" /* optional argument (separated with space) */
311+
"--log-color=drop4\0accept6\0" /* optional argument (concatenated with '=') */
312+
"--log-color\0--\0" /* "--" is _not_ handled as argument, and remaining strings are accepted */
313+
"remaining\0-x\0--foo\0",
314+
STRV_MAKE("accept1", "accept2", "accept3", "accept4", "accept5", "accept6", "remaining", "-x", "--foo"));
315+
316+
/* test for "--" */
317+
test_proc_cmdline_filter_pid1_args_one("systemd\0"
318+
"-a\0"
319+
"--dropped\0"
320+
"--\0" /* remaining strings are accepted */
289321
"-x\0"
290-
"foo\0"
291-
"--aaa\0"
292-
"var\0",
293-
STRV_MAKE("hoge", "foo", "var"));
322+
"-abc\0"
323+
"--hoge\0"
324+
"accepted\0",
325+
STRV_MAKE("-x", "-abc", "--hoge", "accepted"));
294326

327+
/* test for space */
295328
test_proc_cmdline_filter_pid1_args_one("/usr/lib/systemd/systemd\0"
296329
"--switched-root\0"
297330
"--system\0"

0 commit comments

Comments
 (0)