summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test-install-root.c3
-rw-r--r--src/test/test-mount-util.c32
-rw-r--r--src/test/test-process-util.c61
3 files changed, 85 insertions, 11 deletions
diff --git a/src/test/test-install-root.c b/src/test/test-install-root.c
index a98de76b43..d0bc8004f3 100644
--- a/src/test/test-install-root.c
+++ b/src/test/test-install-root.c
@@ -22,6 +22,7 @@
#include "install.h"
#include "mkdir.h"
#include "rm-rf.h"
+#include "special.h"
#include "string-util.h"
static void test_basic_mask_and_enable(const char *root) {
@@ -338,7 +339,7 @@ static void test_default(const char *root) {
assert_se(n_changes == 1);
assert_se(changes[0].type == UNIT_FILE_SYMLINK);
assert_se(streq(changes[0].source, "/usr/lib/systemd/system/test-default-real.target"));
- p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/default.target");
+ p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH "/" SPECIAL_DEFAULT_TARGET);
assert_se(streq(changes[0].path, p));
unit_file_changes_free(changes, n_changes);
changes = NULL; n_changes = 0;
diff --git a/src/test/test-mount-util.c b/src/test/test-mount-util.c
index da7f35623b..7c5929d009 100644
--- a/src/test/test-mount-util.c
+++ b/src/test/test-mount-util.c
@@ -23,23 +23,35 @@
#include "mount-util.h"
#include "string-util.h"
-static void test_mount_propagation_flags(const char *name, unsigned long f) {
- assert(mount_propagation_flags_from_string(name) == f);
+static void test_mount_propagation_flags(const char *name, int ret, unsigned long expected) {
+ long unsigned flags;
- if (f != 0)
- assert_se(streq_ptr(mount_propagation_flags_to_string(f), name));
+ assert(mount_propagation_flags_from_string(name, &flags) == ret);
+
+ if (ret >= 0) {
+ const char *c;
+
+ assert_se(flags == expected);
+
+ c = mount_propagation_flags_to_string(flags);
+ if (isempty(name))
+ assert_se(isempty(c));
+ else
+ assert_se(streq(c, name));
+ }
}
int main(int argc, char *argv[]) {
log_set_max_level(LOG_DEBUG);
- test_mount_propagation_flags("shared", MS_SHARED);
- test_mount_propagation_flags("slave", MS_SLAVE);
- test_mount_propagation_flags("private", MS_PRIVATE);
- test_mount_propagation_flags(NULL, 0);
- test_mount_propagation_flags("", 0);
- test_mount_propagation_flags("xxxx", 0);
+ test_mount_propagation_flags("shared", 0, MS_SHARED);
+ test_mount_propagation_flags("slave", 0, MS_SLAVE);
+ test_mount_propagation_flags("private", 0, MS_PRIVATE);
+ test_mount_propagation_flags(NULL, 0, 0);
+ test_mount_propagation_flags("", 0, 0);
+ test_mount_propagation_flags("xxxx", -EINVAL, 0);
+ test_mount_propagation_flags(" ", -EINVAL, 0);
return 0;
}
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;
}