Skip to content

Commit 4d4b584

Browse files
committed
Update test framework to rewrite
1 parent c7a5b33 commit 4d4b584

36 files changed

+186
-319
lines changed

.cargo/config.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
[target.x86_64-unknown-uefi]
2-
runner = "cargo run -p runner"
1+
[unstable]
2+
bindeps = true

Cargo.lock

+56-33
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
cargo-features = ["profile-rustflags"]
2+
13
[package]
24
name = "bootloader"
35
version = "0.11.0-alpha.0"
@@ -31,6 +33,13 @@ raw-cpuid = { version = "10.2.0", optional = true }
3133
rand = { version = "0.8.4", optional = true, default-features = false }
3234
rand_chacha = { version = "0.3.1", optional = true, default-features = false }
3335

36+
[dev-dependencies]
37+
bootloader_test_runner = { path = "tests/runner" }
38+
test_kernel_default_settings = { path = "tests/test_kernels/default_settings", artifact = "bin", target = "x86_64-unknown-none" }
39+
test_kernel_higher_half = { path = "tests/test_kernels/higher_half", artifact = "bin", target = "x86_64-unknown-none" }
40+
test_kernel_map_phys_mem = { path = "tests/test_kernels/map_phys_mem", artifact = "bin", target = "x86_64-unknown-none" }
41+
test_kernel_pie = { path = "tests/test_kernels/pie", artifact = "bin", target = "x86_64-unknown-none" }
42+
3443
# [dependencies.bootloader-x86_64-uefi]
3544
# version = "0.1.0"
3645
# path = "uefi"
@@ -55,6 +64,15 @@ codegen-units = 1
5564
debug = false
5665
overflow-checks = false
5766

67+
[profile.test.package.test_kernel_higher_half]
68+
rustflags = [
69+
"-C",
70+
"link-args=--image-base 0xFFFF800000000000",
71+
"-C",
72+
"relocation-model=static", # pic in higher half not supported yet
73+
"-C",
74+
"code-model=large",
75+
]
5876

5977
[package.metadata.docs.rs]
6078
default-target = "x86_64-unknown-linux-gnu"

rust-toolchain.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[toolchain]
22
channel = "nightly"
33
components = ["rustfmt", "clippy", "rust-src", "llvm-tools-preview"]
4+
targets = ["x86_64-unknown-none"]

src/lib.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,13 @@ for all possible configuration options.
6767

6868
#![warn(missing_docs)]
6969

70+
use anyhow::Context;
7071
use std::{
7172
fs::{self, File},
7273
io::{self, Seek},
7374
path::Path,
7475
};
7576

76-
use anyhow::Context;
77-
7877
pub fn create_uefi_disk_image(
7978
kernel_binary: &Path,
8079
out_fat_path: &Path,
@@ -200,8 +199,3 @@ fn create_gpt_disk(fat_image: &Path, out_gpt_path: &Path) {
200199
disk.seek(io::SeekFrom::Start(start_offset)).unwrap();
201200
io::copy(&mut File::open(&fat_image).unwrap(), &mut disk).unwrap();
202201
}
203-
204-
// Provides a function to turn a bootloader executable into a disk image.
205-
//
206-
// Used by the `builder` binary. Only available when the `builder` feature is enabled.
207-
// pub mod disk_image;

tests/default_settings.rs

+10-15
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
1-
use std::process::Command;
1+
use bootloader_test_runner::run_test_kernel;
22

33
#[test]
44
fn basic_boot() {
5-
run_test_binary("basic_boot");
5+
run_test_kernel(env!(
6+
"CARGO_BIN_FILE_TEST_KERNEL_DEFAULT_SETTINGS_basic_boot"
7+
));
68
}
79

810
#[test]
911
fn should_panic() {
10-
run_test_binary("should_panic");
12+
run_test_kernel(env!(
13+
"CARGO_BIN_FILE_TEST_KERNEL_DEFAULT_SETTINGS_should_panic"
14+
));
1115
}
1216

1317
#[test]
1418
fn check_boot_info() {
15-
run_test_binary("check_boot_info");
16-
}
17-
18-
fn run_test_binary(bin_name: &str) {
19-
let mut cmd = Command::new(env!("CARGO"));
20-
cmd.current_dir("tests/test_kernels/default_settings");
21-
cmd.arg("run");
22-
cmd.arg("--bin").arg(bin_name);
23-
cmd.arg("--target").arg("x86_64-default_settings.json");
24-
cmd.arg("-Zbuild-std=core");
25-
cmd.arg("-Zbuild-std-features=compiler-builtins-mem");
26-
assert!(cmd.status().unwrap().success());
19+
run_test_kernel(env!(
20+
"CARGO_BIN_FILE_TEST_KERNEL_DEFAULT_SETTINGS_check_boot_info"
21+
));
2722
}

tests/higher_half.rs

+9-16
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,25 @@
1-
use std::process::Command;
1+
use bootloader_test_runner::run_test_kernel;
22

33
#[test]
44
fn basic_boot() {
5-
run_test_binary("basic_boot");
5+
run_test_kernel(env!("CARGO_BIN_FILE_TEST_KERNEL_HIGHER_HALF_basic_boot"));
66
}
77

88
#[test]
99
fn should_panic() {
10-
run_test_binary("should_panic");
10+
run_test_kernel(env!("CARGO_BIN_FILE_TEST_KERNEL_HIGHER_HALF_should_panic"));
1111
}
1212

1313
#[test]
1414
fn check_boot_info() {
15-
run_test_binary("check_boot_info");
15+
run_test_kernel(env!(
16+
"CARGO_BIN_FILE_TEST_KERNEL_HIGHER_HALF_check_boot_info"
17+
));
1618
}
1719

1820
#[test]
1921
fn verify_higher_half() {
20-
run_test_binary("verify_higher_half");
21-
}
22-
23-
fn run_test_binary(bin_name: &str) {
24-
let mut cmd = Command::new(env!("CARGO"));
25-
cmd.current_dir("tests/test_kernels/higher_half");
26-
cmd.arg("run");
27-
cmd.arg("--bin").arg(bin_name);
28-
cmd.arg("--target").arg("x86_64-higher_half.json");
29-
cmd.arg("-Zbuild-std=core");
30-
cmd.arg("-Zbuild-std-features=compiler-builtins-mem");
31-
assert!(cmd.status().unwrap().success());
22+
run_test_kernel(env!(
23+
"CARGO_BIN_FILE_TEST_KERNEL_HIGHER_HALF_verify_higher_half"
24+
));
3225
}

tests/map_phys_mem.rs

+7-14
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
1-
use std::process::Command;
1+
use bootloader_test_runner::run_test_kernel;
22

33
#[test]
44
fn check_boot_info() {
5-
run_test_binary("check_boot_info");
5+
run_test_kernel(env!(
6+
"CARGO_BIN_FILE_TEST_KERNEL_MAP_PHYS_MEM_check_boot_info"
7+
));
68
}
79

810
#[test]
911
fn access_phys_mem() {
10-
run_test_binary("access_phys_mem");
11-
}
12-
13-
fn run_test_binary(bin_name: &str) {
14-
let mut cmd = Command::new(env!("CARGO"));
15-
cmd.current_dir("tests/test_kernels/map_phys_mem");
16-
cmd.arg("run");
17-
cmd.arg("--bin").arg(bin_name);
18-
cmd.arg("--target").arg("x86_64-map_phys_mem.json");
19-
cmd.arg("-Zbuild-std=core");
20-
cmd.arg("-Zbuild-std-features=compiler-builtins-mem");
21-
assert!(cmd.status().unwrap().success());
12+
run_test_kernel(env!(
13+
"CARGO_BIN_FILE_TEST_KERNEL_MAP_PHYS_MEM_access_phys_mem"
14+
));
2215
}

tests/pie.rs

+5-16
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,21 @@
1-
use std::process::Command;
1+
use bootloader_test_runner::run_test_kernel;
22

33
#[test]
44
fn basic_boot() {
5-
run_test_binary("basic_boot");
5+
run_test_kernel(env!("CARGO_BIN_FILE_TEST_KERNEL_PIE_basic_boot"));
66
}
77

88
#[test]
99
fn should_panic() {
10-
run_test_binary("should_panic");
10+
run_test_kernel(env!("CARGO_BIN_FILE_TEST_KERNEL_PIE_should_panic"));
1111
}
1212

1313
#[test]
1414
fn check_boot_info() {
15-
run_test_binary("check_boot_info");
15+
run_test_kernel(env!("CARGO_BIN_FILE_TEST_KERNEL_PIE_check_boot_info"));
1616
}
1717

1818
#[test]
1919
fn global_variable() {
20-
run_test_binary("global_variable");
21-
}
22-
23-
fn run_test_binary(bin_name: &str) {
24-
let mut cmd = Command::new(env!("CARGO"));
25-
cmd.current_dir("tests/test_kernels/pie");
26-
cmd.arg("run");
27-
cmd.arg("--bin").arg(bin_name);
28-
cmd.arg("--target").arg("x86_64-pie.json");
29-
cmd.arg("-Zbuild-std=core");
30-
cmd.arg("-Zbuild-std-features=compiler-builtins-mem");
31-
assert!(cmd.status().unwrap().success());
20+
run_test_kernel(env!("CARGO_BIN_FILE_TEST_KERNEL_PIE_global_variable"));
3221
}

tests/runner/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[package]
2-
name = "runner"
2+
name = "bootloader_test_runner"
33
version = "0.1.0"
44
authors = ["Philipp Oppermann <[email protected]>"]
55
edition = "2018"
66

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

99
[dependencies]
10-
bootloader-locator = "0.0.4"
11-
locate-cargo-manifest = "0.2.1"
10+
bootloader = { path = "../.." }
11+
strip-ansi-escapes = "0.1.1"

0 commit comments

Comments
 (0)