Fix Intel 4004 CPU instruction set and improve MCS-4 timing accuracy
Overhaul the Intel 4004 instruction set to match the real opcode map, adding missing instructions (NOP, FIM, FIN, JIN, ISZ, KBP, DCL, WR0-3, RD0-3) and refining two-byte instruction handling with proper M1/M2 data phases. Rewrite the CPU fetch-execute cycle to correctly process two-byte opcodes across separate clock cycles. Improve Intel 4001 ROM timing with M1/M2 nibble phase tracking and an A3 wait counter so the ROM drives data only when the CPU expects it. Fix state-machine transition helpers in Intel 4002 and 4003 to capture the old state before processing events, preventing incorrect exit/entry callbacks. Add non-propagating pin driver methods to prevent deadlocks caused by bidirectional pin connections during signal propagation. Add Fibonacci integration test and opcode fix plan document. Update all README files to reflect the new instruction set.
This commit is contained in:
parent
54144d10e9
commit
6a335a15d4
14 changed files with 4125 additions and 1062 deletions
108
tests/README.md
108
tests/README.md
|
|
@ -15,13 +15,17 @@ timing, clock handling, and bus operations for Intel 400x series chips.
|
|||
|
||||
### Integration Tests (in tests/ directory)
|
||||
|
||||
1. **`intel_400x_tests.rs`** - Tests for the common intel_400x functionality
|
||||
2. **`mocks.rs`** - Mock implementations for testing hardware interactions
|
||||
3. **`mock_based_tests.rs`** - Tests using mocks for data bus and pin operations
|
||||
4. **`property_based_tests.rs`** - Property-based tests for state machine verification
|
||||
5. **`integration_tests.rs`** - Integration tests with concrete chip implementations
|
||||
6. **`working_test.rs`** - Working demonstration of core functionality
|
||||
7. **`lib.rs`** - Test library and common utilities
|
||||
1. **`lib.rs`** - Test library and common utilities
|
||||
2. **`intel_400x_tests.rs`** - Tests for the common intel_400x functionality
|
||||
3. **`intel_4001_state_machine_test.rs`** - Intel 4001 ROM state machine tests
|
||||
4. **`intel_4002_state_machine_test.rs`** - Intel 4002 RAM state machine tests
|
||||
5. **`intel_4003_state_machine_test.rs`** - Intel 4003 shift register state machine tests
|
||||
6. **`intel_4004_state_machine_test.rs`** - Intel 4004 CPU state machine tests
|
||||
7. **`integration_tests.rs`** - Integration tests with concrete chip implementations
|
||||
8. **`json_integration_tests.rs`** - JSON system configuration integration tests
|
||||
9. **`simple_test.rs`** - Working demonstration of core functionality
|
||||
10. **`gui_tests.rs`** - GUI component tests
|
||||
11. **`gui_integration_tests.rs`** - GUI integration tests
|
||||
|
||||
### Test Categories
|
||||
|
||||
|
|
@ -34,35 +38,37 @@ timing, clock handling, and bus operations for Intel 400x series chips.
|
|||
- **Data Bus Operations**: Test bit manipulation for 4-bit bus
|
||||
- **Utility Functions**: Test helper functions and pin operations
|
||||
|
||||
#### 2. Mock-Based Tests (`mock_based_tests.rs`)
|
||||
#### 2. State Machine Tests (`intel_400x_state_machine_test.rs`)
|
||||
|
||||
- **Data Bus Operations**: Test read/write operations with controlled inputs
|
||||
- **Clock Handling**: Test clock pin interactions and edge scenarios
|
||||
- **Control Pins**: Test SYNC, CM, and RESET pin behavior
|
||||
- **Timing State**: Test state machine with mock timing
|
||||
- **Error Handling**: Test behavior with invalid inputs
|
||||
- **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. Property-Based Tests (`property_based_tests.rs`)
|
||||
|
||||
- **State Machine Invariants**: Verify state consistency properties
|
||||
- **Type Conversions**: Test enum conversion roundtrips
|
||||
- **Address Properties**: Test address assembly properties
|
||||
- **Timing Properties**: Test duration and timing constraints
|
||||
- **Concurrency Safety**: Test thread-safe behavior
|
||||
|
||||
#### 4. Integration Tests (`integration_tests.rs`)
|
||||
#### 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
|
||||
|
||||
#### 5. Working Tests (`working_test.rs`)
|
||||
#### 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
|
||||
|
|
@ -74,20 +80,23 @@ cargo test
|
|||
### Run Specific Test Categories
|
||||
|
||||
```bash
|
||||
# Unit tests only
|
||||
# Common functionality tests
|
||||
cargo test intel_400x_tests
|
||||
|
||||
# Mock-based tests only
|
||||
cargo test mock_based_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
|
||||
|
||||
# Property-based tests only
|
||||
cargo test property_based_tests
|
||||
|
||||
# Integration tests only
|
||||
# Integration tests
|
||||
cargo test integration_tests
|
||||
|
||||
# Demo tests only
|
||||
cargo test demo
|
||||
# JSON configuration tests
|
||||
cargo test json_integration_tests
|
||||
|
||||
# Simple/core tests
|
||||
cargo test simple_test
|
||||
```
|
||||
|
||||
### Run with Detailed Output
|
||||
|
|
@ -104,23 +113,13 @@ cargo test test_name
|
|||
|
||||
## Test Architecture
|
||||
|
||||
### Mock System
|
||||
### Test Infrastructure
|
||||
|
||||
The test suite includes a comprehensive mock system that provides:
|
||||
The test suite uses the shared test library (`lib.rs`) which provides:
|
||||
|
||||
- **MockPin**: Simulates pin behavior with operation counting
|
||||
- **MockIntel400xComponent**: Full component mock implementing all traits
|
||||
- **MockScenario**: Test scenario builder with common setups
|
||||
- **MockTimeProvider**: Deterministic time source for timing tests
|
||||
|
||||
### Property-Based Testing
|
||||
|
||||
Uses `proptest` to verify:
|
||||
|
||||
- State machine invariants hold for all inputs
|
||||
- Type conversions are consistent
|
||||
- Address assembly works for all valid inputs
|
||||
- Timing constraints are maintained
|
||||
- **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
|
||||
|
||||
|
|
@ -167,12 +166,12 @@ Tests verify that:
|
|||
|
||||
## Adding New Tests
|
||||
|
||||
When adding new functionality to `intel_400x.rs`, add corresponding tests:
|
||||
When adding new functionality, add corresponding tests:
|
||||
|
||||
1. **Unit tests** for pure functions in `intel_400x_tests.rs`
|
||||
2. **Mock tests** for hardware interactions in `mock_based_tests.rs`
|
||||
3. **Property tests** for behavioral properties in `property_based_tests.rs`
|
||||
4. **Integration tests** for concrete usage in `integration_tests.rs`
|
||||
2. **State machine tests** for component behavior in `intel_400x_state_machine_test.rs`
|
||||
3. **Integration tests** for concrete usage in `integration_tests.rs`
|
||||
4. **JSON config tests** for system configuration in `json_integration_tests.rs`
|
||||
|
||||
## Test Data
|
||||
|
||||
|
|
@ -185,12 +184,11 @@ The tests use realistic data patterns that reflect actual Intel 4004/4001 usage:
|
|||
|
||||
## Dependencies
|
||||
|
||||
The test suite uses these testing libraries:
|
||||
The test suite uses standard Rust testing:
|
||||
|
||||
- `proptest`: Property-based testing
|
||||
- `mockall`: Mock generation (if needed)
|
||||
- `pretty_assertions`: Enhanced assertion messages
|
||||
- `std::time`: Timing simulation
|
||||
- `serde_json`: JSON configuration parsing (for integration tests)
|
||||
- Standard `#[test]` attributes with `cargo test`
|
||||
|
||||
## Continuous Integration
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue