src/t_truncate_cmtime: test truncate up too

Currently src/t_truncate_cmtime only tests the truncate down case,
truncate up case should be tested too. A recent ext4 bug shows that we
missed that coverage.

See kernel commit 911af577de4e ("ext4: update c/mtime on truncate up")

Signed-off-by: Eryu Guan <eguan@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
This commit is contained in:
Eryu Guan
2015-09-21 13:06:18 +10:00
committed by Dave Chinner
parent 7dc0112d72
commit 80b486101b
+38 -5
View File
@@ -53,17 +53,18 @@ int do_test(const char *file, int is_ftrunc)
exit(EXIT_FAILURE);
}
/* Test [f]truncate(2) down */
sleep(1);
if (is_ftrunc) {
ret = ftruncate(fd, 0);
if (ret == -1) {
perror("ftruncate(2) failed");
perror("ftruncate(2) down failed");
exit(EXIT_FAILURE);
}
} else {
ret = truncate(file, 0);
if (ret == -1) {
perror("truncate(2) failed");
perror("truncate(2) down failed");
exit(EXIT_FAILURE);
}
}
@@ -75,15 +76,47 @@ int do_test(const char *file, int is_ftrunc)
exit(EXIT_FAILURE);
}
/* Check whether timestamps got updated */
/* Check whether timestamps got updated on [f]truncate(2) down */
if (statbuf1.st_ctime == statbuf2.st_ctime) {
fprintf(stderr, "ctime not updated after %s\n",
is_ftrunc ? "ftruncate" : "truncate");
is_ftrunc ? "ftruncate" : "truncate" " down");
ret++;
}
if (statbuf1.st_mtime == statbuf2.st_mtime) {
fprintf(stderr, "mtime not updated after %s\n",
is_ftrunc ? "ftruncate" : "truncate");
is_ftrunc ? "ftruncate" : "truncate" " down");
ret++;
}
/* Test [f]truncate(2) up */
sleep(1);
if (is_ftrunc) {
ret = ftruncate(fd, 123);
if (ret == -1) {
perror("ftruncate(2) up failed");
exit(EXIT_FAILURE);
}
} else {
ret = truncate(file, 123);
if (ret == -1) {
perror("truncate(2) up failed");
exit(EXIT_FAILURE);
}
}
ret = fstat(fd, &statbuf1);
if (ret == -1) {
perror("fstat(2) failed");
exit(EXIT_FAILURE);
}
/* Check whether timestamps got updated on [f]truncate(2) up */
if (statbuf1.st_ctime == statbuf2.st_ctime) {
fprintf(stderr, "ctime not updated after %s\n",
is_ftrunc ? "ftruncate" : "truncate" " up");
ret++;
}
if (statbuf1.st_mtime == statbuf2.st_mtime) {
fprintf(stderr, "mtime not updated after %s\n",
is_ftrunc ? "ftruncate" : "truncate" " up");
ret++;
}