This guide demonstrates how to verify that your cache simulator is running perfectly and showcases all available functionalities.
# Run the comprehensive test script
./test_comprehensive.shThis script tests all 12 major functionality areas and provides colored output showing success/failure.
# Run built-in test suite
make test
# Run with default configuration
make run./build/cache_simulator -s 512 -b 32 -a 1 -v
# Verify: Output shows "Direct Mapped" and single block per set./build/cache_simulator -s 1024 -b 32 -a 4 -v
# Verify: Output shows "4-way" and 4 blocks per set./build/cache_simulator -s 512 -b 32 -a 0 -v
# Verify: Output shows "Fully Associative" and 1 set with all blocks./build/cache_simulator -r LRU -v
# Verify: Output shows "LRU" policy in configuration./build/cache_simulator -r FIFO -v
# Verify: Output shows "FIFO" policy in configuration./build/cache_simulator -r RANDOM -v
# Verify: Output shows "Random" policy in configuration./build/cache_simulator -w WRITE_THROUGH -v
# Verify: Output shows "Write-Through" and dirty bits remain 0 (D:0)./build/cache_simulator -w WRITE_BACK -v
# Verify: Output shows "Write-Back" and dirty bits set on writes (D:1)./build/cache_simulator -m WRITE_ALLOCATE -v
# Verify: Write misses allocate cache blocks./build/cache_simulator -m NO_WRITE_ALLOCATE -v
# Verify: Write misses go directly to memory without allocation# Test specific addresses and operations
./build/cache_simulator -A 0x1000,0x2000,0x3000,0x1000 -O READ,WRITE,READ,WRITE -v
# Verify:
# - Address 0x1000 first access: MISS
# - Address 0x1000 second access: HIT (shows caching works)
# - Statistics show correct hit/miss ratios./build/cache_simulator -v
# Verify output includes:
# - "Accessing address X with operation Y"
# - Cache Contents section showing [V:X D:X Tag:X] format
# - Detailed statistics breakdown./build/cache_simulator --interactive
# Test these commands:
cache> access 0x100 read # Should show MISS
cache> access 0x100 write # Should show HIT
cache> stats # Should show statistics
cache> config # Should show configuration
cache> contents # Should show cache state
cache> reset # Should clear cache
cache> batch 0x100,0x200 read,write # Batch operations
cache> help # Show available commands
cache> quit # Exit- Cache size, block size, associativity correctly shown
- Number of sets and blocks calculated correctly
- Bit breakdowns (offset, index, tag) accurate
- Policies displayed correctly
- Addresses displayed in hex format
- Operations (READ/WRITE) shown correctly
- Results (HIT/MISS/WRITE HIT/WRITE MISS) accurate
- Hit rates improve with repeated accesses
- Total accesses count correctly
- Hit/miss counts accurate
- Hit rate percentages correct
- Read/write breakdowns separate
- Statistics reset properly
- Valid bits (V:0/1) shown correctly
- Dirty bits (D:0/1) for write-back policy
- Tags displayed in hex format
- Invalid blocks marked clearly
- Set organization visible
# Test invalid cache size
./build/cache_simulator -s 0
# Should show: "Error: Cache size and block size must be greater than 0"
# Test mismatched sizes
./build/cache_simulator -s 100 -b 32
# Should show: "Error: Cache size must be a multiple of block size"# Test unknown option
./build/cache_simulator --invalid-option
# Should show: "Unknown option. Use --help for usage information."# Test with large cache (64KB, 16-way)
./build/cache_simulator -s 65536 -b 64 -a 16 -v
# Verify:
# - Configuration calculates correctly
# - Performance remains responsive
# - Memory access patterns work
# - Statistics accurate for large numbers# Test with many addresses
./build/cache_simulator -A 0x0,0x1000,0x2000,0x3000,0x4000,0x5000,0x6000,0x7000 -O READ,READ,READ,READ,READ,READ,READ,READ -v| Command | Functionality | Verification |
|---|---|---|
access <addr> <op> |
Single memory access | Shows correct HIT/MISS |
batch <addrs> <ops> |
Multiple accesses | Processes all correctly |
stats |
Show statistics | Displays current stats |
reset |
Clear cache | Zeros all statistics |
config |
Show configuration | Displays current config |
contents |
Show cache state | Shows all cache blocks |
help |
Show commands | Lists all commands |
quit |
Exit mode | Cleanly exits |
Your cache simulator is working perfectly if:
- All 12 test categories pass in the comprehensive test
- Cache types behave differently with same input patterns
- Replacement policies show expected victim selection
- Write policies correctly manage dirty bits
- Statistics accurately reflect cache behavior
- Interactive mode responds to all commands
- Error handling catches invalid inputs
- Performance scales with larger configurations
- Help system provides comprehensive information
- Verbose output shows detailed operation traces
✅ Test suite shows all green checkmarks
✅ Hit rates improve with locality of reference
✅ Different cache configurations produce different results
✅ Dirty bits appear only with write-back policy
✅ Interactive mode responds correctly to all commands
✅ Error messages appear for invalid inputs
✅ Cache contents display shows valid cache organization
✅ Statistics reset and accumulate correctly
✅ Help system provides complete usage information
✅ Large configurations work without issues
If all these indicators are met, your cache simulator is functioning perfectly with all features working as designed!
If any test fails:
- Check build environment:
make clean && make - Verify file permissions:
chmod +x test_comprehensive.sh - Check dependencies: Ensure C++17 compiler and CMake 3.14+
- Review error messages for specific issues
- Test individual components before running full suite