Skip to content

Latest commit

 

History

History
251 lines (200 loc) · 7.26 KB

File metadata and controls

251 lines (200 loc) · 7.26 KB

Cache Simulator - Functionality Verification Guide

This guide demonstrates how to verify that your cache simulator is running perfectly and showcases all available functionalities.

🚀 Quick Verification

1. Run Automated Test Suite

# Run the comprehensive test script
./test_comprehensive.sh

This script tests all 12 major functionality areas and provides colored output showing success/failure.

2. Basic Functionality Check

# Run built-in test suite
make test

# Run with default configuration
make run

🔍 Manual Feature Verification

Cache Types

Direct-Mapped Cache (Associativity = 1)

./build/cache_simulator -s 512 -b 32 -a 1 -v
# Verify: Output shows "Direct Mapped" and single block per set

Set-Associative Cache (Associativity = N)

./build/cache_simulator -s 1024 -b 32 -a 4 -v
# Verify: Output shows "4-way" and 4 blocks per set

Fully Associative Cache (Associativity = 0)

./build/cache_simulator -s 512 -b 32 -a 0 -v
# Verify: Output shows "Fully Associative" and 1 set with all blocks

Replacement Policies

LRU (Least Recently Used)

./build/cache_simulator -r LRU -v
# Verify: Output shows "LRU" policy in configuration

FIFO (First In First Out)

./build/cache_simulator -r FIFO -v
# Verify: Output shows "FIFO" policy in configuration

Random Replacement

./build/cache_simulator -r RANDOM -v
# Verify: Output shows "Random" policy in configuration

Write Policies

Write-Through Policy

./build/cache_simulator -w WRITE_THROUGH -v
# Verify: Output shows "Write-Through" and dirty bits remain 0 (D:0)

Write-Back Policy

./build/cache_simulator -w WRITE_BACK -v
# Verify: Output shows "Write-Back" and dirty bits set on writes (D:1)

Write Miss Policies

Write-Allocate

./build/cache_simulator -m WRITE_ALLOCATE -v
# Verify: Write misses allocate cache blocks

No-Write-Allocate

./build/cache_simulator -m NO_WRITE_ALLOCATE -v
# Verify: Write misses go directly to memory without allocation

🎯 Advanced Feature Testing

Custom Memory Access Patterns

# 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

Verbose Output Verification

./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

Interactive Mode Testing

./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

📊 Output Verification Checklist

✅ Configuration Display

  • Cache size, block size, associativity correctly shown
  • Number of sets and blocks calculated correctly
  • Bit breakdowns (offset, index, tag) accurate
  • Policies displayed correctly

✅ Memory Access Simulation

  • Addresses displayed in hex format
  • Operations (READ/WRITE) shown correctly
  • Results (HIT/MISS/WRITE HIT/WRITE MISS) accurate
  • Hit rates improve with repeated accesses

✅ Statistics Accuracy

  • Total accesses count correctly
  • Hit/miss counts accurate
  • Hit rate percentages correct
  • Read/write breakdowns separate
  • Statistics reset properly

✅ Cache Contents Display

  • 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

🧪 Error Handling Verification

Invalid Configurations

# 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"

Invalid Arguments

# Test unknown option
./build/cache_simulator --invalid-option
# Should show: "Unknown option. Use --help for usage information."

🎪 Performance Testing

Large Configuration Test

# 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

Stress Testing

# 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

🎭 Interactive Mode Feature Matrix

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

📈 Expected Results Summary

Your cache simulator is working perfectly if:

  1. All 12 test categories pass in the comprehensive test
  2. Cache types behave differently with same input patterns
  3. Replacement policies show expected victim selection
  4. Write policies correctly manage dirty bits
  5. Statistics accurately reflect cache behavior
  6. Interactive mode responds to all commands
  7. Error handling catches invalid inputs
  8. Performance scales with larger configurations
  9. Help system provides comprehensive information
  10. Verbose output shows detailed operation traces

🎉 Success Indicators

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!

🔧 Troubleshooting

If any test fails:

  1. Check build environment: make clean && make
  2. Verify file permissions: chmod +x test_comprehensive.sh
  3. Check dependencies: Ensure C++17 compiler and CMake 3.14+
  4. Review error messages for specific issues
  5. Test individual components before running full suite