deqp_runner/
test_status.rs

1use std::{str::FromStr, time::Duration};
2
3/// Enum for the basic types of test result that we track
4#[derive(Clone, Copy, Debug, PartialEq, Eq)]
5pub enum TestStatus {
6    Pass,
7    Fail,
8    Warn,
9    Skip,
10    Crash,
11    Timeout,
12}
13
14impl std::fmt::Display for TestStatus {
15    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
16        write!(f, "{:?}", self)
17    }
18}
19
20impl FromStr for TestStatus {
21    type Err = anyhow::Error;
22
23    // Parses the status name from dEQP's output.
24    fn from_str(input: &str) -> Result<TestStatus, Self::Err> {
25        match input {
26            "Pass" => Ok(TestStatus::Pass),
27            "Fail" => Ok(TestStatus::Fail),
28            "Skip" => Ok(TestStatus::Skip),
29            "Warn" => Ok(TestStatus::Warn),
30            "Crash" => Ok(TestStatus::Crash),
31            "Timeout" => Ok(TestStatus::Timeout),
32            _ => anyhow::bail!("unknown test status '{}'", input),
33        }
34    }
35}
36
37/// A test result entry in a CaselistResult from running a group of tests
38#[derive(Debug)]
39pub struct TestResult {
40    pub name: String,
41    pub status: TestStatus,
42    pub duration: Duration,
43    pub subtests: Vec<TestResult>,
44}
45
46/// The collection of results from invoking a binary to run a bunch of tests (or
47/// parsing an old results.csv back off disk).
48#[derive(Debug)]
49pub struct CaselistResult {
50    pub results: Vec<TestResult>,
51    pub stdout: Vec<String>,
52}
53
54// For comparing equality, we ignore the test runtime (particularly of use for the unit tests )
55impl PartialEq for TestResult {
56    fn eq(&self, other: &Self) -> bool {
57        self.name == other.name && self.status == other.status && self.subtests == other.subtests
58    }
59}
60
61// For comparing equality, we ignore the test runtime (particularly of use for the unit tests )
62impl PartialEq for CaselistResult {
63    fn eq(&self, other: &Self) -> bool {
64        self.results == other.results && self.stdout == other.stdout
65    }
66}
67
68#[cfg(test)]
69mod tests {
70    use super::*;
71    #[test]
72    fn test_status_display() {
73        assert_eq!(format!("{}", TestStatus::Pass), "Pass".to_owned());
74    }
75    #[test]
76    fn test_status_parse() {
77        assert_eq!(
78            "Warn".parse::<TestStatus>().expect("parsing"),
79            TestStatus::Warn
80        );
81    }
82}