added tests + exiting by interacting with qemu through a I/O port
This commit is contained in:
parent
745b574bd6
commit
c3f181a641
3 changed files with 48 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
[unstable]
|
[unstable]
|
||||||
build-std-features = ["compiler-builtins-mem"]
|
build-std-features = ["compiler-builtins-mem"]
|
||||||
build-std = ["core", "compiler_builtins"]
|
build-std = ["core", "compiler_builtins"]
|
||||||
|
panic-abort-tests = true
|
||||||
|
|
||||||
[build]
|
[build]
|
||||||
target = "x86_64-totos.json"
|
target = "x86_64-totos.json"
|
||||||
|
|
|
@ -5,7 +5,7 @@ edition = "2024"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "totos"
|
name = "totos"
|
||||||
test = false
|
test = true
|
||||||
bench = false
|
bench = false
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
|
@ -18,7 +18,13 @@ panic = "abort" # disable stack unwinding on panic
|
||||||
bootloader = "0.9"
|
bootloader = "0.9"
|
||||||
volatile = "0.2.6"
|
volatile = "0.2.6"
|
||||||
spin = "0.5.2"
|
spin = "0.5.2"
|
||||||
|
x86_64 = "0.14.2"
|
||||||
|
|
||||||
[dependencies.lazy_static]
|
[dependencies.lazy_static]
|
||||||
version = "1.0"
|
version = "1.0"
|
||||||
features = ["spin_no_std"]
|
features = ["spin_no_std"]
|
||||||
|
|
||||||
|
# this enables exiting qemu from the guest system
|
||||||
|
[package.metadata.bootimage]
|
||||||
|
test-args = ["-device", "isa-debug-exit,iobase=0xf4,iosize=0x04"]
|
||||||
|
test-success-exit-code = 33 # (0x10 << 1) | 1 = 33
|
||||||
|
|
40
src/main.rs
40
src/main.rs
|
@ -1,5 +1,8 @@
|
||||||
#![no_std] // dont link the standard library
|
#![no_std] // dont link the standard library
|
||||||
#![no_main] // disable all rust-level entry points
|
#![no_main] // disable all rust-level entry points
|
||||||
|
#![feature(custom_test_frameworks)]
|
||||||
|
#![test_runner(crate::test_runner)]
|
||||||
|
#![reexport_test_harness_main = "test_main"]
|
||||||
|
|
||||||
use core::panic::PanicInfo;
|
use core::panic::PanicInfo;
|
||||||
|
|
||||||
|
@ -7,12 +10,31 @@ mod vga_buffer;
|
||||||
|
|
||||||
static HELLO: &[u8] = b"Hello toto :3";
|
static HELLO: &[u8] = b"Hello toto :3";
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
#[repr(u32)]
|
||||||
|
pub enum QemuExitCode {
|
||||||
|
Success = 0x10,
|
||||||
|
Failed = 0x11,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn exit_qemu(exit_code: QemuExitCode) {
|
||||||
|
use x86_64::instructions::port::Port;
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
let mut port = Port::new(0xF4);
|
||||||
|
port.write(exit_code as u32);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// this function is the entry point since the linker
|
// this function is the entry point since the linker
|
||||||
// looks for a function named `_start` by default
|
// looks for a function named `_start` by default
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub extern "C" fn _start() -> ! {
|
pub extern "C" fn _start() -> ! {
|
||||||
println!("smoking cigarettes in the shower\nwhen they get wet i just light another\n:{}", 3);
|
println!("smoking cigarettes in the shower\nwhen they get wet i just light another\n:{}", 3);
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
test_main();
|
||||||
|
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,3 +45,21 @@ fn panic(info: &PanicInfo) -> ! {
|
||||||
|
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
pub fn test_runner(tests: &[&dyn Fn()]) {
|
||||||
|
println!("Running {} tests", tests.len());
|
||||||
|
|
||||||
|
for test in tests {
|
||||||
|
test();
|
||||||
|
}
|
||||||
|
|
||||||
|
exit_qemu(QemuExitCode::Success);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test_case]
|
||||||
|
fn trivial_assertion() {
|
||||||
|
print!("asserzione triviale... ");
|
||||||
|
assert_eq!(1, 1);
|
||||||
|
println!("[ok]");
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue