mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Add tests for the VGA buffer
This commit is contained in:
@@ -58,10 +58,3 @@ pub unsafe fn exit_qemu(exit_code: QemuExitCode) {
|
|||||||
let mut port = Port::new(0xf4);
|
let mut port = Port::new(0xf4);
|
||||||
port.write(exit_code as u32);
|
port.write(exit_code as u32);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test_case]
|
|
||||||
fn trivial_assertion() {
|
|
||||||
serial_print!("trivial assertion... ");
|
|
||||||
assert_eq!(1, 1);
|
|
||||||
serial_println!("[ok]");
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use core::fmt;
|
|||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use spin::Mutex;
|
use spin::Mutex;
|
||||||
use volatile::Volatile;
|
use volatile::Volatile;
|
||||||
|
use crate::{serial_print, serial_println};
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
/// A global `Writer` instance that can be used for printing to the VGA text buffer.
|
/// A global `Writer` instance that can be used for printing to the VGA text buffer.
|
||||||
@@ -169,3 +170,33 @@ pub fn _print(args: fmt::Arguments) {
|
|||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
WRITER.lock().write_fmt(args).unwrap();
|
WRITER.lock().write_fmt(args).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test_case]
|
||||||
|
fn test_println_simple() {
|
||||||
|
serial_print!("test_println... ");
|
||||||
|
println!("test_println_simple output");
|
||||||
|
serial_println!("[ok]");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test_case]
|
||||||
|
fn test_println_many() {
|
||||||
|
serial_print!("test_println_many... ");
|
||||||
|
for _ in 0..200 {
|
||||||
|
println!("test_println_many output");
|
||||||
|
}
|
||||||
|
serial_println!("[ok]");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test_case]
|
||||||
|
fn test_println_output() {
|
||||||
|
serial_print!("test_println_output... ");
|
||||||
|
|
||||||
|
let s = "Some test string that fits on a single line";
|
||||||
|
println!("{}", s);
|
||||||
|
for (i, c) in s.chars().enumerate() {
|
||||||
|
let screen_char = WRITER.lock().buffer.chars[BUFFER_HEIGHT - 2][i].read();
|
||||||
|
assert_eq!(char::from(screen_char.ascii_character), c);
|
||||||
|
}
|
||||||
|
|
||||||
|
serial_println!("[ok]");
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user