]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Added yet another regression test.
authorBart Van Assche <bvanassche@acm.org>
Thu, 29 Apr 2010 06:06:29 +0000 (06:06 +0000)
committerBart Van Assche <bvanassche@acm.org>
Thu, 29 Apr 2010 06:06:29 +0000 (06:06 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11108

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

index fff5d03974a899255e890ba2817d6c5a40e70af0..08d24aa7fe019aa8d5c139fbcbfa96ca1014c1d4 100644 (file)
@@ -61,6 +61,8 @@ EXTRA_DIST =                                        \
        bar_trivial.vgtest                          \
        boost_thread.stderr.exp                     \
        boost_thread.vgtest                         \
+       bug-235681.stderr.exp                       \
+       bug-235681.vgtest                           \
        circular_buffer.stderr.exp                  \
        circular_buffer.vgtest                      \
        custom_alloc.stderr.exp                     \
@@ -260,6 +262,7 @@ check_PROGRAMS =      \
   annotate_ignore_write \
   annotate_publish_hg \
   annotate_static     \
+  bug-235681          \
   custom_alloc        \
   fp_race             \
   hold_lock           \
diff --git a/drd/tests/bug-235681.c b/drd/tests/bug-235681.c
new file mode 100644 (file)
index 0000000..3b306ec
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * pthread_cond_wait() test program.
+ * See also https://bugs.kde.org/show_bug.cgi?id=235681.
+ */
+
+#include <string.h>
+#include <stdio.h>
+#include <assert.h>
+#include <pthread.h>
+#include <errno.h>
+#include <unistd.h>
+
+pthread_mutex_t mutex;
+pthread_cond_t cond_var;
+int status;
+
+static void *run_fn(void *v)
+{
+    int rc;
+
+    fprintf(stderr, "run_fn starting\n");
+
+    rc = pthread_mutex_lock(&mutex);
+    assert(!rc);
+
+    while (!status) {
+        fprintf(stderr, "run_fn(): status==0\n");
+        rc = pthread_cond_wait(&cond_var, &mutex);
+        assert(!rc);
+        fprintf(stderr, "run_fn(): woke up\n");
+    }
+    fprintf(stderr, "run_fn(): status==1\n");
+
+    rc = pthread_mutex_unlock(&mutex);
+    assert(!rc);
+
+    fprintf(stderr, "run_fn done\n");
+
+    return NULL;
+}
+
+int main(int argc, char **argv)
+{
+    int rc;
+    pthread_t other_thread;
+
+    rc = pthread_mutex_init(&mutex, NULL);
+    assert(!rc);
+    rc = pthread_cond_init(&cond_var, NULL);
+    assert(!rc);
+
+    status = 0;
+
+    rc = pthread_create(&other_thread, NULL, run_fn, NULL);
+    assert(!rc);
+
+    /* yield the processor, and give the other thread a chance to get into the while loop */
+    fprintf(stderr, "main(): sleeping...\n");
+    sleep(1);
+
+    rc = pthread_mutex_lock(&mutex);
+    assert(!rc);
+    /**** BEGIN CS *****/
+
+    fprintf(stderr, "main(): status=1\n");
+    status = 1;
+    rc = pthread_cond_broadcast(&cond_var);
+    assert(!rc);
+
+    /**** END CS *****/
+    rc = pthread_mutex_unlock(&mutex);
+    assert(!rc);
+
+    fprintf(stderr, "joining...\n");
+
+    rc = pthread_join(other_thread, NULL);
+    assert(!rc);
+
+    return 0;
+}
diff --git a/drd/tests/bug-235681.stderr.exp b/drd/tests/bug-235681.stderr.exp
new file mode 100644 (file)
index 0000000..8aa6612
--- /dev/null
@@ -0,0 +1,11 @@
+
+run_fn starting
+run_fn(): status==0
+main(): sleeping...
+main(): status=1
+joining...
+run_fn(): woke up
+run_fn(): status==1
+run_fn done
+
+ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
diff --git a/drd/tests/bug-235681.vgtest b/drd/tests/bug-235681.vgtest
new file mode 100644 (file)
index 0000000..45ff5fd
--- /dev/null
@@ -0,0 +1,4 @@
+prereq: test -e bug-235681 && ./supported_libpthread
+vgopts: --read-var-info=yes --check-stack-var=yes --show-confl-seg=no --num-callers=3
+prog: bug-235681
+stderr_filter: filter_stderr