Skip to content

Commit 615f70c

Browse files
savente93ehuss
authored andcommitted
add timeout functionality for bisecting hangs using the GNU coreutils timeout
1 parent 63a18d8 commit 615f70c

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

Diff for: src/main.rs

+7
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ struct Opts {
114114
)]
115115
prompt: bool,
116116

117+
#[structopt(
118+
long = "timeout",
119+
short = "t",
120+
help = "Assume failure after specified number of seconds (for bisecting hangs)"
121+
)]
122+
timeout: Option<usize>,
123+
117124
#[structopt(short = "v", long = "verbose", parse(from_occurrences))]
118125
verbosity: usize,
119126

Diff for: src/toolchains.rs

+32-3
Original file line numberDiff line numberDiff line change
@@ -317,14 +317,15 @@ impl Toolchain {
317317
.join(&format!("target-{}", self.rustup_name())),
318318
);
319319
}
320-
let mut cmd = match cfg.args.script {
321-
Some(ref script) => {
320+
321+
let mut cmd = match (cfg.args.script.as_ref(), cfg.args.timeout) {
322+
(Some(script), None) => {
322323
let mut cmd = Command::new(script);
323324
cmd.env("RUSTUP_TOOLCHAIN", self.rustup_name());
324325
cmd.args(&cfg.args.command_args);
325326
cmd
326327
}
327-
None => {
328+
(None, None) => {
328329
let mut cmd = Command::new("cargo");
329330
cmd.arg(&format!("+{}", self.rustup_name()));
330331
if cfg.args.command_args.is_empty() {
@@ -334,6 +335,26 @@ impl Toolchain {
334335
}
335336
cmd
336337
}
338+
(Some(script), Some(timeout)) => {
339+
let mut cmd = Command::new("timeout");
340+
cmd.arg(timeout.to_string());
341+
cmd.arg(script);
342+
cmd.args(&cfg.args.command_args);
343+
cmd.env("RUSTUP_TOOLCHAIN", self.rustup_name());
344+
cmd
345+
}
346+
(None, Some(timeout)) => {
347+
let mut cmd = Command::new("timeout");
348+
cmd.arg(timeout.to_string());
349+
cmd.arg("cargo");
350+
cmd.arg(format!("+{}", self.rustup_name()));
351+
if cfg.args.command_args.is_empty() {
352+
cmd.arg("build");
353+
} else {
354+
cmd.args(&cfg.args.command_args);
355+
}
356+
cmd
357+
}
337358
};
338359
cmd.current_dir(&cfg.args.test_dir);
339360
cmd.env("CARGO_TARGET_DIR", format!("target-{}", self.rustup_name()));
@@ -377,6 +398,14 @@ impl Toolchain {
377398
let output = self.run_test(cfg);
378399
let status = output.status;
379400

401+
//timeout returns exit code 124 on expiration
402+
if status.code() == Some(124) {
403+
match cfg.args.timeout {
404+
Some(_) => break TestOutcome::Regressed,
405+
None => panic!("Process timed out but no timeout was specified. Please check host configuration for timeouts and try again.")
406+
}
407+
}
408+
380409
eprintln!("\n\n{} finished with exit code {:?}.", self, status.code());
381410
eprintln!("please select an action to take:");
382411

0 commit comments

Comments
 (0)