Intrepid/Prometeu/Runtime/pipeline/head There was a failure building this commit
Coordinate bounded native publication progress during frame advance while preserving watchdogs, guest budgets and resource ownership. Add controlled and packaged reopen regressions, clarify the runtime specs, and retain qualification evidence.
674 lines
24 KiB
Rust
674 lines
24 KiB
Rust
use std::fmt;
|
|
use std::sync::Arc;
|
|
|
|
use prometeu_drivers::hardware::Hardware;
|
|
use prometeu_drivers::{ControlledWallClock, MemoryBanks};
|
|
use prometeu_firmware::firmware_state::{AppCrashesStep, ResetStep};
|
|
use prometeu_firmware::{BootTarget, Firmware, FirmwareState};
|
|
use prometeu_hal::{
|
|
AssetBridge, AudioBridge, FrameId, Game2DFrameComposer, InputPlatform, InputSignals,
|
|
OwnedRgba8888Frame, RenderBackend, RenderSubmission, RenderSubmissionSink, RenderSubmitError,
|
|
RuntimePlatform, TelemetryPlatform, WallClock,
|
|
};
|
|
use prometeu_system::{CrashReport, LatestRenderFrameStore};
|
|
#[path = "memcard.rs"]
|
|
mod memcard;
|
|
pub use memcard::{
|
|
MediaAccess, MediaAction, MemcardChoice, MemcardFailure, MemcardMount, MemcardState,
|
|
PendingWrites, TeardownPolicy,
|
|
};
|
|
|
|
const BOOT_TICK_LIMIT: usize = 5000;
|
|
const HOST_FRAME_ADVANCE_TICK_LIMIT: usize = 100_000;
|
|
|
|
/// One published logical frame plus the automation counter.
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
pub struct CapturedFrame {
|
|
pub logical_frame_index: u64,
|
|
pub frame: OwnedRgba8888Frame,
|
|
}
|
|
|
|
/// Debugger-shaped execution snapshot.
|
|
#[derive(Debug, Clone)]
|
|
pub struct HostState {
|
|
pub pc: usize,
|
|
pub stack_top: prometeu_hal::ValueSnapshot,
|
|
pub frame_index: u64,
|
|
pub tick_index: u64,
|
|
pub app_id: u32,
|
|
pub status: HostExecutionStatus,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
pub enum HostExecutionStatus {
|
|
Running,
|
|
Paused,
|
|
Terminated,
|
|
Faulted,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
pub enum AdvanceFrameOutcome {
|
|
FrameCompleted { logical_frame_index: u64, frame_id: FrameId },
|
|
Faulted(CrashReport),
|
|
Terminated,
|
|
ActionRequired,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
pub enum AdvanceFramesStop {
|
|
Completed,
|
|
Faulted(CrashReport),
|
|
Terminated,
|
|
ActionRequired,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
pub struct AdvanceFramesOutcome {
|
|
pub requested: u64,
|
|
pub completed: u64,
|
|
pub stop: AdvanceFramesStop,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
pub enum HostError {
|
|
Memcard(Box<MemcardFailure>),
|
|
AlreadyBooted,
|
|
BootFailed { reason: String, report: Option<Box<CrashReport>> },
|
|
InvalidState { operation: &'static str, status: HostExecutionStatus },
|
|
FrameAdvanceWatchdogExpired { host_tick_limit: usize },
|
|
FrameNotPublished { previous: Option<FrameId> },
|
|
NoFrameAvailable,
|
|
}
|
|
|
|
impl fmt::Display for HostError {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
match self {
|
|
Self::Memcard(error) => write!(f, "{}: {}", error.operation, error.reason),
|
|
Self::AlreadyBooted => write!(f, "boot requires reset before another attempt"),
|
|
Self::BootFailed { reason, .. } => write!(f, "boot failed: {reason}"),
|
|
Self::InvalidState { operation, status } => {
|
|
write!(f, "{operation} is invalid while execution is {status:?}")
|
|
}
|
|
Self::FrameAdvanceWatchdogExpired { host_tick_limit } => {
|
|
write!(
|
|
f,
|
|
"headless host frame-advance watchdog expired after {host_tick_limit} firmware ticks"
|
|
)
|
|
}
|
|
Self::FrameNotPublished { .. } => {
|
|
write!(f, "logical frame closed without its canonical published frame")
|
|
}
|
|
Self::NoFrameAvailable => write!(f, "no completed frame is available for capture"),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl std::error::Error for HostError {}
|
|
|
|
/// In-process host. The desktop winit runner is a separate crate and is not linked here.
|
|
pub struct HeadlessHost {
|
|
firmware: Firmware,
|
|
platform: HeadlessPlatform,
|
|
signals: InputSignals,
|
|
boot_attempted: bool,
|
|
last_completed_frame: Option<CompletedFrame>,
|
|
controlled_wall_clock: Option<Arc<ControlledWallClock>>,
|
|
media: memcard::MediaSelection,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy)]
|
|
struct CompletedFrame {
|
|
logical_frame_index: u64,
|
|
frame_id: FrameId,
|
|
}
|
|
|
|
struct HeadlessPlatform {
|
|
hardware: Hardware,
|
|
store: LatestRenderFrameStore,
|
|
}
|
|
|
|
impl HeadlessHost {
|
|
/// Install storage through the shared worker. Progress is driven by ordinary host ticks.
|
|
pub fn install_memcard(
|
|
&mut self,
|
|
storage: Box<dyn prometeu_hal::memcard::MemcardStorage>,
|
|
) -> prometeu_system::memcard::image::Result<()> {
|
|
self.firmware.os.memcard().mount_card(storage)
|
|
}
|
|
pub fn memcard_preparation(&mut self) -> prometeu_system::memcard::admission::PreparationState {
|
|
self.firmware.os.memcard().admission.state
|
|
}
|
|
|
|
pub fn new() -> Self {
|
|
let clock = Arc::new(ControlledWallClock::default());
|
|
Self::with_clock(clock.clone(), Some(clock))
|
|
}
|
|
|
|
/// Supply a host-owned civil clock. The caller retains control of this provider.
|
|
pub fn new_with_wall_clock(clock: Arc<dyn WallClock>) -> Self {
|
|
Self::with_clock(clock, None)
|
|
}
|
|
|
|
fn with_clock(
|
|
clock: Arc<dyn WallClock>,
|
|
controlled_wall_clock: Option<Arc<ControlledWallClock>>,
|
|
) -> Self {
|
|
let memory_banks = Arc::new(MemoryBanks::new());
|
|
let hardware = Hardware::new_with_memory_banks(Arc::clone(&memory_banks), clock);
|
|
let store = LatestRenderFrameStore::default();
|
|
Self {
|
|
firmware: Firmware::new(None),
|
|
platform: HeadlessPlatform { hardware, store },
|
|
signals: InputSignals::default(),
|
|
boot_attempted: false,
|
|
last_completed_frame: None,
|
|
controlled_wall_clock,
|
|
media: Default::default(),
|
|
}
|
|
}
|
|
|
|
/// Read the same clock supplied to the runtime platform.
|
|
pub fn wall_clock(&self) -> &dyn WallClock {
|
|
self.platform.wall_clock()
|
|
}
|
|
|
|
/// Native controls for the default clock; custom providers are controlled by their owner.
|
|
pub fn controlled_wall_clock(&self) -> Option<&ControlledWallClock> {
|
|
self.controlled_wall_clock.as_deref()
|
|
}
|
|
|
|
/// Observe native log history without advancing, draining or changing lifecycle.
|
|
pub fn log_snapshot(
|
|
&self,
|
|
after: Option<u64>,
|
|
limit: usize,
|
|
) -> (Vec<prometeu_hal::log::LogEvent>, Option<u64>, Option<u64>) {
|
|
self.firmware.os.log_snapshot(after, limit)
|
|
}
|
|
|
|
/// Load `path` and tick until the firmware is in `GameRunning`.
|
|
///
|
|
/// The transition into `GameRunning` is the last tick. The first game
|
|
/// logical frame stays available for [`Self::advance_frame`].
|
|
pub fn boot(&mut self, path: impl Into<String>) -> Result<(), HostError> {
|
|
self.boot_with_choice(path, None)
|
|
}
|
|
pub fn boot_with_memcard_choice(
|
|
&mut self,
|
|
path: impl Into<String>,
|
|
choice: prometeu_system::memcard::admission::Choice,
|
|
) -> Result<(), HostError> {
|
|
self.boot_with_choice(path, Some(choice))
|
|
}
|
|
fn boot_with_choice(
|
|
&mut self,
|
|
path: impl Into<String>,
|
|
choice: Option<prometeu_system::memcard::admission::Choice>,
|
|
) -> Result<(), HostError> {
|
|
if self.boot_attempted {
|
|
return Err(HostError::AlreadyBooted);
|
|
}
|
|
self.boot_attempted = true;
|
|
self.media.choice = choice;
|
|
self.media.boot_phase = "loading";
|
|
let path = path.into();
|
|
self.firmware.boot_target = BootTarget::Cartridge { path, debug: false, debug_port: 7777 };
|
|
|
|
let boot_deadline = std::time::Instant::now() + std::time::Duration::from_secs(5);
|
|
let mut choice_submitted = false;
|
|
for _ in 0..BOOT_TICK_LIMIT {
|
|
if matches!(self.firmware.state, FirmwareState::GameRunning(_)) {
|
|
self.media.boot_phase = "running";
|
|
return Ok(());
|
|
}
|
|
if matches!(self.firmware.state, FirmwareState::AppCrashes(_)) {
|
|
self.media.boot_phase = "failed";
|
|
let report = self.get_fault();
|
|
let reason = report
|
|
.as_ref()
|
|
.map(CrashReport::summary)
|
|
.unwrap_or_else(|| "cartridge crashed during boot".to_string());
|
|
return Err(HostError::BootFailed { reason, report: report.map(Box::new) });
|
|
}
|
|
if matches!(self.firmware.state, FirmwareState::HubHome(_)) {
|
|
self.media.boot_phase = "failed";
|
|
return Err(HostError::BootFailed {
|
|
reason: "cartridge did not load".to_string(),
|
|
report: None,
|
|
});
|
|
}
|
|
let progress = self.firmware.os.memcard().lane.progress_stamp();
|
|
if let FirmwareState::LoadCartridge(step) = &self.firmware.state
|
|
&& step.cartridge.memcard_slots.is_none()
|
|
&& choice.is_some()
|
|
{
|
|
self.media.boot_phase = "failed";
|
|
return Err(self.memcard_error("boot", "invalid_state"));
|
|
}
|
|
if choice_submitted
|
|
&& let prometeu_system::memcard::admission::PreparationState::Failed(error) =
|
|
self.firmware.os.memcard().admission.state
|
|
{
|
|
self.media.boot_phase = "failed";
|
|
return Err(self.memcard_error("boot", memcard::error_name(error)));
|
|
}
|
|
let waiting = matches!(&self.firmware.state,FirmwareState::LoadCartridge(step) if step.needs_memcard_choice());
|
|
if waiting {
|
|
let Some(choice) = choice else {
|
|
self.media.boot_phase = "choice_required";
|
|
return Err(self.memcard_error("boot", "choice_required"));
|
|
};
|
|
if self.firmware.os.memcard().preparation_active() {
|
|
self.poll_memcard();
|
|
self.firmware
|
|
.os
|
|
.memcard()
|
|
.lane
|
|
.wait_for_progress(progress, std::time::Duration::from_millis(5));
|
|
continue;
|
|
}
|
|
let created_at = self.platform.wall_clock().utc_unix_seconds();
|
|
let result = match &mut self.firmware.state {
|
|
FirmwareState::LoadCartridge(step) => {
|
|
step.choose_memcard(&mut self.firmware.os, choice, created_at)
|
|
}
|
|
_ => unreachable!(),
|
|
};
|
|
if let Err(error) = result {
|
|
self.media.boot_phase = "failed";
|
|
return Err(self.memcard_error("boot", memcard::error_name(error)));
|
|
}
|
|
choice_submitted = true;
|
|
self.media.boot_phase = "preparing";
|
|
}
|
|
self.tick_once();
|
|
self.signals = InputSignals::default();
|
|
if matches!(self.firmware.state, FirmwareState::LoadCartridge(_)) {
|
|
if std::time::Instant::now() >= boot_deadline {
|
|
break;
|
|
}
|
|
self.firmware
|
|
.os
|
|
.memcard()
|
|
.lane
|
|
.wait_for_progress(progress, std::time::Duration::from_millis(16));
|
|
}
|
|
}
|
|
|
|
if matches!(self.firmware.state, FirmwareState::GameRunning(_)) {
|
|
Ok(())
|
|
} else {
|
|
self.media.boot_phase = "failed";
|
|
Err(HostError::BootFailed {
|
|
reason: "boot did not reach the game".to_string(),
|
|
report: self.get_fault().map(Box::new),
|
|
})
|
|
}
|
|
}
|
|
|
|
pub fn reset(&mut self) -> Result<(), HostError> {
|
|
self.reset_with_policy(TeardownPolicy::default()).map(|_| ())
|
|
}
|
|
fn reset_inner(&mut self) {
|
|
self.signals = InputSignals::default();
|
|
self.firmware.change_state(
|
|
FirmwareState::Reset(ResetStep),
|
|
&self.signals,
|
|
&mut self.platform,
|
|
);
|
|
self.platform.store = LatestRenderFrameStore::default();
|
|
self.boot_attempted = false;
|
|
self.last_completed_frame = None;
|
|
}
|
|
|
|
pub fn pause(&mut self) -> Result<(), HostError> {
|
|
self.require_active("pause")?;
|
|
self.firmware.os.vm().set_paused(true);
|
|
Ok(())
|
|
}
|
|
|
|
pub fn resume(&mut self) -> Result<(), HostError> {
|
|
self.require_active("resume")?;
|
|
self.firmware.os.vm().set_paused(false);
|
|
Ok(())
|
|
}
|
|
|
|
/// Execute one VM instruction. This does not close a logical frame.
|
|
pub fn step(&mut self) -> Result<Option<CrashReport>, HostError> {
|
|
self.require_active("step")?;
|
|
self.firmware.os.vm().set_paused(true);
|
|
let report = self.firmware.os.vm().debug_step_active_session(&mut self.platform);
|
|
self.platform.hardware.audio.transport().consume_silently();
|
|
Ok(report)
|
|
}
|
|
|
|
pub fn advance_frame(&mut self) -> Result<AdvanceFrameOutcome, HostError> {
|
|
if let Some(report) = self.get_fault() {
|
|
return Ok(AdvanceFrameOutcome::Faulted(report));
|
|
}
|
|
if !matches!(self.firmware.state, FirmwareState::GameRunning(_)) {
|
|
return Ok(if self.host_action_required() {
|
|
AdvanceFrameOutcome::ActionRequired
|
|
} else {
|
|
AdvanceFrameOutcome::Terminated
|
|
});
|
|
}
|
|
|
|
let start = self.firmware.os.vm().logical_frame_index();
|
|
let previous_frame_id = self.platform.store.latest_frame().map(|frame| frame.frame_id);
|
|
self.firmware.os.vm().set_paused(false);
|
|
self.firmware.os.vm().request_debug_step();
|
|
|
|
for _ in 0..HOST_FRAME_ADVANCE_TICK_LIMIT {
|
|
// A controlled lifecycle slice can consume the runtime step marker
|
|
// without closing a logical frame. This operation still owns the
|
|
// request until its first frame or an explicit stop boundary.
|
|
self.firmware.os.vm().set_paused(false);
|
|
self.firmware.os.vm().request_debug_step();
|
|
self.tick_once();
|
|
if let Some(report) = self.get_fault() {
|
|
self.finish_frame_advance();
|
|
return Ok(AdvanceFrameOutcome::Faulted(report));
|
|
}
|
|
if !matches!(self.firmware.state, FirmwareState::GameRunning(_)) {
|
|
self.finish_frame_advance();
|
|
return Ok(if self.host_action_required() {
|
|
AdvanceFrameOutcome::ActionRequired
|
|
} else {
|
|
AdvanceFrameOutcome::Terminated
|
|
});
|
|
}
|
|
|
|
let logical_frame_index = self.firmware.os.vm().logical_frame_index();
|
|
if logical_frame_index > start {
|
|
self.finish_frame_advance();
|
|
let frame = self
|
|
.platform
|
|
.store
|
|
.latest_frame()
|
|
.ok_or(HostError::FrameNotPublished { previous: previous_frame_id })?;
|
|
if Some(frame.frame_id) == previous_frame_id {
|
|
return Err(HostError::FrameNotPublished { previous: previous_frame_id });
|
|
}
|
|
self.last_completed_frame =
|
|
Some(CompletedFrame { logical_frame_index, frame_id: frame.frame_id });
|
|
return Ok(AdvanceFrameOutcome::FrameCompleted {
|
|
logical_frame_index,
|
|
frame_id: frame.frame_id,
|
|
});
|
|
}
|
|
}
|
|
|
|
self.finish_frame_advance();
|
|
Err(HostError::FrameAdvanceWatchdogExpired {
|
|
host_tick_limit: HOST_FRAME_ADVANCE_TICK_LIMIT,
|
|
})
|
|
}
|
|
|
|
pub fn advance_frames(&mut self, count: u64) -> Result<AdvanceFramesOutcome, HostError> {
|
|
let mut completed = 0;
|
|
for _ in 0..count {
|
|
match self.advance_frame()? {
|
|
AdvanceFrameOutcome::FrameCompleted { .. } => completed += 1,
|
|
AdvanceFrameOutcome::Faulted(report) => {
|
|
return Ok(AdvanceFramesOutcome {
|
|
requested: count,
|
|
completed,
|
|
stop: AdvanceFramesStop::Faulted(report),
|
|
});
|
|
}
|
|
AdvanceFrameOutcome::Terminated => {
|
|
return Ok(AdvanceFramesOutcome {
|
|
requested: count,
|
|
completed,
|
|
stop: AdvanceFramesStop::Terminated,
|
|
});
|
|
}
|
|
AdvanceFrameOutcome::ActionRequired => {
|
|
return Ok(AdvanceFramesOutcome {
|
|
requested: count,
|
|
completed,
|
|
stop: AdvanceFramesStop::ActionRequired,
|
|
});
|
|
}
|
|
}
|
|
}
|
|
Ok(AdvanceFramesOutcome { requested: count, completed, stop: AdvanceFramesStop::Completed })
|
|
}
|
|
|
|
pub fn set_input(&mut self, signals: InputSignals) {
|
|
self.signals = signals;
|
|
}
|
|
|
|
pub fn clear_input(&mut self) {
|
|
self.signals = InputSignals::default();
|
|
}
|
|
|
|
pub fn set_right(&mut self, down: bool) {
|
|
self.signals.right_signal = down;
|
|
}
|
|
|
|
pub fn capture_frame(&self) -> Result<CapturedFrame, HostError> {
|
|
let completed = self.last_completed_frame.ok_or(HostError::NoFrameAvailable)?;
|
|
let frame = self.platform.store.latest_frame().ok_or(HostError::NoFrameAvailable)?;
|
|
if frame.frame_id != completed.frame_id {
|
|
return Err(HostError::FrameNotPublished { previous: Some(completed.frame_id) });
|
|
}
|
|
Ok(CapturedFrame { logical_frame_index: completed.logical_frame_index, frame })
|
|
}
|
|
|
|
pub fn get_state(&mut self) -> HostState {
|
|
let status = self.execution_status();
|
|
HostState {
|
|
pc: self.firmware.os.vm().active_pc().unwrap_or(0),
|
|
stack_top: self.firmware.os.vm().active_operand_stack_top(10),
|
|
frame_index: self.firmware.os.vm().logical_frame_index(),
|
|
tick_index: self.firmware.os.vm().tick_index(),
|
|
app_id: self.firmware.os.vm().current_app_id(),
|
|
status,
|
|
}
|
|
}
|
|
|
|
pub fn get_fault(&mut self) -> Option<CrashReport> {
|
|
if let Some(report) = self.firmware.os.vm().last_crash_report() {
|
|
return Some(report.clone());
|
|
}
|
|
match &self.firmware.state {
|
|
FirmwareState::AppCrashes(AppCrashesStep { report }) => Some(report.clone()),
|
|
_ => None,
|
|
}
|
|
}
|
|
|
|
fn tick_once(&mut self) {
|
|
self.firmware.tick(&self.signals, &mut self.platform);
|
|
self.platform.hardware.audio.transport().consume_silently();
|
|
}
|
|
|
|
fn execution_status(&mut self) -> HostExecutionStatus {
|
|
if self.fault_is_visible() {
|
|
HostExecutionStatus::Faulted
|
|
} else if self.host_action_required() {
|
|
HostExecutionStatus::Paused
|
|
} else if !matches!(self.firmware.state, FirmwareState::GameRunning(_)) {
|
|
HostExecutionStatus::Terminated
|
|
} else if self.firmware.os.vm().paused() {
|
|
HostExecutionStatus::Paused
|
|
} else {
|
|
HostExecutionStatus::Running
|
|
}
|
|
}
|
|
|
|
fn fault_is_visible(&mut self) -> bool {
|
|
self.firmware.os.vm().last_crash_report().is_some()
|
|
|| matches!(self.firmware.state, FirmwareState::AppCrashes(_))
|
|
}
|
|
|
|
fn require_active(&mut self, operation: &'static str) -> Result<(), HostError> {
|
|
let status = self.execution_status();
|
|
if matches!(status, HostExecutionStatus::Running | HostExecutionStatus::Paused)
|
|
&& !self.host_action_required()
|
|
{
|
|
Ok(())
|
|
} else {
|
|
Err(HostError::InvalidState { operation, status })
|
|
}
|
|
}
|
|
|
|
fn finish_frame_advance(&mut self) {
|
|
self.firmware.os.vm().set_paused(true);
|
|
self.firmware.os.vm().clear_debug_step_request();
|
|
}
|
|
}
|
|
|
|
impl Default for HeadlessHost {
|
|
fn default() -> Self {
|
|
Self::new()
|
|
}
|
|
}
|
|
|
|
#[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,
|
|
submission: RenderSubmission,
|
|
) -> Result<(), RenderSubmitError> {
|
|
let frame_id = submission.frame_id;
|
|
let ownership = submission.ownership;
|
|
self.hardware.submit_render_submission(submission)?;
|
|
// Host dialogs use their own producer and may reuse FrameId::ZERO.
|
|
// Capture/advance observe only canonical game publications.
|
|
if ownership.app_mode != prometeu_hal::app_mode::AppMode::Game {
|
|
return Ok(());
|
|
}
|
|
let (width, height) = self.hardware.gfx.size();
|
|
let pixels = self.hardware.gfx.front_buffer().to_vec();
|
|
let frame = OwnedRgba8888Frame::packed(frame_id, ownership, width, height, pixels)
|
|
.map_err(|_| RenderSubmitError::SubmissionRejected)?;
|
|
self.store.publish_frame(frame);
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
impl RuntimePlatform for HeadlessPlatform {
|
|
fn wall_clock(&self) -> &dyn WallClock {
|
|
self.hardware.wall_clock()
|
|
}
|
|
|
|
fn display_size(&self) -> (usize, usize) {
|
|
(Hardware::W, Hardware::H)
|
|
}
|
|
|
|
fn render_submission_sink(&mut self) -> &mut dyn RenderSubmissionSink {
|
|
self
|
|
}
|
|
|
|
fn render_backend(&mut self) -> &mut dyn RenderBackend {
|
|
&mut self.hardware
|
|
}
|
|
|
|
fn game2d_frame_composer(&mut self) -> &mut dyn Game2DFrameComposer {
|
|
&mut self.hardware
|
|
}
|
|
|
|
fn audio(&self) -> &dyn AudioBridge {
|
|
self.hardware.audio()
|
|
}
|
|
|
|
fn audio_mut(&mut self) -> &mut dyn AudioBridge {
|
|
self.hardware.audio_mut()
|
|
}
|
|
|
|
fn input(&self) -> &dyn InputPlatform {
|
|
self.hardware.input()
|
|
}
|
|
|
|
fn input_mut(&mut self) -> &mut dyn InputPlatform {
|
|
self.hardware.input_mut()
|
|
}
|
|
|
|
fn assets(&self) -> &dyn AssetBridge {
|
|
self.hardware.assets()
|
|
}
|
|
|
|
fn assets_mut(&mut self) -> &mut dyn AssetBridge {
|
|
self.hardware.assets_mut()
|
|
}
|
|
|
|
fn telemetry(&self) -> &dyn TelemetryPlatform {
|
|
self.hardware.telemetry()
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use prometeu_bytecode::registry::FunctionDecl;
|
|
use prometeu_test_support::program::{TestProgram, int64_signature};
|
|
use std::fs;
|
|
|
|
use prometeu_bytecode::assembler::assemble;
|
|
use prometeu_bytecode::model::Export;
|
|
|
|
use super::{AdvanceFrameOutcome, HeadlessHost};
|
|
|
|
#[test]
|
|
fn termination_during_frame_advance_clears_host_step_control() {
|
|
let cartridge = non_closing_cartridge();
|
|
let mut host = HeadlessHost::new();
|
|
host.boot(cartridge.to_string_lossy()).expect("boot non-closing cartridge");
|
|
host.firmware.request_home_from_host();
|
|
|
|
assert_eq!(
|
|
host.advance_frame().expect("lifecycle termination"),
|
|
AdvanceFrameOutcome::Terminated
|
|
);
|
|
assert!(host.firmware.os.vm().paused());
|
|
assert!(!host.firmware.os.vm().debug_step_requested());
|
|
|
|
fs::remove_dir_all(cartridge).expect("remove test cartridge");
|
|
}
|
|
|
|
fn non_closing_cartridge() -> std::path::PathBuf {
|
|
let directory = std::env::temp_dir().join(format!(
|
|
"prometeu-headless-termination-cleanup-{}-{}",
|
|
std::process::id(),
|
|
std::time::SystemTime::now()
|
|
.duration_since(std::time::UNIX_EPOCH)
|
|
.expect("system clock")
|
|
.as_nanos()
|
|
));
|
|
fs::create_dir_all(&directory).expect("create test cartridge");
|
|
|
|
let code = assemble("JMP 0\n").expect("assemble non-closing program");
|
|
let module = TestProgram {
|
|
const_pool: vec![],
|
|
functions: vec![FunctionDecl {
|
|
lifecycle_role: Default::default(),
|
|
code_offset: 0,
|
|
code_len: code.len() as u32,
|
|
local_slots: 0,
|
|
max_stack_slots: 1,
|
|
signature: int64_signature(0, 0),
|
|
captures: vec![],
|
|
name: None,
|
|
}],
|
|
code,
|
|
debug_info: None,
|
|
exports: vec![Export { symbol: "main".into(), func_idx: 0 }],
|
|
syscalls: vec![],
|
|
}
|
|
.serialize();
|
|
fs::write(directory.join("program.pbx"), module).expect("write test program");
|
|
fs::write(
|
|
directory.join("manifest.json"),
|
|
"{\n \"magic\": \"PMTU\",\n \"cartridge_version\": 1,\n \"app_id\": 91,\n \"title\": \"Termination Cleanup\",\n \"app_version\": \"0.1.0\",\n \"app_mode\": \"Game\",\n \"capabilities\": []\n}\n",
|
|
)
|
|
.expect("write test manifest");
|
|
|
|
directory
|
|
}
|
|
}
|