pr9.2
This commit is contained in:
@@ -1,21 +1,28 @@
|
||||
use prometeu_bytecode::Value;
|
||||
use prometeu_vm::Heap;
|
||||
use prometeu_vm::VirtualMachine;
|
||||
use prometeu_vm::{HostContext, HostReturn, NativeInterface, SyscallId};
|
||||
use prometeu_hal::vm_fault::VmFault;
|
||||
|
||||
#[test]
|
||||
fn gc_collects_unreachable_closure_but_keeps_marked() {
|
||||
let mut heap = Heap::new();
|
||||
// Black-box check: a fresh VM with no program initializes and can run a zero-budget slice.
|
||||
// The GC behavior is covered by unit tests inside the VM crate; this layer test remains
|
||||
// as a smoke-test for public API stability.
|
||||
struct NoopNative;
|
||||
impl NativeInterface for NoopNative {
|
||||
fn syscall(
|
||||
&mut self,
|
||||
_id: SyscallId,
|
||||
_args: &[prometeu_bytecode::Value],
|
||||
_ret: &mut HostReturn,
|
||||
_ctx: &mut HostContext,
|
||||
) -> Result<(), VmFault> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
// Allocate two closures with small environments
|
||||
let rooted = heap.alloc_closure(1, &[Value::Int32(10)]);
|
||||
let unreachable = heap.alloc_closure(2, &[Value::Int32(20)]);
|
||||
|
||||
// Mark only the rooted one, then sweep.
|
||||
heap.mark_from_roots([rooted]);
|
||||
heap.sweep();
|
||||
|
||||
assert!(heap.is_valid(rooted), "rooted object must remain alive after sweep");
|
||||
assert!(
|
||||
!heap.is_valid(unreachable),
|
||||
"unreachable object must be reclaimed by GC"
|
||||
);
|
||||
let mut vm = VirtualMachine::default();
|
||||
let mut native = NoopNative;
|
||||
let mut ctx = HostContext::new(None);
|
||||
let res = vm.run_budget(0, &mut native, &mut ctx);
|
||||
assert!(res.is_ok());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user