From: Yu Watanabe Date: Fri, 14 Jul 2023 04:09:22 +0000 (+0900) Subject: test: add more test cases for proc_cmdline_filter_pid1_args() X-Git-Tag: v254-rc2~15^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=542f99cc8bd6f10037110a5ae931be53a239021c;p=thirdparty%2Fsystemd.git test: add more test cases for proc_cmdline_filter_pid1_args() --- diff --git a/src/test/test-proc-cmdline.c b/src/test/test-proc-cmdline.c index 2d51dbe4b9a..4fd91253781 100644 --- a/src/test/test-proc-cmdline.c +++ b/src/test/test-proc-cmdline.c @@ -284,14 +284,47 @@ TEST(proc_cmdline_filter_pid1_args) { test_proc_cmdline_filter_pid1_args_one("systemd\0", STRV_MAKE_EMPTY); + /* short option */ test_proc_cmdline_filter_pid1_args_one("systemd\0" - "hoge\0" + "-a\0" /* unknown option */ + "-abc\0" /* unknown options */ + "-h\0" /* known option */ + "-hDbs\0" /* known options */ + "-hsx\0" /* mixed (known and unknown) options */ + "-z\0drop1\0" /* option with argument */ + "-z\0-z\0accept1\0" /* the second -z is handled as argument */ + "-az\0drop2\0" /* options with argument */ + "-za\0accept2\0" /* options with argument */ + "-z\0--\0-x\0", /* "--" is handled as argument */ + STRV_MAKE("accept1", "accept2")); + + /* long option */ + test_proc_cmdline_filter_pid1_args_one("systemd\0" + "--unknown\0accept1\0" /* unknown option */ + "--system\0accept2\0" /* no argument */ + "--log-level\0drop1\0" /* required argument (separated with space) */ + "--log-level=drop2\0accept3\0" /* required argument (concatenated with '=') */ + "--log-level\0--log-level\0accept4\0" /* the second "--log-level" is handled as argument */ + "--log-level\0--\0-x\0" /* "--" is handled as argument */ + "--log-color\0--log-level\0drop3\0" /* optional argument ("--log-level" is handled as another option) */ + "--log-color\0accept5\0" /* optional argument (separated with space) */ + "--log-color=drop4\0accept6\0" /* optional argument (concatenated with '=') */ + "--log-color\0--\0" /* "--" is _not_ handled as argument, and remaining strings are accepted */ + "remaining\0-x\0--foo\0", + STRV_MAKE("accept1", "accept2", "accept3", "accept4", "accept5", "accept6", "remaining", "-x", "--foo")); + + /* test for "--" */ + test_proc_cmdline_filter_pid1_args_one("systemd\0" + "-a\0" + "--dropped\0" + "--\0" /* remaining strings are accepted */ "-x\0" - "foo\0" - "--aaa\0" - "var\0", - STRV_MAKE("hoge", "foo", "var")); + "-abc\0" + "--hoge\0" + "accepted\0", + STRV_MAKE("-x", "-abc", "--hoge", "accepted")); + /* test for space */ test_proc_cmdline_filter_pid1_args_one("/usr/lib/systemd/systemd\0" "--switched-root\0" "--system\0"