|
|
@@ -0,0 +1,161 @@
|
|
|
+#!/usr/bin/env python3
|
|
|
+"""Validation and replay verification for 6400 V2.0 DEFLATE 9 packages."""
|
|
|
+
|
|
|
+from __future__ import annotations
|
|
|
+
|
|
|
+import hashlib
|
|
|
+import json
|
|
|
+import subprocess
|
|
|
+import sys
|
|
|
+import tempfile
|
|
|
+import zipfile
|
|
|
+from pathlib import Path
|
|
|
+
|
|
|
+ROOT = Path(__file__).resolve().parents[2]
|
|
|
+
|
|
|
+
|
|
|
+def sha256_file(path: Path) -> str:
|
|
|
+ digest = hashlib.sha256()
|
|
|
+ with path.open("rb") as stream:
|
|
|
+ for chunk in iter(lambda: stream.read(1024 * 1024), b""):
|
|
|
+ digest.update(chunk)
|
|
|
+ return digest.hexdigest()
|
|
|
+
|
|
|
+
|
|
|
+def test_firmware_package_deflate9_and_contents() -> None:
|
|
|
+ firmware_zips = sorted(ROOT.glob("dist/prod2u-6400-v2-firmware-*.zip"))
|
|
|
+ assert firmware_zips, "No 6400-v2 firmware package found in dist/"
|
|
|
+ fw_zip = firmware_zips[-1]
|
|
|
+
|
|
|
+ with zipfile.ZipFile(fw_zip, "r") as zf:
|
|
|
+ infolist = zf.infolist()
|
|
|
+ assert len(infolist) > 0
|
|
|
+ for info in infolist:
|
|
|
+ if info.file_size > 0:
|
|
|
+ assert info.compress_type == zipfile.ZIP_DEFLATED, f"{info.filename} not ZIP_DEFLATED"
|
|
|
+
|
|
|
+ names = set(zf.namelist())
|
|
|
+ assert "manifest.json" in names
|
|
|
+ assert "SHA256SUMS" in names
|
|
|
+ assert "prod2u_6400_v2.bit" in names
|
|
|
+ assert "TD-BUILD-RECEIPT.json" in names
|
|
|
+ assert "FLASH-INSTRUCTIONS.zh-CN.txt" in names
|
|
|
+
|
|
|
+ manifest = json.loads(zf.read("manifest.json").decode("utf-8"))
|
|
|
+ receipt = json.loads(zf.read("TD-BUILD-RECEIPT.json").decode("utf-8"))
|
|
|
+
|
|
|
+ assert manifest["profile"] == "6400-v2"
|
|
|
+ assert manifest["deployment_status"] == "TD_QUALIFIED_HARDWARE_NOT_RUN"
|
|
|
+ assert manifest["hardware_validation"] == "NOT RUN"
|
|
|
+ assert manifest["bitstream_sha256"] == receipt["bitstream_sha256"]
|
|
|
+
|
|
|
+ # Check checksums in SHA256SUMS
|
|
|
+ sums_text = zf.read("SHA256SUMS").decode("utf-8")
|
|
|
+ for line in sums_text.splitlines():
|
|
|
+ if not line.strip():
|
|
|
+ continue
|
|
|
+ expected_hash, fname = line.split(" ", 1)
|
|
|
+ actual_hash = hashlib.sha256(zf.read(fname)).hexdigest()
|
|
|
+ assert actual_hash == expected_hash, f"Hash mismatch for {fname} in {fw_zip.name}"
|
|
|
+
|
|
|
+
|
|
|
+def test_source_and_review_packages_deflate9() -> None:
|
|
|
+ for kind in ("source", "review"):
|
|
|
+ zips = sorted(ROOT.glob(f"dist/prod2u-6400-v2-{kind}-*.zip"))
|
|
|
+ assert zips, f"No 6400-v2 {kind} package found in dist/"
|
|
|
+ pkg = zips[-1]
|
|
|
+
|
|
|
+ with zipfile.ZipFile(pkg, "r") as zf:
|
|
|
+ infolist = zf.infolist()
|
|
|
+ assert len(infolist) > 0
|
|
|
+ for info in infolist:
|
|
|
+ if info.file_size > 0:
|
|
|
+ assert info.compress_type == zipfile.ZIP_DEFLATED, f"{info.filename} not ZIP_DEFLATED"
|
|
|
+
|
|
|
+ manifest = json.loads(zf.read("manifest.json").decode("utf-8"))
|
|
|
+ assert manifest["profile"] == "6400-v2"
|
|
|
+ assert manifest["kind"] == kind
|
|
|
+
|
|
|
+ sums_text = zf.read("SHA256SUMS").decode("utf-8")
|
|
|
+ for line in sums_text.splitlines():
|
|
|
+ if not line.strip():
|
|
|
+ continue
|
|
|
+ expected_hash, fname = line.split(" ", 1)
|
|
|
+ actual_hash = hashlib.sha256(zf.read(fname)).hexdigest()
|
|
|
+ assert actual_hash == expected_hash, f"Hash mismatch for {fname} in {pkg.name}"
|
|
|
+
|
|
|
+
|
|
|
+def test_delivery_package_deflate9_and_self_check() -> None:
|
|
|
+ head_commit = subprocess.check_output(["git", "rev-parse", "--short=8", "HEAD"], cwd=ROOT, text=True).strip()
|
|
|
+ delivery_zip = ROOT / f"dist/Prod2U-6400-V2.0-Delivery-{head_commit}.zip"
|
|
|
+ assert delivery_zip.is_file(), f"Delivery package not found: {delivery_zip}"
|
|
|
+
|
|
|
+ with zipfile.ZipFile(delivery_zip, "r") as zf:
|
|
|
+ infolist = zf.infolist()
|
|
|
+ for info in infolist:
|
|
|
+ if info.file_size > 0:
|
|
|
+ assert info.compress_type == zipfile.ZIP_DEFLATED, f"{info.filename} not ZIP_DEFLATED"
|
|
|
+
|
|
|
+ manifest = json.loads(zf.read("PACKAGE-MANIFEST.json").decode("utf-8"))
|
|
|
+ assert manifest["product"] == "6400-v2"
|
|
|
+ assert manifest["hardware"] == "NOT_RUN"
|
|
|
+
|
|
|
+ identity = json.loads(zf.read("RELEASE-IDENTITY.json").decode("utf-8"))
|
|
|
+ assert identity["product"] == "6400-v2"
|
|
|
+ assert identity["board"] == "FCB V2.0"
|
|
|
+ assert identity["hardware"] == "NOT_RUN"
|
|
|
+
|
|
|
+ sums_text = zf.read("SHA256SUMS").decode("utf-8")
|
|
|
+ for line in sums_text.splitlines():
|
|
|
+ if not line.strip():
|
|
|
+ continue
|
|
|
+ expected_hash, fname = line.split(" ", 1)
|
|
|
+ actual_hash = hashlib.sha256(zf.read(fname)).hexdigest()
|
|
|
+ assert actual_hash == expected_hash, f"Hash mismatch for {fname} in {delivery_zip.name}"
|
|
|
+
|
|
|
+ res = subprocess.run(
|
|
|
+ [sys.executable, str(ROOT / "tools/package_prod2u.py"), "verify", str(delivery_zip)],
|
|
|
+ capture_output=True,
|
|
|
+ text=True,
|
|
|
+ )
|
|
|
+ assert res.returncode == 0, f"Delivery package verify failed: {res.stderr}\n{res.stdout}"
|
|
|
+
|
|
|
+
|
|
|
+def test_isolated_source_replay() -> None:
|
|
|
+ """Extract source package in clean temporary dir and verify RTL compile & simulation."""
|
|
|
+ head_commit = subprocess.check_output(["git", "rev-parse", "--short=12", "HEAD"], cwd=ROOT, text=True).strip()
|
|
|
+ source_zips = sorted(ROOT.glob(f"dist/prod2u-6400-v2-source-{head_commit}*.zip"))
|
|
|
+ assert source_zips, f"No source zip found for commit {head_commit}"
|
|
|
+ source_zip = source_zips[-1]
|
|
|
+
|
|
|
+ with tempfile.TemporaryDirectory() as tmpdir:
|
|
|
+ tmp = Path(tmpdir)
|
|
|
+ with zipfile.ZipFile(source_zip, "r") as zf:
|
|
|
+ zf.extractall(tmp)
|
|
|
+
|
|
|
+ # Check all 24 source closure files are present
|
|
|
+ closure = json.loads((tmp / "source-closure-expanded.json").read_text(encoding="utf-8"))
|
|
|
+ assert len(closure["sources"]) == 24
|
|
|
+ for src in closure["sources"]:
|
|
|
+ assert (tmp / src).is_file(), f"Missing source file in unpacked package: {src}"
|
|
|
+
|
|
|
+ assert (tmp / "project.json").is_file()
|
|
|
+ assert (tmp / "generated/6400/prod2u_6400_v1_params.vh").is_file()
|
|
|
+
|
|
|
+ # Copy testbench to temporary directory and run iverilog compilation
|
|
|
+ tb_src = ROOT / "tests/sim/prod2u_6400_v2_tb.v"
|
|
|
+ sh_out = tmp / "top_test.vvp"
|
|
|
+ src_files = [str(tmp / s) for s in closure["sources"]]
|
|
|
+
|
|
|
+ res = subprocess.run(
|
|
|
+ ["iverilog", "-g2012", f"-I{tmp / 'generated/6400'}", "-o", str(sh_out), str(tb_src), *src_files],
|
|
|
+ capture_output=True,
|
|
|
+ text=True,
|
|
|
+ )
|
|
|
+ assert res.returncode == 0, f"iverilog compilation failed in isolated replay:\n{res.stderr}"
|
|
|
+
|
|
|
+ # Execute simulation in the isolated environment
|
|
|
+ sim_res = subprocess.run(["vvp", str(sh_out)], capture_output=True, text=True)
|
|
|
+ assert sim_res.returncode == 0, f"vvp simulation failed:\n{sim_res.stderr}\n{sim_res.stdout}"
|
|
|
+ assert "prod2u_6400_v2_tb PASS" in sim_res.stdout
|
|
|
+
|