Files
OpenCellular/test/interrupt.c
Vic (Chun-Ju) Yang 7c686dd68b emulator: Move trace dump to a separate module
The implementation of trace dump has little to do with task scheduling,
so we should move it to a separate module for cleaner code. This
requires exposing some emulator-specific task info, as defined in
host_task.h.

BUG=chrome-os-partner:19235
TEST=Pass all tests
BRANCH=None

Change-Id: Iba9bc0794a4e1dd4ddb92b98345162b398fa6a8d
Signed-off-by: Vic (Chun-Ju) Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/183238
2014-01-22 04:52:49 +00:00

83 lines
1.6 KiB
C

/* 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 "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 run_test(void)
{
test_reset();
RUN_TEST(interrupt_test);
RUN_TEST(interrupt_disable_test);
test_print_result();
}