diff options
author | Vic Yang <victoryang@chromium.org> | 2013-04-11 11:12:53 +0800 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-04-11 11:29:32 -0700 |
commit | 5018f1d9d6adfd02d967fea32ab3d9e0ba11b443 (patch) | |
tree | 269e27cc688b90695f6cc1ac5670a0cf7f5c7574 | |
parent | f1eddf778abd12ab48d77a60130291cfdd7d0f68 (diff) | |
download | chrome-ec-5018f1d9d6adfd02d967fea32ab3d9e0ba11b443.tar.gz |
Fix mutex test
Puts test behind a console command and also fix uart_printf calls. Also
reduces stack size to fit tasks into STM32 memory.
BUG=chrome-os-partner:18598
TEST=Run mutex test on Spring.
BRANCH=none
Change-Id: Icac77876ae01fc98b4e38f27e07f788b6c9bdd70
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/47834
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r-- | test/mutex.c | 43 | ||||
-rw-r--r-- | test/mutex.tasklist | 10 |
2 files changed, 32 insertions, 21 deletions
diff --git a/test/mutex.c b/test/mutex.c index 9fc1cd76b7..47f7fa97c4 100644 --- a/test/mutex.c +++ b/test/mutex.c @@ -6,10 +6,11 @@ * Tasks for mutexes basic tests. */ +#include "console.h" #include "common.h" -#include "uart.h" #include "task.h" #include "timer.h" +#include "util.h" static struct mutex mtx; @@ -31,11 +32,11 @@ int mutex_random_task(void *unused) while (1) { task_wait_event(0); - uart_printf("%c+\n", letter); + ccprintf("%c+\n", letter); mutex_lock(&mtx); - uart_printf("%c=\n", letter); + ccprintf("%c=\n", letter); task_wait_event(0); - uart_printf("%c-\n", letter); + ccprintf("%c-\n", letter); mutex_unlock(&mtx); } @@ -48,14 +49,14 @@ int mutex_second_task(void *unused) { task_id_t id = task_get_current(); - uart_printf("\n[Mutex second task %d]\n", id); + ccprintf("\n[Mutex second task %d]\n", id); task_wait_event(0); - uart_printf("MTX2: locking..."); + ccprintf("MTX2: locking..."); mutex_lock(&mtx); - uart_printf("done\n"); + ccprintf("done\n"); task_wake(TASK_ID_MTX1); - uart_printf("MTX2: unlocking...\n"); + ccprintf("MTX2: unlocking...\n"); mutex_unlock(&mtx); task_wait_event(0); @@ -70,30 +71,32 @@ int mutex_main_task(void *unused) uint32_t rtask = (uint32_t)0x1a4e1dea; int i; - uart_printf("\n[Mutex main task %d]\n", id); + ccprintf("\n[Mutex main task %d]\n", id); + + task_wait_event(0); /* --- Lock/Unlock without contention --- */ - uart_printf("No contention :"); + ccprintf("No contention :"); mutex_lock(&mtx); mutex_unlock(&mtx); mutex_lock(&mtx); mutex_unlock(&mtx); mutex_lock(&mtx); mutex_unlock(&mtx); - uart_printf("done.\n"); + ccprintf("done.\n"); /* --- Serialization to test simple contention --- */ - uart_printf("Simple contention :\n"); + ccprintf("Simple contention :\n"); /* lock the mutex from the other task */ task_set_event(TASK_ID_MTX2, TASK_EVENT_WAKE, 1); /* block on the mutex */ - uart_printf("MTX1: blocking...\n"); + ccprintf("MTX1: blocking...\n"); mutex_lock(&mtx); - uart_printf("MTX1: get lock\n"); + ccprintf("MTX1: get lock\n"); mutex_unlock(&mtx); /* --- mass lock-unlocking from several tasks --- */ - uart_printf("Massive locking/unlocking :\n"); + ccprintf("Massive locking/unlocking :\n"); for (i = 0; i < 500; i++) { /* Wake up a random task */ task_wake(RANDOM_TASK(rtask)); @@ -105,8 +108,16 @@ int mutex_main_task(void *unused) rdelay = prng(rdelay); } - uart_printf("Test done.\n"); + ccprintf("Pass!\n"); task_wait_event(0); return EC_SUCCESS; } + +static int command_run_test(int argc, char **argv) +{ + task_wake(TASK_ID_MTX1); + return EC_SUCCESS; +} +DECLARE_CONSOLE_COMMAND(runtest, command_run_test, + NULL, NULL, NULL); diff --git a/test/mutex.tasklist b/test/mutex.tasklist index 4233108fc0..d4865f3456 100644 --- a/test/mutex.tasklist +++ b/test/mutex.tasklist @@ -15,8 +15,8 @@ * 's' is the stack size in bytes; must be a multiple of 8 */ #define CONFIG_TEST_TASK_LIST \ - TASK_TEST(MTX3C, mutex_random_task, NULL, TASK_STACK_SIZE) \ - TASK_TEST(MTX3B, mutex_random_task, NULL, TASK_STACK_SIZE) \ - TASK_TEST(MTX3A, mutex_random_task, NULL, TASK_STACK_SIZE) \ - TASK_TEST(MTX2, mutex_second_task, NULL, TASK_STACK_SIZE) \ - TASK_TEST(MTX1, mutex_main_task, NULL, TASK_STACK_SIZE) + TASK_TEST(MTX3C, mutex_random_task, NULL, 384) \ + TASK_TEST(MTX3B, mutex_random_task, NULL, 384) \ + TASK_TEST(MTX3A, mutex_random_task, NULL, 384) \ + TASK_TEST(MTX2, mutex_second_task, NULL, 384) \ + TASK_TEST(MTX1, mutex_main_task, NULL, 384) |