Skip to content

Commit

Permalink
Proper Qemu Test Exits
Browse files Browse the repository at this point in the history
  • Loading branch information
jeebuscrossaint committed Jul 6, 2024
1 parent 98ac939 commit 670619e
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
39 changes: 38 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"
bootloader = "0.9"
volatile = "0.2.6"
spin = "0.5.2"
x86_64 = "0.14.2"

#// DO NOTE THAT IN CARGO AS OF TO MY KNOWLEDGE 2019 AND EVEN NOW IN 2024
#// THERE IS A BUG IN CARGO WHERE THERE ARE "duplicate lang item" ERRORS
Expand All @@ -25,4 +26,5 @@ version = "1.0"
features = ["spin_no_std"]

[package.metadata.bootimage]
test-args = ["-device", "isa-debug-exit,iobase=0xf4,iosize=0x04"]
test-args = ["-device", "isa-debug-exit,iobase=0xf4,iosize=0x04"]
test-success-exit-code = 33 # (0x10 << 1) | 1
20 changes: 19 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,34 @@ pub extern "C" fn _start() -> ! {
// ON CARGO TEST IN SOME CASES. TO FIX REMOVE/COMMENT OUT THE ' panic = "abort" '
// FOR A PROFILE IN THE CARGO.TOML FILE
#[cfg(test)]
pub fn test_runner(tests: &[&dyn Fn()]) {
fn test_runner(tests: &[&dyn Fn()]) {
println!("Running {} tests", tests.len());
for test in tests {
test();
}
//new
exit_qemu(QemuExitCode::Success);
}

#[test_case]
fn trivial_assertion() {
print!("trivial assertion... ");
assert_eq!(1, 1);
println!("[ok]");
}

#[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);
}
}
2 changes: 1 addition & 1 deletion src/vga_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ use lazy_static::lazy_static;
lazy_static! {
pub static ref WRITER: Mutex<Writer> = Mutex::new(Writer {
column_position: 0,
color_code: ColorCode::new(Color::Yellow, Color::Black),
color_code: ColorCode::new(Color::White, Color::Black),
buffer: unsafe { &mut *(0xb8000 as *mut Buffer) },
});
}
Expand Down

0 comments on commit 670619e

Please sign in to comment.