summaryrefslogtreecommitdiffstats
path: root/src/test/test-copy.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/test-copy.c')
-rw-r--r--src/test/test-copy.c68
1 files changed, 54 insertions, 14 deletions
diff --git a/src/test/test-copy.c b/src/test/test-copy.c
index 9674e78..7b16cf2 100644
--- a/src/test/test-copy.c
+++ b/src/test/test-copy.c
@@ -45,7 +45,7 @@ TEST(copy_file) {
assert_se(copy_file(fn, fn_copy, 0, 0644, COPY_REFLINK) == 0);
assert_se(read_full_file(fn_copy, &buf, &sz) == 0);
- assert_se(streq(buf, "foo bar bar bar foo\n"));
+ ASSERT_STREQ(buf, "foo bar bar bar foo\n");
assert_se(sz == 20);
}
@@ -125,7 +125,7 @@ TEST(copy_file_fd) {
assert_se(lseek(out_fd, SEEK_SET, 0) == 0);
assert_se(read(out_fd, buf, sizeof buf) == (ssize_t) strlen(text));
- assert_se(streq(buf, text));
+ ASSERT_STREQ(buf, text);
}
TEST(copy_tree) {
@@ -202,7 +202,7 @@ TEST(copy_tree) {
assert_se(access(f, F_OK) == 0);
assert_se(read_full_file(f, &buf, &sz) == 0);
- assert_se(streq(buf, "file\n"));
+ ASSERT_STREQ(buf, "file\n");
k = lgetxattr_malloc(f, "user.testxattr", &c);
assert_se(xattr_worked < 0 || ((k >= 0) == !!xattr_worked));
@@ -211,7 +211,7 @@ TEST(copy_tree) {
_cleanup_free_ char *d = NULL;
assert_se(base64mem(*p, strlen(*p), &d) >= 0);
- assert_se(streq(d, c));
+ ASSERT_STREQ(d, c);
}
}
@@ -253,7 +253,44 @@ TEST(copy_tree) {
(void) rm_rf(original_dir, REMOVE_ROOT|REMOVE_PHYSICAL);
}
-TEST(copy_bytes) {
+TEST(copy_tree_at_symlink) {
+ _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";
+
+ tfd = mkdtemp_open(NULL, O_PATH, &t);
+ assert_se(tfd >= 0);
+
+ assert_se(symlinkat(expect, tfd, "from") >= 0);
+
+ assert_se(copy_tree_at(tfd, "from", tfd, "to_1", UID_INVALID, GID_INVALID, 0, NULL, NULL) >= 0);
+ assert_se(readlinkat_malloc(tfd, "to_1", &p) >= 0);
+ ASSERT_STREQ(p, expect);
+ p = mfree(p);
+
+ assert_se(q = path_join(t, "from"));
+ assert_se(copy_tree_at(AT_FDCWD, q, tfd, "to_2", UID_INVALID, GID_INVALID, 0, NULL, NULL) >= 0);
+ assert_se(readlinkat_malloc(tfd, "to_2", &p) >= 0);
+ ASSERT_STREQ(p, expect);
+ p = mfree(p);
+ q = mfree(q);
+
+ fd = openat(tfd, "from", O_CLOEXEC | O_PATH | O_NOFOLLOW);
+ assert_se(fd >= 0);
+ assert_se(copy_tree_at(fd, NULL, tfd, "to_3", UID_INVALID, GID_INVALID, 0, NULL, NULL) >= 0);
+ assert_se(readlinkat_malloc(tfd, "to_3", &p) >= 0);
+ ASSERT_STREQ(p, expect);
+ p = mfree(p);
+
+ assert_se(copy_tree_at(fd, "", tfd, "to_4", UID_INVALID, GID_INVALID, 0, NULL, NULL) >= 0);
+ assert_se(readlinkat_malloc(tfd, "to_4", &p) >= 0);
+ ASSERT_STREQ(p, expect);
+ p = mfree(p);
+ fd = safe_close(fd);
+}
+
+TEST_RET(copy_bytes) {
_cleanup_close_pair_ int pipefd[2] = EBADF_PAIR;
_cleanup_close_ int infd = -EBADF;
int r, r2;
@@ -262,7 +299,8 @@ TEST(copy_bytes) {
infd = open("/usr/lib/os-release", O_RDONLY|O_CLOEXEC);
if (infd < 0)
infd = open("/etc/os-release", O_RDONLY|O_CLOEXEC);
- assert_se(infd >= 0);
+ if (infd < 0)
+ return log_tests_skipped_errno(errno, "Could not open /usr/lib/os-release or /etc/os-release: %m");
assert_se(pipe2(pipefd, O_CLOEXEC) == 0);
@@ -287,6 +325,8 @@ TEST(copy_bytes) {
r = copy_bytes(pipefd[1], infd, 1, 0);
assert_se(r == -EBADF);
+
+ return 0;
}
static void test_copy_bytes_regular_file_one(const char *src, bool try_reflink, uint64_t max_bytes) {
@@ -381,7 +421,7 @@ TEST(copy_proc) {
assert_se(read_one_line_file("/proc/version", &a) >= 0);
assert_se(read_one_line_file(f, &b) >= 0);
- assert_se(streq(a, b));
+ ASSERT_STREQ(a, b);
assert_se(!isempty(a));
}
@@ -404,7 +444,7 @@ TEST_RET(copy_holes) {
return log_tests_skipped("Filesystem doesn't support hole punching");
assert_se(r >= 0);
- assert_se(fstat(fd, &stat) >= 0);
+ ASSERT_OK_ERRNO(fstat(fd, &stat));
blksz = stat.st_blksize;
buf = alloca_safe(blksz);
memset(buf, 1, blksz);
@@ -429,7 +469,7 @@ TEST_RET(copy_holes) {
assert_se(lseek(fd_copy, 2 * blksz, SEEK_DATA) < 0 && errno == ENXIO);
/* Test that the copied file has the correct size. */
- assert_se(fstat(fd_copy, &stat) >= 0);
+ ASSERT_OK_ERRNO(fstat(fd_copy, &stat));
assert_se(stat.st_size == 3 * blksz);
close(fd);
@@ -450,7 +490,7 @@ TEST_RET(copy_holes_with_gaps) {
assert_se((fd = openat(tfd, "src", O_CREAT | O_RDWR, 0600)) >= 0);
assert_se((fd_copy = openat(tfd, "dst", O_CREAT | O_WRONLY, 0600)) >= 0);
- assert_se(fstat(fd, &st) >= 0);
+ ASSERT_OK_ERRNO(fstat(fd, &st));
blksz = st.st_blksize;
buf = alloca_safe(blksz);
memset(buf, 1, blksz);
@@ -479,7 +519,7 @@ TEST_RET(copy_holes_with_gaps) {
/* Copy to the start of the second hole */
assert_se(copy_bytes(fd, fd_copy, 3 * blksz, COPY_HOLES) >= 0);
- assert_se(fstat(fd_copy, &st) >= 0);
+ ASSERT_OK_ERRNO(fstat(fd_copy, &st));
assert_se(st.st_size == 3 * blksz);
/* Copy to the middle of the second hole */
@@ -487,7 +527,7 @@ TEST_RET(copy_holes_with_gaps) {
assert_se(lseek(fd_copy, 0, SEEK_SET) >= 0);
assert_se(ftruncate(fd_copy, 0) >= 0);
assert_se(copy_bytes(fd, fd_copy, 4 * blksz, COPY_HOLES) >= 0);
- assert_se(fstat(fd_copy, &st) >= 0);
+ ASSERT_OK_ERRNO(fstat(fd_copy, &st));
assert_se(st.st_size == 4 * blksz);
/* Copy to the end of the second hole */
@@ -495,7 +535,7 @@ TEST_RET(copy_holes_with_gaps) {
assert_se(lseek(fd_copy, 0, SEEK_SET) >= 0);
assert_se(ftruncate(fd_copy, 0) >= 0);
assert_se(copy_bytes(fd, fd_copy, 5 * blksz, COPY_HOLES) >= 0);
- assert_se(fstat(fd_copy, &st) >= 0);
+ ASSERT_OK_ERRNO(fstat(fd_copy, &st));
assert_se(st.st_size == 5 * blksz);
/* Copy everything */
@@ -503,7 +543,7 @@ TEST_RET(copy_holes_with_gaps) {
assert_se(lseek(fd_copy, 0, SEEK_SET) >= 0);
assert_se(ftruncate(fd_copy, 0) >= 0);
assert_se(copy_bytes(fd, fd_copy, UINT64_MAX, COPY_HOLES) >= 0);
- assert_se(fstat(fd_copy, &st) >= 0);
+ ASSERT_OK_ERRNO(fstat(fd_copy, &st));
assert_se(st.st_size == 6 * blksz);
return 0;