This page describes the testing methodology for validating the multi-detector memory growth monitoring system. The test suite includes synthetic leak generators, false positive tests, and validation procedures.
Test Environment Setup
Prerequisites
# Verify kernel support
uname -r # Need 5.8+
ls /sys/kernel/btf/vmlinux # BTF support# Check tracepoint
sudo ls /sys/kernel/debug/tracing/events/kmem/rss_stat/
# Install tools
sudo apt-get install linux-tools-generic bpftool
Building Test Suite
cd test/memory-leak-simulators
# Build all test programs
make build-tests
# Verify builds
ls -la bin/
Test Simulators
Detector-Specific Tests
Simulator
Target
Detection Method
Expected Result
linear_growth.c
Linear Regression
Steady 1MB/s leak
R² > 0.90, 30-60s detection
anon_ratio.c
RSS Ratio
90%+ heap allocations
Anon > 85%, <30s detection
vsz_divergence.c
Threshold
mmap without touch
VSZ/RSS > 2.5, <60s detection
monotonic_growth.c
Threshold
No decreases for 5+ min
Monotonic flag, 5-6 min detection
Combined Tests
Simulator
Purpose
Expected Result
combined_leak.c
Trigger all detectors
Confidence > 95
accelerating_leak.c
Exponential growth
Fast detection, high confidence
oscillating_leak.c
Sawtooth pattern
Low confidence (correct)
False Positive Tests
Simulator
Pattern
Expected Result
cache_growth.c
File cache expansion
No detection ✅
startup_spike.c
Initial burst then stable
No detection ✅
gc_pattern.c
Garbage collection sawtooth
No detection ✅
mmap_database.c
Memory-mapped file growth
Low confidence ✅
Running Tests
Individual Test Execution
# Run a specific test
./bin/vsz_divergence
# With parameters
./bin/monotonic_growth --leak-rate=1MB --duration=600
# Monitor in background
./bin/combined_leak &
PID=$!
Monitoring eBPF Output
# Terminal 1: Run test
./bin/linear_growth
# Terminal 2: Monitor trace pipe
sudo cat /sys/kernel/debug/tracing/trace_pipe | grep memgrowth
# Terminal 3: Check BPF maps
watch -n 1 'sudo bpftool map dump name process_states | head -20'
Automated Test Suite
# Run all tests with validation
./run-tests.sh
# Quick smoke tests
./run-quick-tests.sh
# Output format:# [PASS] linear_growth: Detected in 45s, confidence 82# [PASS] cache_growth: No false positive# [FAIL] vsz_divergence: Not detected (expected detection)
Validation Criteria
Detection Accuracy
Metric
Target
Acceptable Range
True Positive Rate
>95%
90-100%
False Positive Rate
<5%
0-10%
Detection Latency
<60s for fast leaks
30-120s
Confidence Accuracy
±10 points
50-100
Per-Detector Validation
Linear Regression
R² value matches expected range
Slope calculation within 10% of actual
History buffer doesn't overflow
Coalescing works correctly
RSS Ratio
Anonymous ratio calculated correctly
Growth rates track accurately
Swap detection functions
Component separation works
Threshold
VSZ/RSS ratio accurate
Monotonic timer resets properly
Weights sum correctly
All thresholds trigger independently
Performance Testing
CPU Overhead
# Baseline CPU usage
top -p $(pgrep test_program) -b -n 1
# With monitoring enabled
sudo ./load_ebpf_programs.sh
top -p $(pgrep test_program) -b -n 1
# Calculate overhead# Should be <0.1% difference