Introduces a VirtualClock-based timing system replacing wall-clock Instant-based timing for hardware-accurate simulation. New modules: - virtual_clock.rs: Shared virtual time source with condvar sync - real_time_governor.rs: Thread that advances virtual time - component_timing.rs: Per-component timing constraints Key changes: - Component trait: added update_at_time(), timing(), set_virtual_clock_optional() - All Intel 400x components migrated to virtual-time-aware operation - ConfigurableSystem: start() returns Result, spawns governor thread - GUI: timing controls (speed slider, mode selector, step button) - Console: speed/mode/step/time commands - Backward compatible: legacy fallback for components without VirtualClock Reviewed-by: code review found 2 warnings (clock resume() dead code, reset() safety docs) — both fixed. |
||
|---|---|---|
| .. | ||
| fibonacci_test.rs | ||
| gui_integration_tests.rs | ||
| gui_tests.rs | ||
| integration_tests.rs | ||
| intel_400x_tests.rs | ||
| intel_4001_state_machine_test.rs | ||
| intel_4002_state_machine_test.rs | ||
| intel_4003_state_machine_test.rs | ||
| intel_4004_state_machine_test.rs | ||
| json_integration_tests.rs | ||
| lib.rs | ||
| README.md | ||
| simple_test.rs | ||
| virtual_time_tests.rs | ||
Intel 400x Common Functionality Tests
This directory contains comprehensive tests for the intel_400x.rs common functionality module, which provides shared
timing, clock handling, and bus operations for Intel 400x series chips.
Test Organization
Unit Tests (in implementation files)
- Intel4001 unit tests: Located in
src/components/memory/intel_4001.rs- Component creation and configuration
- Memory operations and data loading
- State management and transitions
- Error handling and edge cases
Integration Tests (in tests/ directory)
lib.rs- Test library and common utilitiesintel_400x_tests.rs- Tests for the common intel_400x functionalityintel_4001_state_machine_test.rs- Intel 4001 ROM state machine testsintel_4002_state_machine_test.rs- Intel 4002 RAM state machine testsintel_4003_state_machine_test.rs- Intel 4003 shift register state machine testsintel_4004_state_machine_test.rs- Intel 4004 CPU state machine testsintegration_tests.rs- Integration tests with concrete chip implementationsjson_integration_tests.rs- JSON system configuration integration testssimple_test.rs- Working demonstration of core functionalitygui_tests.rs- GUI component testsgui_integration_tests.rs- GUI integration tests
Test Categories
1. Common Functionality Tests (intel_400x_tests.rs)
- Timing Constants: Verify access times and setup requirements
- Address Assembly: Test nibble-to-address conversion logic
- State Machine: Test state transition logic and queries
- Clock Edge Detection: Test edge detection algorithms
- Data Bus Operations: Test bit manipulation for 4-bit bus
- Utility Functions: Test helper functions and pin operations
2. State Machine Tests (intel_400x_state_machine_test.rs)
- Intel 4001 ROM: State machine transitions for ROM operations
- Intel 4002 RAM: State machine transitions for RAM operations
- Intel 4003 Shift Register: State machine transitions for shift register operations
- Intel 4004 CPU: State machine transitions for CPU instruction processing
3. Integration Tests (integration_tests.rs)
- Trait Implementation: Verify concrete types implement traits correctly
- Cross-Component Compatibility: Test multiple components work together
- Real Component Testing: Test with actual Intel4001 implementation
- Lifecycle Testing: Test component initialization and cleanup
4. JSON Configuration Tests (json_integration_tests.rs)
- System Creation: Test JSON-based system configuration loading
- Component Wiring: Verify automatic pin connections from config
- Multiple Configurations: Test basic, max, and I/O demo configurations
5. Simple Tests (simple_test.rs)
- Core Functionality: Demonstrates that the intel_400x module is testable
- Basic Operations: Tests fundamental features that work correctly
- Regression Prevention: Ensures core functionality remains stable
6. GUI Tests (gui_tests.rs, gui_integration_tests.rs)
- GUI Components: Test GUI component rendering and state
- GUI Integration: Test GUI with full system integration
Running the Tests
Run All Tests
cargo test
Run Specific Test Categories
# Common functionality tests
cargo test intel_400x_tests
# State machine tests
cargo test intel_4001_state_machine_test
cargo test intel_4002_state_machine_test
cargo test intel_4003_state_machine_test
cargo test intel_4004_state_machine_test
# Integration tests
cargo test integration_tests
# JSON configuration tests
cargo test json_integration_tests
# Simple/core tests
cargo test simple_test
Run with Detailed Output
cargo test -- --nocapture
Run Specific Test
cargo test test_name
Test Architecture
Test Infrastructure
The test suite uses the shared test library (lib.rs) which provides:
- Helper functions: Common test utilities for component creation and configuration
- Shared assertions: Reusable assertion patterns for state machine testing
- Test fixtures: Pre-configured component setups for common test scenarios
Integration Testing
Tests verify that:
- Concrete implementations (like Intel4001) correctly use the common traits
- Multiple components can interact through the common interface
- The common functionality works correctly in real usage scenarios
Key Testing Areas
1. Timing and Clock Logic
- Clock edge detection accuracy
- Two-phase clock handling
- Access time simulation
- State machine timing
2. Address Handling
- Nibble assembly into full addresses
- Address latching during clock phases
- Address validation and bounds checking
3. Data Bus Operations
- 4-bit data bus read/write operations
- Bus tri-stating for contention avoidance
- Bit-level manipulation and verification
4. State Machine Verification
- State transition correctness
- State invariant preservation
- Reset behavior verification
- Error state handling
5. Hardware Abstraction
- Pin operation safety
- Driver management
- Hardware timing simulation
- Bus contention avoidance
Adding New Tests
When adding new functionality, add corresponding tests:
- Unit tests for pure functions in
intel_400x_tests.rs - State machine tests for component behavior in
intel_400x_state_machine_test.rs - Integration tests for concrete usage in
integration_tests.rs - JSON config tests for system configuration in
json_integration_tests.rs
Test Data
The tests use realistic data patterns that reflect actual Intel 4004/4001 usage:
- Address ranges: 0x0000 to 0x0FFF (12-bit addressing)
- Data values: 0x00 to 0x0F (4-bit data)
- Timing values: nanosecond precision for hardware simulation
- Pin states: High, Low, and High-Z (tri-state)
Dependencies
The test suite uses standard Rust testing:
std::time: Timing simulationserde_json: JSON configuration parsing (for integration tests)- Standard
#[test]attributes withcargo test
Continuous Integration
These tests are designed to run in CI environments and provide:
- Deterministic results (no race conditions)
- Reasonable execution time
- Clear failure messages
- Comprehensive coverage of edge cases
Troubleshooting
If tests fail:
- Check that timing-related tests account for system timing variations
- Verify that mock setups match the expected hardware behavior
- Ensure that property-based tests have appropriate generation strategies
- Check that integration tests use the correct trait implementations
The test suite is designed to be robust and provide clear feedback about what functionality is broken and why.