]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Add the helgrind/tests/bug322621 regression test
authorBart Van Assche <bart.vanassche@wdc.com>
Sat, 17 Mar 2018 20:50:05 +0000 (13:50 -0700)
committerBart Van Assche <bart.vanassche@wdc.com>
Sun, 18 Mar 2018 04:32:56 +0000 (21:32 -0700)
.gitignore
helgrind/tests/Makefile.am
helgrind/tests/bug322621.cpp [new file with mode: 0644]
helgrind/tests/bug322621.stderr.exp [new file with mode: 0644]
helgrind/tests/bug322621.vgtest [new file with mode: 0644]

index f9776ec412ba8488cddbec0ea985334f5095aeab..4a38b11e4e35ea02c60b29a3e97aa534b86f36f9 100644 (file)
 /helgrind/tests/annotate_rwlock
 /helgrind/tests/bar_bad
 /helgrind/tests/bar_trivial
+/helgrind/tests/bug322621
 /helgrind/tests/cond_init_destroy
 /helgrind/tests/cond_timedwait_invalid
 /helgrind/tests/cond_timedwait_test
index 040790ce18f711f99cc06639f59cc99e027702a5..f86cbde55a720e3aff21aa4a96839168a733f01b 100644 (file)
@@ -13,6 +13,7 @@ EXTRA_DIST = \
                annotate_rwlock.stderr.exp \
        annotate_smart_pointer.vgtest annotate_smart_pointer.stdout.exp \
                annotate_smart_pointer.stderr.exp \
+       bug322621.vgtest bug322621.stderr.exp \
        cond_init_destroy.vgtest cond_init_destroy.stderr.exp \
        cond_timedwait_invalid.vgtest cond_timedwait_invalid.stdout.exp \
                cond_timedwait_invalid.stderr.exp \
@@ -126,6 +127,7 @@ noinst_HEADERS = safe-pthread.h safe-semaphore.h
 # should be conditionally compiled like tc20_verifywrap is.
 check_PROGRAMS = \
        annotate_hbefore \
+       bug322621 \
        cond_init_destroy \
        cond_timedwait_invalid \
        cond_timedwait_test \
@@ -201,7 +203,7 @@ tc08_hbl2_CFLAGS        = $(AM_CFLAGS)
 endif
 
 if HAVE_PTHREAD_BARRIER
-check_PROGRAMS += bar_bad bar_trivial
+check_PROGRAMS += bar_bad bar_trivial bug322621
 endif
 
 if HAVE_PTHREAD_MUTEX_TIMEDLOCK
@@ -222,3 +224,5 @@ annotate_hbefore_CFLAGS = $(AM_CFLAGS) -mdynamic-no-pic
 else
 annotate_hbefore_CFLAGS = $(AM_CFLAGS)
 endif
+
+bug322621_SOURCES = bug322621.cpp
diff --git a/helgrind/tests/bug322621.cpp b/helgrind/tests/bug322621.cpp
new file mode 100644 (file)
index 0000000..8d31ca5
--- /dev/null
@@ -0,0 +1,89 @@
+// See also https://bugs.kde.org/show_bug.cgi?id=322621
+
+#include <pthread.h>
+#include <iostream>
+#include "../helgrind.h"
+
+static int verbose;
+static pthread_t ls_thread;
+static pthread_barrier_t ls_barrier;
+
+char* ls_buf[2];
+
+#define LS_BUF_SIZE (1024*1024)
+#define NR_RUNS 2
+
+void fill_buffer(int buf)
+{
+   if (verbose)
+      std::cerr << "Fill " << buf << "\n";
+   for (int i = 0; i < LS_BUF_SIZE; i++)
+      ls_buf[buf][i] = 1;
+   if (verbose)
+      std::cerr << "Fill " << buf << " done\n";
+}
+
+int read_buffer(int buf)
+{
+   if (verbose)
+      std::cerr << "Read " << buf << "\n";
+   int res = 0;
+   for (int i = 0; i < LS_BUF_SIZE; i++)
+      res += ls_buf[buf][i];
+   if (verbose)
+      std::cerr << "Read " << buf << " done\n";
+   return res;
+}
+
+void *the_thread(void *ptr)
+{
+   int buf = 1;
+
+   for (int i = 0; i < NR_RUNS; i++) {
+
+      fill_buffer(buf);
+
+      if (verbose)
+        std::cerr << "Aux at barrier " << i << "\n";
+      pthread_barrier_wait(&ls_barrier);
+      if (verbose)
+        std::cerr << "Aux after barrier " << i << "\n";
+
+      buf = buf ^ 1;
+   }
+   return ptr;
+}
+
+
+int main()
+{
+   VALGRIND_HG_DISABLE_CHECKING(&std::cerr, sizeof(std::cerr));
+       
+   ls_buf[0] = new char[LS_BUF_SIZE];
+   ls_buf[1] = new char[LS_BUF_SIZE]; // second buffer only when multithreaded
+
+   pthread_barrier_init(&ls_barrier, NULL, 2);
+
+   pthread_attr_t attr;
+   pthread_attr_init(&attr);
+   pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
+   pthread_create(&ls_thread, &attr, the_thread, NULL);
+   pthread_attr_destroy(&attr);
+
+   int buf = 0;
+   int res = 0;
+   for (int i = 0; i < NR_RUNS; i++) {
+      std::cerr << "Main at barrier " << i << "\n";
+      pthread_barrier_wait(&ls_barrier);
+      std::cerr << "Main after barrier " << i << "\n";
+      buf = buf ^ 1;
+      res += read_buffer(buf);
+   }
+
+   pthread_join(ls_thread,NULL);
+   pthread_barrier_destroy(&ls_barrier);
+   delete[] ls_buf[1]; // second buffer only when multithreaded
+   delete[] ls_buf[0];
+
+   return 0;
+}
diff --git a/helgrind/tests/bug322621.stderr.exp b/helgrind/tests/bug322621.stderr.exp
new file mode 100644 (file)
index 0000000..e85a7b8
--- /dev/null
@@ -0,0 +1,4 @@
+Main at barrier 0
+Main after barrier 0
+Main at barrier 1
+Main after barrier 1
diff --git a/helgrind/tests/bug322621.vgtest b/helgrind/tests/bug322621.vgtest
new file mode 100644 (file)
index 0000000..e4fcd44
--- /dev/null
@@ -0,0 +1,2 @@
+vgopts: -q
+prog: bug322621