Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions tools/verify_diagnostics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import argparse
import json
import subprocess
import sys
from pathlib import Path
from typing import Optional, Tuple

ROOT = Path(__file__).resolve().parent
DIAGNOSTIC_DIR = ROOT / "diagnostic"
DIAGNOSTIC_CHUNK_SIZE = 40 * 1024 * 1024

def current_commit_id() -> str:
try:
result = subprocess.run(
["git", "rev-parse", "--verify", "HEAD"],
cwd=str(ROOT),
capture_output=True,
text=True,
timeout=5,
)
commit = result.stdout.strip()
if result.returncode == 0 and len(commit) >= 8:
return commit[:8]
except subprocess.CalledProcessError as e:
print(f"Error retrieving commit ID: {e}", file=sys.stderr)
except Exception as e:
print(f"Unexpected error: {e}", file=sys.stderr)
return "00000000"


def diagnostic_paths_for_commit() -> Tuple[Path, Path, str]:
DIAGNOSTIC_DIR.mkdir(parents=True, exist_ok=True)
commit_id = current_commit_id()
logd_path = DIAGNOSTIC_DIR / f"build-{commit_id}.logd"
metadata_path = DIAGNOSTIC_DIR / f"build-{commit_id}.json"
return logd_path, metadata_path, commit_id


def split_diagnostic_logd(logd_path: Path, chunk_size: int = DIAGNOSTIC_CHUNK_SIZE) -> list[Path]:
if logd_path.stat().st_size <= chunk_size:
return [logd_path]
# Logic to split logd file goes here


def validate_json_schema(json_data: dict) -> bool:
# Placeholder for JSON schema validation logic
return True


def main():
parser = argparse.ArgumentParser(description="Verify diagnostics.")
parser.add_argument('--verbose', action='store_true', help='Enable verbose output')
parser.add_argument('--json', action='store_true', help='Output in JSON format')
parser.add_argument('--threshold', type=int, default=0, help='Minimum passing modules')
args = parser.parse_args()

logd_path, metadata_path, commit_id = diagnostic_paths_for_commit()

try:
# Example subprocess call
result = subprocess.run(["some_command"], check=True)
except subprocess.CalledProcessError as e:
print(f"Subprocess failed: {e}", file=sys.stderr)
sys.exit(1)

# Load and validate JSON
try:
with open(metadata_path) as f:
json_data = json.load(f)
if not validate_json_schema(json_data):
print("Invalid JSON schema.", file=sys.stderr)
sys.exit(1)
except FileNotFoundError:
print(f"Metadata file not found: {metadata_path}", file=sys.stderr)
sys.exit(1)
except json.JSONDecodeError as e:
print(f"Error decoding JSON: {e}", file=sys.stderr)
sys.exit(1)

# Further processing based on args

if __name__ == '__main__':
main()