From: Zbigniew Jędrzejewski-Szmek Date: Tue, 7 Jun 2022 14:03:12 +0000 (+0200) Subject: test-process-util: do not pass NULL to printf, simplify tests X-Git-Tag: v252-rc1~841^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fa1aa468b941f7d89677ea09cd413f55b5c8c030;p=thirdparty%2Fsystemd.git test-process-util: do not pass NULL to printf, simplify tests We don't need to fork to test that the function returns -EINVAL on null input. So let's simplify things a bit. --- diff --git a/src/test/test-process-util.c b/src/test/test-process-util.c index 7a8adad50c8..990eb1e2b67 100644 --- a/src/test/test-process-util.c +++ b/src/test/test-process-util.c @@ -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 */