From d851deeac18af31ccb0a4aa5aff1a998c6837637 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 9 Jun 2011 21:53:28 -0700 Subject: [PATCH] qa: add short directio read test This tests for the bug fixed by linux commit:c3cd628. Signed-off-by: Sage Weil --- qa/src/Makefile.am | 3 ++- qa/src/test_short_dio_read.c | 29 +++++++++++++++++++++++++++++ qa/workunits/direct_io.sh | 2 ++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 qa/src/test_short_dio_read.c diff --git a/qa/src/Makefile.am b/qa/src/Makefile.am index 6f74c0c297927..56e7a3d7d20bf 100644 --- a/qa/src/Makefile.am +++ b/qa/src/Makefile.am @@ -5,7 +5,8 @@ bin_PROGRAMS = direct_io_test_SOURCES = direct_io_test.c test_sync_io_SOURCES = test_sync_io.c +test_short_dio_read_SOURCES = test_short_dio_read.c if WITH_DEBUG -bin_PROGRAMS += direct_io_test test_sync_io +bin_PROGRAMS += direct_io_test test_sync_io test_short_dio_read endif diff --git a/qa/src/test_short_dio_read.c b/qa/src/test_short_dio_read.c new file mode 100644 index 0000000000000..d63f9f51ea66f --- /dev/null +++ b/qa/src/test_short_dio_read.c @@ -0,0 +1,29 @@ +#define _GNU_SOURCE +#include +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + char buf[409600]; + int fd = open(argv[1], O_WRONLY|O_CREAT); + ssize_t r; + + printf("writing first 3 bytes of 10k file\n"); + write(fd, "foo", 3); + ftruncate(fd, 10000); + fsync(fd); + close(fd); + + printf("reading O_DIRECT\n"); + fd = open(argv[1], O_RDONLY|O_DIRECT); + r = read(fd, buf, sizeof(buf)); + close(fd); + + printf("got %d\n", r); + if (r != 10000) + return 1; + return 0; +} diff --git a/qa/workunits/direct_io.sh b/qa/workunits/direct_io.sh index e333344274c77..7d2acc7f3d7bb 100755 --- a/qa/workunits/direct_io.sh +++ b/qa/workunits/direct_io.sh @@ -2,6 +2,8 @@ direct_io_test +test_short_dio_read + # a few test cases from henry echo "test read from hole" dd if=/dev/zero of=dd3 bs=1 seek=1048576 count=0 -- 2.39.5