From 78e9bb837c258ac0ec7712b3d612cc2f407e731e Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 12 Jun 2024 05:50:42 +0200 Subject: Merging upstream version 256. Signed-off-by: Daniel Baumann --- src/test/test-fs-util.c | 74 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 52 insertions(+), 22 deletions(-) (limited to 'src/test/test-fs-util.c') diff --git a/src/test/test-fs-util.c b/src/test/test-fs-util.c index b32feff..d44e043 100644 --- a/src/test/test-fs-util.c +++ b/src/test/test-fs-util.c @@ -45,7 +45,7 @@ TEST(readlink_and_make_absolute) { log_tests_skipped_errno(errno, "symlink() not possible"); } else { assert_se(readlink_and_make_absolute(name_alias, &r1) >= 0); - assert_se(streq(r1, name)); + ASSERT_STREQ(r1, name); assert_se(unlink(name_alias) >= 0); assert_se(safe_getcwd(&pwd) >= 0); @@ -53,7 +53,7 @@ TEST(readlink_and_make_absolute) { assert_se(chdir(tempdir) >= 0); assert_se(symlink(name2, name_alias) >= 0); assert_se(readlink_and_make_absolute(name_alias, &r2) >= 0); - assert_se(streq(r2, name)); + ASSERT_STREQ(r2, name); assert_se(unlink(name_alias) >= 0); assert_se(chdir(pwd) >= 0); @@ -97,33 +97,33 @@ TEST(var_tmp) { assert_se(unsetenv("TMP") >= 0); assert_se(var_tmp_dir(&tmp_dir) >= 0); - assert_se(streq(tmp_dir, "/var/tmp")); + ASSERT_STREQ(tmp_dir, "/var/tmp"); assert_se(setenv("TMPDIR", "/tmp", true) >= 0); - assert_se(streq(getenv("TMPDIR"), "/tmp")); + ASSERT_STREQ(getenv("TMPDIR"), "/tmp"); assert_se(var_tmp_dir(&tmp_dir) >= 0); - assert_se(streq(tmp_dir, "/tmp")); + ASSERT_STREQ(tmp_dir, "/tmp"); assert_se(setenv("TMPDIR", "/88_does_not_exist_88", true) >= 0); - assert_se(streq(getenv("TMPDIR"), "/88_does_not_exist_88")); + ASSERT_STREQ(getenv("TMPDIR"), "/88_does_not_exist_88"); assert_se(var_tmp_dir(&tmp_dir) >= 0); - assert_se(streq(tmp_dir, "/var/tmp")); + ASSERT_STREQ(tmp_dir, "/var/tmp"); if (tmpdir_backup) { assert_se(setenv("TMPDIR", tmpdir_backup, true) >= 0); - assert_se(streq(getenv("TMPDIR"), tmpdir_backup)); + ASSERT_STREQ(getenv("TMPDIR"), tmpdir_backup); } if (temp_backup) { assert_se(setenv("TEMP", temp_backup, true) >= 0); - assert_se(streq(getenv("TEMP"), temp_backup)); + ASSERT_STREQ(getenv("TEMP"), temp_backup); } if (tmp_backup) { assert_se(setenv("TMP", tmp_backup, true) >= 0); - assert_se(streq(getenv("TMP"), tmp_backup)); + ASSERT_STREQ(getenv("TMP"), tmp_backup); } } @@ -275,14 +275,14 @@ TEST(unlinkat_deallocate) { assert_se(write(fd, "hallo\n", 6) == 6); - assert_se(fstat(fd, &st) >= 0); + ASSERT_OK_ERRNO(fstat(fd, &st)); assert_se(st.st_size == 6); assert_se(st.st_blocks > 0); assert_se(st.st_nlink == 1); assert_se(unlinkat_deallocate(AT_FDCWD, p, UNLINK_ERASE) >= 0); - assert_se(fstat(fd, &st) >= 0); + ASSERT_OK_ERRNO(fstat(fd, &st)); assert_se(IN_SET(st.st_size, 0, 6)); /* depending on whether hole punching worked the size will be 6 (it worked) or 0 (we had to resort to truncation) */ assert_se(st.st_blocks == 0); @@ -522,9 +522,9 @@ static void test_parse_cifs_service_one(const char *f, const char *h, const char _cleanup_free_ char *a = NULL, *b = NULL, *c = NULL; assert_se(parse_cifs_service(f, &a, &b, &c) == ret); - assert_se(streq_ptr(a, h)); - assert_se(streq_ptr(b, s)); - assert_se(streq_ptr(c, d)); + ASSERT_STREQ(a, h); + ASSERT_STREQ(b, s); + ASSERT_STREQ(c, d); } TEST(parse_cifs_service) { @@ -557,13 +557,13 @@ TEST(open_mkdir_at) { fd = open_mkdir_at(AT_FDCWD, "/", O_CLOEXEC, 0); assert_se(fd >= 0); assert_se(stat("/", &sta) >= 0); - assert_se(fstat(fd, &stb) >= 0); + ASSERT_OK_ERRNO(fstat(fd, &stb)); assert_se(stat_inode_same(&sta, &stb)); fd = safe_close(fd); fd = open_mkdir_at(AT_FDCWD, ".", O_CLOEXEC, 0); assert_se(stat(".", &sta) >= 0); - assert_se(fstat(fd, &stb) >= 0); + ASSERT_OK_ERRNO(fstat(fd, &stb)); assert_se(stat_inode_same(&sta, &stb)); fd = safe_close(fd); @@ -753,6 +753,36 @@ TEST(xopenat_lock_full) { assert_se(xopenat_lock_full(tfd, "def", O_DIRECTORY, 0, 0755, LOCK_POSIX, LOCK_EX) == -EBADF); } +TEST(linkat_replace) { + _cleanup_(rm_rf_physical_and_freep) char *t = NULL; + _cleanup_close_ int tfd = -EBADF; + + assert_se((tfd = mkdtemp_open(NULL, 0, &t)) >= 0); + + _cleanup_close_ int fd1 = openat(tfd, "foo", O_CREAT|O_RDWR|O_CLOEXEC, 0600); + assert_se(fd1 >= 0); + + assert_se(linkat_replace(tfd, "foo", tfd, "bar") >= 0); + assert_se(linkat_replace(tfd, "foo", tfd, "bar") >= 0); + + _cleanup_close_ int fd1_check = openat(tfd, "bar", O_RDWR|O_CLOEXEC); + assert_se(fd1_check >= 0); + + assert_se(inode_same_at(fd1, NULL, fd1_check, NULL, AT_EMPTY_PATH) > 0); + + _cleanup_close_ int fd2 = openat(tfd, "baz", O_CREAT|O_RDWR|O_CLOEXEC, 0600); + assert_se(fd2 >= 0); + + assert_se(inode_same_at(fd1, NULL, fd2, NULL, AT_EMPTY_PATH) == 0); + + assert_se(linkat_replace(tfd, "foo", tfd, "baz") >= 0); + + _cleanup_close_ int fd2_check = openat(tfd, "baz", O_RDWR|O_CLOEXEC); + + assert_se(inode_same_at(fd2, NULL, fd2_check, NULL, AT_EMPTY_PATH) == 0); + assert_se(inode_same_at(fd1, NULL, fd2_check, NULL, AT_EMPTY_PATH) > 0); +} + static int intro(void) { arg_test_dir = saved_argv[1]; return EXIT_SUCCESS; @@ -770,25 +800,25 @@ TEST(readlinkat_malloc) { assert_se(symlinkat(expect, tfd, "linkname") >= 0); assert_se(readlinkat_malloc(tfd, "linkname", &p) >= 0); - assert_se(streq(p, expect)); + ASSERT_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)); + ASSERT_STREQ(p, expect); p = mfree(p); assert_se(readlinkat_malloc(fd, "", &p) >= 0); - assert_se(streq(p, expect)); + ASSERT_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)); + ASSERT_STREQ(p, expect); p = mfree(p); assert_se(readlinkat_malloc(INT_MAX, q, &p) >= 0); - assert_se(streq(p, expect)); + ASSERT_STREQ(p, expect); p = mfree(p); q = mfree(q); } -- cgit v1.2.3