Add test for travis

toolchain_update
WangRunji 7 years ago
parent 2e405a0393
commit c446d2bb5e

@ -28,5 +28,10 @@ addons:
packages:
- nasm
env:
matrix:
- TASK="build"
- TASK="run travis=1"
script:
- make
- make ${TASK}

@ -7,6 +7,7 @@ authors = ["Philipp Oppermann <dev@phil-opp.com>"]
crate-type = ["staticlib"]
[features]
test = []
qemu_auto_exit = []
[dependencies]

@ -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

@ -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 { }
}

@ -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());
arch::driver::acpi::init();
loop {
test!(find_mp);
}
arch::driver::acpi::init();
arch::driver::ioapic::init();
io::init();
println!("Hello World{}", "!");
@ -67,10 +66,32 @@ pub extern "C" fn rust_main(multiboot_information_address: usize) {
// initialize our IDT
interrupts::init(&mut memory_controller);
test!(global_allocator);
test!(guard_page);
test_end!();
}
use linked_list_allocator::LockedHeap;
pub const HEAP_START: usize = 0o_000_001_000_000_0000;
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();
@ -81,15 +102,6 @@ pub extern "C" fn rust_main(multiboot_information_address: usize) {
// trigger a stack overflow
stack_overflow();
println!("It did not crash!");
loop {}
}
use linked_list_allocator::LockedHeap;
pub const HEAP_START: usize = 0o_000_001_000_000_0000;
pub const HEAP_SIZE: usize = 100 * 1024; // 100 KiB
#[global_allocator]
static HEAP_ALLOCATOR: LockedHeap = LockedHeap::empty();
}

@ -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));
}
)
}
Loading…
Cancel
Save