#![no_std] #![no_main] #![feature(custom_test_frameworks)] #![test_runner(amongos::test_runner)] #![reexport_test_harness_main = "test_main"] extern crate alloc; use bootloader::{entry_point, BootInfo}; use core::panic::PanicInfo; entry_point!(main); fn main(boot_info: &'static BootInfo) -> ! { use amongos::allocator; use amongos::memory::{self, BootInfoFrameAllocator}; use x86_64::VirtAddr; amongos::init(); let phys_mem_offset = VirtAddr::new(boot_info.physical_memory_offset); let mut mapper = unsafe { memory::init(phys_mem_offset) }; let mut frame_allocator = unsafe { BootInfoFrameAllocator::init(&boot_info.memory_map) }; allocator::init_heap(&mut mapper, &mut frame_allocator) .expect("heap initialization failed"); test_main(); amongos::hlt_loop() } use alloc::boxed::Box; #[test_case] fn simple_allocation() { let heap_value_1 = Box::new(31); let heap_value_2 = Box::new(69); assert_eq!(*heap_value_1, 31); assert_eq!(*heap_value_2, 69); } use alloc::vec::Vec; #[test_case] fn large_vec() { let n = 1000; let mut vec = Vec::new(); for i in 0..n { vec.push(i); } assert_eq!(vec.iter().sum::(), (n - 1) * n / 2); } use amongos::allocator::HEAP_SIZE; #[test_case] fn many_boxes() { for i in 0..HEAP_SIZE { let x = Box::new(i); assert_eq!(*x, i); } } #[test_case] fn many_boxes_long_lived() { let long_lived = Box::new(1); for i in 0..HEAP_SIZE { let x = Box::new(i); assert_eq!(*x, i); } assert_eq!(*long_lived, 1); } #[panic_handler] fn panic(info: &PanicInfo) -> ! { amongos::test_panic_handler(info) }