imix/test/
virtual_uart_rx_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 reception on the virtualized UART by creating two readers that
6//! read in parallel. To add this test, include the line
7//! ```
8//!    virtual_uart_rx_test::run_virtual_uart_receive(uart_mux);
9//! ```
10//! to the imix boot sequence, where `uart_mux` is a
11//! `capsules_core::virtualizers::virtual_uart::MuxUart`.  There is a 3-byte and a 7-byte
12//! read running in parallel. Test that they are both working by typing
13//! and seeing that they both get all characters. If you repeatedly
14//! type 'a', for example (0x61), you should see something like:
15//! ```
16//! Starting receive of length 3
17//! Virtual uart read complete: CommandComplete:
18//! 61
19//! 61
20//! 61
21//! 61
22//! 61
23//! 61
24//! 61
25//! Starting receive of length 7
26//! Virtual uart read complete: CommandComplete:
27//! 61
28//! 61
29//! 61
30//! Starting receive of length 3
31//! Virtual uart read complete: CommandComplete:
32//! 61
33//! 61
34//! 61
35//! Starting receive of length 3
36//! Virtual uart read complete: CommandComplete:
37//! 61
38//! 61
39//! 61
40//! 61
41//! 61
42//! 61
43//! 61
44//! Starting receive of length 7
45//! Virtual uart read complete: CommandComplete:
46//! 61
47//! 61
48//! 61
49//! ```
50
51use core::ptr::addr_of_mut;
52
53use capsules_core::test::virtual_uart::TestVirtualUartReceive;
54use capsules_core::virtualizers::virtual_uart::{MuxUart, UartDevice};
55use kernel::debug;
56use kernel::hil::uart::Receive;
57use kernel::static_init;
58
59pub unsafe fn run_virtual_uart_receive(mux: &'static MuxUart<'static>) {
60    debug!("Starting virtual reads.");
61    let small = static_init_test_receive_small(mux);
62    let large = static_init_test_receive_large(mux);
63    small.run();
64    large.run();
65}
66
67unsafe fn static_init_test_receive_small(
68    mux: &'static MuxUart<'static>,
69) -> &'static TestVirtualUartReceive {
70    static mut SMALL: [u8; 3] = [0; 3];
71    let device = static_init!(UartDevice<'static>, UartDevice::new(mux, true));
72    device.setup();
73    let test = static_init!(
74        TestVirtualUartReceive,
75        TestVirtualUartReceive::new(device, &mut *addr_of_mut!(SMALL))
76    );
77    device.set_receive_client(test);
78    test
79}
80
81unsafe fn static_init_test_receive_large(
82    mux: &'static MuxUart<'static>,
83) -> &'static TestVirtualUartReceive {
84    static mut BUFFER: [u8; 7] = [0; 7];
85    let device = static_init!(UartDevice<'static>, UartDevice::new(mux, true));
86    device.setup();
87    let test = static_init!(
88        TestVirtualUartReceive,
89        TestVirtualUartReceive::new(device, &mut *addr_of_mut!(BUFFER))
90    );
91    device.set_receive_client(test);
92    test
93}