]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-process-util: do not pass NULL to printf, simplify tests
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 7 Jun 2022 14:03:12 +0000 (16:03 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 9 Jun 2022 11:25:17 +0000 (13:25 +0200)
We don't need to fork to test that the function returns -EINVAL
on null input. So let's simplify things a bit.

src/test/test-process-util.c

index 7a8adad50c8a0a4165fa6b1aa4ffd48a85c71439..990eb1e2b674be23be4ee74a9a2a6422dd441f2f 100644 (file)
@@ -528,7 +528,7 @@ static void test_rename_process_now(const char *p, int ret) {
         _cleanup_free_ char *comm = NULL, *cmdline = NULL;
         int r;
 
-        log_info("/* %s */", __func__);
+        log_info("/* %s(%s) */", __func__, p);
 
         r = rename_process(p);
         assert_se(r == ret ||
@@ -574,7 +574,7 @@ static void test_rename_process_one(const char *p, int ret) {
         siginfo_t si;
         pid_t pid;
 
-        log_info("/* %s */", __func__);
+        log_info("/* %s(%s) */", __func__, p);
 
         pid = fork();
         assert_se(pid >= 0);
@@ -590,6 +590,11 @@ static void test_rename_process_one(const char *p, int ret) {
         assert_se(si.si_status == EXIT_SUCCESS);
 }
 
+TEST(rename_process_invalid) {
+        assert_se(rename_process(NULL) == -EINVAL);
+        assert_se(rename_process("") == -EINVAL);
+}
+
 TEST(rename_process_multi) {
         pid_t pid;
 
@@ -612,14 +617,10 @@ TEST(rename_process_multi) {
         (void) setresuid(99, 99, 99); /* change uid when running privileged */
         test_rename_process_now("time!", 0);
         test_rename_process_now("0", 1); /* shorter than "one", should fit */
-        test_rename_process_one("", -EINVAL);
-        test_rename_process_one(NULL, -EINVAL);
         _exit(EXIT_SUCCESS);
 }
 
 TEST(rename_process) {
-        test_rename_process_one(NULL, -EINVAL);
-        test_rename_process_one("", -EINVAL);
         test_rename_process_one("foo", 1); /* should always fit */
         test_rename_process_one("this is a really really long process name, followed by some more words", 0); /* unlikely to fit */
         test_rename_process_one("1234567", 1); /* should always fit */