Skip to content

Commit 0417bbd

Browse files
committed
Allow running tests only with uefi or bios
1 parent fb59bc9 commit 0417bbd

File tree

3 files changed

+34
-20
lines changed

3 files changed

+34
-20
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ bootloader-x86_64-bios-common = { version = "0.11.0", path = "bios/common" }
3939

4040
[features]
4141
default = ["bios", "uefi"]
42-
bios = ["mbrman"]
43-
uefi = ["gpt"]
42+
bios = ["mbrman", "bootloader_test_runner/bios"]
43+
uefi = ["gpt", "bootloader_test_runner/uefi"]
4444

4545
[dependencies]
4646
anyhow = "1.0.32"

tests/runner/Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ edition = "2021"
66

77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

9+
[features]
10+
bios = ["bootloader/bios"]
11+
uefi = ["bootloader/uefi", "ovmf-prebuilt"]
12+
913
[dependencies]
10-
bootloader = { path = "../.." }
14+
bootloader = { path = "../..", default-features = false }
1115
strip-ansi-escapes = "0.1.1"
12-
ovmf-prebuilt = "0.1.0-alpha.1"
16+
ovmf-prebuilt = { version = "0.1.0-alpha.1", optional = true }

tests/runner/src/lib.rs

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,35 @@ const QEMU_ARGS: &[&str] = &[
1313
pub fn run_test_kernel(kernel_binary_path: &str) {
1414
let kernel_path = Path::new(kernel_binary_path);
1515

16-
// create an MBR disk image for legacy BIOS booting
17-
let mbr_path = kernel_path.with_extension("mbr");
18-
bootloader::BiosBoot::new(kernel_path)
19-
.create_disk_image(&mbr_path)
20-
.unwrap();
16+
#[cfg(feature = "uefi")]
17+
{
18+
// create a GPT disk image for UEFI booting
19+
let gpt_path = kernel_path.with_extension("gpt");
20+
let uefi_builder = bootloader::UefiBoot::new(kernel_path);
21+
uefi_builder.create_disk_image(&gpt_path).unwrap();
22+
23+
// create a TFTP folder with the kernel executable and UEFI bootloader for
24+
// UEFI PXE booting
25+
let tftp_path = kernel_path.with_extension(".tftp");
26+
uefi_builder.create_pxe_tftp_folder(&tftp_path).unwrap();
2127

22-
// create a GPT disk image for UEFI booting
23-
let gpt_path = kernel_path.with_extension("gpt");
24-
let uefi_builder = bootloader::UefiBoot::new(kernel_path);
25-
uefi_builder.create_disk_image(&gpt_path).unwrap();
28+
run_test_kernel_on_uefi(&gpt_path);
29+
run_test_kernel_on_uefi_pxe(&tftp_path);
30+
}
2631

27-
// create a TFTP folder with the kernel executable and UEFI bootloader for
28-
// UEFI PXE booting
29-
let tftp_path = kernel_path.with_extension(".tftp");
30-
uefi_builder.create_pxe_tftp_folder(&tftp_path).unwrap();
32+
#[cfg(feature = "bios")]
33+
{
34+
// create an MBR disk image for legacy BIOS booting
35+
let mbr_path = kernel_path.with_extension("mbr");
36+
bootloader::BiosBoot::new(kernel_path)
37+
.create_disk_image(&mbr_path)
38+
.unwrap();
3139

32-
run_test_kernel_on_uefi(&gpt_path);
33-
run_test_kernel_on_bios(&mbr_path);
34-
run_test_kernel_on_uefi_pxe(&tftp_path);
40+
run_test_kernel_on_bios(&mbr_path);
41+
}
3542
}
3643

44+
#[cfg(feature = "uefi")]
3745
pub fn run_test_kernel_on_uefi(out_gpt_path: &Path) {
3846
let mut run_cmd = Command::new("qemu-system-x86_64");
3947
run_cmd
@@ -57,6 +65,7 @@ pub fn run_test_kernel_on_uefi(out_gpt_path: &Path) {
5765
}
5866
}
5967

68+
#[cfg(feature = "bios")]
6069
pub fn run_test_kernel_on_bios(out_mbr_path: &Path) {
6170
let mut run_cmd = Command::new("qemu-system-x86_64");
6271
run_cmd
@@ -79,6 +88,7 @@ pub fn run_test_kernel_on_bios(out_mbr_path: &Path) {
7988
}
8089
}
8190

91+
#[cfg(feature = "uefi")]
8292
pub fn run_test_kernel_on_uefi_pxe(out_tftp_path: &Path) {
8393
let mut run_cmd = Command::new("qemu-system-x86_64");
8494
run_cmd.arg("-netdev").arg(format!(

0 commit comments

Comments
 (0)