summaryrefslogtreecommitdiff
path: root/cts/interrupt/th.c
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2016-07-27 15:46:42 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-10-07 21:51:54 -0700
commit473ecbe2b36bc44da2552cd5814874a495913fc1 (patch)
tree116b0c658c2fa7916941d114d3ddb6ea33e8a71a /cts/interrupt/th.c
parent241d9e3728c6e2d23d71330be6ddfa5015414f1d (diff)
downloadchrome-ec-473ecbe2b36bc44da2552cd5814874a495913fc1.tar.gz
cts: Add real interrupt test
Interrupt test checks whether DUT can be interrupted by an interrupt and an interrupt handler can be invoked as expected. Note the previous interrupt test ported from test/interrupt.c runs in an emulated environment on the host, thus does not test the real interrupt capability of the chip. BUG=chromium:653195 BRANCH=none TEST=Run cts.py -m interrupt Change-Id: I21cecff07594f048633d1c1b699fb3a1876379e0 Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/363943 Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'cts/interrupt/th.c')
-rw-r--r--cts/interrupt/th.c101
1 files changed, 42 insertions, 59 deletions
diff --git a/cts/interrupt/th.c b/cts/interrupt/th.c
index 63a377fb3c..3bcf2168b6 100644
--- a/cts/interrupt/th.c
+++ b/cts/interrupt/th.c
@@ -1,84 +1,67 @@
-/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+/* 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 interrupt support of EC emulator.
*/
#include "common.h"
-#include "console.h"
-#include "task.h"
-#include "test_util.h"
+#include "th_common.h"
+#include "gpio.h"
#include "timer.h"
-#include "util.h"
+#include "watchdog.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)
+static void trigger_interrupt(void)
{
- int i = main_count;
-
- udelay(3 * PERIOD_US(prng_no_seed()));
- if (i != main_count || !in_interrupt_context())
- has_error = 1;
- interrupt_count++;
+ usleep(CTS_INTERRUPT_TRIGGER_DELAY_US);
+ gpio_set_level(GPIO_OUTPUT_TEST, 0);
+ usleep(CTS_INTERRUPT_TRIGGER_DELAY_US);
}
-void interrupt_generator(void)
+enum cts_rc test_task_wait_event(void)
{
- while (1) {
- udelay(3 * PERIOD_US(prng_no_seed()));
- task_trigger_test_interrupt(my_isr);
- }
+ trigger_interrupt();
+ return CTS_RC_SUCCESS;
}
-static int interrupt_test(void)
+enum cts_rc test_task_disable_irq(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;
+ trigger_interrupt();
+ return CTS_RC_SUCCESS;
}
-static int interrupt_disable_test(void)
+enum cts_rc test_interrupt_enable(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);
+ trigger_interrupt();
+ return CTS_RC_SUCCESS;
+}
- return EC_SUCCESS;
+enum cts_rc test_interrupt_disable(void)
+{
+ trigger_interrupt();
+ return CTS_RC_SUCCESS;
}
+#include "cts_testlist.h"
+
void cts_task(void)
{
- test_reset();
+ enum cts_rc rc;
+ int i;
- RUN_TEST(interrupt_test);
- RUN_TEST(interrupt_disable_test);
+ gpio_set_flags(GPIO_OUTPUT_TEST, GPIO_ODR_HIGH);
- test_print_result();
+ for (i = 0; i < CTS_TEST_ID_COUNT; i++) {
+ gpio_set_level(GPIO_OUTPUT_TEST, 1);
+ sync();
+ rc = tests[i].run();
+ CPRINTF("\n%s %d\n", tests[i].name, rc);
+ cflush();
+ }
+
+ CPRINTS("Interrupt test suite finished");
+ cflush();
+
+ while (1) {
+ watchdog_reload();
+ sleep(1);
+ }
}