Add trace_analysis/tests/test_core.py
This commit is contained in:
parent
4c58dd1bbe
commit
22488407d2
1 changed files with 48 additions and 0 deletions
48
trace_analysis/tests/test_core.py
Normal file
48
trace_analysis/tests/test_core.py
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
import pytest
|
||||||
|
from trace_analysis import core
|
||||||
|
|
||||||
|
|
||||||
|
def test_analyze_trace_basic_case():
|
||||||
|
trace_data = {
|
||||||
|
"events": [
|
||||||
|
{"timestamp": 0.0, "cpu_path": "CPU0", "reorder_score": 0.1, "mixed_snapshot_signature_count": 2},
|
||||||
|
{"timestamp": 0.1, "cpu_path": "CPU1", "reorder_score": 0.3, "mixed_snapshot_signature_count": 1},
|
||||||
|
{"timestamp": 0.2, "cpu_path": "CPU1", "reorder_score": 0.4, "mixed_snapshot_signature_count": 0},
|
||||||
|
{"timestamp": 0.3, "cpu_path": "CPU0", "reorder_score": 0.2, "mixed_snapshot_signature_count": 3}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
result = core.analyze_trace(trace_data)
|
||||||
|
|
||||||
|
assert isinstance(result, dict)
|
||||||
|
assert "cpu_migrations" in result
|
||||||
|
assert result["cpu_migrations"] > 0
|
||||||
|
assert "avg_reorder_score" in result
|
||||||
|
assert result["avg_reorder_score"] == pytest.approx(0.25, 0.05)
|
||||||
|
assert "anomaly_count" in result
|
||||||
|
assert isinstance(result["anomaly_count"], int)
|
||||||
|
|
||||||
|
|
||||||
|
def test_analyze_trace_empty_data():
|
||||||
|
trace_data = {"events": []}
|
||||||
|
result = core.analyze_trace(trace_data)
|
||||||
|
|
||||||
|
assert result["cpu_migrations"] == 0
|
||||||
|
assert result["avg_reorder_score"] == 0.0
|
||||||
|
assert result["anomaly_count"] == 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_analyze_trace_detection_of_anomalies():
|
||||||
|
trace_data = {
|
||||||
|
"events": [
|
||||||
|
{"timestamp": 0.0, "cpu_path": "CPU0", "reorder_score": 0.9, "mixed_snapshot_signature_count": 6},
|
||||||
|
{"timestamp": 0.1, "cpu_path": "CPU1", "reorder_score": 0.8, "mixed_snapshot_signature_count": 7},
|
||||||
|
{"timestamp": 0.2, "cpu_path": "CPU2", "reorder_score": 0.2, "mixed_snapshot_signature_count": 8}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
result = core.analyze_trace(trace_data)
|
||||||
|
|
||||||
|
assert result["cpu_migrations"] >= 2
|
||||||
|
assert result["avg_reorder_score"] > 0.0
|
||||||
|
assert result["anomaly_count"] >= 1
|
||||||
Loading…
Reference in a new issue