Skip to content

Commit 109b76a

Browse files
authored
Merge pull request #36 from rust-osdev/updates
New features for `bootimage runner`
2 parents 34aaec2 + 2dc7bb3 commit 109b76a

File tree

21 files changed

+429
-82
lines changed

21 files changed

+429
-82
lines changed

Changelog.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
2+
- New features for `bootimage runner`
3+
- Pass additional arguments to the run command (e.g. QEMU)
4+
- Consider all binaries in the `target/deps` folder as test executables
5+
- Apply `test-timeout` config key when running tests in `bootimage runner`
6+
- Don't apply `run-args` for test executables
7+
- Add a new `test-args` config key for test arguments
8+
- Add a new `test-success-exit-code` config key for interpreting an exit code as success
9+
- This is useful when the `isa-debug-exit` QEMU device is used.
10+
- Improve printing of the run command (print string instead of array, print non-canonicalized executable path, respect `--quiet`)
11+
112
# 0.7.1
213

314
- Fix for backwards compatibility: Ignore `test-` executables for `bootimage run`.

Readme.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,23 @@ Configuration is done through a through a `[package.metadata.bootimage]` table i
6767
# This target is used if no `--target` is passed
6868
default-target = ""
6969

70-
# The command invoked on `bootimage run` or `bootimage runner`
71-
# (the "{}" will be replaced with the path to the bootable disk image)
70+
# The command invoked with the created bootimage (the "{}" will be replaced
71+
# with the path to the bootable disk image)
72+
# Applies to `bootimage run` and `bootimage runner`
7273
run-command = ["qemu-system-x86_64", "-drive", "format=raw,file={}"]
7374

74-
# Additional arguments passed to the runner on `bootimage run` or `bootimage runner`
75-
# (this is useful when you want to add some arguments to the default QEMU command)
75+
# Additional arguments passed to the run command for non-test executables
76+
# Applies to `bootimage run` and `bootimage runner`
7677
run-args = []
7778

78-
# The timeout for running an integration test through `bootimage test` in seconds
79+
# Additional arguments passed to the run command for test executables
80+
# Applies to `bootimage runner`
81+
test-args = []
82+
83+
# An exit code that should be considered as success for test executables
84+
test-success-exit-code = {integer}
85+
86+
# The timeout for running a test through `bootimage test` or `bootimage runner` (in seconds)
7987
test-timeout = 300
8088
```
8189

azure-pipelines.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,52 @@ jobs:
198198
if [ $? -eq 109 ]; then (exit 0); else (exit 1); fi
199199
workingDirectory: example-kernels/runner
200200
displayName: 'Run `cargo xrun` for "runner" kernel'
201+
202+
- script: cargo xtest
203+
workingDirectory: example-kernels/runner-test
204+
displayName: 'Run `cargo xtest` for "runner-test" kernel'
205+
206+
- job: formatting
207+
displayName: Check Formatting
208+
209+
strategy:
210+
matrix:
211+
linux:
212+
image_name: 'ubuntu-16.04'
213+
rustup_toolchain: stable
214+
215+
pool:
216+
vmImage: $(image_name)
217+
218+
steps:
219+
- bash: |
220+
echo "Hello world from $AGENT_NAME running on $AGENT_OS"
221+
echo "Reason: $BUILD_REASON"
222+
case "$BUILD_REASON" in
223+
"Manual") echo "$BUILD_REQUESTEDFOR manually queued the build." ;;
224+
"PullRequest") echo "This is a CI build for a pull request on $BUILD_REQUESTEDFOR." ;;
225+
"IndividualCI") echo "This is a CI build for $BUILD_REQUESTEDFOR." ;;
226+
"BatchedCI") echo "This is a batched CI build for $BUILD_REQUESTEDFOR." ;;
227+
*) "$BUILD_REASON" ;;
228+
esac
229+
displayName: 'Build Info'
230+
continueOnError: true
231+
232+
- script: |
233+
set -euxo pipefail
234+
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain $RUSTUP_TOOLCHAIN
235+
echo "##vso[task.setvariable variable=PATH;]$PATH:$HOME/.cargo/bin"
236+
condition: or(eq( variables['Agent.OS'], 'Linux' ), eq( variables['Agent.OS'], 'Darwin' ))
237+
displayName: 'Install Rust'
238+
239+
- script: |
240+
rustc -Vv
241+
cargo -V
242+
displayName: 'Print Rust Version'
243+
continueOnError: true
244+
245+
- script: rustup component add rustfmt
246+
displayName: 'Install Rustfmt'
247+
248+
- script: cargo fmt -- --check
249+
displayName: 'Check Formatting'

example-kernels/Cargo.lock

Lines changed: 31 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example-kernels/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ members = [
44
"default-target-bootimage",
55
"default-target-cargo",
66
"runner",
7+
"runner-test",
78
"testing-qemu-exit-code",
89
"testing-serial-result",
910
]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[build]
2+
target = "../x86_64-bootimage-example-kernels.json"
3+
4+
[target.'cfg(target_os = "none")']
5+
runner = "bootimage runner"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target/
2+
**/*.rs.bk
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "runner-test"
3+
version = "0.1.0"
4+
authors = ["Philipp Oppermann <[email protected]>"]
5+
edition = "2018"
6+
7+
[[test]]
8+
name = "no-harness"
9+
harness = false
10+
11+
[dependencies]
12+
bootloader = "0.5.1"
13+
x86_64 = "0.5.3"
14+
15+
[package.metadata.bootimage]
16+
test-success-exit-code = 33 # (0x10 << 1) | 1
17+
test-args = ["-device", "isa-debug-exit,iobase=0xf4,iosize=0x04", "-display", "none"]
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#![no_std]
2+
#![cfg_attr(test, no_main)]
3+
4+
#![feature(custom_test_frameworks)]
5+
#![test_runner(crate::test_runner)]
6+
#![reexport_test_harness_main = "test_main"]
7+
8+
pub fn test_runner(tests: &[&dyn Fn()]) {
9+
for test in tests.iter() {
10+
test();
11+
}
12+
13+
unsafe { exit_qemu(ExitCode::Success); }
14+
}
15+
16+
#[test_case]
17+
fn test1() {
18+
assert_eq!(0, 0);
19+
}
20+
21+
#[test_case]
22+
fn test2() {
23+
assert_eq!(1, 1);
24+
}
25+
26+
pub enum ExitCode {
27+
Success,
28+
Failed
29+
}
30+
31+
impl ExitCode {
32+
fn code(&self) -> u32 {
33+
match self {
34+
ExitCode::Success => 0x10,
35+
ExitCode::Failed => 0x11,
36+
}
37+
}
38+
}
39+
40+
/// exit QEMU (see https://os.phil-opp.com/integration-tests/#shutting-down-qemu)
41+
pub unsafe fn exit_qemu(exit_code: ExitCode) {
42+
use x86_64::instructions::port::Port;
43+
44+
let mut port = Port::<u32>::new(0xf4);
45+
port.write(exit_code.code());
46+
}
47+
48+
#[cfg(test)]
49+
#[no_mangle]
50+
pub extern "C" fn _start() -> ! {
51+
test_main();
52+
53+
unsafe { exit_qemu(ExitCode::Failed); }
54+
55+
loop {}
56+
}
57+
58+
#[cfg(test)]
59+
#[panic_handler]
60+
fn panic(_info: &core::panic::PanicInfo) -> ! {
61+
unsafe { exit_qemu(ExitCode::Failed); }
62+
loop {}
63+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#![no_std]
2+
#![no_main]
3+
4+
#![feature(custom_test_frameworks)]
5+
#![test_runner(runner_test::test_runner)]
6+
#![reexport_test_harness_main = "test_main"]
7+
8+
use core::panic::PanicInfo;
9+
use runner_test::{exit_qemu, ExitCode};
10+
11+
#[no_mangle]
12+
pub extern "C" fn _start() -> ! {
13+
#[cfg(test)]
14+
test_main();
15+
16+
unsafe { exit_qemu(ExitCode::Failed); }
17+
18+
loop {}
19+
}
20+
21+
#[test_case]
22+
fn test1() {
23+
assert_eq!(0, 0);
24+
}
25+
26+
#[panic_handler]
27+
fn panic(_info: &PanicInfo) -> ! {
28+
unsafe { exit_qemu(ExitCode::Failed); }
29+
loop {}
30+
}

0 commit comments

Comments
 (0)