-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from YushiOMOTE/add-tests
Add CI to run integration test
- Loading branch information
Showing
6 changed files
with
132 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[build] | ||
target = "x86_64-unknown-none" | ||
rustflags = ["-Crelocation-model=static"] | ||
|
||
[target.'cfg(target_os = "none")'] | ||
runner = "bootimage runner" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
[package] | ||
name = "testing" | ||
version = "0.1.0" | ||
authors = ["Philipp Oppermann <[email protected]>"] | ||
edition = "2018" | ||
|
||
[[test]] | ||
name = "basic" | ||
harness = false | ||
|
||
[dependencies] | ||
bootloader = "0.9.10" | ||
uart_16550 = "0.2.8" | ||
spin = "0.5.0" | ||
x86_64 = "0.15.1" | ||
com_logger = { path = ".." } | ||
log = "0.4.22" | ||
|
||
[dependencies.lazy_static] | ||
version = "1.3.0" | ||
features = ["spin_no_std"] | ||
|
||
[package.metadata.bootimage] | ||
test-args = [ | ||
"-device", "isa-debug-exit,iobase=0xf4,iosize=0x04", "-serial", "stdio", | ||
"-display", "none" | ||
] | ||
test-success-exit-code = 33 |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#![feature(custom_test_frameworks)] | ||
#![test_runner(crate::test_runner)] | ||
#![reexport_test_harness_main = "test_main"] | ||
#![no_std] | ||
#![no_main] | ||
|
||
use core::panic::PanicInfo; | ||
use log::error; | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
#[repr(u32)] | ||
pub enum QemuExitCode { | ||
Success = 0x10, | ||
Failed = 0x11, | ||
} | ||
|
||
pub fn exit() { | ||
exit_qemu(QemuExitCode::Success) | ||
} | ||
|
||
pub fn exit_qemu(exit_code: QemuExitCode) { | ||
use x86_64::instructions::port::PortWriteOnly; | ||
|
||
unsafe { | ||
let mut port = PortWriteOnly::new(0xf4); | ||
port.write(exit_code as u32); | ||
} | ||
} | ||
|
||
pub fn test_runner(tests: &[&dyn Fn()]) { | ||
for test in tests { | ||
test(); | ||
} | ||
exit_qemu(QemuExitCode::Success); | ||
} | ||
|
||
pub fn test_panic_handler(info: &PanicInfo) -> ! { | ||
error!("{:#?}", info); | ||
exit_qemu(QemuExitCode::Failed); | ||
loop {} | ||
} | ||
|
||
#[cfg(test)] | ||
#[no_mangle] | ||
pub extern "C" fn _start() -> ! { | ||
test_main(); | ||
loop {} | ||
} | ||
|
||
#[cfg(test)] | ||
#[panic_handler] | ||
fn panic(info: &PanicInfo) -> ! { | ||
test_panic_handler(info) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
use core::panic::PanicInfo; | ||
|
||
#[no_mangle] // don't mangle the name of this function | ||
pub extern "C" fn _start() { | ||
com_logger::init(); | ||
log::info!("Hello world"); | ||
testing::exit(); | ||
} | ||
|
||
#[panic_handler] | ||
fn panic(info: &PanicInfo) -> ! { | ||
testing::test_panic_handler(info) | ||
} |