feat(runtime): preserve structured Play v2 diagnostics
Intrepid/Prometeu/Runtime/pipeline/head This commit looks good
Intrepid/Prometeu/Runtime/pipeline/head This commit looks good
Confirm loaded PBX identity, emit bounded fault envelopes and retain the primary crash report through teardown. Start background IO before audio initialization and update native protocol and process fixtures.
This commit is contained in:
@@ -7,6 +7,7 @@ license.workspace = true
|
||||
[dependencies]
|
||||
serde = { version = "1.0.228", features = ["derive"] }
|
||||
serde_json = "1.0.149"
|
||||
sha2 = "0.10.9"
|
||||
prometeu-vm = { path = "../prometeu-vm" }
|
||||
prometeu-bytecode = { path = "../prometeu-bytecode" }
|
||||
prometeu-hal = { path = "../prometeu-hal" }
|
||||
|
||||
@@ -11,6 +11,22 @@ pub enum CrashReport {
|
||||
}
|
||||
|
||||
impl CrashReport {
|
||||
/// Canonical machine facts; presentation and transport envelopes remain host-owned.
|
||||
pub fn diagnostic(&self) -> serde_json::Value {
|
||||
use serde_json::json;
|
||||
let mut result = json!({"kind":self.kind(),"pc":self.pc(),"summary":self.summary()});
|
||||
match self {
|
||||
Self::VmTrap { trap } => {
|
||||
result["trap"] = json!({"code":trap.code,"opcode":trap.opcode,
|
||||
"message":trap.message,"pc":trap.pc,"span":trap.span,"resource":trap.resource})
|
||||
}
|
||||
Self::VmPanic { message, .. } => result["message"] = json!(message),
|
||||
Self::VmInit { .. } => {
|
||||
result["initError"] = self.init_diagnostic().expect("initialization report")
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
||||
/// The same machine fields serve headless and desktop transports.
|
||||
pub fn init_diagnostic(&self) -> Option<serde_json::Value> {
|
||||
match self {
|
||||
|
||||
@@ -425,6 +425,12 @@ impl<'a> VmFacade<'a> {
|
||||
.unwrap_or(self.os.vm_runtime.current_app_id)
|
||||
}
|
||||
|
||||
pub fn loaded_program_sha256(&self) -> Option<[u8; 32]> {
|
||||
self.active_session()
|
||||
.and_then(|session| session.runtime.loaded_program_sha256)
|
||||
.or(self.os.vm_runtime.loaded_program_sha256)
|
||||
}
|
||||
|
||||
pub fn current_cartridge_title(&self) -> String {
|
||||
self.active_session()
|
||||
.map(|session| session.runtime.current_cartridge_title.clone())
|
||||
|
||||
@@ -35,6 +35,7 @@ impl VirtualMachineRuntime {
|
||||
game_lifecycle_events_delivered: Vec::new(),
|
||||
atomic_telemetry,
|
||||
last_crash_report: None,
|
||||
loaded_program_sha256: None,
|
||||
certifier: Certifier::new(cap_config.unwrap_or_default()),
|
||||
paused: false,
|
||||
debug_step_request: false,
|
||||
@@ -139,6 +140,7 @@ impl VirtualMachineRuntime {
|
||||
self.game_lifecycle_events_delivered.clear();
|
||||
|
||||
self.last_crash_report = None;
|
||||
self.loaded_program_sha256 = None;
|
||||
|
||||
self.paused = false;
|
||||
self.debug_step_request = false;
|
||||
@@ -226,6 +228,8 @@ impl VirtualMachineRuntime {
|
||||
) -> Result<(), CrashReport> {
|
||||
self.clear_cartridge_state();
|
||||
vm.set_capabilities(cartridge.capabilities);
|
||||
use sha2::Digest;
|
||||
self.loaded_program_sha256 = Some(sha2::Sha256::digest(&cartridge.program).into());
|
||||
|
||||
match vm.initialize(cartridge.program.clone()) {
|
||||
Ok(_) => {
|
||||
|
||||
@@ -53,6 +53,8 @@ pub struct VirtualMachineRuntime {
|
||||
pub game_lifecycle_events_delivered: Vec<GameLifecycleEvent>,
|
||||
pub atomic_telemetry: Arc<AtomicTelemetry>,
|
||||
pub last_crash_report: Option<CrashReport>,
|
||||
/// Digest of the exact bounded PBX input supplied to initialization.
|
||||
pub loaded_program_sha256: Option<[u8; 32]>,
|
||||
pub certifier: Certifier,
|
||||
pub paused: bool,
|
||||
pub debug_step_request: bool,
|
||||
|
||||
@@ -25,6 +25,9 @@ ringbuf = "0.4.7"
|
||||
serde_json = "1.0.149"
|
||||
clap = { version = "4.5", features = ["derive"] }
|
||||
|
||||
[dev-dependencies]
|
||||
sha2 = "0.10.9"
|
||||
|
||||
[[bench]]
|
||||
name = "wall_clock"
|
||||
harness = false
|
||||
|
||||
@@ -153,6 +153,7 @@ pub struct HostRunner {
|
||||
/// Tracks whether a new logical frame or host-only surface invalidation requires presentation.
|
||||
presentation: PresentationState,
|
||||
studio_capture: bool,
|
||||
studio_loaded_program_sha256: Option<[u8; 32]>,
|
||||
}
|
||||
|
||||
impl HostRunner {
|
||||
@@ -242,6 +243,7 @@ impl HostRunner {
|
||||
render_frame_store,
|
||||
presentation: PresentationState::default(),
|
||||
studio_capture: false,
|
||||
studio_loaded_program_sha256: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -274,6 +276,12 @@ impl HostRunner {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn studio_start_background_io(&mut self) {
|
||||
// Mount admission may precede audio setup. Its worker must already run
|
||||
// while a platform audio driver initializes, without advancing the VM.
|
||||
self.firmware.os.poll_background_io(&mut self.hardware);
|
||||
}
|
||||
|
||||
pub(crate) fn studio_boot_step(&mut self, disposable: bool) -> Result<bool, String> {
|
||||
self.studio_capture = true;
|
||||
if matches!(self.firmware.state, FirmwareState::GameRunning(_)) {
|
||||
@@ -317,6 +325,22 @@ impl HostRunner {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn studio_crash_report(&self) -> Option<prometeu_system::CrashReport> {
|
||||
match &self.firmware.state {
|
||||
FirmwareState::AppCrashes(step) => Some(step.report.clone()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn studio_program_sha256(&mut self) -> Option<[u8; 32]> {
|
||||
// Firmware may remove the failed VM session when entering AppCrashes.
|
||||
// Keep the identity observed before READY for the final diagnostic.
|
||||
if let Some(digest) = self.firmware.os.vm().loaded_program_sha256() {
|
||||
self.studio_loaded_program_sha256 = Some(digest);
|
||||
}
|
||||
self.studio_loaded_program_sha256
|
||||
}
|
||||
|
||||
pub(crate) fn studio_pause(&mut self, paused: bool) {
|
||||
self.input.clear_guest_signals();
|
||||
self.firmware.os.vm().set_paused(paused);
|
||||
@@ -687,6 +711,38 @@ impl ApplicationHandler for HostRunner {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn studio_background_io_runs_admitted_mount_before_any_firmware_tick() {
|
||||
for start_worker in [false, true] {
|
||||
let mut host = HostRunner::new(None, None);
|
||||
let (entered, receiver) = std::sync::mpsc::channel();
|
||||
host.firmware
|
||||
.os
|
||||
.memcard()
|
||||
.mount_card_with(move || {
|
||||
entered.send(()).unwrap();
|
||||
Err(prometeu_system::memcard::image::Error::InvalidState)
|
||||
})
|
||||
.unwrap();
|
||||
if start_worker {
|
||||
host.studio_start_background_io();
|
||||
receiver
|
||||
.recv_timeout(Duration::from_secs(2))
|
||||
.expect("mount worker did not run before firmware");
|
||||
let deadline = Instant::now() + Duration::from_secs(2);
|
||||
while host.firmware.os.memcard().preparation_active() {
|
||||
assert!(Instant::now() < deadline);
|
||||
host.firmware.os.memcard().poll(Instant::now());
|
||||
std::thread::yield_now();
|
||||
}
|
||||
}
|
||||
host.firmware.os.memcard().poll(Instant::now() + Duration::from_secs(2));
|
||||
assert_eq!(host.firmware.os.memcard().host_faulted(), !start_worker);
|
||||
assert!(matches!(host.firmware.state, FirmwareState::Reset(_)));
|
||||
host.studio_abort();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn studio_stress_demoscene_publishes_graphics_and_native_music() {
|
||||
let cart = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
use super::wire::{CONTROL_LIMIT, invalid};
|
||||
use prometeu_system::CrashReport;
|
||||
use serde_json::{Value, json};
|
||||
use std::io;
|
||||
|
||||
pub(super) fn hex(bytes: &[u8]) -> String {
|
||||
bytes.iter().map(|b| format!("{b:02x}")).collect()
|
||||
}
|
||||
|
||||
fn bound_strings(value: &mut Value, limit: usize) -> bool {
|
||||
match value {
|
||||
Value::String(text) if text.len() > limit => {
|
||||
let mut end = limit;
|
||||
while !text.is_char_boundary(end) {
|
||||
end -= 1;
|
||||
}
|
||||
text.truncate(end);
|
||||
true
|
||||
}
|
||||
Value::Array(items) => {
|
||||
items.iter_mut().fold(false, |changed, item| bound_strings(item, limit) | changed)
|
||||
}
|
||||
Value::Object(items) => {
|
||||
items.values_mut().fold(false, |changed, item| bound_strings(item, limit) | changed)
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn payload(
|
||||
report: &CrashReport,
|
||||
session: &[u8; 16],
|
||||
program: Option<[u8; 32]>,
|
||||
tick: u64,
|
||||
) -> io::Result<Vec<u8>> {
|
||||
let mut fault = report.diagnostic();
|
||||
let mut truncated = bound_strings(&mut fault, 8192);
|
||||
let envelope = |fault: &Value, truncated| {
|
||||
json!({"schemaVersion":1,"sessionId":hex(session),
|
||||
"programSha256":program.map(|p|hex(&p)),"tick":tick,"truncated":truncated,"fault":fault})
|
||||
};
|
||||
let mut bytes =
|
||||
serde_json::to_vec(&envelope(&fault, truncated)).map_err(|e| invalid(&e.to_string()))?;
|
||||
if bytes.len() > CONTROL_LIMIT {
|
||||
// Preserve machine identity and location even when rich init detail is too large.
|
||||
fault = json!({"kind":fault["kind"],"pc":fault["pc"],"summary":fault["summary"],
|
||||
"trap":fault["trap"],"message":fault["message"],
|
||||
"initError":{"code":fault["initError"]["code"],"detailsOmitted":true}});
|
||||
// JSON escaping can expand a UTF-8 byte sixfold; reserve space for that too.
|
||||
bound_strings(&mut fault, 2048);
|
||||
truncated = true;
|
||||
bytes = serde_json::to_vec(&envelope(&fault, truncated))
|
||||
.map_err(|e| invalid(&e.to_string()))?;
|
||||
}
|
||||
if bytes.len() > CONTROL_LIMIT {
|
||||
return Err(invalid("Studio fault exceeds control limit"));
|
||||
}
|
||||
Ok(bytes)
|
||||
}
|
||||
|
||||
pub(super) fn host_payload(kind: &str, message: &str, session: &[u8; 16], tick: u64) -> Vec<u8> {
|
||||
let mut fault = json!({"kind": kind, "summary": message, "pc": null});
|
||||
// A single string with worst-case JSON escaping still fits the control budget.
|
||||
let truncated = bound_strings(&mut fault, 8192);
|
||||
serde_json::to_vec(&json!({"schemaVersion":1,"sessionId":hex(session),"programSha256":null,
|
||||
"tick":tick,"truncated":truncated,"fault":fault}))
|
||||
.expect("serializable diagnostic")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn unicode_is_bounded_and_machine_location_is_preserved() {
|
||||
let report = CrashReport::VmPanic { message: "😀".repeat(20_000), pc: Some(42) };
|
||||
let bytes = payload(&report, &[1; 16], Some([2; 32]), 7).unwrap();
|
||||
assert!(bytes.len() <= CONTROL_LIMIT);
|
||||
let value: Value = serde_json::from_slice(&bytes).unwrap();
|
||||
assert_eq!(value["fault"]["pc"], 42);
|
||||
assert_eq!(value["truncated"], true);
|
||||
assert_eq!(value["programSha256"], "02".repeat(32));
|
||||
assert_eq!(value["fault"]["message"].as_str().unwrap().len(), 8192);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn escaped_text_also_fits_the_wire_budget() {
|
||||
let report = CrashReport::VmPanic { message: "\u{1}".repeat(30_000), pc: None };
|
||||
let bytes = payload(&report, &[1; 16], None, u64::MAX).unwrap();
|
||||
assert!(bytes.len() <= CONTROL_LIMIT);
|
||||
let value: Value = serde_json::from_slice(&bytes).unwrap();
|
||||
assert!(value["fault"]["pc"].is_null());
|
||||
assert!(value["programSha256"].is_null());
|
||||
assert_eq!(value["truncated"], true);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
//! Interactive Play integration, separate from the automation host.
|
||||
mod diagnostic;
|
||||
pub(crate) mod platform;
|
||||
mod transport;
|
||||
pub mod wire;
|
||||
@@ -70,6 +71,7 @@ fn input(p: &[u8], width: usize, height: usize) -> io::Result<(u64, InputSignals
|
||||
|
||||
pub(crate) fn run(mut runner: HostRunner, boot: Bootstrap) -> io::Result<()> {
|
||||
let transport = Transport::connect(&boot)?;
|
||||
runner.studio_start_background_io();
|
||||
runner.studio_audio_init();
|
||||
let (width, height) = runner.studio_dimensions();
|
||||
frame_bytes(width as u32, height as u32, width as u32)?;
|
||||
@@ -85,12 +87,15 @@ pub(crate) fn run(mut runner: HostRunner, boot: Bootstrap) -> io::Result<()> {
|
||||
);
|
||||
let mut last_request = 0;
|
||||
let mut last_frame = None;
|
||||
let mut error_kind = "host";
|
||||
let outcome = (|| -> io::Result<()> {
|
||||
loop {
|
||||
if let Some(error) = transport.failure() {
|
||||
error_kind = "transport";
|
||||
return Err(invalid(&error));
|
||||
}
|
||||
if ready && transport.idle() > Duration::from_secs(5) {
|
||||
error_kind = "watchdog";
|
||||
return Err(invalid("Studio control heartbeat expired"));
|
||||
}
|
||||
for _ in 0..64 {
|
||||
@@ -221,10 +226,22 @@ pub(crate) fn run(mut runner: HostRunner, boot: Bootstrap) -> io::Result<()> {
|
||||
}
|
||||
if !ready {
|
||||
if Instant::now() > boot_deadline {
|
||||
error_kind = "watchdog";
|
||||
return Err(invalid("Studio cartridge boot timed out"));
|
||||
}
|
||||
ready = runner.studio_boot_step(boot.disposable).map_err(|e| invalid(&e))?;
|
||||
ready = runner.studio_boot_step(boot.disposable).map_err(|e| {
|
||||
error_kind = "load";
|
||||
invalid(&e)
|
||||
})?;
|
||||
if ready {
|
||||
let digest = runner
|
||||
.studio_program_sha256()
|
||||
.ok_or_else(|| invalid("Studio loaded program identity unavailable"))?;
|
||||
if digest != boot.program_sha256 {
|
||||
return Err(invalid(
|
||||
"Studio loaded program identity differs from prepared compilation",
|
||||
));
|
||||
}
|
||||
runner.studio_pause(true);
|
||||
let mut p = Vec::new();
|
||||
for n in [
|
||||
@@ -235,6 +252,7 @@ pub(crate) fn run(mut runner: HostRunner, boot: Bootstrap) -> io::Result<()> {
|
||||
] {
|
||||
p.extend_from_slice(&n.to_le_bytes());
|
||||
}
|
||||
p.extend_from_slice(&digest);
|
||||
p.extend_from_slice(env!("CARGO_PKG_VERSION").as_bytes());
|
||||
transport.send(READY, 0, p)?;
|
||||
}
|
||||
@@ -255,7 +273,24 @@ pub(crate) fn run(mut runner: HostRunner, boot: Bootstrap) -> io::Result<()> {
|
||||
})();
|
||||
if let Err(error) = &outcome {
|
||||
eprintln!("[Studio] {error}");
|
||||
let _ = transport.send(ERROR, 0, error.to_string().into_bytes());
|
||||
let digest = runner.studio_program_sha256();
|
||||
if let Some(report) = runner.studio_crash_report()
|
||||
&& digest.is_none_or(|value| value == boot.program_sha256)
|
||||
{
|
||||
if let Ok(payload) =
|
||||
diagnostic::payload(&report, &boot.session, digest, runner.studio_tick_index())
|
||||
{
|
||||
let _ = transport.send_flushed(FAULT, 0, payload);
|
||||
}
|
||||
} else {
|
||||
let payload = diagnostic::host_payload(
|
||||
error_kind,
|
||||
&error.to_string(),
|
||||
&boot.session,
|
||||
runner.studio_tick_index(),
|
||||
);
|
||||
let _ = transport.send_flushed(ERROR, 0, payload);
|
||||
}
|
||||
runner.studio_abort();
|
||||
}
|
||||
outcome
|
||||
|
||||
@@ -225,9 +225,13 @@ impl Transport {
|
||||
.map_err(|_| invalid("Studio output queue unavailable"))
|
||||
}
|
||||
pub fn finish(&self, request: u64) -> io::Result<()> {
|
||||
self.send_flushed(STOPPED, request, Vec::new())
|
||||
}
|
||||
/// Observe terminal diagnostic delivery before abort closes the channels.
|
||||
pub fn send_flushed(&self, kind: u16, request: u64, payload: Vec<u8>) -> io::Result<()> {
|
||||
let (tx, rx) = mpsc::sync_channel(1);
|
||||
self.outgoing
|
||||
.try_send(Outbound { kind: STOPPED, request, payload: Vec::new(), flushed: Some(tx) })
|
||||
.try_send(Outbound { kind, request, payload, flushed: Some(tx) })
|
||||
.map_err(|_| invalid("Studio output queue unavailable"))?;
|
||||
rx.recv_timeout(Duration::from_secs(2))
|
||||
.map_err(|_| invalid("Studio shutdown acknowledgement failed"))
|
||||
|
||||
@@ -19,6 +19,7 @@ pub const PONG: u16 = 12;
|
||||
pub const ERROR: u16 = 13;
|
||||
pub const STOPPED: u16 = 14;
|
||||
pub const BOOTSTRAP: u16 = 15;
|
||||
pub const FAULT: u16 = 16;
|
||||
pub const RGBA8: u32 = 1;
|
||||
pub fn invalid(message: &str) -> io::Error {
|
||||
io::Error::new(io::ErrorKind::InvalidData, message)
|
||||
@@ -33,7 +34,7 @@ pub struct Header {
|
||||
}
|
||||
impl Header {
|
||||
fn validate(self) -> io::Result<()> {
|
||||
if !(HELLO..=BOOTSTRAP).contains(&self.kind) || self.sequence == 0 {
|
||||
if !(HELLO..=FAULT).contains(&self.kind) || self.sequence == 0 {
|
||||
return Err(invalid("invalid Studio message type/sequence"));
|
||||
}
|
||||
if self.length > if self.kind == FRAME { FRAME_LIMIT } else { CONTROL_LIMIT } {
|
||||
@@ -45,7 +46,7 @@ impl Header {
|
||||
self.validate()?;
|
||||
let mut b = [0; HEADER_BYTES];
|
||||
b[..4].copy_from_slice(b"PST1");
|
||||
b[4..6].copy_from_slice(&1u16.to_le_bytes());
|
||||
b[4..6].copy_from_slice(&2u16.to_le_bytes());
|
||||
b[8..10].copy_from_slice(&self.kind.to_le_bytes());
|
||||
b[12..16].copy_from_slice(&(self.length as u32).to_le_bytes());
|
||||
b[16..24].copy_from_slice(&self.sequence.to_le_bytes());
|
||||
@@ -53,8 +54,10 @@ impl Header {
|
||||
Ok(b)
|
||||
}
|
||||
pub fn decode(b: &[u8; HEADER_BYTES]) -> io::Result<Self> {
|
||||
if &b[..4] != b"PST1" || b[4..8] != [1, 0, 0, 0] || b[10..12] != [0, 0] {
|
||||
return Err(invalid("invalid Studio magic/version/flags"));
|
||||
if &b[..4] != b"PST1" || b[4..8] != [2, 0, 0, 0] || b[10..12] != [0, 0] {
|
||||
return Err(invalid(
|
||||
"incompatible Studio Play protocol: required 2.0, or invalid magic/flags",
|
||||
));
|
||||
}
|
||||
let h = Self {
|
||||
kind: u16::from_le_bytes(b[8..10].try_into().unwrap()),
|
||||
@@ -126,12 +129,13 @@ pub struct Bootstrap {
|
||||
pub control_port: u16,
|
||||
pub video_port: u16,
|
||||
pub disposable: bool,
|
||||
pub program_sha256: [u8; 32],
|
||||
}
|
||||
impl Bootstrap {
|
||||
pub fn read(input: impl Read) -> io::Result<Self> {
|
||||
let m = Reader::new(input).receive()?;
|
||||
let p = &m.payload;
|
||||
if m.header.kind != BOOTSTRAP || m.header.request != 0 || p.len() != 53 || p[52] > 1 {
|
||||
if m.header.kind != BOOTSTRAP || m.header.request != 0 || p.len() != 85 || p[52] > 1 {
|
||||
return Err(invalid("invalid Studio bootstrap"));
|
||||
}
|
||||
let b = Self {
|
||||
@@ -140,6 +144,7 @@ impl Bootstrap {
|
||||
control_port: u16::from_le_bytes(p[48..50].try_into().unwrap()),
|
||||
video_port: u16::from_le_bytes(p[50..52].try_into().unwrap()),
|
||||
disposable: p[52] != 0,
|
||||
program_sha256: p[53..85].try_into().unwrap(),
|
||||
};
|
||||
if b.control_port == 0 || b.video_port == 0 || b.control_port == b.video_port {
|
||||
return Err(invalid("invalid Studio ports"));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! Real process qualification: no window, slow consumer, pause and broken IPC.
|
||||
use prometeu_host_desktop_winit::studio::wire::*;
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::io::{self, BufRead, Write};
|
||||
use std::net::{Shutdown, TcpListener, TcpStream};
|
||||
use std::process::{Child, Command, ExitStatus, Stdio};
|
||||
@@ -21,6 +22,8 @@ impl Session {
|
||||
let video = TcpListener::bind("127.0.0.1:0").unwrap();
|
||||
let cart = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("../../../test-cartridges/dummy-boy");
|
||||
let program_sha256: [u8; 32] =
|
||||
Sha256::digest(std::fs::read(cart.join("program.pbx")).unwrap()).into();
|
||||
let child = Command::new(env!("CARGO_BIN_EXE_prometeu-host-desktop-winit"))
|
||||
.args(["--studio", "--run"])
|
||||
.arg(cart)
|
||||
@@ -51,6 +54,7 @@ impl Session {
|
||||
p.extend_from_slice(&control.local_addr().unwrap().port().to_le_bytes());
|
||||
p.extend_from_slice(&video.local_addr().unwrap().port().to_le_bytes());
|
||||
p.push(1);
|
||||
p.extend_from_slice(&program_sha256);
|
||||
Writer::new(session_child.stdin.take().unwrap()).send(BOOTSTRAP, 0, &p).unwrap();
|
||||
fn accept(listener: TcpListener) -> TcpStream {
|
||||
listener.set_nonblocking(true).unwrap();
|
||||
@@ -92,7 +96,9 @@ impl Session {
|
||||
};
|
||||
let ready = session.control.receive().unwrap();
|
||||
assert_eq!(ready.header.kind, READY, "{:?}", session.logs.lock().unwrap());
|
||||
assert!(ready.payload.len() >= 48);
|
||||
assert_eq!(u32::from_le_bytes(ready.payload[..4].try_into().unwrap()), 640);
|
||||
assert_eq!(&ready.payload[16..48], &program_sha256);
|
||||
session
|
||||
}
|
||||
fn command(&mut self, kind: u16, request: u64) -> Message {
|
||||
|
||||
@@ -22,17 +22,35 @@ fn rgba_fixture_pins_channel_order_and_metadata() {
|
||||
|
||||
#[test]
|
||||
fn bootstrap_rejects_wrong_roles_lengths_and_ports() {
|
||||
let mut p = vec![0; 53];
|
||||
let mut p = vec![0; 85];
|
||||
p[48..50].copy_from_slice(&1234u16.to_le_bytes());
|
||||
p[50..52].copy_from_slice(&1235u16.to_le_bytes());
|
||||
p[52] = 1;
|
||||
p[53..85].fill(0xab);
|
||||
let mut bytes = Vec::new();
|
||||
Writer::new(&mut bytes).send(BOOTSTRAP, 0, &p).unwrap();
|
||||
let boot = Bootstrap::read(bytes.as_slice()).unwrap();
|
||||
assert!(boot.disposable);
|
||||
assert_eq!(boot.program_sha256, [0xab; 32]);
|
||||
assert_eq!(boot.hello(1).len(), 49);
|
||||
p[50..52].copy_from_slice(&1234u16.to_le_bytes());
|
||||
bytes.clear();
|
||||
Writer::new(&mut bytes).send(BOOTSTRAP, 0, &p).unwrap();
|
||||
assert!(Bootstrap::read(bytes.as_slice()).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn v2_fault_fixture_preserves_unsigned_pc_span_and_unicode() {
|
||||
let hex = include_str!("../../../../devtools/studio-protocol/fixtures/fault.hex");
|
||||
let bytes: Vec<_> =
|
||||
hex.split_whitespace().map(|s| u8::from_str_radix(s, 16).unwrap()).collect();
|
||||
let m = Reader::new(bytes.as_slice()).receive_control().unwrap();
|
||||
assert_eq!(m.header.kind, FAULT);
|
||||
let value: serde_json::Value = serde_json::from_slice(&m.payload).unwrap();
|
||||
assert_eq!(value["fault"]["pc"], u32::MAX);
|
||||
assert_eq!(value["fault"]["trap"]["span"]["file_id"], 7);
|
||||
assert!(value["fault"]["summary"].as_str().unwrap().contains("ação"));
|
||||
let mut old: [u8; 32] = bytes[..32].try_into().unwrap();
|
||||
old[4] = 1;
|
||||
assert!(Header::decode(&old).unwrap_err().to_string().contains("required 2.0"));
|
||||
}
|
||||
|
||||
@@ -422,20 +422,7 @@ fn log_event(event: &prometeu_hal::log::LogEvent) -> Value {
|
||||
}
|
||||
|
||||
pub(super) fn fault(report: &CrashReport) -> Value {
|
||||
let mut result = json!({"kind":report.kind(),"pc":report.pc(),"summary":report.summary()});
|
||||
match report {
|
||||
CrashReport::VmTrap { trap } => {
|
||||
result["trap"] = json!({"code":trap.code,"opcode":trap.opcode,
|
||||
"message":trap.message,"pc":trap.pc,"span":trap.span,"resource":trap.resource});
|
||||
}
|
||||
CrashReport::VmPanic { message, .. } => {
|
||||
result["message"] = json!(message);
|
||||
}
|
||||
CrashReport::VmInit { .. } => {
|
||||
result["initError"] = report.init_diagnostic().expect("initialization report");
|
||||
}
|
||||
}
|
||||
result
|
||||
report.diagnostic()
|
||||
}
|
||||
|
||||
pub(super) fn capture(c: CapturedFrame) -> Result<Value, WireError> {
|
||||
|
||||
Reference in New Issue
Block a user