]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Added --free-is-write stress test.
authorBart Van Assche <bvanassche@acm.org>
Sat, 12 Mar 2011 14:02:06 +0000 (14:02 +0000)
committerBart Van Assche <bvanassche@acm.org>
Sat, 12 Mar 2011 14:02:06 +0000 (14:02 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11634

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

index b936334ae12b7f9b1229364f9c30b3442c2212e4..665a428b5abecd0a74a02506731f69f3d2a0531d 100644 (file)
@@ -72,6 +72,8 @@ EXTRA_DIST =                                        \
        fp_race.vgtest                              \
        fp_race2.stderr.exp                         \
        fp_race2.vgtest                             \
+       free_is_write.vgtest                        \
+       free_is_write.stderr.exp                    \
        hg01_all_ok.stderr.exp                      \
        hg01_all_ok.vgtest                          \
        hg02_deadlock.stderr.exp                    \
@@ -276,6 +278,7 @@ check_PROGRAMS =      \
   bug-235681          \
   custom_alloc        \
   fp_race             \
+  free_is_write              \
   hold_lock           \
   linuxthreads_det    \
   memory_allocation   \
diff --git a/drd/tests/free_is_write.c b/drd/tests/free_is_write.c
new file mode 100644 (file)
index 0000000..899a853
--- /dev/null
@@ -0,0 +1,70 @@
+/* Stress test for the --free-is-write command-line option. */
+
+#include <pthread.h>
+#include <assert.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <pthread.h>
+#include <string.h>
+
+#define MALLOC_SIZE 22816
+#define THREAD_COUNT 10
+#define MALLOC_COUNT 1000
+
+static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
+// 'mutex' protects 'count'.
+static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+static unsigned count;
+
+void* thread_func(void* arg)
+{
+  unsigned i;
+
+  for (i = 0; i < MALLOC_COUNT; ++i) {
+    void* ptr;
+
+    ptr = malloc(MALLOC_SIZE);
+    memset(ptr, 0, MALLOC_SIZE);
+    free(ptr);
+  }
+
+  pthread_mutex_lock(&mutex);
+  ++count;
+  pthread_cond_signal(&cond);
+  pthread_mutex_unlock(&mutex);
+
+  return 0;
+}
+
+int main(int argc, char **argv)
+{
+  pthread_t thread[THREAD_COUNT];
+  int result;
+  int i;
+
+  for (i = 0; i < THREAD_COUNT; i++) {
+    result = pthread_create(&thread[i], 0, thread_func, 0);
+    assert(result == 0);
+  }
+
+  pthread_mutex_lock(&mutex);
+  while (count < THREAD_COUNT && pthread_cond_wait(&cond, &mutex) == 0)
+    ;
+  pthread_mutex_unlock(&mutex);
+
+  for (i = 0; i < THREAD_COUNT; i++)
+    pthread_join(thread[i], 0);
+
+  fflush(stdout);
+
+  fprintf(stderr, "Done.\n");
+
+  return 0;
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 2
+ * End:
+ */
diff --git a/drd/tests/free_is_write.stderr.exp b/drd/tests/free_is_write.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/free_is_write.vgtest b/drd/tests/free_is_write.vgtest
new file mode 100644 (file)
index 0000000..9151098
--- /dev/null
@@ -0,0 +1,4 @@
+prereq: test -e free_is_write && ./supported_libpthread
+vgopts: --read-var-info=yes --free-is-write=yes --show-confl-seg=no
+prog: free_is_write
+args: -q