Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit tests for the scheduler #884

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ exclude = [
crate-type = ["staticlib", "lib"] # "lib" required for integration tests
name = "hermit"

[build]
profiler = true

[[test]]
name = "basic_math"
harness = true
Expand Down
2 changes: 1 addition & 1 deletion src/arch/aarch64/kernel/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl TaskStacks {
}
}
}

#[cfg(target_os = "none")]
impl Drop for TaskStacks {
fn drop(&mut self) {
// we should never deallocate a boot stack
Expand Down
6 changes: 6 additions & 0 deletions src/arch/x86_64/kernel/apic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,12 +645,18 @@ fn __set_oneshot_timer(wakeup_time: Option<u64>) {
}
}

#[cfg(target_os = "none")]
pub fn set_oneshot_timer(wakeup_time: Option<u64>) {
without_interrupts(|| {
__set_oneshot_timer(wakeup_time);
});
}

#[cfg(not(target_os = "none"))]
pub fn set_oneshot_timer(wakeup_time: Option<u64>) {
println!("Mocking : set_oneshot_timer()");
}

pub fn init_x2apic() {
if processor::supports_x2apic() {
debug!("Enable x2APIC support");
Expand Down
7 changes: 7 additions & 0 deletions src/arch/x86_64/kernel/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1007,12 +1007,19 @@ pub fn shutdown() -> ! {
}
}

#[cfg(target_os = "none")]
pub fn get_timer_ticks() -> u64 {
// We simulate a timer with a 1 microsecond resolution by taking the CPU timestamp
// and dividing it by the CPU frequency in MHz.
get_timestamp() / u64::from(get_frequency())
}

#[cfg(not(target_os = "none"))]
pub fn get_timer_ticks() -> u64 {
println!("Mocking get_timer_ticks()");
10
}

pub fn get_frequency() -> u16 {
CPU_FREQUENCY.get()
}
Expand Down
14 changes: 7 additions & 7 deletions src/arch/x86_64/kernel/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,18 @@ struct State {

pub struct BootStack {
/// stack for kernel tasks
stack: VirtAddr,
pub stack: VirtAddr,
/// stack to handle interrupts
ist1: VirtAddr,
pub ist1: VirtAddr,
}

pub struct CommonStack {
/// start address of allocated virtual memory region
virt_addr: VirtAddr,
pub virt_addr: VirtAddr,
/// start address of allocated virtual memory region
phys_addr: PhysAddr,
pub phys_addr: PhysAddr,
/// total size of all stacks
total_size: usize,
pub total_size: usize,
}

pub enum TaskStacks {
Expand Down Expand Up @@ -202,7 +202,7 @@ impl TaskStacks {
IST_SIZE
}
}

#[cfg(target_os = "none")]
impl Drop for TaskStacks {
fn drop(&mut self) {
// we should never deallocate a boot stack
Expand Down Expand Up @@ -366,7 +366,7 @@ extern "x86-interrupt" fn timer_handler(_stack_frame: interrupts::ExceptionStack
increment_irq_counter(apic::TIMER_INTERRUPT_NUMBER);
core_scheduler().handle_waiting_tasks();
apic::eoi();
core_scheduler().reschedule();
core_scheduler().scheduler();
}

pub fn install_timer_handler() {
Expand Down