imix/
multi_timer_test.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Licensed under the Apache License, Version 2.0 or the MIT License.
// SPDX-License-Identifier: Apache-2.0 OR MIT
// Copyright Tock Contributors 2022.

//! Test the behavior of a single alarm.
//! To add this test, include the line
//! ```
//!    multi_timer_test::run_multi_timer(alarm);
//! ```
//! to the imix boot sequence, where `alarm` is a
//! `kernel::hil::Alarm`. The test sets up a series of
//! timer of different durations and prints out when
//! they fire.

use kernel::debug;
use kernel::hil::time::Timer;
use kernel::static_init;

use capsules_core::test::random_timer::TestRandomTimer;
use capsules_core::virtualizers::virtual_timer::{MuxTimer, VirtualTimer};
use sam4l::ast::Ast;

pub unsafe fn run_multi_timer(mux: &'static MuxTimer<'static, Ast<'static>>) {
    debug!("Starting multi timer test.");
    let tests: [&'static TestRandomTimer<'static, VirtualTimer<'static, Ast<'static>>>; 3] =
        static_init_multi_timer_test(mux);
    tests[0].run();
    tests[1].run();
    tests[2].run();
}

unsafe fn static_init_multi_timer_test(
    mux: &'static MuxTimer<'static, Ast<'static>>,
) -> [&'static TestRandomTimer<'static, VirtualTimer<'static, Ast<'static>>>; 3] {
    let virtual_timer1 = static_init!(VirtualTimer<'static, Ast<'static>>, VirtualTimer::new(mux));
    virtual_timer1.setup();

    let test1 = static_init!(
        TestRandomTimer<'static, VirtualTimer<'static, Ast<'static>>>,
        TestRandomTimer::new(virtual_timer1, 19, 'A')
    );
    virtual_timer1.set_timer_client(test1);

    let virtual_timer2 = static_init!(VirtualTimer<'static, Ast<'static>>, VirtualTimer::new(mux));
    virtual_timer2.setup();

    let test2 = static_init!(
        TestRandomTimer<'static, VirtualTimer<'static, Ast<'static>>>,
        TestRandomTimer::new(virtual_timer2, 37, 'B')
    );
    virtual_timer2.set_timer_client(test2);

    let virtual_timer3 = static_init!(VirtualTimer<'static, Ast<'static>>, VirtualTimer::new(mux));
    virtual_timer3.setup();

    let test3 = static_init!(
        TestRandomTimer<'static, VirtualTimer<'static, Ast<'static>>>,
        TestRandomTimer::new(virtual_timer3, 89, 'C')
    );
    virtual_timer3.set_timer_client(test3);
    [&*test1, &*test2, &*test3]
}