summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test-process-util.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/test/test-process-util.c b/src/test/test-process-util.c
index 7242b2c8b5..c5edbcc5d2 100644
--- a/src/test/test-process-util.c
+++ b/src/test/test-process-util.c
@@ -355,10 +355,70 @@ static void test_get_process_cmdline_harder(void) {
_exit(0);
}
+static void test_rename_process_one(const char *p, int ret) {
+ _cleanup_free_ char *comm = NULL, *cmdline = NULL;
+ pid_t pid;
+ int r;
+
+ pid = fork();
+ assert_se(pid >= 0);
+
+ if (pid > 0) {
+ siginfo_t si;
+
+ assert_se(wait_for_terminate(pid, &si) >= 0);
+ assert_se(si.si_code == CLD_EXITED);
+ assert_se(si.si_status == EXIT_SUCCESS);
+
+ return;
+ }
+
+ /* child */
+ r = rename_process(p);
+
+ assert_se(r == ret ||
+ (ret == 0 && r >= 0) ||
+ (ret > 0 && r > 0));
+
+ if (r < 0)
+ goto finish;
+
+#ifdef HAVE_VALGRIND_VALGRIND_H
+ /* see above, valgrind is weird, we can't verify what we are doing here */
+ if (RUNNING_ON_VALGRIND)
+ goto finish;
+#endif
+
+ assert_se(get_process_comm(0, &comm) >= 0);
+ log_info("comm = <%s>", comm);
+ assert_se(strneq(comm, p, 15));
+
+ assert_se(get_process_cmdline(0, 0, false, &cmdline) >= 0);
+ log_info("cmdline = <%s>", cmdline);
+ assert_se(strneq(p, cmdline, strlen("test-process-util")));
+ assert_se(startswith(p, cmdline));
+
+finish:
+ _exit(EXIT_SUCCESS);
+}
+
+static void test_rename_process(void) {
+ 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 */
+}
+
int main(int argc, char *argv[]) {
+
+ log_set_max_level(LOG_DEBUG);
log_parse_environment();
log_open();
+ saved_argc = argc;
+ saved_argv = argv;
+
if (argc > 1) {
pid_t pid = 0;
@@ -373,6 +433,7 @@ int main(int argc, char *argv[]) {
test_pid_is_alive();
test_personality();
test_get_process_cmdline_harder();
+ test_rename_process();
return 0;
}