From eb75c053eb46cbeb4ad9c0b7b179ba1acb20eba4 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 28 Feb 2009 09:39:02 +0000 Subject: Added new benchmarks about semaphores and mutexes to the test suite. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@804 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- test/testbmk.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) (limited to 'test/testbmk.c') diff --git a/test/testbmk.c b/test/testbmk.c index c3a69a5b2..10a4ea439 100644 --- a/test/testbmk.c +++ b/test/testbmk.c @@ -22,6 +22,7 @@ #include "test.h" static Semaphore sem1; +static Mutex mtx1; static msg_t thread1(void *p) { msg_t msg; @@ -328,6 +329,90 @@ const struct testcase testbmk8 = { bmk8_execute }; +static char *bmk9_gettest(void) { + + return "Benchmark, semaphores wait/signal"; +} + +static void bmk9_setup(void) { + + chSemInit(&sem1, 1); +} + +static void bmk9_execute(void) { + uint32_t n = 0; + + test_wait_tick(); + test_start_timer(1000); + do { + chSemWait(&sem1); + chSemSignal(&sem1); + chSemWait(&sem1); + chSemSignal(&sem1); + chSemWait(&sem1); + chSemSignal(&sem1); + chSemWait(&sem1); + chSemSignal(&sem1); + n++; +#if defined(WIN32) + ChkIntSources(); +#endif + } while (!test_timer_done); + test_print("--- Score : "); + test_printn(n * 4); + test_println(" wait+signal/S"); +} + +const struct testcase testbmk9 = { + bmk9_gettest, + bmk9_setup, + NULL, + bmk9_execute +}; + +#if CH_USE_MUTEXES +static char *bmk10_gettest(void) { + + return "Benchmark, mutexes lock/unlock"; +} + +static void bmk10_setup(void) { + + chMtxInit(&mtx1); +} + +static void bmk10_execute(void) { + uint32_t n = 0; + + test_wait_tick(); + test_start_timer(1000); + do { + chMtxLock(&mtx1); + chMtxUnlock(); + chMtxLock(&mtx1); + chMtxUnlock(); + chMtxLock(&mtx1); + chMtxUnlock(); + chMtxLock(&mtx1); + chMtxUnlock(); + n++; +#if defined(WIN32) + ChkIntSources(); +#endif + } while (!test_timer_done); + test_print("--- Score : "); + test_printn(n * 4); + test_println(" lock+unlock/S"); +} + +const struct testcase testbmk10 = { + bmk10_gettest, + bmk10_setup, + NULL, + bmk10_execute +}; +#endif + /* * Test sequence for benchmarks pattern. */ @@ -341,6 +426,10 @@ const struct testcase *patternbmk[] = { &testbmk6, &testbmk7, &testbmk8, + &testbmk9, +#if CH_USE_MUTEXES + &testbmk10, +#endif #endif NULL }; -- cgit v1.2.3