Init now only starts servers. The session server holds ProcessCreate cap and launches apps on demand. Snake is no longer in the boot manifest.
79 lines
2.2 KiB
Rust
79 lines
2.2 KiB
Rust
use crate::protocol::*;
|
|
use crate::server::SessionServer;
|
|
use server_framework::Server;
|
|
|
|
fn test_server() -> SessionServer {
|
|
let mut s = SessionServer::new(0, 0, 0);
|
|
s.register_app("snake", "/apps/snake.elf");
|
|
s.register_app("clock", "/apps/clock.elf");
|
|
s
|
|
}
|
|
|
|
#[test]
|
|
fn list_apps_returns_count() {
|
|
let mut s = test_server();
|
|
let resp = s.handle(SessionRequest::ListApps);
|
|
assert_eq!(resp, SessionResponse::AppList { count: 2 });
|
|
}
|
|
|
|
#[test]
|
|
fn launch_valid_app() {
|
|
let mut s = test_server();
|
|
let resp = s.handle(SessionRequest::Launch { app: AppId::new(0) });
|
|
assert!(matches!(resp, SessionResponse::Launched { .. }));
|
|
}
|
|
|
|
#[test]
|
|
fn launch_sets_active() {
|
|
let mut s = test_server();
|
|
s.handle(SessionRequest::Launch { app: AppId::new(0) });
|
|
let resp = s.handle(SessionRequest::ActiveApp);
|
|
assert_eq!(resp, SessionResponse::Active { app: AppId::new(0) });
|
|
}
|
|
|
|
#[test]
|
|
fn launch_invalid_app_returns_not_found() {
|
|
let mut s = test_server();
|
|
let resp = s.handle(SessionRequest::Launch { app: AppId::new(99) });
|
|
assert_eq!(resp, SessionResponse::NotFound);
|
|
}
|
|
|
|
#[test]
|
|
fn launch_already_running_returns_error() {
|
|
let mut s = test_server();
|
|
s.handle(SessionRequest::Launch { app: AppId::new(0) });
|
|
let resp = s.handle(SessionRequest::Launch { app: AppId::new(0) });
|
|
assert_eq!(resp, SessionResponse::Error);
|
|
}
|
|
|
|
#[test]
|
|
fn kill_running_app() {
|
|
let mut s = test_server();
|
|
s.handle(SessionRequest::Launch { app: AppId::new(0) });
|
|
let resp = s.handle(SessionRequest::Kill { app: AppId::new(0) });
|
|
assert_eq!(resp, SessionResponse::Killed);
|
|
}
|
|
|
|
#[test]
|
|
fn kill_clears_active() {
|
|
let mut s = test_server();
|
|
s.handle(SessionRequest::Launch { app: AppId::new(0) });
|
|
s.handle(SessionRequest::Kill { app: AppId::new(0) });
|
|
let resp = s.handle(SessionRequest::ActiveApp);
|
|
assert_eq!(resp, SessionResponse::NotFound);
|
|
}
|
|
|
|
#[test]
|
|
fn kill_not_running_returns_not_found() {
|
|
let mut s = test_server();
|
|
let resp = s.handle(SessionRequest::Kill { app: AppId::new(0) });
|
|
assert_eq!(resp, SessionResponse::NotFound);
|
|
}
|
|
|
|
#[test]
|
|
fn no_active_app_initially() {
|
|
let mut s = test_server();
|
|
let resp = s.handle(SessionRequest::ActiveApp);
|
|
assert_eq!(resp, SessionResponse::NotFound);
|
|
}
|