mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-20 09:03:28 +00:00
kernel: tests: add memory measurement to test suite
This adds a feature to enable memory measurement, so we can determine if we're leaking memory anywhere. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
e652150c6e
commit
bf15ac08f4
7 changed files with 135 additions and 100 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
|
@ -297,6 +297,7 @@ dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"riscv",
|
"riscv",
|
||||||
"sha3",
|
"sha3",
|
||||||
|
"stats_alloc",
|
||||||
"xous",
|
"xous",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -545,6 +546,12 @@ dependencies = [
|
||||||
"xous",
|
"xous",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "stats_alloc"
|
||||||
|
version = "0.1.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a260c96bf26273969f360c2fc2e2c7732acc2ce49d939c7243c7230c2ad179d0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "strsim"
|
name = "strsim"
|
||||||
version = "0.8.0"
|
version = "0.8.0"
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ description = "Core kernel for Xous, including task switching and memory managem
|
||||||
bitflags = "1.2.1"
|
bitflags = "1.2.1"
|
||||||
xous = { path = "../xous-rs", features = ["forget-memory-messages"] }
|
xous = { path = "../xous-rs", features = ["forget-memory-messages"] }
|
||||||
debug-here = "0.2.2"
|
debug-here = "0.2.2"
|
||||||
|
stats_alloc = { version = "0.1.8", optional = true }
|
||||||
|
|
||||||
[target.'cfg(target_arch = "riscv32")'.dependencies]
|
[target.'cfg(target_arch = "riscv32")'.dependencies]
|
||||||
riscv = "0.5.6"
|
riscv = "0.5.6"
|
||||||
|
|
@ -25,3 +26,4 @@ lazy_static = "1.4"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
debug-print = []
|
debug-print = []
|
||||||
|
report-memory = ["stats_alloc"]
|
||||||
|
|
|
||||||
|
|
@ -54,10 +54,10 @@ fn handle_connection(mut conn: TcpStream, pid: PID, chn: Sender<ThreadMessage>)
|
||||||
// If the connection has gone away, send a `TerminateProcess` message to the main
|
// If the connection has gone away, send a `TerminateProcess` message to the main
|
||||||
// and then exit this thread.
|
// and then exit this thread.
|
||||||
if e.kind() != std::io::ErrorKind::WouldBlock {
|
if e.kind() != std::io::ErrorKind::WouldBlock {
|
||||||
println!(
|
// println!(
|
||||||
"KERNEL({}): Client disconnected: {} ({:?}). Shutting down virtual process.",
|
// "KERNEL({}): Client disconnected: {} ({:?}). Shutting down virtual process.",
|
||||||
pid, e, e
|
// pid, e, e
|
||||||
);
|
// );
|
||||||
chn.send(ThreadMessage::SysCall(pid, xous::SysCall::TerminateProcess))
|
chn.send(ThreadMessage::SysCall(pid, xous::SysCall::TerminateProcess))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
return;
|
return;
|
||||||
|
|
@ -83,7 +83,7 @@ fn handle_connection(mut conn: TcpStream, pid: PID, chn: Sender<ThreadMessage>)
|
||||||
tmp_data.resize(msg.buf.len(), 0);
|
tmp_data.resize(msg.buf.len(), 0);
|
||||||
conn.read_exact(&mut tmp_data)
|
conn.read_exact(&mut tmp_data)
|
||||||
.map_err(|_e| {
|
.map_err(|_e| {
|
||||||
println!("KERNEL({}): Read Error {}", pid, _e);
|
// println!("KERNEL({}): Read Error {}", pid, _e);
|
||||||
chn.send(ThreadMessage::SysCall(
|
chn.send(ThreadMessage::SysCall(
|
||||||
pid,
|
pid,
|
||||||
xous::SysCall::TerminateProcess,
|
xous::SysCall::TerminateProcess,
|
||||||
|
|
@ -250,7 +250,7 @@ pub fn idle() -> bool {
|
||||||
SystemServices::with_mut(|ss| ss.switch_to(new_pid, Some(1))).unwrap();
|
SystemServices::with_mut(|ss| ss.switch_to(new_pid, Some(1))).unwrap();
|
||||||
}
|
}
|
||||||
ThreadMessage::SysCall(pid, call) => {
|
ThreadMessage::SysCall(pid, call) => {
|
||||||
println!("KERNEL({}): Received syscall {:?}", pid, call);
|
// println!("KERNEL({}): Received syscall {:?}", pid, call);
|
||||||
crate::arch::process::set_current_pid(pid);
|
crate::arch::process::set_current_pid(pid);
|
||||||
// println!("KERNEL({}): Now running as the new process", pid);
|
// println!("KERNEL({}): Now running as the new process", pid);
|
||||||
|
|
||||||
|
|
@ -280,7 +280,7 @@ pub fn idle() -> bool {
|
||||||
// Handle the syscall within the Xous kernel
|
// Handle the syscall within the Xous kernel
|
||||||
let response = crate::syscall::handle(pid, call).unwrap_or_else(Result::Error);
|
let response = crate::syscall::handle(pid, call).unwrap_or_else(Result::Error);
|
||||||
|
|
||||||
println!("KERNEL({}): Syscall response {:?}", pid, response);
|
// println!("KERNEL({}): Syscall response {:?}", pid, response);
|
||||||
// There's a response if it wasn't a blocked process and we're not terminating.
|
// There's a response if it wasn't a blocked process and we're not terminating.
|
||||||
// Send the response back to the target.
|
// Send the response back to the target.
|
||||||
if response != Result::BlockedProcess && !is_terminate && !is_shutdown {
|
if response != Result::BlockedProcess && !is_terminate && !is_shutdown {
|
||||||
|
|
@ -308,7 +308,6 @@ pub fn idle() -> bool {
|
||||||
crate::arch::process::set_current_pid(existing_pid);
|
crate::arch::process::set_current_pid(existing_pid);
|
||||||
}
|
}
|
||||||
// SystemServices::with_mut(|ss| {
|
// SystemServices::with_mut(|ss| {
|
||||||
// println!("295: Switching from {}", pid);
|
|
||||||
// ss.switch_from(pid, 1, true)}).unwrap();
|
// ss.switch_from(pid, 1, true)}).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -289,7 +289,7 @@ impl Server {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructure the PID and context ID from the `pid_ctx` field
|
// Destructure the PID and context ID from the `pid_ctx` field
|
||||||
println!("Taking waiting message -- pid: {} ctx: {}", pid, ctx);
|
// println!("Taking waiting message -- pid: {} ctx: {}", pid, ctx);
|
||||||
|
|
||||||
if forget {
|
if forget {
|
||||||
return Ok(WaitingMessage::ForgetMemory(MemoryRange::new(
|
return Ok(WaitingMessage::ForgetMemory(MemoryRange::new(
|
||||||
|
|
@ -616,10 +616,6 @@ impl Server {
|
||||||
// If the context mask matches this context number, remove it
|
// If the context mask matches this context number, remove it
|
||||||
// and return the index.
|
// and return the index.
|
||||||
if self.ready_contexts & test_ctx_mask == test_ctx_mask {
|
if self.ready_contexts & test_ctx_mask == test_ctx_mask {
|
||||||
println!(
|
|
||||||
"Returning ready context {:08b}: {}",
|
|
||||||
self.ready_contexts, ctx_number
|
|
||||||
);
|
|
||||||
self.ready_contexts &= !test_ctx_mask;
|
self.ready_contexts &= !test_ctx_mask;
|
||||||
return Some(ctx_number);
|
return Some(ctx_number);
|
||||||
}
|
}
|
||||||
|
|
@ -651,7 +647,7 @@ impl Server {
|
||||||
|
|
||||||
/// Add the given context to the list of ready and waiting contexts.
|
/// Add the given context to the list of ready and waiting contexts.
|
||||||
pub fn park_context(&mut self, context: CtxID) {
|
pub fn park_context(&mut self, context: CtxID) {
|
||||||
println!("KERNEL({}): Parking context: {}", self.pid, context);
|
// println!("KERNEL({}): Parking context: {}", self.pid, context);
|
||||||
self.ready_contexts |= 1 << context;
|
self.ready_contexts |= 1 << context;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -299,7 +299,7 @@ impl SystemServices {
|
||||||
let new_pid = pid_from_usize(idx + 1)?;
|
let new_pid = pid_from_usize(idx + 1)?;
|
||||||
arch::process::Process::create(new_pid, init_process);
|
arch::process::Process::create(new_pid, init_process);
|
||||||
// #[allow(clippy::unit_arg)]
|
// #[allow(clippy::unit_arg)]
|
||||||
println!("Creating new process for PID {}", new_pid);
|
// println!("Creating new process for PID {}", new_pid);
|
||||||
entry.state = ProcessState::Setup(init_context);
|
entry.state = ProcessState::Setup(init_context);
|
||||||
entry.ppid = crate::arch::process::current_pid();
|
entry.ppid = crate::arch::process::current_pid();
|
||||||
entry.pid = new_pid;
|
entry.pid = new_pid;
|
||||||
|
|
@ -500,7 +500,7 @@ impl SystemServices {
|
||||||
pid, context, other
|
pid, context, other
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
println!("KERNEL({}): Readying context {} -> {:?}", pid, context, process.state);
|
// println!("KERNEL({}): Readying context {} -> {:?}", pid, context, process.state);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -513,7 +513,6 @@ impl SystemServices {
|
||||||
// println!("KERNEL(?): Getting current process...");
|
// println!("KERNEL(?): Getting current process...");
|
||||||
let process = self.get_process_mut(pid)?;
|
let process = self.get_process_mut(pid)?;
|
||||||
// println!("KERNEL(?): Current process is {:?}", process);
|
// println!("KERNEL(?): Current process is {:?}", process);
|
||||||
println!("switch_to (start): PID {}: {:?} @ {:?}", pid, process.state, std::thread::current().id());
|
|
||||||
|
|
||||||
// Determine which context number to switch to
|
// Determine which context number to switch to
|
||||||
process.state = match process.state {
|
process.state = match process.state {
|
||||||
|
|
@ -614,7 +613,6 @@ impl SystemServices {
|
||||||
ProcessState::Running(new_mask)
|
ProcessState::Running(new_mask)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
println!("switch_to (end): PID {}: {:?}", pid, process.state);
|
|
||||||
// self.pid = pid;
|
// self.pid = pid;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
@ -634,7 +632,6 @@ impl SystemServices {
|
||||||
can_resume: bool,
|
can_resume: bool,
|
||||||
) -> Result<(), xous::Error> {
|
) -> Result<(), xous::Error> {
|
||||||
let process = self.get_process_mut(pid)?;
|
let process = self.get_process_mut(pid)?;
|
||||||
println!("switch_from (start): PID {}: {:?}", pid, process.state);
|
|
||||||
process.state = match process.state {
|
process.state = match process.state {
|
||||||
ProcessState::Running(x) if x & (1 << context) != 0 => panic!(
|
ProcessState::Running(x) if x & (1 << context) != 0 => panic!(
|
||||||
"PID {} context {} was already queued for running when `switch_from()` was called",
|
"PID {} context {} was already queued for running when `switch_from()` was called",
|
||||||
|
|
@ -656,7 +653,6 @@ impl SystemServices {
|
||||||
pid, other
|
pid, other
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
println!("switch_from (end): PID {}: {:?}", pid, process.state);
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -696,7 +692,7 @@ impl SystemServices {
|
||||||
// println!("Activating PID {}, context {}", new_pid, new_context);
|
// println!("Activating PID {}, context {}", new_pid, new_context);
|
||||||
let previous_pid = self.current_pid();
|
let previous_pid = self.current_pid();
|
||||||
let previous_context = self.current_context_nr(previous_pid);
|
let previous_context = self.current_context_nr(previous_pid);
|
||||||
println!("KERNEL({}): Activating process {} context {}", previous_pid, new_pid, new_context);
|
// println!("KERNEL({}): Activating process {} context {}", previous_pid, new_pid, new_context);
|
||||||
|
|
||||||
// Save state if the PID has changed. This will activate the new memory
|
// Save state if the PID has changed. This will activate the new memory
|
||||||
// space.
|
// space.
|
||||||
|
|
@ -1423,7 +1419,7 @@ impl SystemServices {
|
||||||
process.activate()?;
|
process.activate()?;
|
||||||
let parent_pid = process.ppid;
|
let parent_pid = process.ppid;
|
||||||
process.terminate()?;
|
process.terminate()?;
|
||||||
println!("KERNEL({}): Terminated", target_pid);
|
// println!("KERNEL({}): Terminated", target_pid);
|
||||||
|
|
||||||
let process = self.get_process(parent_pid)?;
|
let process = self.get_process(parent_pid)?;
|
||||||
process.activate().unwrap();
|
process.activate().unwrap();
|
||||||
|
|
|
||||||
|
|
@ -209,10 +209,10 @@ pub fn handle(pid: PID, call: SysCall) -> core::result::Result<xous::Result, xou
|
||||||
// process and mark ourselves as awaiting an event. When a message
|
// process and mark ourselves as awaiting an event. When a message
|
||||||
// arrives, our return value will already be set to the
|
// arrives, our return value will already be set to the
|
||||||
// MessageEnvelope of the incoming message.
|
// MessageEnvelope of the incoming message.
|
||||||
println!(
|
// println!(
|
||||||
"KERNEL({}): did not have any waiting messages -- parking context {}",
|
// "KERNEL({}): did not have any waiting messages -- parking context {}",
|
||||||
pid, context_nr
|
// pid, context_nr
|
||||||
);
|
// );
|
||||||
server.park_context(context_nr);
|
server.park_context(context_nr);
|
||||||
|
|
||||||
// For baremetal targets, switch away from this process.
|
// For baremetal targets, switch away from this process.
|
||||||
|
|
@ -226,7 +226,6 @@ pub fn handle(pid: PID, call: SysCall) -> core::result::Result<xous::Result, xou
|
||||||
// For hosted targets, simply return `BlockedProcess` indicating we'll make
|
// For hosted targets, simply return `BlockedProcess` indicating we'll make
|
||||||
// a callback to their socket at a later time.
|
// a callback to their socket at a later time.
|
||||||
else {
|
else {
|
||||||
println!("229: Switching from {}", pid);
|
|
||||||
ss.switch_from(pid, context_nr, false)
|
ss.switch_from(pid, context_nr, false)
|
||||||
.map(|_| xous::Result::BlockedProcess)
|
.map(|_| xous::Result::BlockedProcess)
|
||||||
}
|
}
|
||||||
|
|
@ -297,15 +296,15 @@ pub fn handle(pid: PID, call: SysCall) -> core::result::Result<xous::Result, xou
|
||||||
return Err(xous::Error::ProcessNotFound);
|
return Err(xous::Error::ProcessNotFound);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
println!(
|
// println!(
|
||||||
"Returning {} bytes from {:08x} in PID {} to {:08x} in PID {} in context {}",
|
// "Returning {} bytes from {:08x} in PID {} to {:08x} in PID {} in context {}",
|
||||||
len,
|
// len,
|
||||||
server_addr.get(),
|
// server_addr.get(),
|
||||||
pid,
|
// pid,
|
||||||
client_addr.get(),
|
// client_addr.get(),
|
||||||
client_pid,
|
// client_pid,
|
||||||
client_ctx
|
// client_ctx
|
||||||
);
|
// );
|
||||||
|
|
||||||
// Return the memory to the calling process
|
// Return the memory to the calling process
|
||||||
ss.return_memory(
|
ss.return_memory(
|
||||||
|
|
@ -316,10 +315,10 @@ pub fn handle(pid: PID, call: SysCall) -> core::result::Result<xous::Result, xou
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Unblock the client context to allow it to continue.
|
// Unblock the client context to allow it to continue.
|
||||||
println!(
|
// println!(
|
||||||
"KERNEL({}): Unblocking PID {} CTX {}",
|
// "KERNEL({}): Unblocking PID {} CTX {}",
|
||||||
pid, client_pid, client_ctx
|
// pid, client_pid, client_ctx
|
||||||
);
|
// );
|
||||||
ss.ready_context(client_pid, client_ctx)?;
|
ss.ready_context(client_pid, client_ctx)?;
|
||||||
ss.set_context_result(client_pid, client_ctx, xous::Result::Ok)?;
|
ss.set_context_result(client_pid, client_ctx, xous::Result::Ok)?;
|
||||||
ss.switch_to(client_pid, Some(client_ctx))?;
|
ss.switch_to(client_pid, Some(client_ctx))?;
|
||||||
|
|
@ -467,7 +466,6 @@ pub fn handle(pid: PID, call: SysCall) -> core::result::Result<xous::Result, xou
|
||||||
xous::Result::Message(envelope),
|
xous::Result::Message(envelope),
|
||||||
)
|
)
|
||||||
.and_then(|_| {
|
.and_then(|_| {
|
||||||
println!("464: Switching from {}", pid);
|
|
||||||
ss.switch_from(pid, context_nr, false)
|
ss.switch_from(pid, context_nr, false)
|
||||||
})
|
})
|
||||||
.map(|_| xous::Result::BlockedProcess)
|
.map(|_| xous::Result::BlockedProcess)
|
||||||
|
|
@ -523,7 +521,6 @@ pub fn handle(pid: PID, call: SysCall) -> core::result::Result<xous::Result, xou
|
||||||
}
|
}
|
||||||
SysCall::TerminateProcess => SystemServices::with_mut(|ss| {
|
SysCall::TerminateProcess => SystemServices::with_mut(|ss| {
|
||||||
let context_nr = ss.current_context_nr(pid);
|
let context_nr = ss.current_context_nr(pid);
|
||||||
println!("515: Switching from {}", pid);
|
|
||||||
ss.switch_from(pid, context_nr, false)?;
|
ss.switch_from(pid, context_nr, false)?;
|
||||||
let ppid = ss.terminate_process(pid)?;
|
let ppid = ss.terminate_process(pid)?;
|
||||||
if cfg!(baremetal) {
|
if cfg!(baremetal) {
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,12 @@ use xous::{rsyscall, SysCall};
|
||||||
|
|
||||||
mod shutdown;
|
mod shutdown;
|
||||||
|
|
||||||
|
#[cfg(feature = "report-memory")]
|
||||||
|
use stats_alloc::{Region, Stats, StatsAlloc, INSTRUMENTED_SYSTEM};
|
||||||
|
#[cfg(feature = "report-memory")]
|
||||||
|
#[global_allocator]
|
||||||
|
static GLOBAL: &StatsAlloc<std::alloc::System> = &INSTRUMENTED_SYSTEM;
|
||||||
|
|
||||||
const SERVER_SPEC: &str = "localhost:0";
|
const SERVER_SPEC: &str = "localhost:0";
|
||||||
|
|
||||||
fn start_kernel(server_spec: &str) -> (JoinHandle<()>, SocketAddr) {
|
fn start_kernel(server_spec: &str) -> (JoinHandle<()>, SocketAddr) {
|
||||||
|
|
@ -142,8 +148,8 @@ fn send_move_message() {
|
||||||
Box::from_raw(core::slice::from_raw_parts_mut(buf.as_mut_ptr(), buf.len()))
|
Box::from_raw(core::slice::from_raw_parts_mut(buf.as_mut_ptr(), buf.len()))
|
||||||
};
|
};
|
||||||
assert_eq!(*test_bytes, *bt);
|
assert_eq!(*test_bytes, *bt);
|
||||||
// let s = String::from_utf8_lossy(&bt);
|
// let s = String::from_utf8_lossy(&bt);
|
||||||
// println!("Got message: {:?} -> \"{}\"", bt, s);
|
// println!("Got message: {:?} -> \"{}\"", bt, s);
|
||||||
} else {
|
} else {
|
||||||
panic!("unexpected message type");
|
panic!("unexpected message type");
|
||||||
}
|
}
|
||||||
|
|
@ -219,7 +225,9 @@ fn send_borrow_message() {
|
||||||
|
|
||||||
// Send the message to the server
|
// Send the message to the server
|
||||||
println!("CLIENT: Lending message...");
|
println!("CLIENT: Lending message...");
|
||||||
carton.lend(conn, 0).expect("couldn't lend message to server");
|
carton
|
||||||
|
.lend(conn, 0)
|
||||||
|
.expect("couldn't lend message to server");
|
||||||
|
|
||||||
println!("CLIENT: Done");
|
println!("CLIENT: Done");
|
||||||
});
|
});
|
||||||
|
|
@ -278,7 +286,9 @@ fn send_mutableborrow_message() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the message to the server
|
// Send the message to the server
|
||||||
carton.lend_mut(conn, 3).expect("couldn't mutably lend data");
|
carton
|
||||||
|
.lend_mut(conn, 3)
|
||||||
|
.expect("couldn't mutably lend data");
|
||||||
|
|
||||||
let modified_bytes: &[u8] = carton.as_ref();
|
let modified_bytes: &[u8] = carton.as_ref();
|
||||||
assert_eq!(&check_bytes, &modified_bytes);
|
assert_eq!(&check_bytes, &modified_bytes);
|
||||||
|
|
@ -294,69 +304,97 @@ fn send_mutableborrow_message() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn send_mutableborrow_message_long() {
|
fn send_mutableborrow_message_repeat() {
|
||||||
let (main_thread, server_spec) = start_kernel(SERVER_SPEC);
|
#[cfg(feature = "report-memory")]
|
||||||
let (server_addr_send, server_addr_recv) = channel();
|
let mut reg = Region::new(&GLOBAL);
|
||||||
let test_str = "Hello, world!";
|
#[cfg(feature = "report-memory")]
|
||||||
let test_bytes = test_str.as_bytes();
|
reg.reset();
|
||||||
|
|
||||||
let loops = 50;
|
{
|
||||||
|
let (main_thread, server_spec) = start_kernel(SERVER_SPEC);
|
||||||
|
let (server_addr_send, server_addr_recv) = channel();
|
||||||
|
let test_str = "Hello, world!";
|
||||||
|
let test_bytes = test_str.as_bytes();
|
||||||
|
|
||||||
let xous_server = spawn(move || {
|
let loops = 50_000;
|
||||||
xous::hosted::set_xous_address(server_spec);
|
|
||||||
let sid = xous::create_server(0x7884_3123).expect("couldn't create test server");
|
|
||||||
server_addr_send.send(sid).unwrap();
|
|
||||||
|
|
||||||
for iteration in 0..loops {
|
let xous_server = spawn(move || {
|
||||||
let envelope = xous::receive_message(sid).expect("couldn't receive messages");
|
xous::hosted::set_xous_address(server_spec);
|
||||||
let message = envelope.message;
|
let sid = xous::create_server(0x7884_3123).expect("couldn't create test server");
|
||||||
if let xous::Message::MutableBorrow(m) = message {
|
server_addr_send.send(sid).unwrap();
|
||||||
let buf = m.buf;
|
|
||||||
let mut bt = unsafe {
|
for iteration in 0..loops {
|
||||||
Box::from_raw(core::slice::from_raw_parts_mut(buf.as_mut_ptr(), buf.len()))
|
let envelope = xous::receive_message(sid).expect("couldn't receive messages");
|
||||||
};
|
let message = envelope.message;
|
||||||
for letter in bt.iter_mut() {
|
if let xous::Message::MutableBorrow(m) = message {
|
||||||
|
let buf = m.buf;
|
||||||
|
let mut bt = unsafe {
|
||||||
|
Box::from_raw(core::slice::from_raw_parts_mut(buf.as_mut_ptr(), buf.len()))
|
||||||
|
};
|
||||||
|
for letter in bt.iter_mut() {
|
||||||
|
*letter = (*letter).wrapping_add((iteration & 0xff) as u8);
|
||||||
|
}
|
||||||
|
xous::return_memory(envelope.sender, m.buf).unwrap();
|
||||||
|
} else {
|
||||||
|
panic!("unexpected message type");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let xous_client = spawn(move || {
|
||||||
|
xous::hosted::set_xous_address(server_spec);
|
||||||
|
|
||||||
|
// Get the server address (out of band) so we know what to connect to
|
||||||
|
let sid = server_addr_recv.recv().unwrap();
|
||||||
|
|
||||||
|
// Perform a connection to the server
|
||||||
|
let conn = xous::connect(sid).expect("couldn't connect to server");
|
||||||
|
|
||||||
|
// Convert the message into a "Carton" that can be shipped as a message
|
||||||
|
for iteration in 0..loops {
|
||||||
|
let mut carton = xous::carton::Carton::from_bytes(&test_bytes);
|
||||||
|
let mut check_bytes = test_bytes.to_vec();
|
||||||
|
for letter in check_bytes.iter_mut() {
|
||||||
*letter = (*letter).wrapping_add((iteration & 0xff) as u8);
|
*letter = (*letter).wrapping_add((iteration & 0xff) as u8);
|
||||||
}
|
}
|
||||||
xous::return_memory(envelope.sender, m.buf).unwrap();
|
|
||||||
|
// Send the message to the server
|
||||||
|
carton
|
||||||
|
.lend_mut(conn, 3)
|
||||||
|
.expect("couldn't mutably lend data");
|
||||||
|
|
||||||
|
let modified_bytes: &[u8] = carton.as_ref();
|
||||||
|
assert_eq!(&check_bytes, &modified_bytes);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
xous_server.join().expect("couldn't join server process");
|
||||||
|
xous_client.join().expect("couldn't join client process");
|
||||||
|
|
||||||
|
// Any process ought to be able to shut down the system currently.
|
||||||
|
rsyscall(SysCall::Shutdown).expect("unable to shutdown server");
|
||||||
|
|
||||||
|
main_thread.join().expect("couldn't join kernel process");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "report-memory")]
|
||||||
|
{
|
||||||
|
fn memory_in_use(start: &Stats) -> usize {
|
||||||
|
if start.bytes_deallocated > start.bytes_allocated {
|
||||||
|
eprintln!("Allocated a negative number of bytes!");
|
||||||
|
0
|
||||||
} else {
|
} else {
|
||||||
panic!("unexpected message type");
|
start.bytes_allocated - start.bytes_deallocated
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
let xous_client = spawn(move || {
|
let after_join = reg.change();
|
||||||
xous::hosted::set_xous_address(server_spec);
|
println!(
|
||||||
|
"After test: {:#?} ({} bytes in use)",
|
||||||
// Get the server address (out of band) so we know what to connect to
|
after_join,
|
||||||
let sid = server_addr_recv.recv().unwrap();
|
memory_in_use(&after_join)
|
||||||
|
);
|
||||||
// Perform a connection to the server
|
}
|
||||||
let conn = xous::connect(sid).expect("couldn't connect to server");
|
|
||||||
|
|
||||||
// Convert the message into a "Carton" that can be shipped as a message
|
|
||||||
for iteration in 0..loops {
|
|
||||||
let mut carton = xous::carton::Carton::from_bytes(&test_bytes);
|
|
||||||
let mut check_bytes = test_bytes.to_vec();
|
|
||||||
for letter in check_bytes.iter_mut() {
|
|
||||||
*letter = (*letter).wrapping_add((iteration & 0xff) as u8);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send the message to the server
|
|
||||||
carton.lend_mut(conn, 3).expect("couldn't mutably lend data");
|
|
||||||
|
|
||||||
let modified_bytes: &[u8] = carton.as_ref();
|
|
||||||
assert_eq!(&check_bytes, &modified_bytes);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
xous_server.join().expect("couldn't join server process");
|
|
||||||
xous_client.join().expect("couldn't join client process");
|
|
||||||
|
|
||||||
// Any process ought to be able to shut down the system currently.
|
|
||||||
rsyscall(SysCall::Shutdown).expect("unable to shutdown server");
|
|
||||||
|
|
||||||
main_thread.join().expect("couldn't join kernel process");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[test]
|
// #[test]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue