-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpasses.rs
201 lines (173 loc) · 5.68 KB
/
passes.rs
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
mod ast_export;
mod blake3;
mod gccrs_parsing;
mod gccrs_rustc_successes;
mod libcore;
mod rustc_dejagnu;
pub use ast_export::AstExport;
pub use blake3::Blake3;
pub use gccrs_parsing::GccrsParsing;
pub use gccrs_rustc_successes::GccrsRustcSuccesses;
pub use libcore::LibCore;
pub use rustc_dejagnu::RustcDejagnu;
use std::ffi::OsStr;
use std::fmt::Display;
use std::path::{Path, PathBuf};
use crate::compiler::Compiler;
use crate::{args::Args, error::Error};
/// Wrapper struct around an ftf test case. Ideally, this should be provided
/// directly by the ftf crate
#[derive(Debug)]
pub enum TestCase {
Test {
name: String,
binary: String,
exit_code: u8,
timeout: i32,
stderr: String,
stdout: String,
args: Vec<String>,
},
Skip,
}
impl Default for TestCase {
fn default() -> Self {
TestCase::Test {
name: String::new(),
binary: String::new(),
exit_code: 0u8,
// FIXME: Use duration here (#10)
timeout: Self::DEFAULT_TIMEOUT,
stderr: String::new(),
stdout: String::new(),
args: vec![],
}
}
}
impl TestCase {
const DEFAULT_TIMEOUT: i32 = 15; // default timeout is 15 minutes
pub fn from_compiler(mut compiler: Compiler) -> TestCase {
let cmd = compiler.command();
TestCase::default()
.with_binary(cmd.get_program().to_string_lossy().to_string())
.with_args(cmd.get_args().map(OsStr::to_string_lossy))
}
pub fn with_exit_code(mut self, new_exit_code: u8) -> TestCase {
if let TestCase::Test {
ref mut exit_code, ..
} = self
{
*exit_code = new_exit_code;
}
self
}
pub fn with_timeout(mut self, new_timeout: i32) -> TestCase {
if let TestCase::Test {
ref mut timeout, ..
} = self
{
*timeout = new_timeout;
}
self
}
pub fn with_name(mut self, new_name: String) -> TestCase {
if let TestCase::Test { ref mut name, .. } = self {
*name = new_name;
}
self
}
pub fn with_arg<T: Display>(mut self, arg: T) -> TestCase {
if let TestCase::Test { ref mut args, .. } = self {
args.push(arg.to_string());
}
self
}
pub fn with_args<T: Display>(self, args: impl Iterator<Item = T>) -> TestCase {
args.fold(self, TestCase::with_arg)
}
pub fn with_binary<T: Display>(mut self, new_binary: T) -> TestCase {
if let TestCase::Test { ref mut binary, .. } = self {
*binary = new_binary.to_string();
}
self
}
}
impl Display for TestCase {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
TestCase::Skip => Ok(()),
TestCase::Test {
name,
binary,
exit_code,
timeout,
stderr,
stdout,
args,
} => {
writeln!(f, " - name: {name}")?;
writeln!(f, " binary: {binary}")?;
writeln!(f, " timeout: {timeout}")?;
writeln!(f, " exit_code: {exit_code}")?;
writeln!(f, " stdout: \"{stdout}\"")?;
writeln!(f, " stderr: \"{stderr}\"")?;
writeln!(f, " args:")?;
for arg in args {
writeln!(f, " - \"{arg}\"")?;
}
Ok(())
}
}
}
}
pub trait Pass: Sync {
/// Fetch test cases
fn fetch(&self, args: &Args) -> Result<Vec<PathBuf>, Error>;
/// Adapt test cases, running any kind of transformation on them and providing
/// extra information necessary for the test case generation
fn adapt(&self, args: &Args, file: &Path) -> Result<TestCase, Error>;
}
/// Passes to run when generating the test-suite file. One can chose to run only
/// a specific pass, or multiple of them
#[derive(Clone, Copy, clap::ValueEnum)]
pub enum PassKind {
/// Generates test cases for running gccrs and rustc in parse-only mode on
/// the rustc test suite
GccrsParsing,
/// Generates test cases for running rustc on gccrs' test-suite
RustcDejagnu,
/// Testsuite for running gccrs on valid rustc test cases
GccrsRustcSucess,
/// Testsuite for running gccrs on valid rustc test cases in #![no_std] mode
GccrsRustcSucessNoStd,
/// Testsuite for running gccrs on valid rustc test cases in #![no_core] mode
GccrsRustcSucessNoCore,
/// Compile the reference implementation of the Blake3 cryptographic algorithm
Blake3,
/// Compile the core library from various rust versions
LibCore,
/// Test our AST exporting algorithm on the whole gccrs testsuite
AstExport,
}
#[derive(Debug)]
pub struct InvalidPassKind(String);
impl Display for InvalidPassKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "invalid pass name provided: {}", self.0)
}
}
impl Display for PassKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let s = match &self {
PassKind::GccrsParsing => "gccrs-parsing",
PassKind::RustcDejagnu => "rustc-dejagnu",
PassKind::GccrsRustcSucess => "gccrs-rustc-success",
PassKind::GccrsRustcSucessNoStd => "gccrs-rustc-success-no-std",
PassKind::GccrsRustcSucessNoCore => "gccrs-rustc-success-no-core",
PassKind::Blake3 => "blake3",
PassKind::LibCore => "libcore",
PassKind::AstExport => "ast-export",
};
write!(f, "{s}")
}
}