Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xor-bits committed Nov 27, 2023
1 parent 00282ef commit beac054
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 83 deletions.
82 changes: 0 additions & 82 deletions crates/kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,91 +115,9 @@ extern "C" fn _start() -> ! {

#[cfg(test)]
mod tests {
use alloc::{
string::{String, ToString},
vec::Vec,
};

use hyperion_scheduler as scheduler;
use scheduler::yield_now;

#[test_case]
fn scheduler_simple_ipc_test() {
let self_pid = scheduler::process().pid;

let task_3_pid = scheduler::schedule(move || {
scheduler::rename("<Find_Missing>".into());

// let pid = scheduler::process().pid;
// info!("I am pid:{pid}");

let mut buf = [0u8; 256];
loop {
let len = scheduler::recv(&mut buf);
let data = &buf[..len];
let string = core::str::from_utf8(&data).expect("data to be UTF-8");

let mut found = [false; 26];
for c in string.chars() {
found[((c as u8).to_ascii_lowercase() - b'a') as usize] = true;
}

let mut buf = String::new();
for missing in found
.iter()
.enumerate()
.filter(|(_, found)| !*found)
.map(|(i, _)| i)
{
buf.push((missing as u8 + b'a') as char);
}
// println!("<Find_Missing>: '{buf}'");

scheduler::send(self_pid, buf.as_bytes()).expect("send err");
}
});

let task_2_pid = scheduler::schedule(move || {
scheduler::rename("<Clean_Input>".into());

// let pid = scheduler::process().pid;
// info!("I am pid:{pid}");

let mut buf = [0u8; 256];
loop {
let len = scheduler::recv(&mut buf);
let messy_data = &buf[..len];
let messy_string = core::str::from_utf8(&messy_data).expect("data to be UTF-8");

let clean_string = messy_string.replace(|c| !char::is_alphabetic(c), "");
// println!("<Clean_Input>: '{clean_string}'");

scheduler::send(task_3_pid, clean_string.as_bytes()).expect("send err");
}
});

scheduler::schedule(move || {
scheduler::rename("<Get_Input>".into());

// let pid = scheduler::process().pid;
// info!("I am pid:{pid}");

loop {
let messy_string = "abc3de5fgh@lmno&pqr%stuv(w)xyz".to_string();
// println!("<Get_Input>: '{messy_string}'");
scheduler::send(task_2_pid, messy_string.as_bytes()).expect("send err");

// wait 2500ms
scheduler::sleep(time::Duration::milliseconds(2500));
}
});

let mut buf = [0u8; 8];
let len = scheduler::recv(&mut buf);
let result = &buf[..len];
// assert_eq!(&result[..], &b"ijk"[..])
}

#[test_case]
fn scheduler_mutex_trivial() {
let mutex = scheduler::lock::Mutex::new(5);
Expand Down
5 changes: 4 additions & 1 deletion crates/slab-alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//! pushed back into it.
#![no_std]
#![feature(pointer_is_aligned)]
#![feature(pointer_is_aligned, const_pointer_is_aligned)]

//

Expand Down Expand Up @@ -48,7 +48,10 @@ pub struct PageFrames {
}

impl PageFrames {
/// # Safety
/// `first` must point to a valid page allocation of `len * 0x1000` bytes
pub const unsafe fn new(first: *mut u8, len: usize) -> Self {
debug_assert!(first.is_aligned_to(0x1000));
Self { first, len }
}

Expand Down

0 comments on commit beac054

Please sign in to comment.