Skip to content

Commit f5f65a1

Browse files
committed
test: try to fix
1 parent 5a93dda commit f5f65a1

9 files changed

Lines changed: 42 additions & 43 deletions

File tree

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,9 @@ ovmf-prebuilt = "0.1.0-alpha.1"
1414
members = ["kernel"]
1515

1616
[profile.dev]
17+
panic="unwind"
1718
debug = true
18-
split-debuginfo = "unpacked"
19+
split-debuginfo = "unpacked"
20+
21+
[profile.release]
22+
panic="abort"

kernel/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,3 @@ harness = false # disable test runner from default and custom test framewo
5252
[[test]]
5353
name = "stack_overflow"
5454
harness = false
55-

kernel/src/framebuffer.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -199,20 +199,3 @@ fn test_println_many() {
199199
println!("test_println_many output");
200200
}
201201
}
202-
203-
#[test_case]
204-
fn test_println_output() {
205-
use core::fmt::Write;
206-
use x86_64::instructions::interrupts;
207-
208-
let s = "tatakae";
209-
210-
interrupts::without_interrupts(|| {
211-
let mut writer = WRITER.lock();
212-
writeln!(writer, "\n{}", s).expect("writeln failed");
213-
for (i, c) in s.chars().enumerate() {
214-
let screen_char = writer.buffer.chars[BUFFER_HEIGHT - 2][i].read();
215-
assert_eq!(char::from(screen_char.ascii_character), c);
216-
}
217-
});
218-
}

kernel/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ pub fn hlt_loop() -> ! {
6363
}
6464

6565
#[cfg(test)]
66-
use bootloader::{BootInfo, entry_point};
66+
use bootloader_api::{BootInfo, entry_point};
6767

6868
#[cfg(test)]
6969
entry_point!(test_kernel_main);
7070

7171
#[cfg(test)]
72-
fn test_kernel_main(_boot_info: &'static BootInfo) -> ! {
72+
fn test_kernel_main(_boot_info: &'static mut BootInfo) -> ! {
7373
init();
7474
test_main();
7575
hlt_loop();

kernel/src/main.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ extern crate alloc;
1717

1818
pub static BOOTLOADER_CONFIG: BootloaderConfig = {
1919
let mut config = BootloaderConfig::new_default();
20-
config.mappings.kernel_stack = Mapping::FixedAddress(0x10000000000);
2120
config.mappings.physical_memory = Some(Mapping::FixedAddress(0x20000000000));
22-
config.kernel_stack_size = 80 * 1024;
2321
config
2422
};
2523

kernel/tests/basic_boot.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#![no_std]
22
#![no_main]
33
#![feature(custom_test_frameworks)]
4-
#![test_runner(osdev_rust::test_runner)]
4+
#![test_runner(kernel::test_runner)]
55
#![reexport_test_harness_main = "test_main"]
66

77
use core::panic::PanicInfo;
88

9-
use osdev_rust::println;
9+
use kernel::println;
1010

1111
#[unsafe(no_mangle)]
1212
pub extern "C" fn _start() -> ! {
@@ -17,7 +17,7 @@ pub extern "C" fn _start() -> ! {
1717

1818
#[panic_handler]
1919
fn panic(info: &PanicInfo) -> ! {
20-
osdev_rust::test_panic_handler(info)
20+
kernel::test_panic_handler(info)
2121
}
2222

2323
#[test_case]

kernel/tests/heap_allocation.rs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,38 @@
11
#![no_std]
22
#![no_main]
33
#![feature(custom_test_frameworks)]
4-
#![test_runner(osdev_rust::test_runner)]
4+
#![test_runner(kernel::test_runner)]
55
#![reexport_test_harness_main = "test_main"]
66

77
extern crate alloc;
88

99
use alloc::{boxed::Box, vec::Vec};
10-
use bootloader::{BootInfo, entry_point};
10+
use bootloader_api::{
11+
BootInfo,
12+
config::{BootloaderConfig, Mapping},
13+
entry_point,
14+
};
1115
use core::panic::PanicInfo;
12-
use osdev_rust::allocator::HEAP_SIZE;
16+
use kernel::allocator::HEAP_SIZE;
1317

14-
entry_point!(main);
18+
pub static BOOTLOADER_CONFIG: BootloaderConfig = {
19+
let mut config = BootloaderConfig::new_default();
20+
config.mappings.physical_memory = Some(Mapping::FixedAddress(0x20000000000));
21+
config
22+
};
1523

16-
fn main(boot_info: &'static BootInfo) -> ! {
17-
use osdev_rust::allocator;
18-
use osdev_rust::memory::{self, BootInfoFrameAllocator};
24+
entry_point!(main, config = &BOOTLOADER_CONFIG);
25+
26+
fn main(boot_info: &'static mut BootInfo) -> ! {
27+
use kernel::allocator;
28+
use kernel::memory::{self, BootInfoFrameAllocator};
1929
use x86_64::VirtAddr;
2030

21-
osdev_rust::init();
31+
kernel::init();
2232

23-
let phys_mem_offset = VirtAddr::new(boot_info.physical_memory_offset);
33+
let phys_mem_offset = VirtAddr::new(boot_info.physical_memory_offset.into_option().unwrap());
2434
let mut mapper = unsafe { memory::init(phys_mem_offset) };
25-
let mut frame_allocator = unsafe { BootInfoFrameAllocator::init(&boot_info.memory_map) };
35+
let mut frame_allocator = unsafe { BootInfoFrameAllocator::init(&boot_info.memory_regions) };
2636
allocator::init_heap(&mut mapper, &mut frame_allocator).expect("heap initialization failed");
2737

2838
test_main();
@@ -31,7 +41,7 @@ fn main(boot_info: &'static BootInfo) -> ! {
3141

3242
#[panic_handler]
3343
fn panic(info: &PanicInfo) -> ! {
34-
osdev_rust::test_panic_handler(info);
44+
kernel::test_panic_handler(info);
3545
}
3646

3747
#[test_case]

kernel/tests/should_panic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
use core::panic::PanicInfo;
77

8-
use osdev_rust::{QemuExitCode, exit_qemu, serial_print, serial_println};
8+
use kernel::{QemuExitCode, exit_qemu, serial_print, serial_println};
99

1010
#[unsafe(no_mangle)]
1111
pub extern "C" fn _start() -> ! {

kernel/tests/stack_overflow.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
#![no_main]
33
#![feature(abi_x86_interrupt)]
44

5-
use core::panic::PanicInfo;
6-
use lazy_static::lazy_static;
7-
use osdev_rust::{
5+
use core::{panic::PanicInfo, ptr::NonNull};
6+
use kernel::{
87
QemuExitCode, exit_qemu, gdt::DOUBLE_FAULT_IST_INDEX, serial_print, serial_println,
98
test_panic_handler,
109
};
10+
use lazy_static::lazy_static;
1111
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
1212

1313
#[unsafe(no_mangle)]
1414
pub extern "C" fn _start() -> ! {
1515
serial_print!("stack_overflow::stack_overflow...\t");
1616

17-
osdev_rust::gdt::init();
17+
kernel::gdt::init();
1818
init_test_idt();
1919

2020
stack_overflow();
@@ -41,7 +41,12 @@ fn stack_overflow() {
4141
// garante que o compilador não transforme a recursão em um loop.
4242
// devido a tail recursion optimizations.
4343
// isso quebraria o teste.
44-
volatile::Volatile::new(0).read();
44+
unsafe {
45+
volatile::VolatilePtr::new(
46+
NonNull::new(0 as *mut u8).expect("failed to create non-null ptr"),
47+
)
48+
.read();
49+
}
4550
}
4651

4752
lazy_static! {

0 commit comments

Comments
 (0)