imix/alarm_test.rs
1// Licensed under the Apache License, Version 2.0 or the MIT License.
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3// Copyright Tock Contributors 2022.
4
5//! Test the behavior of a single alarm.
6//! To add this test, include the line
7//! ```
8//! alarm_test::run_alarm(alarm);
9//! ```
10//! to the imix boot sequence, where `alarm` is a
11//! `kernel::hil::Alarm`. The test sets up a series of
12//! alarms of different durations and prints out when
13//! they fire. They are large enough (and spaced out
14//! enough that you should be able to tell if things
15//! are working reasonably well. The module also uses
16//! debug_gpio on pin XX so you can more precisely check
17//! the timings with a logic analyzer.
18
19use capsules_core::test::alarm_edge_cases::TestAlarmEdgeCases;
20use kernel::debug;
21use kernel::hil::time::Alarm;
22use kernel::static_init;
23use sam4l::ast::Ast;
24
25pub unsafe fn run_alarm(ast: &'static Ast) {
26 debug!("Starting alarm test.");
27 let test = static_init_alarm_test(ast);
28 test.run();
29}
30
31unsafe fn static_init_alarm_test(
32 ast: &'static Ast,
33) -> &'static TestAlarmEdgeCases<'static, Ast<'static>> {
34 let test = static_init!(
35 TestAlarmEdgeCases<'static, Ast<'static>>,
36 TestAlarmEdgeCases::new(ast)
37 );
38 ast.set_alarm_client(test);
39 test
40}