feat(pbs): align typed values and Pad input facade
This commit is contained in:
@@ -6,7 +6,7 @@ it does not implement a Java approximation of runtime admission.
|
||||
From the Studio root:
|
||||
|
||||
```sh
|
||||
./gradlew :prometeu-compiler:prometeu-build-pipeline:test --tests '*LinkedRegistryTest' --tests '*PbxRegistryConformanceTest' --tests '*TypedCommonPipelineTest' --tests '*RuntimeCatalogPipelineTest'
|
||||
./gradlew :prometeu-compiler:prometeu-build-pipeline:test --tests '*LinkedRegistryTest' --tests '*PbxRegistryConformanceTest' --tests '*TypedCommonPipelineTest' --tests '*RuntimeCatalogPipelineTest' --tests '*PbsRuntimeAlignmentTest'
|
||||
python3 tools/pbx-conformance/run.py --runtime ../runtime
|
||||
```
|
||||
|
||||
@@ -43,8 +43,9 @@ payload or reports those cases as conforming to the unmodified schema. Any
|
||||
other schema failure remains fatal. Track the runtime correction in AGD75;
|
||||
remove the exception once the schema is corrected.
|
||||
|
||||
This corpus qualifies common backend production, not PBS lowering, lifecycle
|
||||
selection, memcard persistence or installed-runtime deployment.
|
||||
The original registry/catalog fixtures qualify common backend production. The
|
||||
PBS fixtures below additionally qualify source lowering; this harness does not
|
||||
claim installed-runtime deployment or memcard persistence.
|
||||
|
||||
## Runtime catalog consumer fixtures
|
||||
|
||||
@@ -62,3 +63,26 @@ at load time, matching the runtime verifier's stricter rule despite the
|
||||
dispatcher's nullable String carrier. These are distinct outcomes. Run the separate provider-export check with
|
||||
`python3 tools/runtime-catalog/verify.py --runtime ../runtime` to compare the
|
||||
selected source revision, imported CSV bytes and exporter output as well.
|
||||
|
||||
|
||||
## PBS source and input qualification
|
||||
|
||||
`PbsRuntimeAlignmentTest` compiles actual SDK declarations and source programs
|
||||
through the PBS frontend, production common IR, typed Registry and PBX writer.
|
||||
Its 114 fixtures execute on the selected runtime: all 48 Pad combinations with
|
||||
both literal Button arguments and enum locals passed through a typed function,
|
||||
six Touch queries, numeric boundaries/conversions/faults, builtin groups,
|
||||
String, fixed multiple returns and named application with observable Y,X effects.
|
||||
|
||||
The controlled input platform asserts the exact button/coordinate reader and
|
||||
one read per public query. Each query is also executed without a platform to
|
||||
prove TRAP_UNAVAILABLE. The loaded PBS registries are checked for the defaults
|
||||
of all eight existing value types, including null String, positive Float zero
|
||||
and complete vec2/pixel groups. No source constructors or new collection API
|
||||
are introduced to test storage defaults.
|
||||
|
||||
The harness requires the complete fixture count. It must not pass by skipping
|
||||
missing PBS fixtures. Integer arithmetic wrapping is distinct from checked
|
||||
Int64-to-Int32 narrowing and Float numeric-range faults. The full installed
|
||||
knowledge gate remains separate and mandatory for SDK resource/producer
|
||||
integration.
|
||||
|
||||
@@ -37,6 +37,7 @@ impl NativeInterface for NoNative {
|
||||
fn main() {
|
||||
let root = std::path::PathBuf::from(std::env::args().nth(1).expect("fixture directory"));
|
||||
verify_catalog_fixtures(&root);
|
||||
verify_pbs_fixtures(&root);
|
||||
for name in [
|
||||
"minimal",
|
||||
"jump-end",
|
||||
@@ -408,3 +409,131 @@ fn replace(bytes: &[u8], kind: usize, payload: &[u8]) -> Vec<u8> {
|
||||
}
|
||||
output
|
||||
}
|
||||
|
||||
// Controlled provider boundary: every input read checks its identity and is counted.
|
||||
struct PbsInput {
|
||||
expected: usize,
|
||||
reads: std::cell::Cell<usize>,
|
||||
button: prometeu_hal::button::Button,
|
||||
}
|
||||
impl PbsInput {
|
||||
fn read(&self, index: usize) -> &prometeu_hal::button::Button {
|
||||
assert_eq!(index, self.expected, "PBS queried an unselected endpoint");
|
||||
self.reads.set(self.reads.get() + 1);
|
||||
&self.button
|
||||
}
|
||||
}
|
||||
impl prometeu_hal::PadBridge for PbsInput {
|
||||
fn begin_frame(&mut self, _: &prometeu_hal::InputSignals) { unreachable!() }
|
||||
fn any(&self) -> bool { unreachable!() }
|
||||
fn up(&self) -> &prometeu_hal::button::Button { self.read(0) }
|
||||
fn down(&self) -> &prometeu_hal::button::Button { self.read(1) }
|
||||
fn left(&self) -> &prometeu_hal::button::Button { self.read(2) }
|
||||
fn right(&self) -> &prometeu_hal::button::Button { self.read(3) }
|
||||
fn a(&self) -> &prometeu_hal::button::Button { self.read(4) }
|
||||
fn b(&self) -> &prometeu_hal::button::Button { self.read(5) }
|
||||
fn x(&self) -> &prometeu_hal::button::Button { self.read(6) }
|
||||
fn y(&self) -> &prometeu_hal::button::Button { self.read(7) }
|
||||
fn l(&self) -> &prometeu_hal::button::Button { self.read(8) }
|
||||
fn r(&self) -> &prometeu_hal::button::Button { self.read(9) }
|
||||
fn start(&self) -> &prometeu_hal::button::Button { self.read(10) }
|
||||
fn select(&self) -> &prometeu_hal::button::Button { self.read(11) }
|
||||
}
|
||||
impl prometeu_hal::TouchBridge for PbsInput {
|
||||
fn begin_frame(&mut self, _: &prometeu_hal::InputSignals) { unreachable!() }
|
||||
fn f(&self) -> &prometeu_hal::button::Button { self.read(12) }
|
||||
fn x(&self) -> i32 { self.read(13); -123 }
|
||||
fn y(&self) -> i32 { self.read(14); 456 }
|
||||
}
|
||||
impl prometeu_hal::InputPlatform for PbsInput {
|
||||
fn pad(&self) -> &dyn prometeu_hal::PadBridge { self }
|
||||
fn pad_mut(&mut self) -> &mut dyn prometeu_hal::PadBridge { self }
|
||||
fn touch(&self) -> &dyn prometeu_hal::TouchBridge { self }
|
||||
fn touch_mut(&mut self) -> &mut dyn prometeu_hal::TouchBridge { self }
|
||||
}
|
||||
impl prometeu_hal::RuntimePlatform for PbsInput {
|
||||
fn input(&self) -> &dyn prometeu_hal::InputPlatform { self }
|
||||
fn input_mut(&mut self) -> &mut dyn prometeu_hal::InputPlatform { self }
|
||||
fn wall_clock(&self) -> &dyn prometeu_hal::WallClock { unreachable!("non-input platform access") }
|
||||
fn render_submission_sink(&mut self) -> &mut dyn prometeu_hal::RenderSubmissionSink { unreachable!("non-input platform access") }
|
||||
fn render_backend(&mut self) -> &mut dyn prometeu_hal::RenderBackend { unreachable!("non-input platform access") }
|
||||
fn game2d_frame_composer(&mut self) -> &mut dyn prometeu_hal::Game2DFrameComposer { unreachable!("non-input platform access") }
|
||||
fn audio(&self) -> &dyn prometeu_hal::AudioBridge { unreachable!("non-input platform access") }
|
||||
fn audio_mut(&mut self) -> &mut dyn prometeu_hal::AudioBridge { unreachable!("non-input platform access") }
|
||||
fn assets(&self) -> &dyn prometeu_hal::AssetBridge { unreachable!("non-input platform access") }
|
||||
fn assets_mut(&mut self) -> &mut dyn prometeu_hal::AssetBridge { unreachable!("non-input platform access") }
|
||||
fn telemetry(&self) -> &dyn prometeu_hal::TelemetryPlatform { unreachable!("non-input platform access") }
|
||||
}
|
||||
fn verify_pbs_fixtures(root: &std::path::Path) {
|
||||
use prometeu_vm::LogicalFrameEndingReason as End;
|
||||
let buttons = ["up","down","left","right","a","b","x","y","l","r","start","select"];
|
||||
let mut count = 0;
|
||||
let mut defaults_checked = std::collections::BTreeSet::new();
|
||||
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; }
|
||||
count += 1;
|
||||
let bytes = std::fs::read(&path).unwrap();
|
||||
let image = ValidatedProgramImage::load(&bytes, &mut LoadBudget::new(LoadLimits::default()), caps::NONE)
|
||||
.unwrap_or_else(|e| panic!("{name}: {e:?}"));
|
||||
for (index, ty) in image.registry().declarations().types.iter().enumerate() {
|
||||
if let prometeu_bytecode::registry::TypeKind::Builtin(id) = ty.kind {
|
||||
let expected = match id.0 {
|
||||
1 | 0x11 => vec![Value::Int64(0)],
|
||||
2 => vec![Value::Float(0.0), Value::Float(0.0)],
|
||||
3 => vec![Value::Int64(0), Value::Int64(0), Value::Int64(0)],
|
||||
0x10 => vec![Value::Int32(0)], 0x12 => vec![Value::Float(0.0)],
|
||||
0x13 => vec![Value::Boolean(false)], 0x14 => vec![Value::Null],
|
||||
_ => panic!("unexpected PBS builtin {}", id.0),
|
||||
};
|
||||
assert_eq!(image.registry().type_layout(prometeu_bytecode::registry::TypeId(index as u32)).unwrap().storage.default_values(), expected);
|
||||
defaults_checked.insert(id.0);
|
||||
}
|
||||
}
|
||||
let mut vm = VirtualMachine::from_image(image, Default::default());
|
||||
vm.prepare_boot_call().unwrap();
|
||||
let parts: Vec<_> = name.split('-').collect();
|
||||
if parts[1] == "pad" || parts[1] == "touch" {
|
||||
let query = if parts[1] == "pad" { &parts[3] } else { parts.last().unwrap() };
|
||||
let expected = if parts[1] == "pad" { buttons.iter().position(|b| *b == parts[2]).unwrap() }
|
||||
else { match *query { "x" => 13, "y" => 14, _ => 12 } };
|
||||
let button = prometeu_hal::button::Button { pressed: expected % 2 == 0, released: expected % 3 == 0, down: expected % 5 == 0, hold_frames: 100 + expected as u16 };
|
||||
let value = match *query {
|
||||
"pressed" => Value::Boolean(button.pressed), "released" => Value::Boolean(button.released), "down" => Value::Boolean(button.down),
|
||||
"hold" => Value::Int64(button.hold_frames.into()), "x" => Value::Int64(-123), "y" => Value::Int64(456), _ => unreachable!()
|
||||
};
|
||||
let mut input = PbsInput { expected, reads: std::cell::Cell::new(0), button };
|
||||
let report = vm.run_budget(10000, &mut NoNative, &mut HostContext::new(Some(&mut input))).unwrap();
|
||||
assert!(matches!(report.reason, End::Halted | End::EndOfRom), "{name}: {report:?}");
|
||||
assert_eq!(vm.operand_stack_top(1), vec![value], "{name}");
|
||||
assert_eq!(input.reads.get(), 1, "{name}: exactly one input query");
|
||||
let unavailable_image = ValidatedProgramImage::load(&bytes, &mut LoadBudget::new(LoadLimits::default()), caps::NONE).unwrap();
|
||||
let mut unavailable_vm = VirtualMachine::from_image(unavailable_image, Default::default());
|
||||
unavailable_vm.prepare_boot_call().unwrap();
|
||||
let unavailable = unavailable_vm.run_budget(10000, &mut NoNative, &mut HostContext::new(None)).unwrap();
|
||||
assert!(matches!(unavailable.reason, End::Trap(ref trap) if trap.code == prometeu_bytecode::TRAP_UNAVAILABLE));
|
||||
} else {
|
||||
let report = vm.run_budget(10000, &mut NoNative, &mut HostContext::new(None)).unwrap();
|
||||
match parts[1] {
|
||||
"numeric" => { assert!(matches!(report.reason, End::Halted | End::EndOfRom), "{report:?}"); assert_eq!(vm.operand_stack_top(1), vec![Value::Int64(2147483655)]); }
|
||||
"vec2" => { assert!(matches!(report.reason, End::Halted | End::EndOfRom)); assert_eq!(vm.operand_stack_top(2), vec![Value::Float(0.0),Value::Float(0.0)]); }
|
||||
"tuple" => { assert!(matches!(report.reason, End::Halted | End::EndOfRom)); assert_eq!(vm.operand_stack_top(2), vec![Value::Int64(8),Value::Int32(7)]); }
|
||||
"named" => { assert!(matches!(report.reason, End::Halted | End::EndOfRom)); assert_eq!(vm.operand_stack_top(1), vec![Value::Int32(211020)]); }
|
||||
"color" => { assert!(matches!(report.reason, End::Halted | End::EndOfRom)); assert_eq!(vm.operand_stack_top(1), vec![Value::Int64(0xFF0000FF)]); }
|
||||
"pixel" => { assert!(matches!(report.reason, End::Halted | End::EndOfRom), "{report:?}"); assert_eq!(vm.operand_stack_top(3), vec![Value::Int64(0xFF0000FF),Value::Int64(-34),Value::Int64(12)]); }
|
||||
"string" => { assert!(matches!(report.reason, End::Halted | End::EndOfRom)); assert!(matches!(&vm.operand_stack_top(1)[0], Value::String(value) if value.as_ref() == "hello")); }
|
||||
"division" => assert!(matches!(report.reason, End::Trap(ref trap) if trap.code == prometeu_bytecode::TRAP_DIV_ZERO)),
|
||||
"minimum" => { assert!(matches!(report.reason, End::Halted | End::EndOfRom)); assert_eq!(vm.operand_stack_top(1), vec![Value::Int64(i64::MIN)]); }
|
||||
"float" => { assert!(matches!(report.reason, End::Halted | End::EndOfRom), "{report:?}"); assert_eq!(vm.operand_stack_top(1), vec![Value::Float(3.75)]); }
|
||||
"overflow" => { assert!(matches!(report.reason, End::Halted | End::EndOfRom)); assert_eq!(vm.operand_stack_top(1), vec![Value::Int32(i32::MIN)]); }
|
||||
"narrow" => assert!(matches!(report.reason, End::Trap(ref trap) if trap.code == prometeu_bytecode::TRAP_NUMERIC_RANGE), "{name}: {report:?}"),
|
||||
_ => panic!("unasserted PBS fixture: {name}"),
|
||||
}
|
||||
}
|
||||
println!("PBS SOURCE/LOAD/EXEC PASS {name}");
|
||||
}
|
||||
assert_eq!(defaults_checked, [1,2,3,0x10,0x11,0x12,0x13,0x14].into_iter().collect());
|
||||
println!("PBS Registry defaults PASS: all eight existing value types");
|
||||
assert_eq!(count, 114, "The complete PBS qualification corpus must be present");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user