summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornatrixaeria <upezu@student.kit.edu>2019-11-09 04:44:04 +0100
committernatrixaeria <upezu@student.kit.edu>2019-11-09 04:44:04 +0100
commitb17a0a41bea7789178919f4a0999ea8519e1f897 (patch)
tree96ef6db92da1c63e99041ef7220e58e8af577543
parenta68a9a11c91c3aca4d6f2e8a32df673ca39ec34d (diff)
Introduce integration test crate
-rw-r--r--kernel/Cargo.toml4
-rwxr-xr-xkernel/run16
-rw-r--r--kernel/src/asm/boot.asm (renamed from kernel/src/boot.asm)2
-rw-r--r--kernel/src/asm/long_mode_init.asm (renamed from kernel/src/long_mode_init.asm)0
-rw-r--r--kernel/src/asm/multiboot_header.asm (renamed from kernel/src/multiboot_header.asm)0
-rw-r--r--kernel/src/lib.rs36
-rw-r--r--kernel/src/main.rs58
-rw-r--r--kernel/tests/test01.rs25
8 files changed, 101 insertions, 40 deletions
diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml
index 9ac2848..a2ce08c 100644
--- a/kernel/Cargo.toml
+++ b/kernel/Cargo.toml
@@ -5,8 +5,8 @@ authors = ["Dennis Kobert <dennis@kobert.dev>",
"Jan Zwerschke"]
edition = "2018"
-[lib]
-crate-type = ["staticlib"]
+# [lib]
+# crate-type = ["staticlib"]
[package.metadata.cargo-xbuild]
sysroot_path = "target/sysroot"
diff --git a/kernel/run b/kernel/run
index 1353d92..f9c8df3 100755
--- a/kernel/run
+++ b/kernel/run
@@ -12,6 +12,7 @@ build_mode=release
action=help
target=x86_64
test_mode=false
+serial_mode=false
function define_vars() {
target_name="$target-$name"
target_path="target/"
@@ -20,7 +21,7 @@ function define_vars() {
iso_path="$target_path/iso/"
obj_path="$iso_path/obj/"
src_path="src/"
- asm_path="$src_path/"
+ asm_path="$src_path/asm/"
link_script="$src_path/linker.ld"
grub_cfg="$src_path/grub.cfg"
}
@@ -33,6 +34,7 @@ print_help() {
echo " -mode=<str> set build mode (standard: $build_mode)"
echo " -target=<str> set target (standard: $target)"
echo " -test enable test mode (standard: disabled)"
+ echo " -serial enable serial mode (standard: disabled)"
echo
echo "actions:"
echo " build build the iso"
@@ -90,7 +92,10 @@ run() {
"x86_64")
qemu="qemu-system-x86_64 -cdrom $iso_path/$name.iso"
if $test_mode; then
- qemu="$qemu -device isa-debug-exit,iobase=0xf4,iosize=0x04 -serial stdio -display none"
+ qemu="$qemu -device isa-debug-exit,iobase=0xf4,iosize=0x04 -serial stdio"
+ if $serial_mode; then
+ qemu="$qemu -display none"
+ fi
fi
$qemu
case "$?" in
@@ -115,14 +120,15 @@ for arg in "$@"; do
target="$(echo $arg | sed "s/^-target=//")"; define_vars;;
-test)
test_mode=true; define_vars;;
- /*kernel-*)
- kernel_libary=$arg;;
+ -serial)
+ serial_mode=true; define_vars;;
"run") action=run;;
"build") action=build;;
"test") action=test;;
"help") action=help;;
*)
- echo "warn: ignoring unknown option '$arg'";;
+ echo "warn: ignoring unknown option '$arg'"
+ kernel_libary=$arg;;
esac
done
diff --git a/kernel/src/boot.asm b/kernel/src/asm/boot.asm
index 36b1ef9..2ecaba8 100644
--- a/kernel/src/boot.asm
+++ b/kernel/src/asm/boot.asm
@@ -168,5 +168,5 @@ p2_table:
resb 4096
alignb 4096 * 512 ; align memory into huge memory page
stack_bottom:
- resb 4096 * 42
+ resb 4096 * 512
stack_top:
diff --git a/kernel/src/long_mode_init.asm b/kernel/src/asm/long_mode_init.asm
index 8c1b1e7..8c1b1e7 100644
--- a/kernel/src/long_mode_init.asm
+++ b/kernel/src/asm/long_mode_init.asm
diff --git a/kernel/src/multiboot_header.asm b/kernel/src/asm/multiboot_header.asm
index 9c9d859..9c9d859 100644
--- a/kernel/src/multiboot_header.asm
+++ b/kernel/src/asm/multiboot_header.asm
diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs
index 59888d1..e5ab3d3 100644
--- a/kernel/src/lib.rs
+++ b/kernel/src/lib.rs
@@ -11,47 +11,19 @@ pub mod interrupts;
pub mod io;
pub mod testing;
-use core::fmt::Write;
pub use io::qemu::{exit_qemu, QemuExitCode};
pub use io::vga_text::OStream;
pub use io::{qemu, serial, vga_text};
+pub use qemu::*;
+#[cfg(test)]
#[no_mangle]
pub extern "C" fn _start() -> ! {
- interrupts::gdt::init();
- interrupts::table::init();
- if cfg!(test) {
- #[cfg(test)]
- test_main();
- qemu::exit_qemu(qemu::QemuExitCode::Success);
- }
-
- x86_64::instructions::interrupts::int3();
-
- /// TODO: write test
- ///fn _loop(i: u64) -> u64 {
- /// if i > 0b1010101001101101 {
- /// return i;
- /// }
- /// let n = i;
- /// let mut stdout = OStream::new();
- /// write!(&mut stdout, "{:x}", &n as *const u64 as u64).unwrap();
- /// _loop(i + 1)
- ///}
- ///_loop(0);
- /// TODO: write test
- ///x86_64::instructions::interrupts::int3();
loop {}
}
+#[cfg(test)]
#[panic_handler]
-#[no_mangle]
-pub extern "C" fn panic_handler(info: &core::panic::PanicInfo) -> ! {
- io::panic_screen::show(info.message());
-
- if cfg!(test) {
- write!(serial::SerialStream::new(), "Testing failed\n").unwrap();
- qemu::exit_qemu(qemu::QemuExitCode::Failed);
- }
+fn panic(_info: &core::panic::PanicInfo) -> ! {
loop {}
}
diff --git a/kernel/src/main.rs b/kernel/src/main.rs
new file mode 100644
index 0000000..ae78c93
--- /dev/null
+++ b/kernel/src/main.rs
@@ -0,0 +1,58 @@
+#![no_main]
+#![feature(compiler_builtins_lib)]
+#![feature(custom_test_frameworks)]
+#![feature(abi_x86_interrupt)]
+#![feature(panic_info_message)]
+#![test_runner(crate::testing::serial_test_runner)]
+#![reexport_test_harness_main = "test_main"]
+#![no_std]
+
+pub mod interrupts;
+pub mod io;
+pub mod testing;
+
+use core::fmt::Write;
+pub use io::qemu::{exit_qemu, QemuExitCode};
+pub use io::vga_text::OStream;
+pub use io::{qemu, serial, vga_text};
+
+#[cfg(not(test))]
+#[no_mangle]
+extern "C" fn _start() -> ! {
+ interrupts::gdt::init();
+ interrupts::table::init();
+ if cfg!(test) {
+ #[cfg(test)]
+ test_main();
+ qemu::exit_qemu(qemu::QemuExitCode::Success);
+ }
+
+ x86_64::instructions::interrupts::int3();
+
+ /// TODO: write test
+ ///fn _loop(i: u64) -> u64 {
+ /// if i > 0b1010101001101101 {
+ /// return i;
+ /// }
+ /// let n = i;
+ /// let mut stdout = OStream::new();
+ /// write!(&mut stdout, "{:x}", &n as *const u64 as u64).unwrap();
+ /// _loop(i + 1)
+ ///}
+ ///_loop(0);
+ /// TODO: write test
+ ///x86_64::instructions::interrupts::int3();
+ loop {}
+}
+
+#[panic_handler]
+#[no_mangle]
+extern "C" fn panic_handler(info: &core::panic::PanicInfo) -> ! {
+ io::panic_screen::show(info.message());
+
+ if cfg!(test) {
+ write!(serial::SerialStream::new(), "Testing failed\n").unwrap();
+ qemu::exit_qemu(qemu::QemuExitCode::Failed);
+ }
+ loop {}
+}
diff --git a/kernel/tests/test01.rs b/kernel/tests/test01.rs
new file mode 100644
index 0000000..933d689
--- /dev/null
+++ b/kernel/tests/test01.rs
@@ -0,0 +1,25 @@
+#![no_main]
+#![feature(compiler_builtins_lib)]
+#![feature(custom_test_frameworks)]
+#![feature(abi_x86_interrupt)]
+#![feature(panic_info_message)]
+#![test_runner(crate::testing::serial_test_runner)]
+#![no_std]
+
+use kernel;
+use kernel::io::qemu;
+
+#[no_mangle]
+extern "C" fn _start() -> ! {
+ kernel::io::panic_screen::show(Some(&format_args!("hey bro")));
+
+
+ loop {}
+}
+
+#[cfg(test)]
+#[panic_handler]
+#[no_mangle]
+extern "C" fn panic_handler(info: &core::panic::PanicInfo) -> ! {
+ loop {}
+}