]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
drd/tests/concurrent_close: Add
authorBart Van Assche <bvanassche@acm.org>
Sat, 24 Aug 2013 17:50:38 +0000 (17:50 +0000)
committerBart Van Assche <bvanassche@acm.org>
Sat, 24 Aug 2013 17:50:38 +0000 (17:50 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13508

drd/tests/Makefile.am
drd/tests/concurrent_close.cpp [new file with mode: 0644]
drd/tests/concurrent_close.stderr.exp [new file with mode: 0644]
drd/tests/concurrent_close.vgtest [new file with mode: 0644]

index 62276cafe4a34b25f5755c967f5fc7e20e06a34b..2067c0d001a796c581c76a4e9a9d09f00e163a4d 100644 (file)
@@ -84,6 +84,8 @@ EXTRA_DIST =                                        \
        bug-235681.vgtest                           \
        circular_buffer.stderr.exp                  \
        circular_buffer.vgtest                      \
+       concurrent_close.stderr.exp                 \
+       concurrent_close.vgtest                     \
        custom_alloc.stderr.exp                     \
        custom_alloc.vgtest                         \
        custom_alloc_fiw.stderr.exp                 \
@@ -311,6 +313,7 @@ check_PROGRAMS =      \
   annotate_trace_memory \
   bug-235681          \
   custom_alloc        \
+  concurrent_close    \
   fp_race             \
   free_is_write              \
   hold_lock           \
@@ -395,6 +398,7 @@ AM_CXXFLAGS += $(AM_FLAG_M3264_PRI) @FLAG_W_EXTRA@ -Wno-inline -Wno-unused-param
 LDADD = -lpthread
 
 
+concurrent_close_SOURCES    = concurrent_close.cpp
 monitor_example_SOURCES     = monitor_example.cpp
 new_delete_SOURCES          = new_delete.cpp
 
diff --git a/drd/tests/concurrent_close.cpp b/drd/tests/concurrent_close.cpp
new file mode 100644 (file)
index 0000000..9f7e6d6
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Reproducer for bug #323905. See also
+ * http://bugs.kde.org/show_bug.cgi?id=323905.
+ */
+
+#include <climits>    /* PTHREAD_STACK_MIN */
+#include <cstdio>     /* fprintf() */
+#include <fcntl.h>    /* O_RDONLY */
+#include <pthread.h>
+#include <unistd.h>   /* close() */
+
+/* Happens with two threads also */
+#define THREAD_COUNT 256
+
+void* thread(void*)
+{
+  int fd;
+
+  /* Happens with any file, not just /dev/null */
+  fd = open("/dev/null", O_RDONLY);
+  if (fd >= 0)
+    close(fd);
+  else
+    fprintf(stderr, "Failed to open /dev/null\n");
+  return 0;
+}
+
+int main()
+{
+  int i, r;
+  pthread_attr_t attr;
+  pthread_t threads[THREAD_COUNT];
+
+  pthread_attr_init(&attr);
+  pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN);
+  for (i = 0; i < THREAD_COUNT; ++i) {
+    r = pthread_create(&threads[i], &attr, thread, 0);
+    if (r != 0) {
+      fprintf(stderr, "Failed to create thread %d\n", i);
+      return 1;
+    }
+  }
+  pthread_attr_destroy(&attr);
+  for (i = 0; i < THREAD_COUNT; ++i) {
+    r = pthread_join(threads[i], 0);
+    if (r != 0) {
+      fprintf(stderr, "Failed to join thread %d\n", i);
+      return 1;
+    }
+  }
+  fprintf(stderr, "Done.\n");
+  return 0;
+}
diff --git a/drd/tests/concurrent_close.stderr.exp b/drd/tests/concurrent_close.stderr.exp
new file mode 100644 (file)
index 0000000..d16127f
--- /dev/null
@@ -0,0 +1,4 @@
+
+Done.
+
+ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
diff --git a/drd/tests/concurrent_close.vgtest b/drd/tests/concurrent_close.vgtest
new file mode 100644 (file)
index 0000000..19c339b
--- /dev/null
@@ -0,0 +1,4 @@
+prereq: ./supported_libpthread
+vgopts: --read-var-info=yes --check-stack-var=yes --show-confl-seg=no --num-callers=3
+prog: concurrent_close
+stderr_filter: filter_stderr