From: Sage Weil Date: Thu, 4 Jul 2013 04:53:48 +0000 (-0700) Subject: qa: add O_TRUNC test X-Git-Tag: v0.67-rc1~151 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=22227cd1c1bec01de4c5a3cfd46a52ce596e345a;p=ceph.git qa: add O_TRUNC test From: Yan, Zheng Simple reproducer for #5453, modified to run for a finite number of iterations. Signed-off-by: Sage Weil --- diff --git a/qa/Makefile b/qa/Makefile index ad655b7e743..c4efe2c9f3a 100644 --- a/qa/Makefile +++ b/qa/Makefile @@ -1,4 +1,4 @@ -DIRS= workunits btrfs +DIRS= workunits btrfs fs all: for d in $(DIRS) ; do ( cd $$d ; $(MAKE) all ) ; done diff --git a/qa/fs/Makefile b/qa/fs/Makefile new file mode 100644 index 00000000000..c9934254d35 --- /dev/null +++ b/qa/fs/Makefile @@ -0,0 +1,11 @@ +CFLAGS = -Wall -Wextra -D_GNU_SOURCE + +TARGETS = test_o_trunc + +.c: + $(CC) $(CFLAGS) $@.c -o $@ + +all: $(TARGETS) + +clean: + rm $(TARGETS) diff --git a/qa/fs/test_o_trunc.c b/qa/fs/test_o_trunc.c new file mode 100644 index 00000000000..02105288217 --- /dev/null +++ b/qa/fs/test_o_trunc.c @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + int fd, ret; + char obuf[32], ibuf[1024]; + int n, max = 0; + + if (argc > 2) + max = atoi(argv[2]); + if (!max) + max = 600; + + memset(obuf, 0xff, sizeof(obuf)); + + for (n = 1; n <= max; ++n) { + fd = open(argv[1], O_RDWR | O_CREAT | O_TRUNC, 0644); + printf("%d/%d: open fd = %d\n", n, max, fd); + + ret = write(fd, obuf, sizeof(obuf)); + printf("write ret = %d\n", ret); + + sleep(1); + + ret = write(fd, obuf, sizeof(obuf)); + printf("write ret = %d\n", ret); + + ret = pread(fd, ibuf, sizeof(ibuf), 0); + printf("pread ret = %d\n", ret); + + if (memcmp(obuf, ibuf, sizeof(obuf))) { + printf("mismatch\n"); + break; + } + close(fd); + } + return 0; +} diff --git a/qa/workunits/misc/test_o_trunc.sh b/qa/workunits/misc/test_o_trunc.sh new file mode 100755 index 00000000000..dda24d8d422 --- /dev/null +++ b/qa/workunits/misc/test_o_trunc.sh @@ -0,0 +1,6 @@ +#!/bin/sh -ex + +../../fs/test_o_trunc trunc.foo 600 + +echo OK +