Running Tests
To run all tests in the project:The project is in early development, so test coverage is still being expanded. The current focus is on CPU instruction correctness.
Test Structure
The test suite is organized into several categories:CPU Instruction Tests
Located incore/src/tests/run.rs, these tests verify ARM64 instruction emulation using the Unicorn engine backend.
Test Framework
The test framework provides:- Warmup phase - JIT compiler initialization to avoid cold-start timeouts
- Timeout detection - Platform-specific timeouts (100ms Linux, 500ms macOS)
- Result tracking - Pass/fail status with execution duration
- ARM64 instruction helpers - Functions to encode ARM64 instructions
Example: Running a CPU Test
Example: Running a CPU Test
- Encodes the ARM64 instruction
ADD X1, X1, #2 - Sets register X1 to 5
- Executes the instruction
- Verifies X1 now contains 7
Current Test Cases
The following ARM64 instructions are tested:Basic Instructions
- NOP - No operation
- ADD immediate -
ADD X1, X1, #2 - SUB immediate -
SUB X2, X2, #1 - ADD register -
ADD X0, X0, X1 - MOV register -
MOV X3, X4 - RET - Return instruction
All tests are executed through the
run_tests() function, which can be triggered from the GUI or run via cargo test.Multicore Tests
Located incore/src/tests/multicore_test.rs, these tests verify the multi-core CPU manager:
test_multicore_initialization
Verifies that the CPU manager correctly initializes:
- 8 CPU cores (matching Switch 2 architecture)
- 12GB of shared memory
core/src/tests/multicore_test.rs:6
test_shared_memory_access
Verifies that multiple cores can access the same shared memory:
- Core 0 writes value
0xDEADBEEFto address0x1000 - Core 1 reads from address
0x1000 - Asserts that Core 1 sees the value written by Core 0
core/src/tests/multicore_test.rs:15
Platform Considerations
macOS Testing
On macOS, especially with Apple Silicon (M1/M2), JIT compilation can have cold-start overhead: The test framework accounts for this with:- Extended timeout (500ms vs 100ms on Linux)
- Warmup phase before running tests
- Clear messaging when macOS-specific issues occur
core/src/tests/run.rs:10
Running Tests from GUI
The GUI provides a “Run CPU Tests” button that executes the instruction test suite in a background thread.
Reference:
gui/src/gui/gui.rs:157
Adding New Tests
When adding new functionality, please include tests:Test Output
Test results include:- Test name
- Pass/fail status
- Execution duration
- Total summary with pass/fail counts
For debugging failed tests, see the Debugging page for information on enabling trace logging.
