Back to Repositories

Testing LogReader Corrupt Data Handling in openpilot

This test suite validates the LogReader functionality in openpilot’s replay tools, focusing on handling corrupt log files and data integrity. It ensures the system can properly process and validate log data even under compromised conditions.

Test Coverage Overview

The test suite specifically covers the LogReader component’s ability to handle corrupt log data scenarios.

  • Tests corrupt log file handling and processing
  • Validates successful loading of partial log content
  • Verifies event extraction from compromised data
  • Ensures system resilience with incomplete logs

Implementation Analysis

The implementation uses Catch2 testing framework to validate LogReader functionality. The approach involves deliberately corrupting log data by truncating content and testing the system’s ability to process it.

Key patterns include:
  • BZ2 decompression handling
  • File content manipulation
  • Event extraction validation
  • Remote file access testing

Technical Details

Testing infrastructure includes:

  • Catch2 testing framework
  • FileReader utility for remote file access
  • BZ2 compression/decompression tools
  • Azure blob storage for test data
  • Custom LogReader implementation

Best Practices Demonstrated

The test demonstrates robust error handling and data validation practices.

  • Explicit test case organization
  • Real-world data usage
  • Edge case handling
  • Clear section separation
  • Systematic corruption testing

commaai/openpilot

tools/replay/tests/test_replay.cc

            
#define CATCH_CONFIG_MAIN
#include "catch2/catch.hpp"
#include "tools/replay/replay.h"

const std::string TEST_RLOG_URL = "https://commadataci.blob.core.windows.net/openpilotci/0c94aa1e1296d7c6/2021-05-05--19-48-37/0/rlog.bz2";

TEST_CASE("LogReader") {
  SECTION("corrupt log") {
    FileReader reader(true);
    std::string corrupt_content = reader.read(TEST_RLOG_URL);
    corrupt_content.resize(corrupt_content.length() / 2);
    corrupt_content = decompressBZ2(corrupt_content);
    LogReader log;
    REQUIRE(log.load(corrupt_content.data(), corrupt_content.size()));
    REQUIRE(log.events.size() > 0);
  }
}