feat: 发布固件底层开发 Skill 套件
This commit is contained in:
commit
c7ae3b4ce1
72 files changed
+10212
No files matched your search
+142
@@ -0,0 +1,142 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Behavioral tests for validate_bsp_handoff.py."""
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
import validate_bsp_handoff
|
||||
|
||||
|
||||
def main() -> int:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
imgs = root / "imgs" / "20260902_1"
|
||||
imgs.mkdir(parents=True)
|
||||
artifact = imgs / "boot.bin"
|
||||
artifact.write_bytes(b"boot")
|
||||
kernel = imgs / "kernel.bin"
|
||||
kernel.write_bytes(b"kernel")
|
||||
rootfs = imgs / "rootfs.bin"
|
||||
rootfs.write_bytes(b"rootfs")
|
||||
project = root / "CV1841CP-BOARD_dualos"
|
||||
partition = project / "configs" / "board" / "partition" / "partition_spinand.xml"
|
||||
partition.parent.mkdir(parents=True)
|
||||
partition.write_text(
|
||||
"""<physical_partition type="spinand">
|
||||
<partition label="BOOT" alias="kernel.A" size_in_kb="1024" file="kernel.bin"/>
|
||||
<partition label="ROOTFS" alias="rootfs.A" size_in_kb="1024" file="rootfs.bin"/>
|
||||
</physical_partition>
|
||||
""",
|
||||
encoding="utf-8",
|
||||
)
|
||||
checks = []
|
||||
for image in (kernel, rootfs):
|
||||
size = image.stat().st_size
|
||||
checks.append(
|
||||
{
|
||||
"image": image.name,
|
||||
"image_path": str(image),
|
||||
"image_size_bytes": size,
|
||||
"partitions": [
|
||||
{
|
||||
"label": "BOOT" if image.name == "kernel.bin" else "ROOTFS",
|
||||
"alias": "kernel.A" if image.name == "kernel.bin" else "rootfs.A",
|
||||
"file": image.name,
|
||||
"size_in_kb": 1024,
|
||||
"size_bytes": 1024 * 1024,
|
||||
}
|
||||
],
|
||||
"effective_partition_size_bytes": 1024 * 1024,
|
||||
"required_margin_bytes": 512 * 1024,
|
||||
"actual_margin_bytes": 1024 * 1024 - size,
|
||||
"passed": True,
|
||||
}
|
||||
)
|
||||
margin = {
|
||||
"schema_version": 1,
|
||||
"passed": True,
|
||||
"checked_at": "2026-09-02T00:00:00+00:00",
|
||||
"partition_table": str(partition),
|
||||
"partition_table_sha256": hashlib.sha256(partition.read_bytes()).hexdigest(),
|
||||
"required_margin_bytes": 512 * 1024,
|
||||
"checks": checks,
|
||||
}
|
||||
margin_path = project / "doc" / "bsp_adaptation" / "validation" / "image_partition_margin_20260902_1.json"
|
||||
margin_path.parent.mkdir(parents=True)
|
||||
margin_path.write_text(json.dumps(margin), encoding="utf-8")
|
||||
manifest = root / "psp_handoff.json"
|
||||
payload = {
|
||||
"schema_version": 1,
|
||||
"handoff_type": "bsp-to-psp",
|
||||
"producer": {
|
||||
"project": "CV1841CP-BOARD_dualos",
|
||||
"project_path": str(project),
|
||||
},
|
||||
"baseline": {
|
||||
"chip": "CV1841CP",
|
||||
"sdk": "cv184x_v6.3.3",
|
||||
"board_build_type": "cv1841cp_wevb_0015a_spinand",
|
||||
},
|
||||
"build": {
|
||||
"version": "20260902_1",
|
||||
"status": "build_passed",
|
||||
"exit_code": 0,
|
||||
"completion_marker_seen": True,
|
||||
"imgs_version_path": str(imgs),
|
||||
"image_partition_margin_path": str(margin_path),
|
||||
},
|
||||
"artifacts": [
|
||||
{
|
||||
"relative_path": item.name,
|
||||
"absolute_path": str(item),
|
||||
"size": item.stat().st_size,
|
||||
"sha256": hashlib.sha256(item.read_bytes()).hexdigest(),
|
||||
}
|
||||
for item in (artifact, kernel, rootfs)
|
||||
],
|
||||
"validation": {
|
||||
"image_partition_margin": margin,
|
||||
"hardware": "pending",
|
||||
"owner_acceptance": "pending",
|
||||
"release": "not-authorized",
|
||||
},
|
||||
}
|
||||
manifest.write_text(json.dumps(payload), encoding="utf-8")
|
||||
result = validate_bsp_handoff.validate_handoff(
|
||||
manifest,
|
||||
"CV1841CP-BOARD_dualos",
|
||||
"CV1841CP",
|
||||
"cv184x_v6.3.3",
|
||||
"cv1841cp_wevb_0015a_spinand",
|
||||
)
|
||||
assert result["passed"] is True, result
|
||||
assert result["dependency"]["verified_artifact_count"] == 3
|
||||
assert result["dependency"]["build_id"] == "20260902_1"
|
||||
assert result["dependency"]["chip"] == "CV1841CP"
|
||||
assert result["dependency"]["image_partition_margin"]["passed"] is True
|
||||
assert result["dependency"]["artifacts"][0]["sha256"]
|
||||
assert result["warnings"]
|
||||
|
||||
missing_margin_payload = json.loads(json.dumps(payload))
|
||||
missing_margin_payload["validation"].pop("image_partition_margin")
|
||||
missing_margin_payload["build"].pop("image_partition_margin_path")
|
||||
missing_margin_manifest = root / "missing_margin_handoff.json"
|
||||
missing_margin_manifest.write_text(
|
||||
json.dumps(missing_margin_payload), encoding="utf-8"
|
||||
)
|
||||
missing_margin = validate_bsp_handoff.validate_handoff(missing_margin_manifest)
|
||||
assert missing_margin["passed"] is False
|
||||
assert any("分区余量证据" in error for error in missing_margin["errors"])
|
||||
|
||||
artifact.write_bytes(b"tampered")
|
||||
tampered = validate_bsp_handoff.validate_handoff(manifest)
|
||||
assert tampered["passed"] is False
|
||||
assert any("大小不匹配" in error for error in tampered["errors"])
|
||||
print("BSP handoff consumer tests passed")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in new issue
Block a user