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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
use crate::Result as OrigenResult;
use std::fmt;
use std::str::FromStr;
#[derive(Debug, PartialEq, Clone, Eq, Hash, Serialize)]
pub enum SupportedTester {
ALL,
V93K,
V93KSMT7,
V93KSMT8,
IGXL,
J750,
ULTRAFLEX,
SIMULATOR,
DUMMYRENDERER,
DUMMYRENDERERWITHINTERCEPTORS,
CUSTOM(String),
}
impl SupportedTester {
pub fn all_names() -> Vec<String> {
let mut s = vec![
"ALL",
"V93K",
"V93KSMT7",
"V93KSMT8",
"IGXL",
"J750",
"ULTRAFLEX",
"SIMULATOR",
];
if crate::STATUS.is_origen_present {
s.push("DUMMYRENDERER");
s.push("DUMMYRENDERERWITHINTERCEPTORS");
}
let mut s: Vec<String> = s.iter().map(|n| n.to_string()).collect();
for id in crate::STATUS.custom_tester_ids() {
s.push(format!("CUSTOM::{}", id));
}
s
}
pub fn new(name: &str) -> OrigenResult<Self> {
match SupportedTester::from_str(name) {
Ok(n) => Ok(n),
Err(msg) => error!("{}", msg),
}
}
pub fn is_compatible_with(&self, tester: &SupportedTester) -> bool {
self == tester || tester.is_a_derivative_of(self)
}
pub fn is_a_derivative_of(&self, tester: &SupportedTester) -> bool {
match self {
SupportedTester::ALL => tester != &SupportedTester::ALL,
SupportedTester::IGXL => {
tester == &SupportedTester::J750 || tester == &SupportedTester::ULTRAFLEX
}
SupportedTester::V93K => {
tester == &SupportedTester::V93KSMT7 || tester == &SupportedTester::V93KSMT8
}
_ => false,
}
}
}
impl FromStr for SupportedTester {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let mut second: Option<String> = None;
let kind = match s.contains("::") {
true => {
let fields: Vec<&str> = s.split("::").collect();
if fields.len() > 2 {
return Err(error_msg(&s));
}
second = Some(fields[1].to_string());
fields[0]
}
false => s,
};
let kind = kind.to_uppercase().replace("_", "");
match kind.trim() {
"ALL" | "ANY" => Ok(SupportedTester::ALL),
"V93K" => Ok(SupportedTester::V93K),
"V93KSMT7" => Ok(SupportedTester::V93KSMT7),
"V93KSMT8" => Ok(SupportedTester::V93KSMT8),
"IGXL" => Ok(SupportedTester::IGXL),
"J750" => Ok(SupportedTester::J750),
"ULTRAFLEX" | "UFLEX" => Ok(SupportedTester::ULTRAFLEX),
"SIMULATOR" => Ok(SupportedTester::SIMULATOR),
"DUMMYRENDERER" => Ok(SupportedTester::DUMMYRENDERER),
"DUMMYRENDERERWITHINTERCEPTORS" => Ok(SupportedTester::DUMMYRENDERERWITHINTERCEPTORS),
"CUSTOM" => {
if let Some(n) = second {
if crate::STATUS.custom_tester_ids().contains(&n) {
Ok(SupportedTester::CUSTOM(n))
} else {
Err(error_msg(&s))
}
} else {
Err(error_msg(&s))
}
}
_ => Err(error_msg(&s)),
}
}
}
impl fmt::Display for SupportedTester {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", self)
}
}
fn error_msg(val: &str) -> String {
format!(
"'{}' is not a valid tester type, the available testers are: {}",
val,
SupportedTester::all_names().join(", ")
)
}
#[cfg(test)]
mod tests {
use super::*;
use std::collections::HashMap;
#[test]
fn verify_custom_testers_work_as_hash_keys() {
let mut h: HashMap<SupportedTester, usize> = HashMap::new();
let t1 = SupportedTester::J750;
let t2 = SupportedTester::CUSTOM("t2".to_string());
let t3 = SupportedTester::CUSTOM("t3".to_string());
h.insert(t1.clone(), 1);
h.insert(t2.clone(), 2);
h.insert(t3.clone(), 3);
assert_eq!(h[&t1], 1);
assert_eq!(h[&t2], 2);
assert_eq!(h[&t3], 3);
}
}