Skip to main content

tightbeam/testing/
error.rs

1#[cfg(feature = "derive")]
2use crate::Errorizable;
3
4pub type Result<T> = core::result::Result<T, TestingError>;
5
6/// FDR configuration error details
7#[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/// Schedulability violation details
20#[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		if let Some(u) = self.utilization {
32			write!(f, " (utilization: {u:.3})")?;
33		}
34		if let Some(d) = self.deadline_miss {
35			write!(f, " (deadline miss: {d:?})")?;
36		}
37		Ok(())
38	}
39}
40
41/// Testing error types
42#[cfg_attr(feature = "derive", derive(Errorizable))]
43#[derive(Debug)]
44pub enum TestingError {
45	#[cfg_attr(feature = "derive", error("Fuzz input exhausted"))]
46	FuzzInputExhausted,
47	#[cfg_attr(feature = "derive", error("Fuzz input unavailable"))]
48	FuzzInputUnavailable,
49	#[cfg_attr(feature = "derive", error("Fuzz input lock poisoned"))]
50	FuzzInputLockPoisoned,
51	#[cfg_attr(feature = "derive", error("Invalid timing constraint configuration"))]
52	InvalidTimingConstraint,
53	#[cfg_attr(feature = "derive", error("Slack exceeds deadline duration"))]
54	InvalidSlack,
55	#[cfg_attr(feature = "derive", error("Invalid FDR configuration: {0}"))]
56	InvalidFdrConfig(FdrConfigError),
57	#[cfg_attr(feature = "derive", error("Invalid fault model configuration"))]
58	InvalidFaultModel,
59	#[cfg_attr(feature = "derive", error("Schedulability violation: {0}"))]
60	SchedulabilityViolation(SchedulabilityViolationDetail),
61}
62
63crate::impl_error_display!(TestingError {
64	FuzzInputExhausted => "Fuzz input exhausted",
65	FuzzInputUnavailable => "Fuzz input unavailable",
66	FuzzInputLockPoisoned => "Fuzz input lock poisoned",
67	InvalidTimingConstraint => "Invalid timing constraint configuration",
68	InvalidSlack => "Slack exceeds deadline duration",
69	InvalidFdrConfig(detail) => "Invalid FDR configuration: {detail}",
70	InvalidFaultModel => "Invalid fault model configuration",
71	SchedulabilityViolation(detail) => "Schedulability violation: {detail}",
72});
73
74#[cfg(feature = "std")]
75impl<T> From<std::sync::PoisonError<T>> for TestingError {
76	fn from(_: std::sync::PoisonError<T>) -> Self {
77		TestingError::FuzzInputLockPoisoned
78	}
79}