mirror of
https://github.com/azaion/gps-denied-onboard.git
synced 2026-06-21 19:51:12 +00:00
2ba44a33c5
Co-authored-by: Cursor <cursoragent@cursor.com>
87 lines
2.9 KiB
Python
87 lines
2.9 KiB
Python
from pathlib import Path
|
|
|
|
from e2e.replay.harness import BlackboxReplayRunner, ResourceSample, summarize_resource_samples
|
|
from fdr_observability import FdrExportRequest, FdrPayload, InMemoryFlightRecorder
|
|
from shared.contracts import FdrEvent
|
|
|
|
|
|
def test_jetson_resource_metric_summary_captures_memory_and_throttle_fields() -> None:
|
|
# Arrange
|
|
samples = (
|
|
ResourceSample(
|
|
timestamp_s=0.0,
|
|
process_rss_bytes=1_000_000_000,
|
|
shared_memory_used_bytes=2_000_000_000,
|
|
cuda_allocated_bytes=500_000_000,
|
|
throttle_active=False,
|
|
temperature_c=55.0,
|
|
),
|
|
ResourceSample(
|
|
timestamp_s=60.0,
|
|
process_rss_bytes=1_200_000_000,
|
|
shared_memory_used_bytes=2_300_000_000,
|
|
cuda_allocated_bytes=650_000_000,
|
|
throttle_active=False,
|
|
temperature_c=62.0,
|
|
),
|
|
)
|
|
|
|
# Act
|
|
summary = summarize_resource_samples(samples)
|
|
|
|
# Assert
|
|
assert summary["duration_s"] == 60.0
|
|
assert summary["peak_shared_memory_used_bytes"] == 2_300_000_000.0
|
|
assert summary["peak_cuda_allocated_bytes"] == 650_000_000.0
|
|
assert summary["throttle_observed"] is False
|
|
assert summary["max_temperature_c"] == 62.0
|
|
|
|
|
|
def test_missing_thermal_hardware_reports_blocked_prerequisite(tmp_path: Path) -> None:
|
|
# Act
|
|
result = BlackboxReplayRunner(output_root=tmp_path).run()
|
|
|
|
# Assert
|
|
resource_report = next(report for report in result.reports if report.group.value == "resource-limit")
|
|
assert resource_report.result.value == "blocked"
|
|
assert "Jetson prerequisite blocked" in resource_report.error_message
|
|
|
|
|
|
def test_fdr_rollover_logs_segments_without_raw_frame_retention() -> None:
|
|
# Arrange
|
|
recorder = InMemoryFlightRecorder(segment_limit_bytes=100, storage_limit_bytes=500)
|
|
|
|
# Act
|
|
first = recorder.append_event(
|
|
_event("estimate", 1, "fdr://payload/gps-input-1"),
|
|
FdrPayload(ref="fdr://payload/gps-input-1", size_bytes=60, redacted=True),
|
|
)
|
|
second = recorder.append_event(
|
|
_event("health", 2, "fdr://payload/health-1"),
|
|
FdrPayload(ref="fdr://payload/health-1", size_bytes=60, redacted=True),
|
|
)
|
|
export = recorder.export(
|
|
FdrExportRequest(mission_id="mission-001", run_id="run-001", include_analytics=True)
|
|
)
|
|
|
|
# Assert
|
|
assert first.appended is True
|
|
assert second.rollover is True
|
|
assert recorder.health.status == "ready"
|
|
assert export.produced is True
|
|
assert len(export.segments) == 2
|
|
assert all("raw-frame" not in segment.segment_id for segment in export.segments)
|
|
assert export.analytics_ref is not None
|
|
|
|
|
|
def _event(event_type: str, timestamp_ns: int, payload_ref: str) -> FdrEvent:
|
|
return FdrEvent(
|
|
event_type=event_type,
|
|
timestamp_ns=timestamp_ns,
|
|
component="blackbox_resource_test",
|
|
severity="info",
|
|
payload_ref=payload_ref,
|
|
mission_id="mission-001",
|
|
run_id="run-001",
|
|
)
|