diff options
author | Dmitry Vyukov <dvyukov@google.com> | 2015-06-29 13:56:31 +0000 |
---|---|---|
committer | Dmitry Vyukov <dvyukov@google.com> | 2015-06-29 13:56:31 +0000 |
commit | 33ece059235b82a1390e9e7aabb9b7a1bb7a8ff7 (patch) | |
tree | b8b631f1e3aee24f3b407db7cad0601ca07d111f /test/tsan/fd_dup_norace2.cc | |
parent | 1078594d5500eaa6b7bd82019cb2a4c8103dbb35 (diff) |
tsan: fix flaky test
See the comment for explanation.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@240943 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/tsan/fd_dup_norace2.cc')
-rw-r--r-- | test/tsan/fd_dup_norace2.cc | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/test/tsan/fd_dup_norace2.cc b/test/tsan/fd_dup_norace2.cc index 601a39901..662c686f3 100644 --- a/test/tsan/fd_dup_norace2.cc +++ b/test/tsan/fd_dup_norace2.cc @@ -3,6 +3,7 @@ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> +#include <errno.h> // dup2(oldfd, newfd) races with read(newfd). // This is not reported as race because: @@ -14,14 +15,33 @@ int fd; void *Thread(void *x) { char buf; - if (read(fd, &buf, 1) != 1) - exit(printf("read failed\n")); + int n = read(fd, &buf, 1); + if (n != 1) { + // This read can "legitimately" fail regadless of the fact that glibc claims + // that "there is no instant in the middle of calling dup2 at which new is + // closed and not yet a duplicate of old". Strace of the failing runs + // looks as follows: + // + // [pid 122196] open("/dev/urandom", O_RDONLY) = 3 + // [pid 122196] open("/dev/urandom", O_RDONLY) = 4 + // Process 122382 attached + // [pid 122382] read(3, <unfinished ...> + // [pid 122196] dup2(4, 3 <unfinished ...> + // [pid 122382] <... read resumed> 0x7fcd139960b7, 1) = -1 EBADF (Bad file descriptor) + // [pid 122196] <... dup2 resumed> ) = 3 + // read failed: n=-1 errno=9 + // + // The failing read does not interfere with what this test tests, + // so we just ignore the failure. + // + // exit(printf("read failed: n=%d errno=%d\n", n, errno)); + } return 0; } int main() { - fd = open("/dev/random", O_RDONLY); - int fd2 = open("/dev/random", O_RDONLY); + fd = open("/dev/urandom", O_RDONLY); + int fd2 = open("/dev/urandom", O_RDONLY); if (fd == -1 || fd2 == -1) exit(printf("open failed\n")); pthread_t th; |