tester: run tests in order

This commit is contained in:
hosted-fornet 2024-01-17 13:25:02 -08:00
parent a814934af2
commit 0091eeb4f3
5 changed files with 41 additions and 34 deletions

View File

@ -129,7 +129,7 @@ checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c"
[[package]] [[package]]
name = "kinode_process_lib" name = "kinode_process_lib"
version = "0.5.0" version = "0.5.0"
source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?tag=v0.5.3-alpha#8de14aa7132e6b7992c720c6aae24a64e108779d" source = "git+ssh://git@github.com/uqbar-dao/process_lib.git?rev=59da820#59da820e8468c1bab510536062828d4241528145"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bincode", "bincode",

View File

@ -13,10 +13,10 @@ lto = true
[dependencies] [dependencies]
anyhow = "1.0" anyhow = "1.0"
bincode = "1.3.3" bincode = "1.3.3"
kinode_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", rev = "59da820" }
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
thiserror = "1.0" thiserror = "1.0"
kinode_process_lib = { git = "ssh://git@github.com/uqbar-dao/process_lib.git", tag = "v0.5.3-alpha" }
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" } wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" }
[lib] [lib]

View File

@ -2,7 +2,7 @@ use std::str::FromStr;
use kinode_process_lib::{ use kinode_process_lib::{
await_message, our_capabilities, println, spawn, vfs, Address, Message, OnExit, ProcessId, await_message, our_capabilities, println, spawn, vfs, Address, Message, OnExit, ProcessId,
Request, Response, Request, Response, vfs::{DirEntry, FileType},
}; };
mod tester_types; mod tester_types;
@ -24,7 +24,7 @@ fn make_vfs_address(our: &Address) -> anyhow::Result<Address> {
} }
fn handle_message(our: &Address) -> anyhow::Result<()> { fn handle_message(our: &Address) -> anyhow::Result<()> {
let message = await_message().unwrap(); let message = await_message()?;
match message { match message {
Message::Response { .. } => { Message::Response { .. } => {
@ -32,13 +32,15 @@ fn handle_message(our: &Address) -> anyhow::Result<()> {
} }
Message::Request { ref body, .. } => { Message::Request { ref body, .. } => {
match serde_json::from_slice(body)? { match serde_json::from_slice(body)? {
tt::TesterRequest::Run { test_timeout, .. } => { tt::TesterRequest::Run { ref test_names, test_timeout, .. } => {
println!("test_runner: got Run"); println!("test_runner: got Run");
let dir_prefix = "tester:sys/tests";
let response = Request::new() let response = Request::new()
.target(make_vfs_address(&our)?) .target(make_vfs_address(&our)?)
.body(serde_json::to_vec(&vfs::VfsRequest { .body(serde_json::to_vec(&vfs::VfsRequest {
path: "/tester:sys/tests".into(), path: dir_prefix.into(),
action: vfs::VfsAction::ReadDir, action: vfs::VfsAction::ReadDir,
})?) })?)
.send_and_await_response(test_timeout)? .send_and_await_response(test_timeout)?
@ -57,40 +59,43 @@ fn handle_message(our: &Address) -> anyhow::Result<()> {
panic!("") panic!("")
}; };
let caps_file_path = "tester:sys/tests/grant_capabilities.json"; for test_name in test_names {
let caps_index = children.iter().position(|i| *i.path == *caps_file_path); let test_entry = DirEntry {
let caps_by_child: std::collections::HashMap<String, Vec<String>> = path: format!("{}/{}.wasm", dir_prefix, test_name),
match caps_index { file_type: FileType::File,
None => std::collections::HashMap::new(),
Some(caps_index) => {
children.remove(caps_index);
let file = vfs::file::open_file(caps_file_path, false)?;
let file_contents = file.read()?;
serde_json::from_slice(&file_contents)?
}
}; };
if !children.contains(&test_entry) {
return Err(anyhow::anyhow!(
"test {} not found amongst {:?}",
test_name,
children,
));
}
}
let caps_file_path = format!("{}/grant_capabilities.json", dir_prefix);
let caps_index = children.iter().position(|i| *i.path == *caps_file_path);
let caps_by_child: std::collections::HashMap<String, Vec<String>> = match caps_index {
None => std::collections::HashMap::new(),
Some(caps_index) => {
children.remove(caps_index);
let file = vfs::file::open_file(&caps_file_path, false)?;
let file_contents = file.read()?;
serde_json::from_slice(&file_contents)?
}
};
println!("test_runner: running {:?}...", children); println!("test_runner: running {:?}...", children);
for child in &children { for test_name in test_names {
let grant_caps = child let test_path = format!("{}/{}.wasm", dir_prefix, test_name);
.path let grant_caps = caps_by_child
.split("/") .get(test_name)
.last() .and_then(|caps| Some(caps.iter().map(|cap| ProcessId::from_str(cap).unwrap()).collect()))
.and_then(|child_file_name| child_file_name.strip_suffix(".wasm"))
.and_then(|child_file_name| {
caps_by_child.get(child_file_name).and_then(|caps| {
Some(
caps.iter()
.map(|cap| ProcessId::from_str(cap).unwrap())
.collect(),
)
})
})
.unwrap_or(vec![]); .unwrap_or(vec![]);
let child_process_id = match spawn( let child_process_id = match spawn(
None, None,
&child.path, &test_path,
OnExit::None, // TODO: notify us OnExit::None, // TODO: notify us
our_capabilities(), our_capabilities(),
grant_caps, grant_caps,
@ -98,7 +103,7 @@ fn handle_message(our: &Address) -> anyhow::Result<()> {
) { ) {
Ok(child_process_id) => child_process_id, Ok(child_process_id) => child_process_id,
Err(e) => { Err(e) => {
println!("couldn't spawn {}: {}", child.path, e); println!("couldn't spawn {}: {}", test_path, e);
panic!("couldn't spawn"); // TODO panic!("couldn't spawn"); // TODO
} }
}; };

View File

@ -57,6 +57,7 @@ fn handle_message(
tt::TesterRequest::Run { tt::TesterRequest::Run {
input_node_names, input_node_names,
test_timeout, test_timeout,
..
} => { } => {
println!("tester: got Run"); println!("tester: got Run");

View File

@ -19,6 +19,7 @@ pub struct KernelMessage {
pub enum TesterRequest { pub enum TesterRequest {
Run { Run {
input_node_names: Vec<String>, input_node_names: Vec<String>,
test_names: Vec<String>,
test_timeout: u64, test_timeout: u64,
}, },
KernelMessage(KernelMessage), KernelMessage(KernelMessage),