]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: add more test cases for proc_cmdline_filter_pid1_args()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 14 Jul 2023 04:09:22 +0000 (13:09 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 14 Jul 2023 04:36:50 +0000 (13:36 +0900)
src/test/test-proc-cmdline.c

index 2d51dbe4b9ae0781f94c86a7e3220a7529af23fa..4fd91253781c6695bb8a72c56679da76c60591f3 100644 (file)
@@ -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"