From: Jeremy Fitzhardinge Date: Thu, 18 Dec 2003 09:08:51 +0000 (+0000) Subject: Sigh. Add the test files. X-Git-Tag: svn/VALGRIND_2_1_1~172 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=72bfb346c003c2a41ce8ea91f503d4eee2e1525c;p=thirdparty%2Fvalgrind.git Sigh. Add the test files. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2130 --- diff --git a/none/tests/yield.c b/none/tests/yield.c new file mode 100644 index 0000000000..45694d8d94 --- /dev/null +++ b/none/tests/yield.c @@ -0,0 +1,70 @@ +#include +#include +#include +#include + +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 index 0000000000..139597f9cb --- /dev/null +++ b/none/tests/yield.stderr.exp @@ -0,0 +1,2 @@ + + diff --git a/none/tests/yield.stdout.exp b/none/tests/yield.stdout.exp new file mode 100644 index 0000000000..7ef22e9a43 --- /dev/null +++ b/none/tests/yield.stdout.exp @@ -0,0 +1 @@ +PASS diff --git a/none/tests/yield.vgtest b/none/tests/yield.vgtest new file mode 100644 index 0000000000..49e68a74a2 --- /dev/null +++ b/none/tests/yield.vgtest @@ -0,0 +1 @@ +prog: yield