]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Sigh. Add the test files.
authorJeremy Fitzhardinge <jeremy@valgrind.org>
Thu, 18 Dec 2003 09:08:51 +0000 (09:08 +0000)
committerJeremy Fitzhardinge <jeremy@valgrind.org>
Thu, 18 Dec 2003 09:08:51 +0000 (09:08 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2130

none/tests/yield.c [new file with mode: 0644]
none/tests/yield.stderr.exp [new file with mode: 0644]
none/tests/yield.stdout.exp [new file with mode: 0644]
none/tests/yield.vgtest [new file with mode: 0644]

diff --git a/none/tests/yield.c b/none/tests/yield.c
new file mode 100644 (file)
index 0000000..45694d8
--- /dev/null
@@ -0,0 +1,70 @@
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+static pthread_mutex_t m_go;
+static pthread_cond_t c_go;
+
+static volatile int alive;
+
+static int sch_yield;
+static int rep_nop;
+
+static void *th1(void *v)
+{
+       pthread_mutex_lock(&m_go);
+       while(!alive)
+               pthread_cond_wait(&c_go, &m_go);
+       pthread_mutex_unlock(&m_go);
+
+       while(alive) {
+               sch_yield++;
+               sched_yield();
+       }
+
+       return 0;
+}
+
+static void *th2(void *v)
+{
+       pthread_mutex_lock(&m_go);
+       while(!alive)
+               pthread_cond_wait(&c_go, &m_go);
+       pthread_mutex_unlock(&m_go);
+
+       while(alive) {
+               rep_nop++;
+               asm volatile ("rep; nop" : : : "memory");
+       }
+
+       return 0;
+}
+
+int main()
+{
+       pthread_t a, b;
+
+       pthread_create(&a, NULL, th1, NULL);
+       pthread_create(&b, NULL, th2, NULL);
+
+       /* make sure both threads start at the same time */
+       pthread_mutex_lock(&m_go);
+       alive = 1;
+       pthread_cond_signal(&c_go);
+       pthread_mutex_unlock(&m_go);
+
+       sleep(1);
+
+       alive = 0;
+       pthread_join(a, NULL);
+       pthread_join(b, NULL);
+
+       if (abs(sch_yield - rep_nop) < 2)
+               printf("PASS\n");
+       else
+               printf("FAIL sch_yield=%d rep_nop=%d\n", 
+                      sch_yield, rep_nop);
+
+       return 0;
+}
diff --git a/none/tests/yield.stderr.exp b/none/tests/yield.stderr.exp
new file mode 100644 (file)
index 0000000..139597f
--- /dev/null
@@ -0,0 +1,2 @@
+
+
diff --git a/none/tests/yield.stdout.exp b/none/tests/yield.stdout.exp
new file mode 100644 (file)
index 0000000..7ef22e9
--- /dev/null
@@ -0,0 +1 @@
+PASS
diff --git a/none/tests/yield.vgtest b/none/tests/yield.vgtest
new file mode 100644 (file)
index 0000000..49e68a7
--- /dev/null
@@ -0,0 +1 @@
+prog: yield