From e776216d02920673266e31d553078f4edec4a264 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 13 Nov 2007 16:38:23 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@89 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- test/test.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/test.c b/test/test.c index fbaedd280..8fe61794c 100644 --- a/test/test.c +++ b/test/test.c @@ -46,10 +46,29 @@ static void wait(void) { chThdWait(t5); } -static void println(char *msgp) { +static void printn(unsigned int n) { + char buf[16], *p; + + if (!n) + chFDDPut(comp, '0'); + else { + p = buf; + while (n) + *p++ = (n % 10) + '0', n /= 10; + while (p > buf) + chFDDPut(comp, *--p); + } +} + +static void print(char *msgp) { while (*msgp) chFDDPut(comp, *msgp++); +} + +static void println(char *msgp) { + + print(msgp); chFDDPut(comp, '\r'); chFDDPut(comp, '\n'); } @@ -94,12 +113,19 @@ t_msg Thread5(void *p) { return 0; } +t_msg Thread6(void *p) { + + while (!chThdShouldTerminate()) + chMsgRelease(chMsgWait() + 1); + return 0; +} + /** * Tester thread, this thread must be created with priority \p NORMALPRIO. */ t_msg TestThread(void *p) { t_msg msg; - int i; + unsigned int i; comp = p; println("*****************************"); @@ -202,6 +228,27 @@ t_msg TestThread(void *p) { chThdWait(t1); println(""); + /* + * Kernel benchmarks. + */ + println("*** Kernel Benchmark, context switch stress test:"); + t_time time = chSysGetTime() + 1; + while (chSysGetTime() < time) + ; + time += 1000; + i = 0; + t1 = chThdCreate(NORMALPRIO+1, 0, wsT1, sizeof(wsT1), Thread6, chThdSelf()); + while (chSysGetTime() < time) + i = chMsgSend(t1, i); + chThdTerminate(t1); + chMsgSend(t1, 0); /* Lets the thread check the termination flag.*/ + chThdWait(t1); + print("Messages throughput = "); + printn(i); + print(" msg/S, "); + printn(i << 1); + println(" ctxsw/S"); + println("\r\nTest complete"); return 0; } -- cgit v1.2.3