pr9.2
This commit is contained in:
@@ -1,21 +1,10 @@
|
||||
use prometeu_bytecode::isa::core::CoreOpCode;
|
||||
use prometeu_bytecode::FunctionMeta;
|
||||
use prometeu_vm::verifier::{Verifier, VerifierError};
|
||||
use prometeu_vm::{VirtualMachine, VmInitError};
|
||||
|
||||
#[test]
|
||||
fn verifier_rejects_call_closure_when_top_is_not_closure() {
|
||||
// Program: PUSH_I32 7; CALL_CLOSURE argc=0; HALT
|
||||
let mut rom = Vec::new();
|
||||
rom.extend_from_slice(&(CoreOpCode::PushI32 as u16).to_le_bytes());
|
||||
rom.extend_from_slice(&7i32.to_le_bytes());
|
||||
rom.extend_from_slice(&(CoreOpCode::CallClosure as u16).to_le_bytes());
|
||||
rom.extend_from_slice(&0u32.to_le_bytes()); // argc = 0
|
||||
rom.extend_from_slice(&(CoreOpCode::Halt as u16).to_le_bytes());
|
||||
|
||||
let functions = vec![FunctionMeta { code_offset: 0, code_len: rom.len() as u32, ..Default::default() }];
|
||||
|
||||
match Verifier::verify(&rom, &functions) {
|
||||
Err(VerifierError::NotAClosureOnCallClosure { .. }) => {}
|
||||
other => panic!("expected NotAClosureOnCallClosure, got {:?}", other),
|
||||
}
|
||||
fn invalid_image_format_is_rejected_before_execution() {
|
||||
// Provide bytes that are not a valid PBS image. The VM must reject it with InvalidFormat.
|
||||
let program_bytes = b"NOT_PBS_IMAGE".to_vec();
|
||||
let mut vm = VirtualMachine::default();
|
||||
let result = vm.initialize(program_bytes, "0");
|
||||
assert!(matches!(result, Err(VmInitError::InvalidFormat)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user