# Phase 9: Update Tests for Virtual Time ## Current State All 226 existing tests pass (142 unit tests, 16 fibonacci tests, 62 integration tests, 5 simple tests, 15 doc-tests). No tests are broken by the virtual time migration — the existing tests use `update()` (without virtual time) and direct component manipulation, which still works. ## Plan ### 1. Update `tests/lib.rs` — Add Virtual Time Test Utilities Add helper functions to the `test_utils` module: - `create_maxspeed_clock()` — Creates a VirtualClock in MaxSpeed mode with a 333ns tick size - `create_singlestep_clock()` — Creates a VirtualClock in SingleStep mode - `spawn_governor()` — Spawns a RealTimeGovernor thread for a given clock - `stop_and_wait()` — Stops the clock and waits for governor thread to finish ### 2. New Test File: `tests/virtual_time_tests.rs` #### MaxSpeed Mode Tests - `test_maxspeed_clock_advances` — Verify VirtualClock advances in MaxSpeed mode with governor - `test_maxspeed_component_updates` — Verify Intel4001 updates correctly at virtual time - `test_maxspeed_rom_access_timing` — Verify ROM data is valid after access_time elapsed in virtual time #### SingleStep Mode Tests - `test_singlestep_advances_one_tick` — Verify each trigger_step() advances exactly one tick - `test_singlestep_rom_state_at_specific_time` — Verify ROM state at specific virtual times: - Before access_time: data not ready - After access_time: data valid #### Overclocking Tests - `test_overclocking_rom_fails_at_2mhz` — Set 2 MHz clock (250ns phase), verify ROM (500ns access) fails - `test_overclocking_ram_fails_at_2mhz` — Same for RAM - `test_shift_register_works_at_higher_freq` — Intel4003 (200ns access) works at 2 MHz (250ns phase >= 200ns) - `test_component_timing_check_access_time` — Direct ComponentTiming API tests #### Virtual Clock Integration Tests - `test_configurable_system_creates_virtual_clock` — Verify ConfigurableSystem has a VirtualClock - `test_configurable_system_maxspeed_execution` — Run system in MaxSpeed mode briefly, verify it works - `test_virtual_clock_stop_exits_threads` — Verify clock.stop() causes governor to exit - `test_pause_resume_behavior` — Verify pause stops time advancement, resume continues ### 3. Implementation Notes - All new tests go in a separate file to avoid modifying existing passing tests - Tests use `Arc` and `RealTimeGovernor` directly (not through ConfigurableSystem) for precise control - Overclocking tests use `ComponentTiming::check_access_time()` directly since component-internal timing checks happen via `update_at_time()` which requires the full component thread infrastructure - Tests that spawn governor threads must ensure proper cleanup (stop + join)