tightbeam/testing/
error.rs1#[cfg(feature = "derive")]
2use crate::Errorizable;
3
4pub type Result<T> = core::result::Result<T, TestingError>;
5
6#[derive(Debug, Clone, PartialEq, Eq)]
8pub struct FdrConfigError {
9 pub field: &'static str,
10 pub reason: &'static str,
11}
12
13impl core::fmt::Display for FdrConfigError {
14 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
15 write!(f, "Invalid FDR config field '{}': {}", self.field, self.reason)
16 }
17}
18
19#[derive(Debug, Clone, PartialEq)]
21pub struct SchedulabilityViolationDetail {
22 pub task_id: &'static str,
23 pub message: &'static str,
24 pub utilization: Option<f64>,
25 pub deadline_miss: Option<core::time::Duration>,
26}
27
28impl core::fmt::Display for SchedulabilityViolationDetail {
29 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
30 write!(f, "Task '{}': {}", self.task_id, self.message)?;
31
32 if let Some(u) = self.utilization {
33 write!(f, " (utilization: {u:.3})")?;
34 }
35 if let Some(d) = self.deadline_miss {
36 write!(f, " (deadline miss: {d:?})")?;
37 }
38
39 Ok(())
40 }
41}
42
43#[cfg_attr(feature = "derive", derive(Errorizable))]
45#[derive(Debug)]
46pub enum TestingError {
47 #[cfg_attr(feature = "derive", error("Fuzz input exhausted"))]
48 FuzzInputExhausted,
49 #[cfg_attr(feature = "derive", error("Fuzz oracle deadlock in state {0}"))]
50 FuzzDeadlock(&'static str),
51 #[cfg_attr(feature = "derive", error("Fuzz oracle rejected event {0}"))]
52 FuzzEventRejected(&'static str),
53 #[cfg_attr(feature = "derive", error("Fuzz input unavailable"))]
54 FuzzInputUnavailable,
55 #[cfg_attr(feature = "derive", error("Fuzz input lock poisoned"))]
56 FuzzInputLockPoisoned,
57 #[cfg_attr(feature = "derive", error("Invalid timing constraint configuration"))]
58 InvalidTimingConstraint,
59 #[cfg_attr(feature = "derive", error("Slack exceeds deadline duration"))]
60 InvalidSlack,
61 #[cfg_attr(feature = "derive", error("Invalid FDR configuration: {0}"))]
62 InvalidFdrConfig(FdrConfigError),
63 #[cfg_attr(feature = "derive", error("Invalid fault model configuration"))]
64 InvalidFaultModel,
65 #[cfg_attr(feature = "derive", error("Schedulability violation: {0}"))]
66 SchedulabilityViolation(SchedulabilityViolationDetail),
67 #[cfg_attr(feature = "derive", error("Invariant violated"))]
68 InvariantViolated,
69}
70
71crate::impl_error_display!(TestingError {
72 FuzzInputExhausted => "Fuzz input exhausted",
73 FuzzDeadlock(state) => "Fuzz oracle deadlock in state {state}",
74 FuzzEventRejected(event) => "Fuzz oracle rejected event {event}",
75 FuzzInputUnavailable => "Fuzz input unavailable",
76 FuzzInputLockPoisoned => "Fuzz input lock poisoned",
77 InvalidTimingConstraint => "Invalid timing constraint configuration",
78 InvalidSlack => "Slack exceeds deadline duration",
79 InvalidFdrConfig(detail) => "Invalid FDR configuration: {detail}",
80 InvalidFaultModel => "Invalid fault model configuration",
81 SchedulabilityViolation(detail) => "Schedulability violation: {detail}",
82 InvariantViolated => "Invariant violated",
83});
84
85#[cfg(feature = "std")]
86impl<T> From<std::sync::PoisonError<T>> for TestingError {
87 fn from(_: std::sync::PoisonError<T>) -> Self {
88 TestingError::FuzzInputLockPoisoned
89 }
90}