summaryrefslogtreecommitdiff
path: root/libmudflap/testsuite/libmudflap.cth
diff options
context:
space:
mode:
Diffstat (limited to 'libmudflap/testsuite/libmudflap.cth')
-rw-r--r--libmudflap/testsuite/libmudflap.cth/cthfrags.exp25
-rw-r--r--libmudflap/testsuite/libmudflap.cth/pass37-frag.c58
-rw-r--r--libmudflap/testsuite/libmudflap.cth/pass39-frag.c57
-rw-r--r--libmudflap/testsuite/libmudflap.cth/pass40-frag.c59
-rw-r--r--libmudflap/testsuite/libmudflap.cth/pass59-frag.c39
5 files changed, 238 insertions, 0 deletions
diff --git a/libmudflap/testsuite/libmudflap.cth/cthfrags.exp b/libmudflap/testsuite/libmudflap.cth/cthfrags.exp
new file mode 100644
index 000000000..e5a7de843
--- /dev/null
+++ b/libmudflap/testsuite/libmudflap.cth/cthfrags.exp
@@ -0,0 +1,25 @@
+global MUDFLAP_FLAGS
+set MUDFLAP_FLAGS [list {} {-static -DSTATIC} {-O2} {-O3}]
+
+libmudflap-init c
+
+dg-init
+
+global srcdir
+foreach flags $MUDFLAP_FLAGS {
+ foreach srcfile [lsort [glob -nocomplain ${srcdir}/libmudflap.cth/*.c]] {
+ set bsrc [file tail $srcfile]
+ setenv MUDFLAP_OPTIONS "-viol-segv"
+ if {$libmudflapth} then {
+ # --noinhibit-exec works around a ld problem that causes
+ # "Dwarf Error: Invalid or unhandled FORM value: 14"
+ # to fail builds unnecessarily.
+ dg-runtest $srcfile $flags "-fmudflapth -lmudflapth -lpthread -Wl,--noinhibit-exec"
+ } else {
+ if {$flags != ""} {set f " ($flags)"} {set f ""}
+ untested "libmudflap.cth/$bsrc$f"
+ }
+ }
+}
+
+dg-finish
diff --git a/libmudflap/testsuite/libmudflap.cth/pass37-frag.c b/libmudflap/testsuite/libmudflap.cth/pass37-frag.c
new file mode 100644
index 000000000..877803c1e
--- /dev/null
+++ b/libmudflap/testsuite/libmudflap.cth/pass37-frag.c
@@ -0,0 +1,58 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <pthread.h>
+#include <sched.h>
+
+static void *
+func (void *p)
+{
+ int *counter = (int *) p;
+ unsigned i;
+
+ for (i=0; i<100; i++)
+ {
+ (*counter) ++;
+ {
+ int array[17];
+ unsigned x = i % (sizeof(array)/sizeof(array[0]));
+ /* VRP could prove that x is within [0,16], but until then, the
+ following access will ensure that array[] is registered to
+ libmudflap. */
+ array[x] = i;
+ }
+ sched_yield (); /* sleep (1); */
+ }
+
+ return (NULL);
+}
+
+
+int main ()
+{
+ int rc;
+ unsigned i;
+ enum foo { NT=10 };
+ pthread_t threads[NT];
+ int counts[NT];
+
+
+ for (i=0; i<NT; i++)
+ {
+ counts[i] = 0;
+ rc = pthread_create (& threads[i], NULL, func, (void *) & counts[i]);
+ if (rc) abort();
+ }
+
+ for (i=0; i<NT; i++)
+ {
+ rc = pthread_join (threads[i], NULL);
+ if (rc) abort();
+ printf ("%d%s", counts[i], (i==NT-1) ? "\n" : " ");
+ }
+
+ return 0;
+}
+
+/* { dg-output "100 100 100 100 100 100 100 100 100 100" } */
+/* { dg-repetitions 20 } */
+/* { dg-timeout 10 } */
diff --git a/libmudflap/testsuite/libmudflap.cth/pass39-frag.c b/libmudflap/testsuite/libmudflap.cth/pass39-frag.c
new file mode 100644
index 000000000..cd3eb5abd
--- /dev/null
+++ b/libmudflap/testsuite/libmudflap.cth/pass39-frag.c
@@ -0,0 +1,57 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <pthread.h>
+#include <sched.h>
+#include <assert.h>
+
+static void *
+func (void *p)
+{
+ int *counter = (int *) p;
+ unsigned i;
+ enum { numarrays = 100, numels = 17 };
+ char *arrays [numarrays];
+
+ for (i=0; i<numarrays; i++)
+ {
+ (*counter) ++;
+ unsigned x = i % numels;
+ arrays[i] = calloc (numels, sizeof(arrays[i][0]));
+ assert (arrays[i] != NULL);
+ arrays[i][x] = i;
+ free (arrays[i]);
+ sched_yield (); /* sleep (1); */
+ }
+
+ return (NULL);
+}
+
+
+int main ()
+{
+ int rc;
+ unsigned i;
+ enum foo { NT=10 };
+ pthread_t threads[NT];
+ int counts[NT];
+
+
+ for (i=0; i<NT; i++)
+ {
+ counts[i] = 0;
+ rc = pthread_create (& threads[i], NULL, func, (void *) & counts[i]);
+ if (rc) abort();
+ }
+
+ for (i=0; i<NT; i++)
+ {
+ rc = pthread_join (threads[i], NULL);
+ if (rc) abort();
+ printf ("%d%s", counts[i], (i==NT-1) ? "\n" : " ");
+ }
+
+ return 0;
+}
+/* { dg-output "100 100 100 100 100 100 100 100 100 100" } */
+/* { dg-repetitions 20 } */
+/* { dg-timeout 10 } */
diff --git a/libmudflap/testsuite/libmudflap.cth/pass40-frag.c b/libmudflap/testsuite/libmudflap.cth/pass40-frag.c
new file mode 100644
index 000000000..007cb1607
--- /dev/null
+++ b/libmudflap/testsuite/libmudflap.cth/pass40-frag.c
@@ -0,0 +1,59 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <pthread.h>
+
+static void *
+func (void *p)
+{
+ return (NULL);
+}
+
+static void
+test (void)
+{
+ int rc;
+ pthread_attr_t my_pthread_attr;
+ pthread_t h;
+ long i;
+
+ rc = pthread_attr_init (&my_pthread_attr);
+
+ for (i = 1; i <= 10000; ++i) {
+ if (i%100 == 0) fprintf (stderr, "%i ", i);
+ if (i%1000 == 0) fprintf (stderr, "\n");
+#ifndef STATIC
+ /* Some glibc versions don't like static multithreaded programs doing this. */
+ if (i==5000) __mf_set_options ("-thread-stack=192");
+#endif
+ rc = pthread_create (&h, &my_pthread_attr,
+ func, NULL);
+ if (rc)
+ break;
+
+ rc = pthread_join (h, NULL);
+ if (rc)
+ break;
+ }
+
+ rc = pthread_attr_destroy (&my_pthread_attr);
+}
+
+int main ()
+{
+ test ();
+
+ return (0);
+}
+
+/* { dg-timeout 30 } */
+/* { dg-output "100 200 300 400 500 600 700 800 900 1000 \n" } */
+/* { dg-output "1100 1200 1300 1400 1500 1600 1700 1800 1900 2000 \n" } */
+/* { dg-output "2100 2200 2300 2400 2500 2600 2700 2800 2900 3000 \n" } */
+/* { dg-output "3100 3200 3300 3400 3500 3600 3700 3800 3900 4000 \n" } */
+/* { dg-output "4100 4200 4300 4400 4500 4600 4700 4800 4900 5000 \n" } */
+/* { dg-output "5100 5200 5300 5400 5500 5600 5700 5800 5900 6000 \n" } */
+/* { dg-output "6100 6200 6300 6400 6500 6600 6700 6800 6900 7000 \n" } */
+/* { dg-output "7100 7200 7300 7400 7500 7600 7700 7800 7900 8000 \n" } */
+/* { dg-output "8100 8200 8300 8400 8500 8600 8700 8800 8900 9000 \n" } */
+/* { dg-output "9100 9200 9300 9400 9500 9600 9700 9800 9900 10000 \n" } */
+
diff --git a/libmudflap/testsuite/libmudflap.cth/pass59-frag.c b/libmudflap/testsuite/libmudflap.cth/pass59-frag.c
new file mode 100644
index 000000000..490130677
--- /dev/null
+++ b/libmudflap/testsuite/libmudflap.cth/pass59-frag.c
@@ -0,0 +1,39 @@
+#include <stdio.h>
+#include <pthread.h>
+
+/* PR 28578 */
+
+void* test_thread(void* arg)
+{
+ printf("Hello from thread!\n");
+ pthread_exit(NULL);
+ return 0;
+}
+
+int main()
+{
+ pthread_t thread;
+ void *arg = NULL;
+ pthread_create(&thread, NULL, test_thread, arg);
+ pthread_join(thread, NULL);
+ pthread_exit(NULL);
+ return 0;
+}
+
+/* { dg-output "Hello from thread!\n" } */
+
+#if 0
+
+/* Even this test case replicates the problem. However, when built in
+ static mode, it blows up during __mf_init (?!?!?!) with a
+ pthread_mutex_lock deadlock error. */
+
+#include <stdio.h>
+#include <pthread.h>
+
+int main ()
+{
+ pthread_exit(NULL);
+ return 0;
+}
+#endif