mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Fix code snippets and resolve some todos
This commit is contained in:
@@ -104,7 +104,7 @@ To make the serial port easily usable, we add `serial_print!` and `serial_printl
|
|||||||
```rust
|
```rust
|
||||||
pub fn print(args: ::core::fmt::Arguments) {
|
pub fn print(args: ::core::fmt::Arguments) {
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
let _ = COM1.lock().write_fmt(args);
|
SERIAL1.lock().write_fmt(args).expect("Printing to serial failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Prints to the host through the serial interface.
|
/// Prints to the host through the serial interface.
|
||||||
@@ -234,7 +234,11 @@ pub extern "C" fn _start() -> ! {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
You should see that QEMU immediately closes after booting.
|
You should see that QEMU immediately closes after booting when executing:
|
||||||
|
|
||||||
|
```
|
||||||
|
bootimage run -- -serial mon:stdio -device isa-debug-exit,iobase=0xf4,iosize=0x04
|
||||||
|
```
|
||||||
|
|
||||||
## Hiding QEMU
|
## Hiding QEMU
|
||||||
|
|
||||||
@@ -341,8 +345,7 @@ pub extern "C" fn _start() -> ! {
|
|||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
#[panic_implementation]
|
#[panic_implementation]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn panic(info: &PanicInfo) -> ! {
|
pub fn panic(_info: &PanicInfo) -> ! {
|
||||||
println!("{}", info);
|
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -407,6 +410,9 @@ pub unsafe fn exit_qemu() {
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate blog_os;
|
extern crate blog_os;
|
||||||
|
|
||||||
|
#[cfg(not(test))]
|
||||||
|
use core::panic::PanicInfo;
|
||||||
|
|
||||||
/// This function is the entry point, since the linker looks for a function
|
/// This function is the entry point, since the linker looks for a function
|
||||||
/// named `_start_` by default.
|
/// named `_start_` by default.
|
||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
@@ -467,6 +473,8 @@ We are finally able to create our first integration test executable. We start si
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate blog_os;
|
extern crate blog_os;
|
||||||
|
|
||||||
|
#[cfg(not(test))]
|
||||||
|
use core::panic::PanicInfo;
|
||||||
use blog_os::exit_qemu;
|
use blog_os::exit_qemu;
|
||||||
|
|
||||||
/// This function is the entry point, since the linker looks for a function
|
/// This function is the entry point, since the linker looks for a function
|
||||||
@@ -514,7 +522,7 @@ We got our `ok`, so it worked! Try inserting a `panic!()` before the `ok` printi
|
|||||||
|
|
||||||
```
|
```
|
||||||
failed
|
failed
|
||||||
panic: explicit panic at src/bin/test-basic-boot.rs:16:5
|
panicked at 'explicit panic', src/bin/test-basic-boot.rs:19:5
|
||||||
```
|
```
|
||||||
|
|
||||||
### Test Panic
|
### Test Panic
|
||||||
@@ -532,6 +540,8 @@ To test that our panic handler is really invoked on a panic, we create a `test-p
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate blog_os;
|
extern crate blog_os;
|
||||||
|
|
||||||
|
#[cfg(not(test))]
|
||||||
|
use core::panic::PanicInfo;
|
||||||
use blog_os::exit_qemu;
|
use blog_os::exit_qemu;
|
||||||
|
|
||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
@@ -576,11 +586,26 @@ The `test-basic-boot` and `test-panic` tests we created above begin with `test-`
|
|||||||
|
|
||||||
```
|
```
|
||||||
> bootimage test
|
> bootimage test
|
||||||
|
test-panic
|
||||||
|
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
|
||||||
|
Updating registry `https://github.com/rust-lang/crates.io-index`
|
||||||
|
Ok
|
||||||
|
|
||||||
TODO output
|
test-basic-boot
|
||||||
|
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
|
||||||
|
Updating registry `https://github.com/rust-lang/crates.io-index`
|
||||||
|
Ok
|
||||||
|
|
||||||
|
test-something
|
||||||
|
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
|
||||||
|
Updating registry `https://github.com/rust-lang/crates.io-index`
|
||||||
|
Timed Out
|
||||||
|
|
||||||
|
The following tests failed:
|
||||||
|
test-something: TimedOut
|
||||||
```
|
```
|
||||||
|
|
||||||
We see that TODO
|
We see that our `test-panic` and `test-basic-boot` succeeded and that the `test-something` test timed out after one minute. We no longer need `test-something`, so we delete it (if you haven't done already). Now `bootimage test` should execute successfully.
|
||||||
|
|
||||||
## Summary
|
## Summary
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user