aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/dma/ringbuffer/tests/prop_test/mod.rs
blob: eff5b40581d3c884bf51974a07a4190db6f7ba85 (plain)
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
use std::task::Waker;

use proptest::prop_oneof;
use proptest::strategy::{self, BoxedStrategy, Strategy as _};
use proptest_state_machine::{ReferenceStateMachine, StateMachineTest, prop_state_machine};

use super::*;

const CAP: usize = 128;

#[derive(Debug, Default)]
struct DmaMock {
    pos: usize,
    wraps: usize,
}

impl DmaMock {
    pub fn advance(&mut self, steps: usize) {
        let next = self.pos + steps;
        self.pos = next % CAP;
        self.wraps += next / CAP;
    }
}

impl DmaCtrl for DmaMock {
    fn get_remaining_transfers(&self) -> usize {
        CAP - self.pos
    }

    fn reset_complete_count(&mut self) -> usize {
        core::mem::replace(&mut self.wraps, 0)
    }

    fn set_waker(&mut self, _waker: &Waker) {}
}

#[derive(Debug, Clone)]
enum Status {
    Available(usize),
    Failed,
}

impl Status {
    pub fn new(capacity: usize) -> Self {
        Self::Available(capacity)
    }
}

mod reader;
mod writer;