diff --git a/.travis.yml b/.travis.yml index 9ac1567..76bda75 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,5 +28,10 @@ addons: packages: - nasm +env: + matrix: + - TASK="build" + - TASK="run travis=1" + script: - - make + - make ${TASK} diff --git a/Cargo.toml b/Cargo.toml index 4dc861a..a60b1f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ authors = ["Philipp Oppermann "] crate-type = ["staticlib"] [features] +test = [] qemu_auto_exit = [] [dependencies] diff --git a/Makefile b/Makefile index d47c279..06eaef3 100644 --- a/Makefile +++ b/Makefile @@ -11,9 +11,18 @@ assembly_source_files := $(wildcard $(boot_src)/*.asm) assembly_object_files := $(patsubst $(boot_src)/%.asm, \ build/arch/$(arch)/boot/%.o, $(assembly_source_files)) qemu_opts := -cdrom $(iso) \ - -smp 2 \ - -device isa-debug-exit # enable shutdown inside the qemu -features := qemu_auto_exit + -smp 2 + +ifdef travis + test := 1 + features := $(features) qemu_auto_exit +endif + +ifdef test + features := $(features) test + # enable shutdown inside the qemu + qemu_opts := $(qemu_opts) -device isa-debug-exit +endif ifeq ($(shell uname), Linux) prefix := @@ -23,7 +32,7 @@ endif ld := $(prefix)ld -.PHONY: all clean run iso kernel +.PHONY: all clean run iso kernel build all: $(kernel) @@ -31,10 +40,12 @@ clean: @rm -r build run: $(iso) - @qemu-system-$(arch) $(qemu_opts) + @qemu-system-$(arch) $(qemu_opts) || [ $$? -eq 1 ] # run qemu and assert it exit 1 iso: $(iso) +build: iso + $(iso): $(kernel) $(grub_cfg) @mkdir -p build/isofiles/boot/grub @cp $(kernel) build/isofiles/boot/kernel.bin @@ -47,7 +58,7 @@ $(kernel): kernel $(rust_os) $(assembly_object_files) $(linker_script) $(assembly_object_files) $(rust_os) kernel: - @RUST_TARGET_PATH=$(shell pwd) xargo build --target $(target) --features $(features) + @RUST_TARGET_PATH=$(shell pwd) xargo build --target $(target) --features "$(features)" # compile assembly files build/arch/$(arch)/boot/%.o: $(boot_src)/%.asm diff --git a/src/lang.rs b/src/lang.rs index 936dec2..e6f6fec 100644 --- a/src/lang.rs +++ b/src/lang.rs @@ -13,7 +13,7 @@ pub extern fn panic_fmt(fmt: core::fmt::Arguments, file: &'static str, line: u32 println!("\n\nPANIC in {} at line {}:", file, line); println!(" {}", fmt); if cfg!(feature = "qemu_auto_exit") { - unsafe{ cpu::exit_in_qemu(1) } + unsafe{ cpu::exit_in_qemu(3) } } else { loop { } } diff --git a/src/lib.rs b/src/lib.rs index 968ae21..1d6c0f0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,8 +33,9 @@ mod io; mod memory; mod interrupts; mod lang; -#[macro_use] mod util; +#[macro_use] // test! +mod test_util; #[allow(dead_code)] #[cfg(target_arch = "x86_64")] @@ -45,11 +46,9 @@ mod arch; #[no_mangle] pub extern "C" fn rust_main(multiboot_information_address: usize) { // ATTENTION: we have a very small stack and no guard page - println!("MP = {:?}", arch::driver::mp::find_mp()); + test!(find_mp); + arch::driver::acpi::init(); - loop { - - } arch::driver::ioapic::init(); io::init(); println!("Hello World{}", "!"); @@ -67,23 +66,9 @@ pub extern "C" fn rust_main(multiboot_information_address: usize) { // initialize our IDT interrupts::init(&mut memory_controller); - for i in 0..10000 { - format!("Some String"); - } - - // invoke a breakpoint exception - x86_64::instructions::interrupts::int3(); - - fn stack_overflow() { - stack_overflow(); // for each recursion, the return address is pushed - } - - // trigger a stack overflow - stack_overflow(); - - - println!("It did not crash!"); - loop {} + test!(global_allocator); + test!(guard_page); + test_end!(); } use linked_list_allocator::LockedHeap; @@ -93,3 +78,30 @@ pub const HEAP_SIZE: usize = 100 * 1024; // 100 KiB #[global_allocator] static HEAP_ALLOCATOR: LockedHeap = LockedHeap::empty(); + +mod test { + pub fn global_allocator() { + for i in 0..10000 { + format!("Some String"); + } + } + pub fn find_mp() { + use arch; + let mp = arch::driver::mp::find_mp(); + assert!(mp.is_some()); + } + pub fn guard_page() { + use x86_64; + // invoke a breakpoint exception + x86_64::instructions::interrupts::int3(); + + fn stack_overflow() { + stack_overflow(); // for each recursion, the return address is pushed + } + + // trigger a stack overflow + stack_overflow(); + + println!("It did not crash!"); + } +} \ No newline at end of file diff --git a/src/test_util.rs b/src/test_util.rs new file mode 100644 index 0000000..9bab06b --- /dev/null +++ b/src/test_util.rs @@ -0,0 +1,25 @@ +macro_rules! test_end { + () => ( + println!("Test end"); + // test success + unsafe{ arch::cpu::exit_in_qemu(1) } + ) +} + +macro_rules! test { + // ($name:expr, $body:expr) => ( + // if cfg!(feature = "test") { + // println!("Testing: {}", $name); + // $body; + // println!("Success: {}", $name); + // } + // ); + ($func:ident) => ( + if cfg!(feature = "test") { + println!("Testing: {}", stringify!($func)); + use self::test::$func; + test::$func(); + println!("Success: {}", stringify!($func)); + } + ) +} \ No newline at end of file