Skip to content

Commit 4c3bca0

Browse files
committed
Make test_timeout configurable
1 parent 9287964 commit 4c3bca0

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

Readme.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,15 @@ Configuration is done through a through a `[package.metadata.bootimage]` table i
3535

3636
```toml
3737
[package.metadata.bootimage]
38-
default-target = "" # This target is used if no `--target` is passed
38+
# This target is used if no `--target` is passed
39+
default-target = ""
40+
3941
# The command invoked on `bootimage run`
4042
# (the "{}" will be replaced with the path to the bootable disk image)
4143
run-command = ["qemu-system-x86_64", "-drive", "format=raw,file={}"]
44+
45+
# The timeout for running an integration test in seconds
46+
test-timeout = 300
4247
```
4348

4449
## License

src/config.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub struct Config {
77
pub manifest_path: PathBuf,
88
pub default_target: Option<String>,
99
pub run_command: Vec<String>,
10+
pub test_timeout: u64,
1011
}
1112

1213
pub(crate) fn read_config(manifest_path: PathBuf) -> Result<Config, ErrorString> {
@@ -16,7 +17,7 @@ pub(crate) fn read_config(manifest_path: PathBuf) -> Result<Config, ErrorString>
1617
}
1718

1819
pub(crate) fn read_config_inner(manifest_path: PathBuf) -> Result<Config, ErrorString> {
19-
use std::{fs::File, io::Read};
20+
use std::{convert::TryFrom, fs::File, io::Read};
2021
let cargo_toml: Value = {
2122
let mut content = String::new();
2223
File::open(&manifest_path)
@@ -53,6 +54,11 @@ pub(crate) fn read_config_inner(manifest_path: PathBuf) -> Result<Config, ErrorS
5354
for (key, value) in metadata {
5455
match (key.as_str(), value.clone()) {
5556
("default-target", Value::String(s)) => config.default_target = From::from(s),
57+
("test-timeout", Value::Integer(s)) => {
58+
config.test_timeout = u64::try_from(s)
59+
.map_err(|err| format!("test-timeout is not valid: {}", err))?
60+
.into()
61+
}
5662
("run-command", Value::Array(array)) => {
5763
let mut command = Vec::new();
5864
for value in array {
@@ -78,6 +84,7 @@ struct ConfigBuilder {
7884
manifest_path: Option<PathBuf>,
7985
default_target: Option<String>,
8086
run_command: Option<Vec<String>>,
87+
test_timeout: Option<u64>,
8188
}
8289

8390
impl Into<Config> for ConfigBuilder {
@@ -90,6 +97,7 @@ impl Into<Config> for ConfigBuilder {
9097
"-drive".into(),
9198
"format=raw,file={}".into(),
9299
]),
100+
test_timeout: self.test_timeout.unwrap_or(60 * 5),
93101
}
94102
}
95103
}

src/help/test_help.txt

+9
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,12 @@ USAGE:
1515

1616
(for other forms of usage see `bootimage --help`)
1717
(for BUILD_OPTS see `bootimage build --help`)
18+
19+
CONFIGURATION:
20+
The behavior of `bootimage test` can be configured through a
21+
`[package.metadata.bootimage]` table in the `Cargo.toml`. The
22+
following options are available to configure test behavior:
23+
24+
[package.metadata.bootimage]
25+
# The timeout for running an integration test in seconds
26+
test-timeout = 300

src/subcommand/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub(crate) fn test(mut args: Args) -> Result<(), ErrorString> {
5050
let mut child = command
5151
.spawn()
5252
.map_err(|e| format!("Failed to launch QEMU: {:?}\n{}", command, e))?;
53-
let timeout = Duration::from_secs(60 * 5);
53+
let timeout = Duration::from_secs(config.test_timeout);
5454
match child
5555
.wait_timeout(timeout)
5656
.map_err(|e| format!("Failed to wait with timeout: {}", e))?

0 commit comments

Comments
 (0)