From 0874f1a197349c464f8e1002096bda8c33598cf4 Mon Sep 17 00:00:00 2001 From: Daisuke Nojiri Date: Wed, 9 Nov 2016 13:00:59 -0800 Subject: eCTS: Add task suite Task A wakes up B and goes to sleep. Task B wakes up C then goes to sleep. Task C wakes up A then goes to sleep. This is repeated repeat_count times: A -> B -> C -> A -> ... It's expected all tasks to run exactly repeat_count times. Tick task runs to inject some irregularity. BUG=chromium:663873 BRANCH=none TEST=cts.py -m task Change-Id: Ib7227f05f09b7a49f8528aff6e6e8d3e6df93ba7 Signed-off-by: Daisuke Nojiri Reviewed-on: https://chromium-review.googlesource.com/409534 Reviewed-by: Randall Spangler --- cts/pingpong/cts.tasklist | 22 ---------- cts/pingpong/dut.c | 70 ------------------------------ cts/pingpong/th.c | 70 ------------------------------ cts/task/cts.tasklist | 22 ++++++++++ cts/task/cts.testlist | 14 ++++++ cts/task/dut.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++ cts/task/th.c | 1 + 7 files changed, 144 insertions(+), 162 deletions(-) delete mode 100644 cts/pingpong/cts.tasklist delete mode 100644 cts/pingpong/dut.c delete mode 100644 cts/pingpong/th.c create mode 100644 cts/task/cts.tasklist create mode 100644 cts/task/cts.testlist create mode 100644 cts/task/dut.c create mode 120000 cts/task/th.c diff --git a/cts/pingpong/cts.tasklist b/cts/pingpong/cts.tasklist deleted file mode 100644 index bb41e4935f..0000000000 --- a/cts/pingpong/cts.tasklist +++ /dev/null @@ -1,22 +0,0 @@ -/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -/** - * List of enabled tasks in the priority order - * - * The first one has the lowest priority. - * - * For each task, use the macro TASK_ALWAYS(n, r, d, s) where : - * 'n' in the name of the task - * 'r' in the main routine of the task - * 'd' in an opaque parameter passed to the routine at startup - * 's' is the stack size in bytes; must be a multiple of 8 - */ -#define CONFIG_CTS_TASK_LIST \ - TASK_ALWAYS(TESTA, task_abc, NULL, TASK_STACK_SIZE) \ - TASK_ALWAYS(TESTB, task_abc, NULL, TASK_STACK_SIZE) \ - TASK_ALWAYS(TESTC, task_abc, NULL, TASK_STACK_SIZE) \ - TASK_ALWAYS(TICK, task_tick, NULL, 256) \ - TASK_ALWAYS(CTS, cts_task, NULL, TASK_STACK_SIZE) diff --git a/cts/pingpong/dut.c b/cts/pingpong/dut.c deleted file mode 100644 index 0dc0320adc..0000000000 --- a/cts/pingpong/dut.c +++ /dev/null @@ -1,70 +0,0 @@ -/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - * - * Tasks for scheduling test. - */ - -#include "common.h" -#include "console.h" -#include "task.h" -#include "test_util.h" -#include "timer.h" -#include "util.h" - -#define TEST_COUNT 3000 - -static int wake_count[3]; - -int task_abc(void *data) -{ - int myid = task_get_current() - TASK_ID_TESTA; - task_id_t next = task_get_current() + 1; - - if (next > TASK_ID_TESTC) - next = TASK_ID_TESTA; - - task_wait_event(-1); - - ccprintf("\n[starting Task %c]\n", ('A' + myid)); - - while (1) { - wake_count[myid]++; - if (myid == 2 && wake_count[myid] == TEST_COUNT) { - if (wake_count[0] == TEST_COUNT && - wake_count[1] == TEST_COUNT) - test_pass(); - else - test_fail(); - wake_count[0] = wake_count[1] = wake_count[2] = 0; - task_wait_event(-1); - } else { - task_set_event(next, TASK_EVENT_WAKE, 1); - } - } - - return EC_SUCCESS; -} - -int task_tick(void *data) -{ - task_wait_event(-1); - ccprintf("\n[starting Task T]\n"); - - /* Wake up every tick */ - while (1) { - /* Wait for timer interrupt message */ - usleep(3000); - } - - return EC_SUCCESS; -} - -void cts_task(void) -{ - wait_for_task_started(); - task_wake(TASK_ID_TICK); - task_wake(TASK_ID_TESTA); - /* Sleep forever */ - task_wait_event(-1); -} diff --git a/cts/pingpong/th.c b/cts/pingpong/th.c deleted file mode 100644 index 0dc0320adc..0000000000 --- a/cts/pingpong/th.c +++ /dev/null @@ -1,70 +0,0 @@ -/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - * - * Tasks for scheduling test. - */ - -#include "common.h" -#include "console.h" -#include "task.h" -#include "test_util.h" -#include "timer.h" -#include "util.h" - -#define TEST_COUNT 3000 - -static int wake_count[3]; - -int task_abc(void *data) -{ - int myid = task_get_current() - TASK_ID_TESTA; - task_id_t next = task_get_current() + 1; - - if (next > TASK_ID_TESTC) - next = TASK_ID_TESTA; - - task_wait_event(-1); - - ccprintf("\n[starting Task %c]\n", ('A' + myid)); - - while (1) { - wake_count[myid]++; - if (myid == 2 && wake_count[myid] == TEST_COUNT) { - if (wake_count[0] == TEST_COUNT && - wake_count[1] == TEST_COUNT) - test_pass(); - else - test_fail(); - wake_count[0] = wake_count[1] = wake_count[2] = 0; - task_wait_event(-1); - } else { - task_set_event(next, TASK_EVENT_WAKE, 1); - } - } - - return EC_SUCCESS; -} - -int task_tick(void *data) -{ - task_wait_event(-1); - ccprintf("\n[starting Task T]\n"); - - /* Wake up every tick */ - while (1) { - /* Wait for timer interrupt message */ - usleep(3000); - } - - return EC_SUCCESS; -} - -void cts_task(void) -{ - wait_for_task_started(); - task_wake(TASK_ID_TICK); - task_wake(TASK_ID_TESTA); - /* Sleep forever */ - task_wait_event(-1); -} diff --git a/cts/task/cts.tasklist b/cts/task/cts.tasklist new file mode 100644 index 0000000000..8c181b3e5c --- /dev/null +++ b/cts/task/cts.tasklist @@ -0,0 +1,22 @@ +/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/** + * List of enabled tasks in the priority order + * + * The first one has the lowest priority. + * + * For each task, use the macro TASK_ALWAYS(n, r, d, s) where : + * 'n' in the name of the task + * 'r' in the main routine of the task + * 'd' in an opaque parameter passed to the routine at startup + * 's' is the stack size in bytes; must be a multiple of 8 + */ +#define CONFIG_CTS_TASK_LIST \ + TASK_ALWAYS(A, task_abc, NULL, TASK_STACK_SIZE) \ + TASK_ALWAYS(B, task_abc, NULL, TASK_STACK_SIZE) \ + TASK_ALWAYS(C, task_abc, NULL, TASK_STACK_SIZE) \ + TASK_ALWAYS(TICK, task_tick, NULL, 256) \ + TASK_ALWAYS(CTS, cts_task, NULL, TASK_STACK_SIZE) diff --git a/cts/task/cts.testlist b/cts/task/cts.testlist new file mode 100644 index 0000000000..c06c4b4163 --- /dev/null +++ b/cts/task/cts.testlist @@ -0,0 +1,14 @@ +/* Copyright 2016 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/* + * Test task switching. Task A wakes up B and goes to sleep. Task B wakes + * up C then goes to sleep. Task C wakes up A then goes to sleep. This is + * repeated TEST_COUNT times. It's expected all tasks to run exactly + * TEST_COUNT times. Tick task runs to inject some irregularity. + */ +CTS_TEST(test_task_switch) + +CTS_TEST(test_task_priority) \ No newline at end of file diff --git a/cts/task/dut.c b/cts/task/dut.c new file mode 100644 index 0000000000..c3a820b7ce --- /dev/null +++ b/cts/task/dut.c @@ -0,0 +1,107 @@ +/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * Tasks for scheduling test. + */ + +#include "common.h" +#include "cts_common.h" +#include "task.h" +#include "timer.h" + +static int repeat_count; +static int wake_count[3]; + +void clear_state(void) +{ + wake_count[0] = wake_count[1] = wake_count[2] = 0; +} + +void task_abc(void *data) +{ + int task_id = task_get_current(); + int id = task_id - TASK_ID_A; + task_id_t next = task_id + 1; + + if (next > TASK_ID_C) + next = TASK_ID_A; + + task_wait_event(-1); + + CPRINTS("%c Starting", 'A' + id); + cflush(); + + while (1) { + wake_count[id]++; + if (id == 2 && wake_count[id] == repeat_count) + task_set_event(TASK_ID_CTS, TASK_EVENT_WAKE, 1); + else + task_set_event(next, TASK_EVENT_WAKE, 1); + } +} + +void task_tick(void *data) +{ + task_wait_event(-1); + ccprintf("\n[starting Task T]\n"); + + /* Wake up every tick */ + while (1) + /* Wait for timer interrupt message */ + usleep(3000); +} + +enum cts_rc test_task_switch(void) +{ + uint32_t event; + + repeat_count = 3000; + + task_wake(TASK_ID_A); + event = task_wait_event(5 * SECOND); + + if (event != TASK_EVENT_WAKE) { + CPRINTS("Woken up by unexpected event: 0x%08x", event); + return CTS_RC_FAILURE; + } + + if (wake_count[0] != repeat_count || wake_count[1] != repeat_count) { + CPRINTS("Unexpected counter values: %d %d %d", + wake_count[0], wake_count[1], wake_count[2]); + return CTS_RC_FAILURE; + } + + /* TODO: Verify no tasks are ready, no events are pending. */ + if (*task_get_event_bitmap(TASK_ID_A) + || *task_get_event_bitmap(TASK_ID_B) + || *task_get_event_bitmap(TASK_ID_C)) { + CPRINTS("Events are pending"); + return CTS_RC_FAILURE; + } + + return CTS_RC_SUCCESS; +} + +#include "cts_testlist.h" + +void cts_task(void) +{ + enum cts_rc rc; + int i; + + task_wake(TASK_ID_TICK); + + for (i = 0; i < CTS_TEST_ID_COUNT; i++) { + clear_state(); + rc = tests[i].run(); + CPRINTF("\n%s %d\n", tests[i].name, rc); + cflush(); + } + + CPRINTS("Task test suite finished"); + cflush(); + + /* Sleep forever */ + task_wait_event(-1); +} diff --git a/cts/task/th.c b/cts/task/th.c new file mode 120000 index 0000000000..41eab28462 --- /dev/null +++ b/cts/task/th.c @@ -0,0 +1 @@ +dut.c \ No newline at end of file -- cgit v1.2.1