|
| 1 | +# InfiniCore Memory Management Test Suite |
| 2 | + |
| 3 | +This test suite provides comprehensive testing for the InfiniCore memory management system, focusing on the critical issues identified in the memory management architecture analysis. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The test suite includes six main test categories: |
| 8 | + |
| 9 | +1. **Basic Memory Tests** - Basic allocation, deallocation, and memory operations |
| 10 | +2. **Concurrency Tests** - Thread safety and concurrent access testing |
| 11 | +3. **Exception Safety Tests** - Exception handling and safety testing |
| 12 | +4. **Memory Leak Tests** - Memory leak detection and prevention |
| 13 | +5. **Performance Tests** - Performance benchmarks and optimization validation |
| 14 | +6. **Stress Tests** - High-load stress testing and edge cases |
| 15 | + |
| 16 | +## Building |
| 17 | + |
| 18 | +### Using XMake (if integrated with main build) |
| 19 | +```bash |
| 20 | +# From InfiniCore root directory |
| 21 | +xmake build infinicore-test |
| 22 | +``` |
| 23 | + |
| 24 | +## Running Tests |
| 25 | + |
| 26 | +### Run All Tests |
| 27 | +```bash |
| 28 | +./infinicore-test |
| 29 | +``` |
| 30 | + |
| 31 | +### Run Specific Test Categories |
| 32 | +```bash |
| 33 | +# Basic memory tests |
| 34 | +./infinicore-test --test basic |
| 35 | + |
| 36 | +# Concurrency tests |
| 37 | +./infinicore-test --test concurrency |
| 38 | + |
| 39 | +# Exception safety tests |
| 40 | +./infinicore-test --test exception |
| 41 | + |
| 42 | +# Memory leak tests |
| 43 | +./infinicore-test --test leak |
| 44 | + |
| 45 | +# Performance tests |
| 46 | +./infinicore-test --test performance |
| 47 | + |
| 48 | +# Stress tests |
| 49 | +./infinicore-test --test stress |
| 50 | +``` |
| 51 | + |
| 52 | +### Run with Specific Device |
| 53 | +```bash |
| 54 | +# Run on CPU |
| 55 | +./infinicore-test --cpu |
| 56 | + |
| 57 | +# Run on NVIDIA GPU |
| 58 | +./infinicore-test --nvidia |
| 59 | + |
| 60 | +# Run on other devices |
| 61 | +./infinicore-test --cambricon |
| 62 | +./infinicore-test --ascend |
| 63 | +./infinicore-test --metax |
| 64 | +./infinicore-test --moore |
| 65 | +./infinicore-test --iluvatar |
| 66 | +./infinicore-test --kunlun |
| 67 | +./infinicore-test --hygon |
| 68 | +``` |
| 69 | + |
| 70 | +### Customize Test Parameters |
| 71 | +```bash |
| 72 | +# Run with custom thread count |
| 73 | +./infinicore-test --threads 8 |
| 74 | + |
| 75 | +# Run with custom iteration count |
| 76 | +./infinicore-test --iterations 5000 |
| 77 | + |
| 78 | +# Combine options |
| 79 | +./infinicore-test --nvidia --test concurrency --threads 16 --iterations 2000 |
| 80 | +``` |
| 81 | + |
| 82 | +## Test Categories |
| 83 | + |
| 84 | +### 1. Basic Memory Tests |
| 85 | +Tests fundamental memory operations: |
| 86 | +- Memory allocation and deallocation |
| 87 | +- Memory size and device properties |
| 88 | +- Memory read/write operations |
| 89 | +- Pinned memory allocation |
| 90 | +- Memory data integrity |
| 91 | + |
| 92 | +### 2. Concurrency Tests |
| 93 | +Tests thread safety and concurrent access: |
| 94 | +- **Concurrent Allocations**: Multiple threads allocating memory simultaneously |
| 95 | +- **Concurrent Device Switching**: Multiple threads switching device contexts |
| 96 | +- **Memory Allocation Race**: Race condition testing for memory operations |
| 97 | + |
| 98 | +### 3. Exception Safety Tests |
| 99 | +Tests exception handling and safety: |
| 100 | +- **Allocation Failure**: Tests behavior when allocation fails |
| 101 | +- **Deallocation Exception**: Tests exception safety during deallocation |
| 102 | +- **Context Switch Exception**: Tests exception handling during device switching |
| 103 | + |
| 104 | +### 4. Memory Leak Tests |
| 105 | +Tests memory leak detection and prevention: |
| 106 | +- **Basic Leak Detection**: Basic memory leak detection |
| 107 | +- **Cross-Device Leak Detection**: Memory leaks in cross-device scenarios |
| 108 | +- **Exception Leak Detection**: Memory leaks during exception handling |
| 109 | + |
| 110 | +### 5. Performance Tests |
| 111 | +Tests performance and benchmarks: |
| 112 | +- **Allocation Performance**: Memory allocation speed benchmarks |
| 113 | +- **Concurrent Performance**: Performance under concurrent load |
| 114 | +- **Memory Copy Performance**: Memory copy bandwidth tests |
| 115 | + |
| 116 | +### 6. Stress Tests |
| 117 | +Tests high-load scenarios and edge cases: |
| 118 | +- **High Frequency Allocations**: Rapid allocation/deallocation cycles |
| 119 | +- **Large Memory Allocations**: Large memory block allocation |
| 120 | +- **Cross-Device Stress**: Stress testing across multiple devices |
| 121 | + |
| 122 | +## Expected Results |
| 123 | + |
| 124 | +### Critical Issues to Watch For |
| 125 | + |
| 126 | +The tests are designed to detect the critical issues identified in the memory management analysis: |
| 127 | + |
| 128 | +1. **Thread Safety Violations** |
| 129 | + - Race conditions in concurrent allocations |
| 130 | + - Inconsistent device context switching |
| 131 | + - Global state corruption |
| 132 | + |
| 133 | +2. **Memory Leaks** |
| 134 | + - Unfreed memory after deallocation |
| 135 | + - Cross-device memory not properly cleaned up |
| 136 | + - Exception-related memory leaks |
| 137 | + |
| 138 | +3. **Exception Safety Issues** |
| 139 | + - Exceptions during allocation causing resource leaks |
| 140 | + - Exceptions in destructors causing `std::terminate` |
| 141 | + - Incomplete cleanup on exceptions |
| 142 | + |
| 143 | +4. **Performance Issues** |
| 144 | + - Slow allocation/deallocation performance |
| 145 | + - Poor concurrent performance |
| 146 | + - Inefficient memory copy operations |
| 147 | + |
| 148 | +### Performance Thresholds |
| 149 | + |
| 150 | +The tests include performance thresholds: |
| 151 | + |
| 152 | +- **Allocation Performance**: < 100μs per allocation |
| 153 | +- **Concurrent Performance**: < 200μs per allocation under load |
| 154 | +- **Memory Bandwidth**: > 100 MB/s for memory copies |
| 155 | + |
| 156 | +## Test Output |
| 157 | + |
| 158 | +### Successful Test Run |
| 159 | +``` |
| 160 | +============================================== |
| 161 | +InfiniCore Memory Management Test Suite |
| 162 | +============================================== |
| 163 | +Device: 0 |
| 164 | +Threads: 4 |
| 165 | +Iterations: 1000 |
| 166 | +============================================== |
| 167 | +
|
| 168 | +[SUITE] Running: BasicMemoryTest |
| 169 | +[TEST] Starting: BasicMemoryTest |
| 170 | +[TEST] PASSED: BasicMemoryTest (Duration: 1234μs) |
| 171 | +
|
| 172 | +[SUITE] Running: ConcurrencyTest |
| 173 | +[TEST] Starting: ConcurrencyTest |
| 174 | +[TEST] PASSED: ConcurrencyTest (Duration: 5678μs) |
| 175 | +
|
| 176 | +... |
| 177 | +
|
| 178 | +============================================== |
| 179 | +Test Summary |
| 180 | +============================================== |
| 181 | +Total Tests: 6 |
| 182 | +Passed: 6 |
| 183 | +Failed: 0 |
| 184 | +Total Time: 12345μs |
| 185 | +============================================== |
| 186 | +
|
| 187 | +✅ All tests passed! |
| 188 | +``` |
| 189 | + |
| 190 | +### Failed Test Run |
| 191 | +``` |
| 192 | +[TEST] FAILED: ConcurrencyTest - Concurrent allocation test failed: expected 8000 successes, got 7995 successes and 5 failures |
| 193 | +
|
| 194 | +============================================== |
| 195 | +Final Results |
| 196 | +============================================== |
| 197 | +Total Tests: 6 |
| 198 | +Passed: 5 |
| 199 | +Failed: 1 |
| 200 | +============================================== |
| 201 | +
|
| 202 | +❌ Some tests failed. Please review the output above. |
| 203 | +``` |
| 204 | + |
| 205 | +## Debugging Failed Tests |
| 206 | + |
| 207 | +### Common Issues and Solutions |
| 208 | + |
| 209 | +1. **Thread Safety Failures** |
| 210 | + - Check for race conditions in global state access |
| 211 | + - Verify proper synchronization in allocators |
| 212 | + - Review device context switching logic |
| 213 | + |
| 214 | +2. **Memory Leak Failures** |
| 215 | + - Check deallocation logic in allocators |
| 216 | + - Verify cross-device cleanup mechanisms |
| 217 | + - Review exception safety in destructors |
| 218 | + |
| 219 | +3. **Performance Failures** |
| 220 | + - Profile allocation/deallocation paths |
| 221 | + - Check for unnecessary context switching |
| 222 | + - Review memory copy implementations |
| 223 | + |
| 224 | +4. **Exception Safety Failures** |
| 225 | + - Verify no-throw guarantees in destructors |
| 226 | + - Check exception handling in allocation paths |
| 227 | + - Review resource cleanup on exceptions |
| 228 | + |
| 229 | +## Integration with CI/CD |
| 230 | + |
| 231 | +### GitHub Actions Example |
| 232 | +```yaml |
| 233 | +- name: Run Memory Tests |
| 234 | + run: | |
| 235 | + cd src/infinicore-test |
| 236 | + mkdir build && cd build |
| 237 | + cmake .. |
| 238 | + make |
| 239 | + ./infinicore-test --test all |
| 240 | +``` |
| 241 | +
|
| 242 | +### Custom Test Targets |
| 243 | +```bash |
| 244 | +# Run specific test categories |
| 245 | +make test-memory-basic |
| 246 | +make test-memory-concurrency |
| 247 | +make test-memory-exception |
| 248 | +make test-memory-leak |
| 249 | +make test-memory-performance |
| 250 | +make test-memory-stress |
| 251 | +make test-memory-all |
| 252 | +``` |
| 253 | + |
| 254 | +## Contributing |
| 255 | + |
| 256 | +When adding new tests: |
| 257 | + |
| 258 | +1. Follow the existing test framework pattern |
| 259 | +2. Add appropriate error messages and logging |
| 260 | +3. Include performance thresholds where applicable |
| 261 | +4. Test both success and failure scenarios |
| 262 | +5. Update this README with new test descriptions |
| 263 | + |
| 264 | +## Dependencies |
| 265 | + |
| 266 | +- InfiniCore library (infinicore, infiniop, infinirt, infiniccl) |
| 267 | +- C++17 compatible compiler |
| 268 | +- Threading library (pthread on Linux) |
| 269 | +- CMake 3.16+ (for CMake build) |
| 270 | + |
| 271 | +## Notes |
| 272 | + |
| 273 | +- Tests are designed to be deterministic where possible |
| 274 | +- Some tests may have timing dependencies |
| 275 | +- Performance tests may vary based on system load |
| 276 | +- Memory leak detection is basic and may not catch all leaks |
| 277 | +- Tests assume proper InfiniCore initialization |
0 commit comments