From: Bart Van Assche Date: Sun, 7 Mar 2010 10:46:43 +0000 (+0000) Subject: Added a test program that triggers several happens-before usage errors. X-Git-Tag: svn/VALGRIND_3_6_0~355 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b1d6b660cb82d4c5f77687e21d8d6269edf05f6f;p=thirdparty%2Fvalgrind.git Added a test program that triggers several happens-before usage errors. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11069 --- diff --git a/drd/tests/annotate_hb_err.c b/drd/tests/annotate_hb_err.c new file mode 100644 index 0000000000..97da9c0d14 --- /dev/null +++ b/drd/tests/annotate_hb_err.c @@ -0,0 +1,53 @@ +/* Test program that triggers several happens-before usage errors. */ + + +#include +#include +#include +#include "unified_annotations.h" + + +int main(int argc, char** argv) +{ + pthread_mutex_t m; + pthread_cond_t cv; + int i[64]; + + pthread_mutex_init(&m, NULL); + pthread_cond_init(&cv, NULL); + + /* happens-after without preceding happens-before. */ + ANNOTATE_HAPPENS_AFTER(&i); + + /* happens-after on a mutex. */ + ANNOTATE_HAPPENS_BEFORE(&m); + + /* happens-after on a condition variable. */ + ANNOTATE_HAPPENS_BEFORE(&cv); + + /* condition variable operation on a h.b. annotated object. */ + ANNOTATE_HAPPENS_BEFORE(&i); + pthread_cond_init((pthread_cond_t*)&i, NULL); + + /* The sequence below is fine. */ + ANNOTATE_HAPPENS_DONE(&i); + ANNOTATE_HAPPENS_BEFORE(&i); + ANNOTATE_HAPPENS_AFTER(&i); + ANNOTATE_HAPPENS_DONE(&i); + ANNOTATE_HAPPENS_BEFORE(&i); + ANNOTATE_HAPPENS_DONE(&i); + + /* happens-before after happens-after without intervening happens-done. */ + ANNOTATE_HAPPENS_BEFORE(&i); + ANNOTATE_HAPPENS_AFTER(&i); + ANNOTATE_HAPPENS_BEFORE(&i); + + fprintf(stderr, "Done.\n"); + return 0; +} + +/* + * Local variables: + * c-basic-offset: 2 + * End: + */ diff --git a/drd/tests/annotate_hb_err.stderr.exp b/drd/tests/annotate_hb_err.stderr.exp new file mode 100644 index 0000000000..bf96a09b77 --- /dev/null +++ b/drd/tests/annotate_hb_err.stderr.exp @@ -0,0 +1,36 @@ + +missing happens-before annotation + at 0x........: vgDrdCl_annotate_happens_after (drd.h:?) + by 0x........: main (annotate_hb_err.c:?) + +wrong type of synchronization object + at 0x........: vgDrdCl_annotate_happens_before (drd.h:?) + by 0x........: main (annotate_hb_err.c:?) +mutex 0x........ was first observed at: + at 0x........: pthread_mutex_init (drd_pthread_intercepts.c:?) + by 0x........: main (annotate_hb_err.c:?) + +wrong type of synchronization object + at 0x........: vgDrdCl_annotate_happens_before (drd.h:?) + by 0x........: main (annotate_hb_err.c:?) +cond 0x........ was first observed at: + at 0x........: pthread_cond_init (drd_pthread_intercepts.c:?) + by 0x........: main (annotate_hb_err.c:?) + +wrong type of synchronization object + at 0x........: pthread_cond_init (drd_pthread_intercepts.c:?) + by 0x........: main (annotate_hb_err.c:?) +order annotation 0x........ was first observed at: + at 0x........: vgDrdCl_annotate_happens_before (drd.h:?) + by 0x........: main (annotate_hb_err.c:?) + +happens-before after happens-after + at 0x........: vgDrdCl_annotate_happens_before (drd.h:?) + by 0x........: main (annotate_hb_err.c:?) +order annotation 0x........ was first observed at: + at 0x........: vgDrdCl_annotate_happens_before (drd.h:?) + by 0x........: main (annotate_hb_err.c:?) + +Done. + +ERROR SUMMARY: 5 errors from 5 contexts (suppressed: 0 from 0) diff --git a/drd/tests/annotate_hb_err.vgtest b/drd/tests/annotate_hb_err.vgtest new file mode 100644 index 0000000000..eab970495b --- /dev/null +++ b/drd/tests/annotate_hb_err.vgtest @@ -0,0 +1,4 @@ +prereq: test -e annotate_hb_err && ./supported_libpthread +vgopts: --read-var-info=yes --check-stack-var=yes --show-confl-seg=no +prog: annotate_hb_err +stderr_filter: filter_stderr_and_thread_no