kernel: convert scalar message test to use processes

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2020-07-28 13:40:02 +08:00
parent 1512d2138e
commit c40e0a138d
2 changed files with 54 additions and 47 deletions

View file

@ -258,6 +258,10 @@ fn listen_thread(
} }
} }
}); });
// Spawn a thread to listen for the `exit` command, and relay that
// to the main thread. This prevents us from needing to poll, since
// all messages are coalesced into a single channel.
spawn(move || match exit_channel.recv() { spawn(move || match exit_channel.recv() {
Ok(ExitMessage::Exit) => { Ok(ExitMessage::Exit) => {
exit_sender.send(ClientMessage::Exit).unwrap() exit_sender.send(ClientMessage::Exit).unwrap()

View file

@ -105,59 +105,62 @@ fn shutdown() {
main_thread.join().expect("couldn't join main thread"); main_thread.join().expect("couldn't join main thread");
} }
// #[test] #[test]
// fn send_scalar_message() { fn send_scalar_message() {
// // Start the server in another thread // Start the server in another thread
// let main_thread = start_kernel(SERVER_SPEC); let main_thread = start_kernel(SERVER_SPEC);
// let (server_addr_send, server_addr_recv) = channel(); let (server_addr_send, server_addr_recv) = channel();
// // Spawn the server "process" (which just lives in a separate thread) // Spawn the server "process" (which just lives in a separate thread)
// // and receive the message. Note that we need to communicate to the // and receive the message. Note that we need to communicate to the
// // "Client" what our server ID is. Normally this would be done via // "Client" what our server ID is. Normally this would be done via
// // an external nameserver. // an external nameserver.
// let xous_server = as_process(move || { let xous_server =
// let sid = xous::create_server(b"send_scalar_mesg").expect("couldn't create test server"); xous::create_process(xous::ProcessArgs::new(move || {
// server_addr_send.send(sid).unwrap(); let sid = xous::create_server(b"send_scalar_mesg").expect("couldn't create test server");
// let envelope = xous::receive_message(sid).expect("couldn't receive messages"); server_addr_send.send(sid).unwrap();
// assert_eq!( let envelope = xous::receive_message(sid).expect("couldn't receive messages");
// envelope.message, assert_eq!(
// xous::Message::Scalar(xous::ScalarMessage { envelope.message,
// id: 1, xous::Message::Scalar(xous::ScalarMessage {
// arg1: 2, id: 1,
// arg2: 3, arg1: 2,
// arg3: 4, arg2: 3,
// arg4: 5 arg3: 4,
// }) arg4: 5
// ); })
// }); );
})).expect("couldn't spawn server process");
// // Spawn the client "process" and wait for the server address. // Spawn the client "process" and wait for the server address.
// let xous_client = as_process(move || { let xous_client = xous::create_process(xous::ProcessArgs::new(move || {
// let sid = server_addr_recv.recv().unwrap(); let sid = server_addr_recv.recv().unwrap();
// let conn = xous::connect(sid).expect("couldn't connect to server"); let conn = xous::connect(sid).expect("couldn't connect to server");
// xous::send_message( xous::send_message(
// conn, conn,
// xous::Message::Scalar(xous::ScalarMessage { xous::Message::Scalar(xous::ScalarMessage {
// id: 1, id: 1,
// arg1: 2, arg1: 2,
// arg2: 3, arg2: 3,
// arg3: 4, arg3: 4,
// arg4: 5, arg4: 5,
// }), }),
// ) )
// .expect("couldn't send message"); .expect("couldn't send message");
// }); })).expect("couldn't spawn client process");
// // Wait for both processes to finish // Wait for both processes to finish
// xous_server.join().expect("couldn't join server process"); crate::wait_process(xous_server).expect("couldn't join server process");
// xous_client.join().expect("couldn't join client process"); crate::wait_process(xous_client).expect("couldn't join client process");
// // Any process ought to be able to shut down the system currently. // Any process ought to be able to shut down the system currently.
// rsyscall(SysCall::Shutdown).expect("unable to shutdown server"); xous::create_process(xous::ProcessArgs::new(|| {
rsyscall(SysCall::Shutdown).expect("unable to shutdown server");
})).expect("couldn't shut down the kernel");
// main_thread.join().expect("couldn't join kernel process"); main_thread.join().expect("couldn't join kernel process");
// } }
// #[test] // #[test]
// fn send_move_message() { // fn send_move_message() {