diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2016-07-14 14:12:21 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-07-15 21:39:36 -0700 |
commit | 9c1e181e16e67f3f8c00b07588b1df9c21be9ed8 (patch) | |
tree | 7c1d14190eff2a5dcb8a1b87b5aa7192b24a6258 /cts | |
parent | a7d454f48b19b6cb2dca76151cb3faa050df24d1 (diff) | |
download | chrome-ec-9c1e181e16e67f3f8c00b07588b1df9c21be9ed8.tar.gz |
cts: Add interrupt test
It's imported from test/interrupt.c and adjusted to CTS.
BUG=chromium:624520
BRANCH=none
TEST=make buildall. Test passed on stm32l476-geval and nucleo-f072rb.
Change-Id: Ie948d284cebad60d97aab1512bb9e3af8838004e
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/360660
Reviewed-by: Chris Chen <twothreecc@google.com>
Diffstat (limited to 'cts')
-rw-r--r-- | cts/interrupt/dut.c | 84 | ||||
-rw-r--r-- | cts/interrupt/th.c | 84 |
2 files changed, 168 insertions, 0 deletions
diff --git a/cts/interrupt/dut.c b/cts/interrupt/dut.c new file mode 100644 index 0000000000..63a377fb3c --- /dev/null +++ b/cts/interrupt/dut.c @@ -0,0 +1,84 @@ +/* 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. + * + * Test interrupt support of EC emulator. + */ + +#include "common.h" +#include "console.h" +#include "task.h" +#include "test_util.h" +#include "timer.h" +#include "util.h" + +static int main_count; +static int has_error; +static int interrupt_count; + +/* period between 50us and 3.2ms */ +#define PERIOD_US(num) (((num % 64) + 1) * 50) + +void my_isr(void) +{ + int i = main_count; + + udelay(3 * PERIOD_US(prng_no_seed())); + if (i != main_count || !in_interrupt_context()) + has_error = 1; + interrupt_count++; +} + +void interrupt_generator(void) +{ + while (1) { + udelay(3 * PERIOD_US(prng_no_seed())); + task_trigger_test_interrupt(my_isr); + } +} + +static int interrupt_test(void) +{ + timestamp_t deadline = get_time(); + + deadline.val += SECOND / 2; + while (!timestamp_expired(deadline, NULL)) + ++main_count; + + ccprintf("Interrupt count: %d\n", interrupt_count); + ccprintf("Main thread tick: %d\n", main_count); + + TEST_ASSERT(!has_error); + TEST_ASSERT(!in_interrupt_context()); + + return EC_SUCCESS; +} + +static int interrupt_disable_test(void) +{ + timestamp_t deadline = get_time(); + int start_int_cnt, end_int_cnt; + + deadline.val += SECOND / 2; + + interrupt_disable(); + start_int_cnt = interrupt_count; + while (!timestamp_expired(deadline, NULL)) + ; + end_int_cnt = interrupt_count; + interrupt_enable(); + + TEST_ASSERT(start_int_cnt == end_int_cnt); + + return EC_SUCCESS; +} + +void cts_task(void) +{ + test_reset(); + + RUN_TEST(interrupt_test); + RUN_TEST(interrupt_disable_test); + + test_print_result(); +} diff --git a/cts/interrupt/th.c b/cts/interrupt/th.c new file mode 100644 index 0000000000..63a377fb3c --- /dev/null +++ b/cts/interrupt/th.c @@ -0,0 +1,84 @@ +/* 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. + * + * Test interrupt support of EC emulator. + */ + +#include "common.h" +#include "console.h" +#include "task.h" +#include "test_util.h" +#include "timer.h" +#include "util.h" + +static int main_count; +static int has_error; +static int interrupt_count; + +/* period between 50us and 3.2ms */ +#define PERIOD_US(num) (((num % 64) + 1) * 50) + +void my_isr(void) +{ + int i = main_count; + + udelay(3 * PERIOD_US(prng_no_seed())); + if (i != main_count || !in_interrupt_context()) + has_error = 1; + interrupt_count++; +} + +void interrupt_generator(void) +{ + while (1) { + udelay(3 * PERIOD_US(prng_no_seed())); + task_trigger_test_interrupt(my_isr); + } +} + +static int interrupt_test(void) +{ + timestamp_t deadline = get_time(); + + deadline.val += SECOND / 2; + while (!timestamp_expired(deadline, NULL)) + ++main_count; + + ccprintf("Interrupt count: %d\n", interrupt_count); + ccprintf("Main thread tick: %d\n", main_count); + + TEST_ASSERT(!has_error); + TEST_ASSERT(!in_interrupt_context()); + + return EC_SUCCESS; +} + +static int interrupt_disable_test(void) +{ + timestamp_t deadline = get_time(); + int start_int_cnt, end_int_cnt; + + deadline.val += SECOND / 2; + + interrupt_disable(); + start_int_cnt = interrupt_count; + while (!timestamp_expired(deadline, NULL)) + ; + end_int_cnt = interrupt_count; + interrupt_enable(); + + TEST_ASSERT(start_int_cnt == end_int_cnt); + + return EC_SUCCESS; +} + +void cts_task(void) +{ + test_reset(); + + RUN_TEST(interrupt_test); + RUN_TEST(interrupt_disable_test); + + test_print_result(); +} |