diff options
author | Vic Yang <victoryang@chromium.org> | 2013-05-20 00:00:27 +0800 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2014-01-06 12:40:45 +0000 |
commit | cdcaf6ed8a1d18bdedb72fb665263c0dbff0ac8e (patch) | |
tree | ab01862ee3a4114e43ec974fbbbdd615e1e61d63 /test/interrupt.c | |
parent | 7c673390aecdd35da01ddf446a23667d95dccef1 (diff) | |
download | chrome-ec-cdcaf6ed8a1d18bdedb72fb665263c0dbff0ac8e.tar.gz |
Add interrupt support for emulator
This provides us a way to inject interrupts during a test. If a test has
interrupt_generator() defined, it will run in a separate thread. The
generator can then trigger interrupts when it decides to. The current
running task is suspended while emulator is executing ISR.
Also fixes a bug that tasks run without scheduler notifying them during
emulator start-up.
BUG=chrome-os-partner:19235
TEST=Repeatedly run all tests.
BRANCH=None
Change-Id: I0f921c47c0f848a9626da6272d9040e2b7c5ac86
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/55671
Diffstat (limited to 'test/interrupt.c')
-rw-r--r-- | test/interrupt.c | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/test/interrupt.c b/test/interrupt.c new file mode 100644 index 0000000000..b7a42d1588 --- /dev/null +++ b/test/interrupt.c @@ -0,0 +1,82 @@ +/* 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 <stdio.h> + +#include "common.h" +#include "console.h" +#include "test_util.h" +#include "task.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 run_test(void) +{ + test_reset(); + + RUN_TEST(interrupt_test); + RUN_TEST(interrupt_disable_test); + + test_print_result(); +} |