-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test kernels to finally add some tests
The test kernels are built by the build.rs file. Unfortunately, there is no #[cfg(test)] for build.rs files yet, so the test kernels are always built. Simply run `cargo test` to run the test kernels.
- Loading branch information
Showing
13 changed files
with
285 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use std::process::Stdio; | ||
|
||
use OS_DISK; | ||
|
||
fn run_test_kernel(kernel: &str, os_disk: &str) { | ||
let mut cmd = std::process::Command::new("qemu-system-x86_64"); | ||
cmd.arg("--no-reboot"); | ||
cmd.arg("-d").arg("guest_errors"); | ||
cmd.arg("-bios").arg(ovmf_prebuilt::ovmf_pure_efi()); | ||
cmd.arg("-drive").arg(format!("format=raw,file={kernel}")); | ||
cmd.arg("-drive") | ||
.arg(format!("file={},if=ide,format=raw", os_disk)); | ||
cmd.arg("-nographic"); | ||
cmd.arg("-device") | ||
.arg("isa-debug-exit,iobase=0xf4,iosize=0x04"); | ||
|
||
cmd.stderr(Stdio::null()); | ||
cmd.stdout(Stdio::null()); | ||
cmd.stdin(Stdio::null()); | ||
|
||
let mut child = cmd.spawn().unwrap(); | ||
let exit_code = child.wait().unwrap(); | ||
assert_eq!(exit_code.code(), Some(33)); // 33=success, 35=failed | ||
} | ||
|
||
#[test] | ||
fn test_kernel_multitasking() { | ||
const KERNEL: &str = env!("TEST_KERNEL_MULTITASKING_PATH"); | ||
run_test_kernel(KERNEL, OS_DISK); | ||
} | ||
|
||
#[test] | ||
fn test_kernel_vfs() { | ||
const KERNEL: &str = env!("TEST_KERNEL_VFS_PATH"); | ||
run_test_kernel(KERNEL, OS_DISK); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "test_kernel_multitasking" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
bootloader_api.workspace = true | ||
kernel = { path = "../../kernel" } | ||
x86_64.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#![no_std] | ||
#![no_main] | ||
#![feature(panic_info_message)] | ||
|
||
use core::panic::PanicInfo; | ||
use core::sync::atomic::AtomicU64; | ||
use core::sync::atomic::Ordering::Relaxed; | ||
|
||
use bootloader_api::{entry_point, BootInfo, BootloaderConfig}; | ||
use x86_64::instructions::hlt; | ||
|
||
use kernel::qemu::ExitCode; | ||
use kernel::{bootloader_config, kernel_init, process, serial_println}; | ||
|
||
const CONFIG: BootloaderConfig = bootloader_config(); | ||
|
||
entry_point!(kernel_main, config = &CONFIG); | ||
|
||
static COUNTER: AtomicU64 = AtomicU64::new(0); | ||
|
||
fn kernel_main(boot_info: &'static mut BootInfo) -> ! { | ||
kernel_init(boot_info); | ||
|
||
assert_eq!(0, COUNTER.load(Relaxed)); | ||
|
||
process::spawn_task_in_current_process("count1", count); | ||
process::spawn_task_in_current_process("count2", count); | ||
process::spawn_task_in_current_process("count3", count); | ||
|
||
for _ in 0..20 { | ||
hlt(); // should be enough to get the functions scheduled 5 times each | ||
} | ||
|
||
assert_eq!(15, COUNTER.load(Relaxed)); | ||
|
||
kernel::qemu::exit(ExitCode::Success) | ||
} | ||
|
||
extern "C" fn count() { | ||
for _ in 0..5 { | ||
COUNTER.fetch_add(1, Relaxed); | ||
} | ||
} | ||
|
||
#[panic_handler] | ||
fn panic_handler(info: &PanicInfo) -> ! { | ||
serial_println!( | ||
"kernel panicked in pid={} ({}) tid={} ({}): {}", | ||
kernel::process::current().process_id(), | ||
kernel::process::current().name(), | ||
kernel::process::current_task().task_id(), | ||
kernel::process::current_task().name(), | ||
info.message().unwrap() | ||
); | ||
if let Some(location) = info.location() { | ||
serial_println!( | ||
"\tat {}:{}:{}", | ||
location.file(), | ||
location.line(), | ||
location.column() | ||
); | ||
} | ||
|
||
kernel::qemu::exit(ExitCode::Failed) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "test_kernel_vfs" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
bootloader_api.workspace = true | ||
kernel = { path = "../../kernel" } |
Oops, something went wrong.