Added and fixed some tests
This commit is contained in:
parent
335b8de9b2
commit
e70a0dffe5
4 changed files with 87 additions and 8 deletions
33
Cargo.lock
generated
33
Cargo.lock
generated
|
@ -14,6 +14,12 @@ version = "0.10.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.6.0"
|
||||
|
@ -52,8 +58,9 @@ dependencies = [
|
|||
"bootloader",
|
||||
"lazy_static",
|
||||
"spin",
|
||||
"uart_16550",
|
||||
"volatile 0.2.7",
|
||||
"x86_64",
|
||||
"x86_64 0.15.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -77,6 +84,17 @@ dependencies = [
|
|||
"lock_api",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uart_16550"
|
||||
version = "0.2.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "614ff2a87880d4bd4374722268598a970bbad05ced8bf630439417347254ab2e"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
"rustversion",
|
||||
"x86_64 0.14.12",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "volatile"
|
||||
version = "0.2.7"
|
||||
|
@ -96,7 +114,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "96cb6fd45bfeab6a5055c5bffdb08768bd0c069f1d946debe585bbb380a7c062"
|
||||
dependencies = [
|
||||
"bit_field",
|
||||
"bitflags",
|
||||
"bitflags 2.6.0",
|
||||
"rustversion",
|
||||
"volatile 0.4.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "x86_64"
|
||||
version = "0.15.1"
|
||||
source = "git+https://github.com/rust-osdev/x86_64?branch=fix%2Fstep-nightly-breakage#b4b66637b7306254447bde805789f1a2cf92b6e5"
|
||||
dependencies = [
|
||||
"bit_field",
|
||||
"bitflags 2.6.0",
|
||||
"rustversion",
|
||||
"volatile 0.4.6",
|
||||
]
|
||||
|
|
|
@ -8,7 +8,8 @@ bootloader = "0.9"
|
|||
lazy_static = { version = "1.5.0", features = ["spin_no_std"] }
|
||||
spin = "0.9.8"
|
||||
volatile = "0.2.6"
|
||||
x86_64 = "0.14.2"
|
||||
x86_64 = { git = "https://github.com/rust-osdev/x86_64", branch = "fix/step-nightly-breakage" }
|
||||
uart_16550 = "0.2.0"
|
||||
|
||||
# the profile used for `cargo build`
|
||||
[profile.dev]
|
||||
|
@ -19,5 +20,9 @@ panic = "abort" # disable stack unwinding on panic
|
|||
panic = "abort" # disable stack unwinding on panic
|
||||
|
||||
[package.metadata.bootimage]
|
||||
test-args = ["-device", "isa-debug-exit,iobase=0xf4,iosize=0x04"]
|
||||
test-args = [
|
||||
"-device", "isa-debug-exit,iobase=0xf4,iosize=0x04", "-serial", "stdio",
|
||||
"-display", "none"
|
||||
]
|
||||
test-success-exit-code = 33
|
||||
test-timeout = 300 # (in seconds)
|
19
src/main.rs
19
src/main.rs
|
@ -6,6 +6,7 @@
|
|||
|
||||
|
||||
mod vga_buffer;
|
||||
mod serial;
|
||||
|
||||
use core::panic::PanicInfo;
|
||||
|
||||
|
@ -18,26 +19,36 @@ pub extern "C" fn _start() -> ! {
|
|||
loop {}
|
||||
}
|
||||
|
||||
#[cfg(not(test))]
|
||||
#[panic_handler]
|
||||
fn panic(info: &PanicInfo) -> ! {
|
||||
println!("{}", info);
|
||||
loop {}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[panic_handler]
|
||||
fn panic(info: &PanicInfo) -> ! {
|
||||
serial_println!("[failed]\n");
|
||||
serial_println!("Error: {}\n", info);
|
||||
exit_qemu(QemuExitCode::Failed);
|
||||
loop {}
|
||||
}
|
||||
|
||||
fn test_runner(tests: &[&dyn Fn()]) {
|
||||
println!("Running {} tests", tests.len());
|
||||
serial_println!("Running {} tests", tests.len());
|
||||
for test in tests {
|
||||
test();
|
||||
}
|
||||
/// new
|
||||
|
||||
exit_qemu(QemuExitCode::Success);
|
||||
}
|
||||
|
||||
#[test_case]
|
||||
fn trivial_assertion() {
|
||||
print!("trivial assertion... ");
|
||||
serial_print!("trivial assertion... ");
|
||||
assert_eq!(1, 1);
|
||||
println!("[ok]");
|
||||
serial_println!("[ok]");
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
|
|
34
src/serial.rs
Normal file
34
src/serial.rs
Normal file
|
@ -0,0 +1,34 @@
|
|||
use uart_16550::SerialPort;
|
||||
use spin::Mutex;
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref SERIAL1: Mutex<SerialPort> = {
|
||||
let mut serial_port = unsafe { SerialPort::new(0x3F8) };
|
||||
serial_port.init();
|
||||
Mutex::new(serial_port)
|
||||
};
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn _print(args: ::core::fmt::Arguments) {
|
||||
use core::fmt::Write;
|
||||
SERIAL1.lock().write_fmt(args).expect("Printing to serial failed");
|
||||
}
|
||||
|
||||
/// Prints to the host through the serial interface.
|
||||
#[macro_export]
|
||||
macro_rules! serial_print {
|
||||
($($arg:tt)*) => {
|
||||
$crate::serial::_print(format_args!($($arg)*));
|
||||
};
|
||||
}
|
||||
|
||||
/// Prints to the host through the serial interface, appending a newline.
|
||||
#[macro_export]
|
||||
macro_rules! serial_println {
|
||||
() => ($crate::serial_print!("\n"));
|
||||
($fmt:expr) => ($crate::serial_print!(concat!($fmt, "\n")));
|
||||
($fmt:expr, $($arg:tt)*) => ($crate::serial_print!(
|
||||
concat!($fmt, "\n"), $($arg)*));
|
||||
}
|
Loading…
Reference in a new issue