ok
ok
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(custom_test_frameworks)]
|
||||
#![test_runner(CrystalOS::test_runner)]
|
||||
#![reexport_test_harness_main = "test_main"]
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
use bootloader::{entry_point, BootInfo};
|
||||
use core::panic::PanicInfo;
|
||||
|
||||
use alloc::{ boxed::Box, vec::Vec };
|
||||
|
||||
|
||||
entry_point!(main);
|
||||
|
||||
fn main(boot_info: &'static BootInfo) -> ! {
|
||||
use CrystalOS::kernel::allocator;
|
||||
use CrystalOS::kernel::memory::{self, BootInfoFrameAllocator};
|
||||
use x86_64::VirtAddr;
|
||||
|
||||
CrystalOS::init();
|
||||
|
||||
let physical_memory_offset = VirtAddr::new(boot_info.physical_memory_offset);
|
||||
let mut mapper = unsafe { memory::init(physical_memory_offset)};
|
||||
let mut frame_allocator = unsafe {
|
||||
BootInfoFrameAllocator::init(&boot_info.memory_map)
|
||||
};
|
||||
allocator::init_heap(&mut mapper, &mut frame_allocator).expect("failed to initialise heap");
|
||||
|
||||
test_main();
|
||||
|
||||
loop {}
|
||||
}
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(info: &PanicInfo) -> ! {
|
||||
CrystalOS::test_panic_handler(info)
|
||||
}
|
||||
|
||||
#[test_case]
|
||||
fn box_allocation() {
|
||||
let heap_1 = Box::new(69);
|
||||
let heap_2 = Box::new(420);
|
||||
assert_eq!(*heap_1, 69);
|
||||
assert_eq!(*heap_2, 420);
|
||||
}
|
||||
|
||||
#[test_case]
|
||||
fn vec_allocation() {
|
||||
let x = 1000;
|
||||
let mut vector = Vec::new();
|
||||
for i in 0..x {
|
||||
vector.push(i);
|
||||
}
|
||||
assert_eq!(vector.iter().sum::<u64>(), (x-1) * x/2);
|
||||
|
||||
}
|
||||
|
||||
#[test_case]
|
||||
fn reallocation() {
|
||||
use CrystalOS::kernel::allocator::HEAP_SIZE;
|
||||
|
||||
for i in 0..HEAP_SIZE {
|
||||
let x = Box::new(i);
|
||||
assert_eq!(*x, i);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
|
||||
use core::panic::PanicInfo;
|
||||
use CrystalOS::{QemuExitCode, exit, serial_println, serial_print};
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(_info: &PanicInfo) -> ! {
|
||||
serial_println!("OK");
|
||||
exit(QemuExitCode::Ok);
|
||||
|
||||
loop {}
|
||||
}
|
||||
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn _start() -> ! {
|
||||
shouldpanic();
|
||||
serial_println!("Err: Test did not panic");
|
||||
exit(QemuExitCode::Err);
|
||||
loop {}
|
||||
}
|
||||
|
||||
fn shouldpanic() {
|
||||
serial_print!("{}...\t", "should_panic::should_panic");
|
||||
assert_eq!(1,2);
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(abi_x86_interrupt)]
|
||||
|
||||
use core::panic::PanicInfo;
|
||||
use lazy_static::lazy_static;
|
||||
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
|
||||
use CrystalOS::{exit, QemuExitCode, serial_println, serial_print};
|
||||
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn _start() -> ! {
|
||||
serial_print!("stack_overflow::stack_overflow...\t");
|
||||
|
||||
CrystalOS::kernel::gdt::init();
|
||||
init_test_idt();
|
||||
|
||||
stack_overflow();
|
||||
|
||||
panic!("stack overflow did not stop execution!");
|
||||
}
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(info: &PanicInfo) -> ! {
|
||||
CrystalOS::test_panic_handler(info);
|
||||
}
|
||||
|
||||
#[allow(unconditional_recursion)]
|
||||
fn stack_overflow() {
|
||||
stack_overflow();
|
||||
volatile::Volatile::new(0).read();
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref TEST_IDT: InterruptDescriptorTable = {
|
||||
let mut idt = InterruptDescriptorTable::new();
|
||||
unsafe {
|
||||
idt.double_fault.set_handler_fn(test_double_fault_handler).set_stack_index(CrystalOS::kernel::gdt::DOUBLE_FAULT_IST_INDEX);
|
||||
}
|
||||
idt
|
||||
};
|
||||
}
|
||||
|
||||
extern "x86-interrupt" fn test_double_fault_handler(
|
||||
_stack_frame: InterruptStackFrame,
|
||||
_error_code: u64,
|
||||
) -> ! {
|
||||
serial_println!("OK");
|
||||
exit(QemuExitCode::Ok);
|
||||
loop {}
|
||||
}
|
||||
|
||||
|
||||
pub fn init_test_idt() {
|
||||
TEST_IDT.load();
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(custom_test_frameworks)]
|
||||
#![test_runner(CrystalOS::test_runner)]
|
||||
#![reexport_test_harness_main = "test_main"]
|
||||
|
||||
use core::panic::PanicInfo;
|
||||
use CrystalOS::println;
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn _start() -> ! {
|
||||
test_main();
|
||||
|
||||
loop {}
|
||||
}
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(info: &PanicInfo) -> ! {
|
||||
CrystalOS::test_panic_handler(info)
|
||||
}
|
||||
|
||||
#[test_case]
|
||||
fn test_println() {
|
||||
println!("testing println output");
|
||||
}
|
||||
Reference in New Issue
Block a user