Skip to content

Commit d740cb3

Browse files
committedApr 3, 2023
Added test exit to main.rs.
1 parent 24882ce commit d740cb3

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed
 

‎Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@ panic = "abort" #this needs to be disable for cargo test
1616
bootloader = "0.9.23"
1717
volatile = "0.2.6"
1818
spin = "0.5.2"
19+
x86_64 = "0.14.2"
1920

2021
[dependencies.lazy_static]
2122
version = "1.0"
2223
features = ["spin_no_std"]
2324

2425
[package.metadata.bootimage]
2526
test-args=["-device", "isa-debug-exit,iobase=0xf4,iosize=0x04"]
27+
#here 0xf4 signifies address the device should live on (unused port)
28+
#here 0x04 signifies is the port size.

‎src/main.rs

+15-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
#![feature(custom_test_frameworks)]
44
#![test_runner(crate::test_runner)] //here crate::test_runner is the name of the function.
55
#![reexport_test_harness_main = "test_main"]
6-
76
mod vga_buffer;
8-
97
use core::fmt::Write;
108
//we will not be using main function as the entrypoint
119
use core::panic::PanicInfo;
@@ -17,16 +15,29 @@ fn panic(info: &PanicInfo) -> ! {
1715
loop{}
1816
}
1917

20-
static HELLO: &[u8] = b"hello world!";
18+
//exit Qemu function
19+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
20+
#[repr(u32)]
21+
pub enum QemuExitCode{
22+
Success = 0x10,
23+
Failed = 0x11
24+
}
25+
pub fn exit_qemu(exit_code : QemuExitCode) {
26+
use x86_64::instructions::port::Port;
27+
unsafe {
28+
let mut port = Port::new(0xf4);
29+
port.write(exit_code as u32);
30+
}
31+
}
2132

33+
static HELLO: &[u8] = b"hello world!";
2234
#[cfg(test)] //panic = "abort" needs to be commented in toml for 'cargo test' to run.
2335
fn test_runner(tests: &[&dyn Fn()]) {
2436
println!("Running {} tests", tests.len());
2537
for test in tests {
2638
test();
2739
}
2840
}
29-
3041
//here are the added test cases.
3142
//test case 1
3243
#[test_case]
@@ -35,7 +46,6 @@ fn trivial_assertion(){
3546
assert_eq!(1,1);
3647
println!("[Ok]");
3748
}
38-
3949
#[test_case]
4050
fn test_2(){
4151
print!("Test for equality...");

0 commit comments

Comments
 (0)
Please sign in to comment.