summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 10:23:34 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 10:23:34 +0000
commit35962ed6b09ac995d663aeb7ab0287743cecc24c (patch)
tree24a36570c53b15b3bd6e955054f8c4846db0e262 /src/test
parentAdding debian version 252.22-1~deb12u1. (diff)
downloadsystemd-35962ed6b09ac995d663aeb7ab0287743cecc24c.tar.xz
systemd-35962ed6b09ac995d663aeb7ab0287743cecc24c.zip
Merging upstream version 252.23.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test-calendarspec.c9
-rw-r--r--src/test/test-date.c3
-rw-r--r--src/test/test-execute.c2
-rw-r--r--src/test/test-fs-util.c38
-rw-r--r--src/test/test-namespace.c2
-rw-r--r--src/test/test-nss-hosts.c6
-rw-r--r--src/test/test-seccomp.c28
-rw-r--r--src/test/test-time-util.c3
8 files changed, 87 insertions, 4 deletions
diff --git a/src/test/test-calendarspec.c b/src/test/test-calendarspec.c
index 564983b..4699991 100644
--- a/src/test/test-calendarspec.c
+++ b/src/test/test-calendarspec.c
@@ -260,4 +260,11 @@ TEST(calendar_spec_from_string) {
assert_se(calendar_spec_from_string("*:4,30:*\n", &c) == -EINVAL);
}
-DEFINE_TEST_MAIN(LOG_INFO);
+static int intro(void) {
+ /* Tests have hard-coded results that do not expect a specific timezone to be set by the caller */
+ assert_se(unsetenv("TZ") >= 0);
+
+ return EXIT_SUCCESS;
+}
+
+DEFINE_TEST_MAIN_WITH_INTRO(LOG_INFO, intro);
diff --git a/src/test/test-date.c b/src/test/test-date.c
index 930f1bd..5f9d387 100644
--- a/src/test/test-date.c
+++ b/src/test/test-date.c
@@ -62,6 +62,9 @@ static void test_one_noutc(const char *p) {
}
int main(int argc, char *argv[]) {
+ /* Tests have hard-coded results that do not expect a specific timezone to be set by the caller */
+ assert_se(unsetenv("TZ") >= 0);
+
test_setup_logging(LOG_DEBUG);
test_one("17:41");
diff --git a/src/test/test-execute.c b/src/test/test-execute.c
index 9538fd3..88bbca5 100644
--- a/src/test/test-execute.c
+++ b/src/test/test-execute.c
@@ -391,7 +391,7 @@ static void test_exec_personality(Manager *m) {
#elif defined(__i386__)
test(m, "exec-personality-x86.service", 0, CLD_EXITED);
-#elif defined(__loongarch64)
+#elif defined(__loongarch_lp64)
test(m, "exec-personality-loongarch64.service", 0, CLD_EXITED);
#else
log_notice("Unknown personality, skipping %s", __func__);
diff --git a/src/test/test-fs-util.c b/src/test/test-fs-util.c
index 67feb68..35b93b6 100644
--- a/src/test/test-fs-util.c
+++ b/src/test/test-fs-util.c
@@ -1068,4 +1068,42 @@ static int intro(void) {
return EXIT_SUCCESS;
}
+TEST(readlinkat_malloc) {
+ _cleanup_(rm_rf_physical_and_freep) char *t = NULL;
+ _cleanup_close_ int tfd = -EBADF, fd = -EBADF;
+ _cleanup_free_ char *p = NULL, *q = NULL;
+ const char *expect = "hgoehogefoobar", *a;
+
+ a = strjoina(arg_test_dir ?: "/tmp", "/readlinkat-malloc.XXXXXX");
+ assert_se(mkdtemp_malloc(a, &t) >= 0);
+
+ tfd = open(t, O_PATH|O_DIRECTORY|O_CLOEXEC);
+ assert_se(tfd >= 0);
+
+ assert_se(symlinkat(expect, tfd, "linkname") >= 0);
+
+ assert_se(readlinkat_malloc(tfd, "linkname", &p) >= 0);
+ assert_se(streq(p, expect));
+ p = mfree(p);
+
+ fd = openat(tfd, "linkname", O_PATH | O_NOFOLLOW | O_CLOEXEC);
+ assert_se(fd >= 0);
+ assert_se(readlinkat_malloc(fd, NULL, &p) >= 0);
+ assert_se(streq(p, expect));
+ p = mfree(p);
+ assert_se(readlinkat_malloc(fd, "", &p) >= 0);
+ assert_se(streq(p, expect));
+ p = mfree(p);
+ fd = safe_close(fd);
+
+ assert_se(q = path_join(t, "linkname"));
+ assert_se(readlinkat_malloc(AT_FDCWD, q, &p) >= 0);
+ assert_se(streq(p, expect));
+ p = mfree(p);
+ assert_se(readlinkat_malloc(INT_MAX, q, &p) >= 0);
+ assert_se(streq(p, expect));
+ p = mfree(p);
+ q = mfree(q);
+}
+
DEFINE_TEST_MAIN_WITH_INTRO(LOG_INFO, intro);
diff --git a/src/test/test-namespace.c b/src/test/test-namespace.c
index 37acc78..7084e70 100644
--- a/src/test/test-namespace.c
+++ b/src/test/test-namespace.c
@@ -94,7 +94,7 @@ static void test_shareable_ns(unsigned long nsflag) {
return;
}
- assert_se(socketpair(AF_UNIX, SOCK_DGRAM, 0, s) >= 0);
+ assert_se(socketpair(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0, s) >= 0);
pid1 = fork();
assert_se(pid1 >= 0);
diff --git a/src/test/test-nss-hosts.c b/src/test/test-nss-hosts.c
index 7758f0a..72a9c64 100644
--- a/src/test/test-nss-hosts.c
+++ b/src/test/test-nss-hosts.c
@@ -451,7 +451,11 @@ static int parse_argv(int argc, char **argv,
} else {
_cleanup_free_ char *hostname = NULL;
assert_se(hostname = gethostname_malloc());
- assert_se(names = strv_new("localhost", "_gateway", "_outbound", "foo_no_such_host", hostname));
+ assert_se(names = strv_new("localhost",
+ "_gateway",
+ "_outbound",
+ hostname,
+ slow_tests_enabled() ? "foo_no_such_host" : NULL));
n = make_addresses(&addrs);
assert_se(n >= 0);
diff --git a/src/test/test-seccomp.c b/src/test/test-seccomp.c
index 4c704ba..874f08b 100644
--- a/src/test/test-seccomp.c
+++ b/src/test/test-seccomp.c
@@ -21,6 +21,7 @@
#include "macro.h"
#include "memory-util.h"
#include "missing_sched.h"
+#include "missing_syscall_def.h"
#include "nsflags.h"
#include "nulstr-util.h"
#include "process-util.h"
@@ -1003,6 +1004,23 @@ static int real_open(const char *path, int flags, mode_t mode) {
#endif
}
+static int try_fchmodat2(int dirfd, const char *path, int flags, mode_t mode) {
+ /* glibc does not provide a direct wrapper for fchmodat2(). Let's hence define our own wrapper for
+ * testing purposes that calls the real syscall, on architectures and in environments where
+ * SYS_fchmodat2 is defined. Otherwise, let's just fall back to the glibc fchmodat() call. */
+
+#if defined __NR_fchmodat2 && __NR_fchmodat2 >= 0
+ int r;
+ r = (int) syscall(__NR_fchmodat2, dirfd, path, flags, mode);
+ /* The syscall might still be unsupported by kernel or libseccomp. */
+ if (r < 0 && errno == ENOSYS)
+ return fchmodat(dirfd, path, flags, mode);
+ return r;
+#else
+ return fchmodat(dirfd, path, flags, mode);
+#endif
+}
+
TEST(restrict_suid_sgid) {
pid_t pid;
@@ -1044,6 +1062,11 @@ TEST(restrict_suid_sgid) {
assert_se(fchmodat(AT_FDCWD, path, 0755 | S_ISGID | S_ISUID, 0) >= 0);
assert_se(fchmodat(AT_FDCWD, path, 0755, 0) >= 0);
+ assert_se(try_fchmodat2(AT_FDCWD, path, 0755 | S_ISUID, 0) >= 0);
+ assert_se(try_fchmodat2(AT_FDCWD, path, 0755 | S_ISGID, 0) >= 0);
+ assert_se(try_fchmodat2(AT_FDCWD, path, 0755 | S_ISGID | S_ISUID, 0) >= 0);
+ assert_se(try_fchmodat2(AT_FDCWD, path, 0755, 0) >= 0);
+
k = real_open(z, O_CREAT|O_RDWR|O_CLOEXEC|O_EXCL, 0644 | S_ISUID);
k = safe_close(k);
assert_se(unlink(z) >= 0);
@@ -1145,6 +1168,11 @@ TEST(restrict_suid_sgid) {
assert_se(fchmodat(AT_FDCWD, path, 0755 | S_ISGID | S_ISUID, 0) < 0 && errno == EPERM);
assert_se(fchmodat(AT_FDCWD, path, 0755, 0) >= 0);
+ assert_se(try_fchmodat2(AT_FDCWD, path, 0755 | S_ISUID, 0) < 0 && errno == EPERM);
+ assert_se(try_fchmodat2(AT_FDCWD, path, 0755 | S_ISGID, 0) < 0 && errno == EPERM);
+ assert_se(try_fchmodat2(AT_FDCWD, path, 0755 | S_ISGID | S_ISUID, 0) < 0 && errno == EPERM);
+ assert_se(try_fchmodat2(AT_FDCWD, path, 0755, 0) >= 0);
+
assert_se(real_open(z, O_CREAT|O_RDWR|O_CLOEXEC|O_EXCL, 0644 | S_ISUID) < 0 && errno == EPERM);
assert_se(real_open(z, O_CREAT|O_RDWR|O_CLOEXEC|O_EXCL, 0644 | S_ISGID) < 0 && errno == EPERM);
assert_se(real_open(z, O_CREAT|O_RDWR|O_CLOEXEC|O_EXCL, 0644 | S_ISUID | S_ISGID) < 0 && errno == EPERM);
diff --git a/src/test/test-time-util.c b/src/test/test-time-util.c
index 5b4bf3a..2738e8a 100644
--- a/src/test/test-time-util.c
+++ b/src/test/test-time-util.c
@@ -616,6 +616,9 @@ TEST(map_clock_usec) {
}
static int intro(void) {
+ /* Tests have hard-coded results that do not expect a specific timezone to be set by the caller */
+ assert_se(unsetenv("TZ") >= 0);
+
log_info("realtime=" USEC_FMT "\n"
"monotonic=" USEC_FMT "\n"
"boottime=" USEC_FMT "\n",