treeboot_spec/report.rs
1use serde::Serialize;
2
3use crate::{CaseMetadata, CommandReport, ConformanceProfile};
4
5/// Serializable result of one conformance case.
6#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
7pub struct CaseResult {
8 /// Stable case metadata.
9 pub case: CaseMetadata,
10 /// Elapsed case duration in milliseconds.
11 pub duration_ms: u64,
12 /// Case outcome and any diagnostic detail.
13 pub outcome: CaseOutcome,
14}
15
16/// Outcome classification for a conformance case.
17#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
18#[serde(rename_all = "snake_case", tag = "kind")]
19pub enum CaseOutcome {
20 /// The candidate satisfied the case.
21 Passed,
22 /// The candidate produced observable non-conforming behavior.
23 Failed {
24 /// Assertion or behavior failure detail.
25 details: String,
26 },
27 /// The host or runner lacks a required capability.
28 Skipped {
29 /// Explicit platform or capability reason.
30 reason: String,
31 },
32 /// The runner, fixture, or candidate launch failed.
33 Error {
34 /// Execution or fixture failure detail.
35 details: String,
36 },
37 /// A candidate or host-helper invocation exceeded its timeout.
38 TimedOut {
39 /// Timeout detail, including retained partial output when available.
40 details: String,
41 },
42}
43
44impl CaseOutcome {
45 /// Returns whether this outcome establishes that the case passed.
46 pub const fn is_passed(&self) -> bool {
47 matches!(self, Self::Passed)
48 }
49
50 /// Returns whether this outcome is an explicit host or capability skip.
51 pub const fn is_skipped(&self) -> bool {
52 matches!(self, Self::Skipped { .. })
53 }
54}
55
56/// Serializable report for one suite execution.
57#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
58#[non_exhaustive]
59pub struct SuiteReport {
60 /// `treeboot-spec` package version.
61 pub crate_version: &'static str,
62 /// Treeboot specification version exercised by the suite.
63 pub specification_version: &'static str,
64 /// Host platform reported as Rust's operating-system and architecture names.
65 pub host_platform: String,
66 /// Lossy report projection of the native candidate command.
67 pub candidate: CommandReport,
68 /// Ordered case results.
69 pub cases: Vec<CaseResult>,
70 /// Compatibility profile selected for this execution.
71 #[serde(skip)]
72 pub profile: ConformanceProfile,
73 /// Exact-identity cases excluded by the selected profile and case filter.
74 #[serde(skip)]
75 pub omitted_exact_case_count: usize,
76}
77
78impl SuiteReport {
79 /// Returns the compatibility profile selected for this execution.
80 pub const fn profile(&self) -> ConformanceProfile {
81 self.profile
82 }
83
84 /// Returns the number of matching exact-identity cases omitted by the profile.
85 pub const fn omitted_exact_case_count(&self) -> usize {
86 self.omitted_exact_case_count
87 }
88
89 /// Returns true when every executed case passed and all other cases skipped.
90 pub fn passed(&self) -> bool {
91 !self.cases.is_empty()
92 && self
93 .cases
94 .iter()
95 .all(|result| result.outcome.is_passed() || result.outcome.is_skipped())
96 }
97
98 /// Returns the number of passed cases.
99 pub fn passed_count(&self) -> usize {
100 self.cases
101 .iter()
102 .filter(|result| result.outcome.is_passed())
103 .count()
104 }
105
106 /// Returns the number of skipped cases.
107 pub fn skipped_count(&self) -> usize {
108 self.cases
109 .iter()
110 .filter(|result| result.outcome.is_skipped())
111 .count()
112 }
113}