Test Suite Overview
ML Defender employs a multi-layered testing strategy validated with real-world datasets and stress testing.Unit Tests
25+ tests covering core algorithms
Integration Tests
End-to-end pipeline validation
Stress Tests
36K+ events, 17-hour stability
Test Structure
Unit Tests
Located in*/tests/ directories:
Integration Tests
Running Tests
Quick Unit Tests
All Components
With Valgrind (Leak Detection)
Stress Testing
8-Hour Stability Test
Validated with 36,000 events across 4 progressive tests (source/stress_test_8h.sh).- Warm-up (30 min): Low load, gradual increase
- Normal Load (2 hours): Mixed protocols (HTTP/HTTPS/DNS)
- Stress Testing (1.5 hours): High bursts (50/s)
- Ransomware Simulation (1 hour): Suspicious patterns
- Sustained Load (3 hours): Continuous moderate traffic
- Cool Down (30 min): Gradual reduction
Stress Test Results (Day 52)
From source/README.md:179-203:| Test | Events | Rate | CPU | Result |
|---|---|---|---|---|
| 1 | 1,000 | 42.6/sec | N/A | ✅ PASS |
| 2 | 5,000 | 94.9/sec | N/A | ✅ PASS |
| 3 | 10,000 | 176.1/sec | 41-45% | ✅ PASS |
| 4 | 20,000 | 364.9/sec | 49-54% | ✅ PASS |
Synthetic Traffic Generation
Tools Available
From source/tools/:Traffic Profiles
Hospital Benchmark (source/scripts/day11_hospital_benchmark/):Validation Scripts
Crypto Pipeline Validation
- ✅ ChaCha20-Poly1305 encryption/decryption
- ✅ LZ4 compression/decompression
- ✅ Protobuf serialization
- ✅ Zero errors at 36K events
Firewall Integration
- ✅ IPSet creation and rules
- ✅ Event reception from ml-detector
- ✅ Decryption and decompression
- ✅ IP blocking via iptables
Full Ecosystem
- Start etcd-server
- Start sniffer (eBPF capture)
- Start ml-detector (inference)
- Start firewall-acl-agent (blocking)
- Generate synthetic traffic
- Verify all components healthy
Test Datasets
CTU-13 Neris Botnet
Used for ransomware detection validation (source/README.md:289-292).- 492K events processed
- 97.6% ransomware detection accuracy
- 0 crashes, 0 memory leaks
Dataset Structure
Performance Benchmarks
17-Hour Stability Test Results
From source/TESTING.md:164-182:Component Latency
From source/TESTING.md:282-296:| Component | Latency | Notes |
|---|---|---|
| eBPF capture | <1 μs | Kernel space |
| Ring buffer | <1 μs | Zero-copy |
| PayloadAnalyzer (fast) | 1.01 μs | Normal traffic |
| PayloadAnalyzer (slow) | 149.3 μs | Suspicious (entropy ≥ 7.0) |
| FastDetector | <1 μs | O(1) heuristics |
| RansomwareProcessor | Async | Every 30s batch |
| Protobuf serialize | ~10 μs | Per event |
| ZMQ PUSH | ~50 μs | Network I/O |
- Normal path: ~64 μs
- Suspicious path: ~212 μs
Coverage and CI/CD
Test Coverage Goals
- Unit tests: >80% code coverage
- Integration tests: All critical paths
- Stress tests: 24h+ continuous operation
Current Coverage
From source/TESTING.md:353-361:| Test Suite | Tests | Status | Coverage |
|---|---|---|---|
| PayloadAnalyzer | 8 | ✅ All pass | Entropy, PE, patterns |
| FastDetector | 5 | ✅ All pass | Heuristics, windows |
| RansomwareProcessor | 7 | ✅ All pass | Features, aggregation |
| Integration | 5 | ✅ All pass | End-to-end flow |
| Total | 25 | ✅ 100% | Comprehensive |
CI/CD Pipeline (Planned)
.github/workflows/test.yml
Test-Driven Development
Writing New Tests
Example: Adding a new feature to PayloadAnalyzersniffer/tests/test_payload_analyzer.cpp
Test Naming Convention
Debugging Failed Tests
Common Issues
Test fails intermittently:Next Steps
Build System
Understand CMake and Makefile configuration
Stress Testing
Deep dive into stress test methodology
eBPF/XDP
Learn eBPF packet capture internals
Performance
Optimize and benchmark components