- unit tests now work properly
- hopefully github actions workflow should run tests now?
This commit is contained in:
@@ -56,10 +56,3 @@ version = "0.3.4"
|
|||||||
default-features = false
|
default-features = false
|
||||||
features = ["alloc"]
|
features = ["alloc"]
|
||||||
|
|
||||||
[[test]]
|
|
||||||
name = "should_panic"
|
|
||||||
harness = false
|
|
||||||
|
|
||||||
[[test]]
|
|
||||||
name = "stack_overflow"
|
|
||||||
harness = false
|
|
||||||
|
|||||||
+1
-1
@@ -21,4 +21,4 @@ COPY . .
|
|||||||
|
|
||||||
RUN cargo update -p proc-macro2
|
RUN cargo update -p proc-macro2
|
||||||
|
|
||||||
CMD ["cargo", "build", "--release", "--verbose"]
|
CMD ["cargo", "build", "--release;", "cargo", "test"]
|
||||||
|
|||||||
+42
-33
@@ -1,6 +1,4 @@
|
|||||||
|
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
#![cfg_attr(test, no_main)]
|
#![cfg_attr(test, no_main)]
|
||||||
#![feature(custom_test_frameworks)]
|
#![feature(custom_test_frameworks)]
|
||||||
#![test_runner(crate::test_runner)]
|
#![test_runner(crate::test_runner)]
|
||||||
@@ -11,23 +9,42 @@
|
|||||||
#![feature(async_closure)]
|
#![feature(async_closure)]
|
||||||
#![feature(global_asm)]
|
#![feature(global_asm)]
|
||||||
|
|
||||||
|
|
||||||
|
use alloc::string::String;
|
||||||
|
use alloc::vec;
|
||||||
|
use bootloader::{entry_point, BootInfo};
|
||||||
use core::panic::PanicInfo;
|
use core::panic::PanicInfo;
|
||||||
|
extern crate alloc;
|
||||||
|
|
||||||
|
|
||||||
pub mod system;
|
pub mod system;
|
||||||
pub mod user;
|
pub mod user;
|
||||||
|
|
||||||
pub use system::std as std;
|
pub use system::std as std;
|
||||||
pub use user::bin::*;
|
pub use user::bin::*;
|
||||||
|
use crate::calc::Calculator;
|
||||||
extern crate alloc;
|
use crate::std::application::Application;
|
||||||
//extern crate fatfs;
|
|
||||||
|
|
||||||
use bootloader::{entry_point, BootInfo};
|
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
entry_point!(test_kernel_main);
|
#[repr(u32)]
|
||||||
|
pub enum QemuExitCode {
|
||||||
|
Ok = 0x10,
|
||||||
|
Err = 0x11,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn poweroff() {
|
||||||
|
exit(QemuExitCode::Ok);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn exit(code: QemuExitCode) {
|
||||||
|
use x86_64::instructions::port::Port;
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
let mut port = Port::new(0xf4);
|
||||||
|
port.write(code as u32);
|
||||||
|
}
|
||||||
|
println!("e");
|
||||||
|
}
|
||||||
|
|
||||||
#[alloc_error_handler]
|
#[alloc_error_handler]
|
||||||
fn alloc_error_handler(layout: alloc::alloc::Layout) -> ! {
|
fn alloc_error_handler(layout: alloc::alloc::Layout) -> ! {
|
||||||
@@ -44,6 +61,17 @@ pub fn hlt() -> ! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
entry_point!(test_kernel_main);
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
fn test_kernel_main(boot_info: &'static BootInfo) -> ! {
|
||||||
|
system::init(boot_info);
|
||||||
|
test_main();
|
||||||
|
hlt();
|
||||||
|
}
|
||||||
|
|
||||||
pub trait Testable {
|
pub trait Testable {
|
||||||
fn run(&self) -> ();
|
fn run(&self) -> ();
|
||||||
}
|
}
|
||||||
@@ -71,12 +99,6 @@ pub fn test_panic_handler(info: &PanicInfo) -> ! {
|
|||||||
hlt();
|
hlt();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
fn test_kernel_main(_boot_info: &'static BootInfo) -> ! {
|
|
||||||
start();
|
|
||||||
test_main();
|
|
||||||
hlt();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[panic_handler]
|
#[panic_handler]
|
||||||
@@ -84,23 +106,10 @@ fn panic(info: &PanicInfo) -> ! {
|
|||||||
test_panic_handler(info)
|
test_panic_handler(info)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
||||||
#[repr(u32)]
|
|
||||||
pub enum QemuExitCode {
|
|
||||||
Ok = 0x10,
|
|
||||||
Err = 0x11,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn poweroff() {
|
|
||||||
exit(QemuExitCode::Ok);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn exit(code: QemuExitCode) {
|
#[cfg(test)]
|
||||||
use x86_64::instructions::port::Port;
|
#[test_case]
|
||||||
|
fn trivial_assertion() {
|
||||||
unsafe {
|
assert_eq!(1, 1);
|
||||||
let mut port = Port::new(0xf4);
|
|
||||||
port.write(code as u32);
|
|
||||||
}
|
|
||||||
println!("e");
|
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-2
@@ -25,11 +25,15 @@ fn panic(info: &PanicInfo) -> ! {
|
|||||||
CrystalOS::test_panic_handler(info)
|
CrystalOS::test_panic_handler(info)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
entry_point!(main);
|
entry_point!(main);
|
||||||
|
|
||||||
fn main(boot_info: &'static BootInfo) -> ! {
|
fn main(boot_info: &'static BootInfo) -> ! {
|
||||||
CrystalOS::start(boot_info);
|
CrystalOS::start(boot_info);
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
test_main();
|
||||||
|
|
||||||
// runs the 'mainloop' of the OS;
|
// runs the 'mainloop' of the OS;
|
||||||
let mut executor = Executor::new();
|
let mut executor = Executor::new();
|
||||||
executor.spawn(Task::new(shell::command_handler()));
|
executor.spawn(Task::new(shell::command_handler()));
|
||||||
@@ -37,8 +41,8 @@ fn main(boot_info: &'static BootInfo) -> ! {
|
|||||||
executor.try_run();
|
executor.try_run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
test_main();
|
|
||||||
|
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,69 +0,0 @@
|
|||||||
|
|
||||||
#![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::start();
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
|
|
||||||
#![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);
|
|
||||||
}
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
|
|
||||||
#![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();
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
|
|
||||||
#![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