summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2017-10-04 15:17:09 +0200
committerSven Eden <yamakuzure@gmx.net>2017-10-04 15:17:09 +0200
commit4e4ce38d455ec4688ead79a7f43907df13a076b0 (patch)
tree270de3cff8c46276dc1fbe44f978de7b467fb6a1
parentc29f90a2b3e0ab88e527db3db2e8818c1b6dabc8 (diff)
test-copy: fix operation when test-copy is too small
Fixes #6981.
-rw-r--r--src/test/test-copy.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/test/test-copy.c b/src/test/test-copy.c
index 0b9195113..fc5a8c169 100644
--- a/src/test/test-copy.c
+++ b/src/test/test-copy.c
@@ -222,6 +222,14 @@ static void test_copy_bytes_regular_file(const char *src, bool try_reflink, uint
else
assert_se(IN_SET(r, 0, 1));
+ assert_se(fstat(fd, &buf) == 0);
+ assert_se(fstat(fd2, &buf2) == 0);
+ assert_se((uint64_t) buf2.st_size == MIN((uint64_t) buf.st_size, max_bytes));
+
+ if (max_bytes < (uint64_t) -1)
+ /* Make sure the file is now higher than max_bytes */
+ assert_se(ftruncate(fd2, max_bytes + 1) == 0);
+
assert_se(lseek(fd2, 0, SEEK_SET) == 0);
r = copy_bytes(fd2, fd3, max_bytes, try_reflink ? COPY_REFLINK : 0);
@@ -235,12 +243,12 @@ static void test_copy_bytes_regular_file(const char *src, bool try_reflink, uint
* are copying is exactly max_bytes bytes. */
assert_se(r == 1);
- assert_se(fstat(fd, &buf) == 0);
- assert_se(fstat(fd2, &buf2) == 0);
assert_se(fstat(fd3, &buf3) == 0);
- assert_se((uint64_t) buf2.st_size == MIN((uint64_t) buf.st_size, max_bytes));
- assert_se(buf3.st_size == buf2.st_size);
+ if (max_bytes == (uint64_t) -1)
+ assert_se(buf3.st_size == buf2.st_size);
+ else
+ assert_se((uint64_t) buf3.st_size == max_bytes);
unlink(fn2);
unlink(fn3);