From: Bart Van Assche Date: Sat, 17 Mar 2018 20:50:05 +0000 (-0700) Subject: Add the helgrind/tests/bug322621 regression test X-Git-Tag: VALGRIND_3_14_0~139 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9cf3d0193dee4cd9e193771ee7c79978debb853c;p=thirdparty%2Fvalgrind.git Add the helgrind/tests/bug322621 regression test --- diff --git a/.gitignore b/.gitignore index f9776ec412..4a38b11e4e 100644 --- a/.gitignore +++ b/.gitignore @@ -644,6 +644,7 @@ /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 diff --git a/helgrind/tests/Makefile.am b/helgrind/tests/Makefile.am index 040790ce18..f86cbde55a 100644 --- a/helgrind/tests/Makefile.am +++ b/helgrind/tests/Makefile.am @@ -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 index 0000000000..8d31ca5a62 --- /dev/null +++ b/helgrind/tests/bug322621.cpp @@ -0,0 +1,89 @@ +// See also https://bugs.kde.org/show_bug.cgi?id=322621 + +#include +#include +#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 index 0000000000..e85a7b86bc --- /dev/null +++ b/helgrind/tests/bug322621.stderr.exp @@ -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 index 0000000000..e4fcd44faa --- /dev/null +++ b/helgrind/tests/bug322621.vgtest @@ -0,0 +1,2 @@ +vgopts: -q +prog: bug322621