]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Added test program for the ANNOTATE_IGNORE_WRITES_*() annotation
authorBart Van Assche <bvanassche@acm.org>
Thu, 13 Aug 2009 09:30:57 +0000 (09:30 +0000)
committerBart Van Assche <bvanassche@acm.org>
Thu, 13 Aug 2009 09:30:57 +0000 (09:30 +0000)
macro's.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@10800

drd/tests/Makefile.am
drd/tests/annotate_ignore_write.c [new file with mode: 0644]
drd/tests/annotate_ignore_write.stderr.exp [new file with mode: 0644]
drd/tests/annotate_ignore_write.vgtest [new file with mode: 0644]
drd/tests/annotate_ignore_write2.stderr.exp [new file with mode: 0644]
drd/tests/annotate_ignore_write2.vgtest [new file with mode: 0644]

index 1abd7a8f3069cb39d0aa3b993f807c23d865660e..54ff4d694c3ede2e85b906b5597e8659f749a635 100644 (file)
@@ -29,6 +29,10 @@ EXTRA_DIST =                                        \
        annotate_ignore_rw.vgtest                   \
        annotate_ignore_rw2.stderr.exp              \
        annotate_ignore_rw2.vgtest                  \
+       annotate_ignore_write.stderr.exp            \
+       annotate_ignore_write.vgtest                \
+       annotate_ignore_write2.stderr.exp           \
+       annotate_ignore_write2.vgtest               \
        annotate_trace_memory.stderr.exp            \
        annotate_trace_memory.vgtest                \
        atomic_var.stderr.exp                       \
@@ -244,6 +248,7 @@ EXTRA_DIST =                                        \
 
 check_PROGRAMS =      \
   annotate_ignore_rw  \
+  annotate_ignore_write \
   custom_alloc        \
   fp_race             \
   hold_lock           \
diff --git a/drd/tests/annotate_ignore_write.c b/drd/tests/annotate_ignore_write.c
new file mode 100644 (file)
index 0000000..16efe03
--- /dev/null
@@ -0,0 +1,63 @@
+/* Test program for the annotations that suppress write operations. */
+
+#include <assert.h>  /* assert() */
+#include <pthread.h>
+#include <stdio.h>   /* EOF */
+#include <unistd.h>  /* getopt() */
+#include "../../drd/drd.h"
+
+static int s_a;
+static int s_b;
+static int s_c;
+
+static void* thread_func(void* arg)
+{
+  /* Read s_a and modify s_b. */
+  s_b = s_a;
+  /* Modify s_c. */
+  s_c = 1;
+
+  return NULL;
+}
+
+int main(int argc, char** argv)
+{
+  int optchar;
+  int ign_rw = 1;
+  pthread_t tid;
+  
+  while ((optchar = getopt(argc, argv, "r")) != EOF)
+  {
+    switch (optchar)
+    {
+    case 'r':
+      ign_rw = 0;
+      break;
+    default:
+      assert(0);
+    }
+  }
+
+  pthread_create(&tid, 0, thread_func, 0);
+  if (ign_rw)
+    ANNOTATE_IGNORE_WRITES_BEGIN();
+  /* Read s_b and modify s_a. */
+  s_a = s_b;
+  if (ign_rw)
+    ANNOTATE_IGNORE_WRITES_END();
+
+  /*
+   * Insert a delay here in order to make sure the load of s_c happens
+   * after s_c has been modified.
+   */
+  sleep(1);
+
+  /* Read s_c and modify s_a. */
+  s_a = s_c;
+
+  pthread_join(tid, 0);
+
+  fprintf(stderr, "Finished.\n");
+
+  return 0;
+}
diff --git a/drd/tests/annotate_ignore_write.stderr.exp b/drd/tests/annotate_ignore_write.stderr.exp
new file mode 100644 (file)
index 0000000..63ade6c
--- /dev/null
@@ -0,0 +1,19 @@
+
+Conflicting load by thread 1 at 0x........ size 4
+   at 0x........: main (annotate_ignore_write.c:?)
+Location 0x........ is 0 bytes inside local var "s_b"
+declared at annotate_ignore_write.c:10, in frame #? of thread 1
+
+Conflicting load by thread 1 at 0x........ size 4
+   at 0x........: main (annotate_ignore_write.c:?)
+Location 0x........ is 0 bytes inside local var "s_c"
+declared at annotate_ignore_write.c:11, in frame #? of thread 1
+
+Conflicting store by thread 1 at 0x........ size 4
+   at 0x........: main (annotate_ignore_write.c:?)
+Location 0x........ is 0 bytes inside local var "s_a"
+declared at annotate_ignore_write.c:9, in frame #? of thread 1
+
+Finished.
+
+ERROR SUMMARY: 3 errors from 3 contexts (suppressed: 0 from 0)
diff --git a/drd/tests/annotate_ignore_write.vgtest b/drd/tests/annotate_ignore_write.vgtest
new file mode 100644 (file)
index 0000000..1cc3ef0
--- /dev/null
@@ -0,0 +1,4 @@
+prereq: ./supported_libpthread
+vgopts: --read-var-info=yes --check-stack-var=yes --show-confl-seg=no
+prog: annotate_ignore_write
+stderr_filter: filter_stderr
diff --git a/drd/tests/annotate_ignore_write2.stderr.exp b/drd/tests/annotate_ignore_write2.stderr.exp
new file mode 100644 (file)
index 0000000..e0eef71
--- /dev/null
@@ -0,0 +1,24 @@
+
+Conflicting load by thread 1 at 0x........ size 4
+   at 0x........: main (annotate_ignore_write.c:?)
+Location 0x........ is 0 bytes inside local var "s_b"
+declared at annotate_ignore_write.c:10, in frame #? of thread 1
+
+Conflicting store by thread 1 at 0x........ size 4
+   at 0x........: main (annotate_ignore_write.c:?)
+Location 0x........ is 0 bytes inside local var "s_a"
+declared at annotate_ignore_write.c:9, in frame #? of thread 1
+
+Conflicting load by thread 1 at 0x........ size 4
+   at 0x........: main (annotate_ignore_write.c:?)
+Location 0x........ is 0 bytes inside local var "s_c"
+declared at annotate_ignore_write.c:11, in frame #? of thread 1
+
+Conflicting store by thread 1 at 0x........ size 4
+   at 0x........: main (annotate_ignore_write.c:?)
+Location 0x........ is 0 bytes inside local var "s_a"
+declared at annotate_ignore_write.c:9, in frame #? of thread 1
+
+Finished.
+
+ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 0 from 0)
diff --git a/drd/tests/annotate_ignore_write2.vgtest b/drd/tests/annotate_ignore_write2.vgtest
new file mode 100644 (file)
index 0000000..b16ced7
--- /dev/null
@@ -0,0 +1,5 @@
+prereq: ./supported_libpthread
+vgopts: --read-var-info=yes --check-stack-var=yes --show-confl-seg=no
+prog: annotate_ignore_write
+args: -r
+stderr_filter: filter_stderr