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
149use std::process::{Child, Command};
use std::sync::RwLock;
use log::error;
use crate::common::{
CheckGroupFileMode, collect_command_to_string, create_new_file_name, create_new_file_name_for_minimization,
try_to_save_file,
};
use crate::settings::{Setting, StabilityMode};
pub static USE_ASAN_ENVS: state::InitCell<RwLock<bool>> = state::InitCell::new();
pub trait ProgramConfig: Sync {
fn get_broken_items_list(&self) -> &[String];
fn get_ignored_items_list(&self) -> &[String];
fn get_minimize_additional_command(&self) -> Option<String> {
None
}
fn is_broken(&self, output: &str, file_content: Option<String>) -> bool;
fn validate_output_and_save_file(&self, full_name: String, output: &str) -> Option<String> {
let new_name = create_new_file_name(self.get_settings(), &full_name);
error!("File {full_name} saved to {new_name}\n{output}");
try_to_save_file(&full_name, &new_name);
Some(new_name)
}
fn get_stability_mode(&self) -> StabilityMode;
fn validate_txt_and_save_file(&self, full_name: String, data: &[String]) -> Option<String> {
let new_name = create_new_file_name(self.get_settings(), &full_name);
let mut diff = match self.get_stability_mode() {
StabilityMode::None => unreachable!(),
StabilityMode::FileContent => "File content between runs differs",
StabilityMode::ConsoleOutput => "Console output between runs differs",
StabilityMode::OutputContent => "Console output or file content between runs differs",
}
.to_string();
for d in data {
diff.push_str(&format!("\n=========================\n{d}"));
}
diff.push_str("\n=========================\n");
error!("File {full_name} saved to {new_name}\n{diff}");
try_to_save_file(&full_name, &new_name);
Some(new_name)
}
// When app crashes, sometimes it not gives any status code
// To be able to ignore certain groups of files, we can use this function
fn ignored_signal_output(&self, _output: &str) -> bool {
false
}
fn get_full_command(&self, full_name: &str) -> Command {
let mut command = self.get_basic_run_command();
command.arg(full_name);
if *USE_ASAN_ENVS.get().read().expect("Failed to get ASAN envs") {
command.envs([
("RUST_BACKTRACE", "1"),
("ASAN_SYMBOLIZER_PATH", "/usr/bin/llvm-symbolizer"),
("ASAN_OPTIONS", "symbolize=1"),
]);
}
command
}
fn get_group_command(&self, files: &[String]) -> Command {
let mut command = self.get_basic_run_command();
command.args(files);
command
}
fn run_command(&self, full_name: &str) -> Child {
self.get_full_command(full_name).spawn().unwrap()
}
fn run_group_command(&self, files: &[String]) -> Child {
self.get_group_command(files).spawn().unwrap()
}
fn get_minimize_command(&self, full_name: &str) -> Command {
let new_full_name = create_new_file_name_for_minimization(self.get_settings(), full_name);
let temp_file_name = "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ";
let run_command = self.get_full_command(temp_file_name);
let mut run_command_as_string = collect_command_to_string(&run_command);
run_command_as_string = run_command_as_string.replace(temp_file_name, "{}");
// minimizer --input-file input.txt --output-file output.txt --command "echo {}" --attempts 300 --broken-info "BROKEN"
let mut minimize_command = Command::new("minimizer");
let broken_info = self
.get_broken_items_list()
.iter()
.flat_map(|e| vec!["--broken-info".to_string(), e.to_string()])
.collect::<Vec<_>>();
let ignored_info = self
.get_ignored_items_list()
.iter()
.flat_map(|e| vec!["--ignored-info".to_string(), e.to_string()])
.collect::<Vec<_>>();
minimize_command.args([
"--input-file",
full_name,
"--output-file",
&new_full_name,
"--command",
&run_command_as_string,
"--attempts",
&self.get_settings().minimization_attempts.to_string(),
// "-v", // Disable verbose flag if not needed
// "-e",
// "-p",
"-t",
&self.get_settings().minimization_time.to_string(),
]);
if self.get_settings().minimization_repeat {
minimize_command.args(["-r"]);
}
if let Some(additional_minimize_command) = self.get_minimize_additional_command() {
minimize_command.args(["--additional-command", &additional_minimize_command]);
}
minimize_command.args(broken_info);
minimize_command.args(ignored_info);
minimize_command
}
fn get_basic_run_command(&self) -> Command;
fn broken_file_creator(&self) -> Child;
fn get_settings(&self) -> &Setting;
fn init(&mut self) {}
fn remove_non_parsable_files(&self, _dir_to_check: &str) {}
// fn is_parsable(&self, _file_to_check: &str) -> bool {
// true
// }
fn get_files_group_mode(&self) -> CheckGroupFileMode {
CheckGroupFileMode::None
}
// fn get_number_of_minimization(&self, output_result: &OutputResult) -> u32 {
// if output_result.is_only_signal_broken() {
// self.get_settings().minimization_attempts_with_signal_timeout
// } else {
// self.get_settings().minimization_attempts
// }
// }
// fn remove_not_needed_lines_from_output(&self, output: String) -> String {
// output
// }
}