mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 22:37:49 +00:00
Compare commits
158 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bb5899e437 | ||
|
|
ceb91f955a | ||
|
|
3340babf51 | ||
|
|
37a0ae0097 | ||
|
|
6fc9fbfb7d | ||
|
|
ebfc7c5f7e | ||
|
|
d1bf96108a | ||
|
|
1d0aa17531 | ||
|
|
e4b3ed6d42 | ||
|
|
b1aec7eb66 | ||
|
|
a6141e8d2e | ||
|
|
deb7c82872 | ||
|
|
fda382c6bc | ||
|
|
75354fe142 | ||
|
|
9edc2c59c7 | ||
|
|
6e7c2f4344 | ||
|
|
3916bebd15 | ||
|
|
f45954e7e4 | ||
|
|
c73b412ec6 | ||
|
|
445833408c | ||
|
|
8622b9c41b | ||
|
|
736a4183db | ||
|
|
c2dd2477ab | ||
|
|
9d16f0a139 | ||
|
|
a671ad3dbc | ||
|
|
765c7b21e9 | ||
|
|
eb2f818194 | ||
|
|
167ef5bb83 | ||
|
|
4f68f9ba93 | ||
|
|
36e4dc22f3 | ||
|
|
0e365109be | ||
|
|
c8f72adeb3 | ||
|
|
cc617ec35e | ||
|
|
bee9a7f7ea | ||
|
|
4c07101f8f | ||
|
|
30be97d035 | ||
|
|
63d0d8cc9f | ||
|
|
4de18a8a10 | ||
|
|
3fac6af7b0 | ||
|
|
d4e1f47e62 | ||
|
|
4215162b62 | ||
|
|
35c642b3c2 | ||
|
|
3d96415940 | ||
|
|
fd8a2e0182 | ||
|
|
3bb076a00f | ||
|
|
e5bd06edcc | ||
|
|
edd155d570 | ||
|
|
c18cd874ca | ||
|
|
6380e069f7 | ||
|
|
7341cff39d | ||
|
|
acf3717551 | ||
|
|
e78d33a5bf | ||
|
|
6292789393 | ||
|
|
bf33685d00 | ||
|
|
3ee6badb33 | ||
|
|
9f9ff59489 | ||
|
|
a1c7931a77 | ||
|
|
2c30310281 | ||
|
|
57cd52b7f5 | ||
|
|
d7e505da9e | ||
|
|
2039cd7a64 | ||
|
|
ebb862de2a | ||
|
|
d588dca953 | ||
|
|
029d6bee78 | ||
|
|
0fc6fedd82 | ||
|
|
56cf71df9f | ||
|
|
adcb547765 | ||
|
|
faf097fd06 | ||
|
|
1636196d54 | ||
|
|
5c964dc7b9 | ||
|
|
0c3e6f95f6 | ||
|
|
23d8bb948e | ||
|
|
ea998c9267 | ||
|
|
79ad84c502 | ||
|
|
2a1f4d047c | ||
|
|
01d9a028a3 | ||
|
|
6e012e5e42 | ||
|
|
f4ed1fce81 | ||
|
|
086c3a02d3 | ||
|
|
14b38a3ea4 | ||
|
|
b1121cdee2 | ||
|
|
e27666cd75 | ||
|
|
6771c2cc7f | ||
|
|
1d60156fce | ||
|
|
467300126b | ||
|
|
19b8ab1c4e | ||
|
|
f927742601 | ||
|
|
210af19293 | ||
|
|
6f90ee89fd | ||
|
|
20ef920fc6 | ||
|
|
9602f4e16d | ||
|
|
d3e4c55fc5 | ||
|
|
f1ae82b220 | ||
|
|
aad98c0611 | ||
|
|
f98145d556 | ||
|
|
99ea302aaa | ||
|
|
133f73ab0b | ||
|
|
28d5eeb9c4 | ||
|
|
5adfe28cf4 | ||
|
|
d2e0d38218 | ||
|
|
7003268b9f | ||
|
|
c8d1bbeef8 | ||
|
|
158aed0c18 | ||
|
|
3098be9653 | ||
|
|
86b57f696f | ||
|
|
ac9b661395 | ||
|
|
ad99afae98 | ||
|
|
8374aa6ab6 | ||
|
|
c8087cdd6f | ||
|
|
ccb8b79ef8 | ||
|
|
a55ced6b7f | ||
|
|
2e5f192f35 | ||
|
|
c2f36e086e | ||
|
|
cdd91df869 | ||
|
|
a2d628cabe | ||
|
|
48e1f72d23 | ||
|
|
3b13211579 | ||
|
|
d0629ba5a2 | ||
|
|
46bb44b95d | ||
|
|
4cbac20b40 | ||
|
|
d4ebbc291a | ||
|
|
3ecf9a9b56 | ||
|
|
1559493802 | ||
|
|
98a0e605be | ||
|
|
dbdd46da9a | ||
|
|
3aa6151729 | ||
|
|
0beb0d80f8 | ||
|
|
3c421e9ccb | ||
|
|
23cbafab1c | ||
|
|
4eb7f94171 | ||
|
|
d497d12649 | ||
|
|
66f79fa254 | ||
|
|
5422f555cf | ||
|
|
ceaa5c2dab | ||
|
|
768c09dffe | ||
|
|
cc949a2ef3 | ||
|
|
c6aaa66420 | ||
|
|
0bec03e080 | ||
|
|
71099663ad | ||
|
|
a53f0573d8 | ||
|
|
b71e0644bf | ||
|
|
078aebe32a | ||
|
|
afc89c9e4c | ||
|
|
2db616bd7d | ||
|
|
237a848459 | ||
|
|
053216ffd4 | ||
|
|
61d10d686b | ||
|
|
52bc8ea29f | ||
|
|
5b3e3642ca | ||
|
|
d516dac0c3 | ||
|
|
c0fcb5f922 | ||
|
|
be46130322 | ||
|
|
76110c1dd8 | ||
|
|
92c4206e86 | ||
|
|
a15e01f2eb | ||
|
|
76a65ca3ee | ||
|
|
8e74084d52 | ||
|
|
5366fe2ff8 |
25
.github/workflows/code.yml
vendored
25
.github/workflows/code.yml
vendored
@@ -67,6 +67,31 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
command: bootimage
|
command: bootimage
|
||||||
|
|
||||||
|
# install QEMU
|
||||||
|
- name: Install QEMU (Linux)
|
||||||
|
run: sudo apt update && sudo apt install qemu-system-x86
|
||||||
|
if: runner.os == 'Linux'
|
||||||
|
- name: Install QEMU (macOS)
|
||||||
|
run: brew install qemu
|
||||||
|
if: runner.os == 'macOS'
|
||||||
|
env:
|
||||||
|
HOMEBREW_NO_AUTO_UPDATE: 1
|
||||||
|
HOMEBREW_NO_BOTTLE_SOURCE_FALLBACK: 1
|
||||||
|
HOMEBREW_NO_INSTALL_CLEANUP: 1
|
||||||
|
- name: Install QEMU (Windows)
|
||||||
|
run: |
|
||||||
|
choco install qemu --version 2021.5.5
|
||||||
|
echo "$Env:Programfiles\qemu" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
|
||||||
|
if: runner.os == 'Windows'
|
||||||
|
shell: pwsh
|
||||||
|
- name: "Print QEMU Version"
|
||||||
|
run: qemu-system-x86_64 --version
|
||||||
|
|
||||||
|
- name: Run `cargo test`
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: test
|
||||||
|
|
||||||
check_formatting:
|
check_formatting:
|
||||||
name: Check Formatting
|
name: Check Formatting
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|||||||
57
Cargo.lock
generated
57
Cargo.lock
generated
@@ -2,6 +2,24 @@
|
|||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 4
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bit_field"
|
||||||
|
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.9.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6a65b545ab31d687cff52899d4890855fec459eb6afe0da6417b8a18da87aa29"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "blog_os"
|
name = "blog_os"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@@ -9,7 +27,9 @@ dependencies = [
|
|||||||
"bootloader",
|
"bootloader",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"spin 0.5.2",
|
"spin 0.5.2",
|
||||||
"volatile",
|
"uart_16550",
|
||||||
|
"volatile 0.2.7",
|
||||||
|
"x86_64",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -27,6 +47,12 @@ dependencies = [
|
|||||||
"spin 0.9.8",
|
"spin 0.9.8",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustversion"
|
||||||
|
version = "1.0.22"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "spin"
|
name = "spin"
|
||||||
version = "0.5.2"
|
version = "0.5.2"
|
||||||
@@ -39,8 +65,37 @@ version = "0.9.8"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67"
|
checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67"
|
||||||
|
|
||||||
|
[[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",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "volatile"
|
name = "volatile"
|
||||||
version = "0.2.7"
|
version = "0.2.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f6b06ad3ed06fef1713569d547cdbdb439eafed76341820fb0e0344f29a41945"
|
checksum = "f6b06ad3ed06fef1713569d547cdbdb439eafed76341820fb0e0344f29a41945"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "volatile"
|
||||||
|
version = "0.4.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "442887c63f2c839b346c192d047a7c87e73d0689c9157b00b53dcc27dd5ea793"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "x86_64"
|
||||||
|
version = "0.14.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c101112411baafbb4bf8d33e4c4a80ab5b02d74d2612331c61e8192fc9710491"
|
||||||
|
dependencies = [
|
||||||
|
"bit_field",
|
||||||
|
"bitflags 2.9.2",
|
||||||
|
"rustversion",
|
||||||
|
"volatile 0.4.6",
|
||||||
|
]
|
||||||
|
|||||||
20
Cargo.toml
20
Cargo.toml
@@ -4,10 +4,16 @@ version = "0.1.0"
|
|||||||
authors = ["Philipp Oppermann <dev@phil-opp.com>"]
|
authors = ["Philipp Oppermann <dev@phil-opp.com>"]
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
|
[[test]]
|
||||||
|
name = "should_panic"
|
||||||
|
harness = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
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"
|
||||||
|
uart_16550 = "0.2.0"
|
||||||
|
|
||||||
[dependencies.lazy_static]
|
[dependencies.lazy_static]
|
||||||
version = "1.0"
|
version = "1.0"
|
||||||
@@ -15,5 +21,17 @@ features = ["spin_no_std"]
|
|||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "blog_os"
|
name = "blog_os"
|
||||||
test = false
|
test = true
|
||||||
bench = false
|
bench = false
|
||||||
|
|
||||||
|
|
||||||
|
[package.metadata.bootimage]
|
||||||
|
test-args = [
|
||||||
|
"-device",
|
||||||
|
"isa-debug-exit,iobase=0xf4,iosize=0x04",
|
||||||
|
"-serial",
|
||||||
|
"stdio",
|
||||||
|
"-display",
|
||||||
|
"none",
|
||||||
|
]
|
||||||
|
test-success-exit-code = 33 # (0x10 << 1) | 1
|
||||||
|
|||||||
12
README.md
12
README.md
@@ -1,10 +1,10 @@
|
|||||||
# Blog OS (VGA Text Mode)
|
# Blog OS (Testing)
|
||||||
|
|
||||||
[](https://github.com/phil-opp/blog_os/actions?query=workflow%3A%22Code%22+branch%3Apost-03)
|
[](https://github.com/phil-opp/blog_os/actions?query=workflow%3A%22Code%22+branch%3Apost-04)
|
||||||
|
|
||||||
This repository contains the source code for the [VGA Text Mode][post] post of the [Writing an OS in Rust](https://os.phil-opp.com) series.
|
This repository contains the source code for the [Testing][post] post of the [Writing an OS in Rust](https://os.phil-opp.com) series.
|
||||||
|
|
||||||
[post]: https://os.phil-opp.com/vga-text-mode/
|
[post]: https://os.phil-opp.com/testing/
|
||||||
|
|
||||||
**Check out the [master branch](https://github.com/phil-opp/blog_os) for more information.**
|
**Check out the [master branch](https://github.com/phil-opp/blog_os) for more information.**
|
||||||
|
|
||||||
@@ -56,6 +56,10 @@ dd if=target/x86_64-blog_os/debug/bootimage-blog_os.bin of=/dev/sdX && sync
|
|||||||
|
|
||||||
Where `sdX` is the device name of your USB stick. **Be careful** to choose the correct device name, because everything on that device is overwritten.
|
Where `sdX` is the device name of your USB stick. **Be careful** to choose the correct device name, because everything on that device is overwritten.
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
To run the unit and integration tests, execute `cargo xtest`.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
Licensed under either of
|
Licensed under either of
|
||||||
|
|||||||
70
src/lib.rs
Normal file
70
src/lib.rs
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
#![no_std]
|
||||||
|
#![cfg_attr(test, no_main)]
|
||||||
|
#![feature(custom_test_frameworks)]
|
||||||
|
#![test_runner(crate::test_runner)]
|
||||||
|
#![reexport_test_harness_main = "test_main"]
|
||||||
|
|
||||||
|
use core::panic::PanicInfo;
|
||||||
|
|
||||||
|
pub mod serial;
|
||||||
|
pub mod vga_buffer;
|
||||||
|
|
||||||
|
pub trait Testable {
|
||||||
|
fn run(&self) -> ();
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Testable for T
|
||||||
|
where
|
||||||
|
T: Fn(),
|
||||||
|
{
|
||||||
|
fn run(&self) {
|
||||||
|
serial_print!("{}...\t", core::any::type_name::<T>());
|
||||||
|
self();
|
||||||
|
serial_println!("[ok]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn test_runner(tests: &[&dyn Testable]) {
|
||||||
|
serial_println!("Running {} tests", tests.len());
|
||||||
|
for test in tests {
|
||||||
|
test.run();
|
||||||
|
}
|
||||||
|
exit_qemu(QemuExitCode::Success);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn test_panic_handler(info: &PanicInfo) -> ! {
|
||||||
|
serial_println!("[failed]\n");
|
||||||
|
serial_println!("Error: {}\n", info);
|
||||||
|
exit_qemu(QemuExitCode::Failed);
|
||||||
|
loop {}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Entry point for `cargo xtest`
|
||||||
|
#[cfg(test)]
|
||||||
|
#[unsafe(no_mangle)]
|
||||||
|
pub extern "C" fn _start() -> ! {
|
||||||
|
test_main();
|
||||||
|
loop {}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
#[panic_handler]
|
||||||
|
fn panic(info: &PanicInfo) -> ! {
|
||||||
|
test_panic_handler(info)
|
||||||
|
}
|
||||||
21
src/main.rs
21
src/main.rs
@@ -1,20 +1,37 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
|
#![feature(custom_test_frameworks)]
|
||||||
|
#![test_runner(blog_os::test_runner)]
|
||||||
|
#![reexport_test_harness_main = "test_main"]
|
||||||
|
|
||||||
|
use blog_os::println;
|
||||||
use core::panic::PanicInfo;
|
use core::panic::PanicInfo;
|
||||||
|
|
||||||
mod vga_buffer;
|
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub extern "C" fn _start() -> ! {
|
pub extern "C" fn _start() -> ! {
|
||||||
println!("Hello World{}", "!");
|
println!("Hello World{}", "!");
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
test_main();
|
||||||
|
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This function is called on panic.
|
/// This function is called on panic.
|
||||||
|
#[cfg(not(test))]
|
||||||
#[panic_handler]
|
#[panic_handler]
|
||||||
fn panic(info: &PanicInfo) -> ! {
|
fn panic(info: &PanicInfo) -> ! {
|
||||||
println!("{}", info);
|
println!("{}", info);
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
#[panic_handler]
|
||||||
|
fn panic(info: &PanicInfo) -> ! {
|
||||||
|
blog_os::test_panic_handler(info)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test_case]
|
||||||
|
fn trivial_assertion() {
|
||||||
|
assert_eq!(1, 1);
|
||||||
|
}
|
||||||
|
|||||||
37
src/serial.rs
Normal file
37
src/serial.rs
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
use lazy_static::lazy_static;
|
||||||
|
use spin::Mutex;
|
||||||
|
use uart_16550::SerialPort;
|
||||||
|
|
||||||
|
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)*));
|
||||||
|
}
|
||||||
@@ -169,3 +169,25 @@ 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() {
|
||||||
|
println!("test_println_simple output");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test_case]
|
||||||
|
fn test_println_many() {
|
||||||
|
for _ in 0..200 {
|
||||||
|
println!("test_println_many output");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test_case]
|
||||||
|
fn 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
25
tests/basic_boot.rs
Normal file
25
tests/basic_boot.rs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#![no_std]
|
||||||
|
#![no_main]
|
||||||
|
#![feature(custom_test_frameworks)]
|
||||||
|
#![test_runner(blog_os::test_runner)]
|
||||||
|
#![reexport_test_harness_main = "test_main"]
|
||||||
|
|
||||||
|
use blog_os::println;
|
||||||
|
use core::panic::PanicInfo;
|
||||||
|
|
||||||
|
#[unsafe(no_mangle)] // don't mangle the name of this function
|
||||||
|
pub extern "C" fn _start() -> ! {
|
||||||
|
test_main();
|
||||||
|
|
||||||
|
loop {}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[panic_handler]
|
||||||
|
fn panic(info: &PanicInfo) -> ! {
|
||||||
|
blog_os::test_panic_handler(info)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test_case]
|
||||||
|
fn test_println() {
|
||||||
|
println!("test_println output");
|
||||||
|
}
|
||||||
25
tests/should_panic.rs
Normal file
25
tests/should_panic.rs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#![no_std]
|
||||||
|
#![no_main]
|
||||||
|
|
||||||
|
use blog_os::{QemuExitCode, exit_qemu, serial_print, serial_println};
|
||||||
|
use core::panic::PanicInfo;
|
||||||
|
|
||||||
|
#[unsafe(no_mangle)]
|
||||||
|
pub extern "C" fn _start() -> ! {
|
||||||
|
should_fail();
|
||||||
|
serial_println!("[test did not panic]");
|
||||||
|
exit_qemu(QemuExitCode::Failed);
|
||||||
|
loop {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn should_fail() {
|
||||||
|
serial_print!("should_panic::should_fail...\t");
|
||||||
|
assert_eq!(0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[panic_handler]
|
||||||
|
fn panic(_info: &PanicInfo) -> ! {
|
||||||
|
serial_println!("[ok]");
|
||||||
|
exit_qemu(QemuExitCode::Success);
|
||||||
|
loop {}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user