feat(vm): add resource diagnostics and macOS stability qualification
Intrepid/Prometeu/Runtime/pipeline/pr-master This commit looks good

This commit is contained in:
2026-10-14 08:26:07 +01:00
parent 6c2a07e579
commit 3899b7f12c
21 changed files with 1502 additions and 33 deletions
@@ -523,6 +523,64 @@ mod tests {
use std::io::{Read, Write};
use std::net::TcpStream;
#[test]
fn desktop_worker_survives_repeated_home_resume_and_cold_reset() {
use prometeu_firmware::firmware::firmware_state::ResetStep;
use prometeu_hal::InputSignals;
let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
.join("../../../test-cartridges/dummy-boy");
let mut runner = HostRunner::new(None, None);
runner.set_boot_target(BootTarget::Cartridge {
path: path.to_string_lossy().into_owned(),
debug: false,
debug_port: 0,
});
let signals = InputSignals::default();
for cycle in 0..32 {
runner.firmware.change_state(
FirmwareState::Reset(ResetStep),
&signals,
&mut runner.hardware,
);
assert_eq!(runner.firmware.os.sessions().vm_session_count(), 0);
for _ in 0..6000 {
runner.firmware.tick(&signals, &mut runner.hardware);
if matches!(runner.firmware.state, FirmwareState::GameRunning(_)) {
break;
}
assert!(!matches!(runner.firmware.state, FirmwareState::AppCrashes(_)));
std::thread::sleep(Duration::from_millis(1));
}
assert!(matches!(runner.firmware.state, FirmwareState::GameRunning(_)), "boot {cycle}");
for _ in 0..8 {
runner.firmware.tick(&signals, &mut runner.hardware);
}
runner.firmware.request_home_from_host();
for _ in 0..32 {
runner.firmware.tick(&signals, &mut runner.hardware);
if matches!(runner.firmware.state, FirmwareState::HubHome(_)) {
break;
}
}
assert!(matches!(runner.firmware.state, FirmwareState::HubHome(_)), "home {cycle}");
assert!(runner.firmware.resume_resident_game_from_home());
for _ in 0..8 {
runner.firmware.tick(&signals, &mut runner.hardware);
}
assert!(
matches!(runner.firmware.state, FirmwareState::GameRunning(_)),
"resume {cycle}"
);
assert_eq!(runner.firmware.os.sessions().vm_session_count(), 1);
}
runner.firmware.change_state(
FirmwareState::Reset(ResetStep),
&signals,
&mut runner.hardware,
);
assert_eq!(runner.firmware.os.sessions().vm_session_count(), 0);
}
#[test]
fn presentation_state_requires_initial_redraw_only_once() {
let mut state = PresentationState::default();
@@ -0,0 +1,68 @@
"""Exercise the real Dummy Boy desktop window on localhost:17959.
Start the host with --debug test-cartridges/dummy-boy --port 17959 first.
This finite smoke observes progress; its timeout is not a realtime guarantee.
"""
import json
import socket
import time
def run():
with socket.create_connection(("127.0.0.1", 17959), timeout=10) as connection:
connection.settimeout(10)
with connection.makefile("rb") as incoming:
def send(kind):
connection.sendall((json.dumps({"type": kind}) + "\n").encode())
def state():
send("getState")
deadline = time.monotonic() + 10
while time.monotonic() < deadline:
line = incoming.readline()
assert line, "Desktop disconnected"
message = json.loads(line)
assert message.get("event") != "fault", message
if message.get("type") == "getState":
return message
raise TimeoutError("Desktop did not answer getState")
def await_progress(previous):
deadline = time.monotonic() + 5
current = state()
while current["frame_index"] == previous and time.monotonic() < deadline:
time.sleep(0.02)
current = state()
return current
handshake = json.loads(incoming.readline())
assert handshake["type"] == "handshake", handshake
assert handshake["cartridge"]["app_id"] == 2, handshake
print(json.dumps(handshake), flush=True)
send("start")
time.sleep(0.5)
first = state()
assert first["app_id"] == 2, first
for _ in range(32):
send("pause")
time.sleep(0.025)
paused = state()
time.sleep(0.025)
still = state()
assert (paused["pc"], paused["frame_index"]) == (still["pc"], still["frame_index"])
send("stepFrame")
stepped = await_progress(paused["frame_index"])
assert stepped["frame_index"] == paused["frame_index"] + 1, (paused, stepped)
send("resume")
resumed = await_progress(stepped["frame_index"])
assert resumed["frame_index"] > stepped["frame_index"], (stepped, resumed)
print(json.dumps({
"result": "pass", "cycles": 32,
"first_frame": first["frame_index"], "last_frame": resumed["frame_index"],
"last_pc": resumed["pc"],
}), flush=True)
send("resume")
if __name__ == "__main__":
run()
@@ -6,6 +6,9 @@ license.workspace = true
repository.workspace = true
description = "In-process Prometeu host that boots and steps cartridges without a window, display, or audio device."
[features]
resource-diagnostics = ["prometeu-vm/resource-diagnostics"]
[dependencies]
prometeu-bytecode = { path = "../../console/prometeu-bytecode" }
prometeu-drivers = { path = "../../console/prometeu-drivers" }
@@ -451,6 +451,10 @@ impl Default for HeadlessHost {
}
}
#[cfg(all(test, feature = "resource-diagnostics"))]
#[path = "resource_qualification_tests.rs"]
mod resource_qualification_tests;
impl RenderSubmissionSink for HeadlessPlatform {
fn submit_render_submission(
&mut self,
@@ -0,0 +1,73 @@
#[allow(dead_code)]
#[path = "../../../console/prometeu-vm/tests/support/callables.rs"]
mod callables;
use super::{AdvanceFrameOutcome, HeadlessHost};
use prometeu_bytecode::{Value, registry::TypeId};
#[test]
fn thousand_reset_reload_cycles_release_session_owners_and_preserve_controls() {
let body =
format!("{}FRAME_SYNC\nGET_CAPTURE 0\nRET", "MAKE_CLOSURE fn=2,type=4\nPOP\n".repeat(1030));
let bytes = callables::bytes(
&[
(
"PUSH_I32 73\nMAKE_CLOSURE fn=1,type=4\nCALL_CLOSURE 4\nRET",
callables::sig(&[], &[0]),
vec![],
),
(&body, callables::sig(&[], &[0]), vec![TypeId(0)]),
("PUSH_I32 1\nRET", callables::sig(&[], &[0]), vec![]),
],
vec![],
&[],
)
.unwrap();
let path = std::env::temp_dir().join(format!("prometeu-resource-reset-{}", std::process::id()));
std::fs::create_dir_all(&path).unwrap();
std::fs::write(path.join("program.pbx"), bytes).unwrap();
std::fs::write(path.join("manifest.json"),r#"{"magic":"PMTU","cartridge_version":1,"app_id":77,"title":"Resource reset qualification","app_version":"1.0.0","app_mode":"Game","capabilities":[]}"#).unwrap();
let mut host = HeadlessHost::new();
for cycle in 0..1000 {
host.boot(path.to_string_lossy()).unwrap();
let observer = host
.firmware
.os
.sessions()
.resident_game_session_for_app(77)
.unwrap()
.vm
.resource_observer();
assert!(
matches!(
host.advance_frame().unwrap(),
AdvanceFrameOutcome::FrameCompleted { logical_frame_index: 1, .. }
),
"cycle {cycle}"
);
{
let sessions = host.firmware.os.sessions();
let vm = &sessions.resident_game_session_for_app(77).unwrap().vm;
assert_eq!(vm.heap().len(), 1);
assert_eq!(vm.resource_snapshot().gc.collections, 1);
}
let pc = host.get_state().pc;
host.pause().unwrap();
host.tick_once();
assert_eq!(host.get_state().pc, pc);
host.resume().unwrap();
assert!(matches!(
host.advance_frame().unwrap(),
AdvanceFrameOutcome::FrameCompleted { logical_frame_index: 2, .. }
));
assert_eq!(&*host.get_state().stack_top, &[Value::Int32(73)]);
assert!(host.get_fault().is_none());
host.reset();
assert_eq!(host.firmware.os.sessions().vm_session_count(), 0);
assert_eq!(
observer.diagnostic_snapshot().used,
[0; 8],
"reset {cycle} retained session allocation"
);
}
std::fs::remove_dir_all(path).unwrap();
}