feat(pbs): implement typed arrays, optional binding and contract execution
This commit is contained in:
@@ -38,6 +38,8 @@ fn main() {
|
||||
let root = std::path::PathBuf::from(std::env::args().nth(1).expect("fixture directory"));
|
||||
verify_catalog_fixtures(&root);
|
||||
verify_pbs_fixtures(&root);
|
||||
verify_pbs_structured_fixtures(&root);
|
||||
verify_pbs_resource_refusals(&root);
|
||||
for name in [
|
||||
"minimal",
|
||||
"jump-end",
|
||||
@@ -472,7 +474,7 @@ fn verify_pbs_fixtures(root: &std::path::Path) {
|
||||
for entry in std::fs::read_dir(root).unwrap() {
|
||||
let path = entry.unwrap().path();
|
||||
let name = path.file_stem().unwrap().to_str().unwrap();
|
||||
if !name.starts_with("pbs-") || path.extension().and_then(|v| v.to_str()) != Some("pbx") { continue; }
|
||||
if name.starts_with("pbs-structured-") || !name.starts_with("pbs-") || path.extension().and_then(|v| v.to_str()) != Some("pbx") { continue; }
|
||||
count += 1;
|
||||
let bytes = std::fs::read(&path).unwrap();
|
||||
let image = ValidatedProgramImage::load(&bytes, &mut LoadBudget::new(LoadLimits::default()), caps::NONE)
|
||||
@@ -537,3 +539,74 @@ fn verify_pbs_fixtures(root: &std::path::Path) {
|
||||
println!("PBS Registry defaults PASS: all eight existing value types");
|
||||
assert_eq!(count, 114, "The complete PBS qualification corpus must be present");
|
||||
}
|
||||
|
||||
fn verify_pbs_structured_fixtures(root: &std::path::Path) {
|
||||
use prometeu_vm::LogicalFrameEndingReason as End;
|
||||
let success = ["array-cycle", "array-nested", "optional-flow", "struct-contract", "service-contract",
|
||||
"optional-tuple", "tuple-storage", "optional-intrinsics", "optional-lazy", "array-context",
|
||||
"binding-scope", "overloads", "single-evaluation", "long-boundaries", "gc-roots", "native-groups", "contract-elements", "imports", "global-array", "installed-example", "return-overloads", "inferred-optional-tuple", "inline-integers"];
|
||||
for name in success.into_iter().chain(["negative-index", "past-end", "negative-length", "large-length"]) {
|
||||
let bytes = std::fs::read(root.join(format!("pbs-structured-{name}.pbx")))
|
||||
.unwrap_or_else(|e| panic!("missing mandatory PBS structured fixture {name}: {e}"));
|
||||
let image = ValidatedProgramImage::load(&bytes, &mut LoadBudget::new(LoadLimits::default()), caps::NONE)
|
||||
.unwrap_or_else(|e| panic!("{name}: {e:?}"));
|
||||
let limits = if name == "inline-integers" {
|
||||
prometeu_vm::resource_budget::RuntimeLimits::default()
|
||||
.lowered(prometeu_vm::resource_budget::RuntimeResource::HandleSlots, 1).unwrap()
|
||||
} else { Default::default() };
|
||||
let mut vm = VirtualMachine::from_image(image, limits);
|
||||
vm.prepare_boot_call().unwrap();
|
||||
let mut report = vm.run_budget(100_000, &mut NoNative, &mut HostContext::new(None)).unwrap();
|
||||
if name == "gc-roots" {
|
||||
assert!(matches!(report.reason, End::FrameSync), "{report:?}");
|
||||
let snapshot = vm.resource_snapshot();
|
||||
assert_eq!(snapshot.gc.collections, 1);
|
||||
assert!(snapshot.gc.reclaimed >= 1100, "{:?}", snapshot.gc);
|
||||
report = vm.run_budget(100_000, &mut NoNative, &mut HostContext::new(None)).unwrap();
|
||||
}
|
||||
match name {
|
||||
"negative-index" | "past-end" | "negative-length" => assert!(matches!(report.reason,
|
||||
End::Trap(ref fault) if fault.code == prometeu_bytecode::TRAP_OOB), "{name}: {report:?}"),
|
||||
"large-length" => assert!(matches!(report.reason,
|
||||
End::Trap(ref fault) if fault.code == prometeu_bytecode::TRAP_RESOURCE_LIMIT), "{name}: {report:?}"),
|
||||
_ => {
|
||||
assert!(matches!(report.reason, End::Halted | End::EndOfRom), "{name}: {report:?}");
|
||||
assert_eq!(vm.operand_stack_top(1), vec![Value::Int32(42)], "{name}");
|
||||
}
|
||||
}
|
||||
if name == "inline-integers" { assert_eq!(vm.heap().len(), 1, "single-slot integers must not allocate boxes"); }
|
||||
let ownership = vm.resource_observer();
|
||||
drop(vm);
|
||||
for resource in [prometeu_vm::resource_budget::RuntimeResource::StringBytes,
|
||||
prometeu_vm::resource_budget::RuntimeResource::StringAllocations] {
|
||||
assert_eq!(ownership.used(resource), 0, "{name}: string ownership released");
|
||||
}
|
||||
println!("PBS STRUCTURED SOURCE/LOAD/EXEC PASS {name}");
|
||||
}
|
||||
}
|
||||
|
||||
fn verify_pbs_resource_refusals(root: &std::path::Path) {
|
||||
use prometeu_vm::{LogicalFrameEndingReason as End, resource_budget::{RuntimeLimits, RuntimeResource}};
|
||||
for name in ["array-cycle", "tuple-storage", "struct-contract"] {
|
||||
for resource in [RuntimeResource::GuestBytes, RuntimeResource::HandleSlots] {
|
||||
for limit in [0, 1, 2] {
|
||||
let bytes = std::fs::read(root.join(format!("pbs-structured-{name}.pbx"))).unwrap();
|
||||
let image = ValidatedProgramImage::load(&bytes, &mut LoadBudget::new(LoadLimits::default()), caps::NONE).unwrap();
|
||||
let limits = RuntimeLimits::default().lowered(resource, limit).unwrap();
|
||||
let mut vm = VirtualMachine::from_image(image, limits);
|
||||
let observer = vm.resource_observer();
|
||||
vm.prepare_boot_call().unwrap();
|
||||
let report = vm.run_budget(100_000, &mut NoNative, &mut HostContext::new(None)).unwrap();
|
||||
assert!(matches!(report.reason, End::Trap(ref fault) if fault.code == prometeu_bytecode::TRAP_RESOURCE_LIMIT), "{name}/{resource:?}/{limit}: {report:?}");
|
||||
assert!(observer.used(resource) <= limit);
|
||||
if limit == 0 { assert_eq!(vm.heap().len(), 0, "no partially published object"); }
|
||||
drop(vm);
|
||||
for domain in [RuntimeResource::GuestBytes, RuntimeResource::HandleSlots,
|
||||
RuntimeResource::AuxiliaryBytes, RuntimeResource::TemporaryBytes] {
|
||||
assert_eq!(observer.used(domain), 0, "{name}: session ownership released after refusal: {domain:?}");
|
||||
}
|
||||
println!("PBS QUOTA/OWNERSHIP PASS {name}/{resource:?}/{limit}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user