120 lines
4.6 KiB
Python
120 lines
4.6 KiB
Python
"""Fail-closed live-DT validation for the temporary IPA DMA test overlay."""
|
|
|
|
import importlib.util
|
|
from pathlib import Path
|
|
import struct
|
|
import tempfile
|
|
import unittest
|
|
|
|
|
|
SPEC = importlib.util.spec_from_file_location(
|
|
"cellular_bam_overlay",
|
|
Path(__file__).resolve().parents[1] / "scripts/phone-cellular-bam-overlay.py",
|
|
)
|
|
OVERLAY = importlib.util.module_from_spec(SPEC)
|
|
SPEC.loader.exec_module(OVERLAY)
|
|
|
|
|
|
class BamOverlayTest(unittest.TestCase):
|
|
def setUp(self):
|
|
self.temp = tempfile.TemporaryDirectory()
|
|
self.addCleanup(self.temp.cleanup)
|
|
self.root = Path(self.temp.name)
|
|
self.put("compatible", b"xiaomi,platina\0qcom,sdm660\0")
|
|
self.put_cells("soc@0/#address-cells", 1)
|
|
self.put_cells("soc@0/#size-cells", 1)
|
|
self.put("soc@0/iommu@16c0000/compatible", b"qcom,sdm630-smmu-v2\0qcom,smmu-v2\0")
|
|
self.put_cells("soc@0/iommu@16c0000/phandle", 0x9C)
|
|
self.put_cells("soc@0/iommu@16c0000/#iommu-cells", 1)
|
|
self.put_cells("soc@0/rpm-cc/phandle", 0x29)
|
|
self.put_cells("soc@0/rpm-cc/#clock-cells", 1)
|
|
self.put("soc@0/ipa@14780000/compatible", b"qcom,sdm660-ipa\0qcom,ipa-v2.6\0")
|
|
self.put("soc@0/ipa@14780000/clock-names", b"core\0")
|
|
self.put_cells("soc@0/ipa@14780000/clocks", 0x29, 0x44)
|
|
|
|
def put(self, name, data):
|
|
path = self.root / name
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
path.write_bytes(data)
|
|
|
|
def put_cells(self, name, *values):
|
|
self.put(name, struct.pack(f">{len(values)}I", *values))
|
|
|
|
def generate(self):
|
|
return OVERLAY.generate(self.root)
|
|
|
|
def test_live_phandles_are_used_without_modifying_parent(self):
|
|
self.put_cells("soc@0/iommu@16c0000/phandle", 0x17)
|
|
self.put_cells("soc@0/rpm-cc/phandle", 0x81)
|
|
self.put_cells("soc@0/ipa@14780000/clocks", 0x81, 0x44)
|
|
result = self.generate()
|
|
self.assertIn("iommus = <0x17 0x19c0>", result)
|
|
self.assertIn("clocks = <0x81 0x44>", result)
|
|
self.assertIn("reg = <0x147c0000 0x1000>, <0x14784000 0x26934>", result)
|
|
self.assertNotIn("#address-cells", result)
|
|
self.assertNotIn("#size-cells", result)
|
|
self.assertNotIn("ipa@14780000", result)
|
|
|
|
def test_other_machine_rejected(self):
|
|
self.put("compatible", b"other,phone\0")
|
|
with self.assertRaisesRegex(ValueError, "not xiaomi,platina"):
|
|
self.generate()
|
|
|
|
def test_other_address_layout_rejected(self):
|
|
self.put_cells("soc@0/#address-cells", 2)
|
|
with self.assertRaisesRegex(ValueError, "address/size"):
|
|
self.generate()
|
|
|
|
def test_existing_ap_stream_rejected(self):
|
|
self.put_cells("soc@0/ipa@14780000/iommus", 0x9C, 0x19C0)
|
|
with self.assertRaisesRegex(ValueError, "already declared"):
|
|
self.generate()
|
|
|
|
def test_non_ap_stream_allowed(self):
|
|
self.put_cells("soc@0/some-device/iommus", 0x9C, 0x19C1, 0x9C, 0x19C2)
|
|
self.assertIn("0x19c0", self.generate())
|
|
|
|
def test_unknown_iommu_provider_rejected(self):
|
|
self.put_cells("soc@0/some-device/iommus", 0xFF, 0x19C0)
|
|
with self.assertRaisesRegex(ValueError, "unresolved IOMMU"):
|
|
self.generate()
|
|
|
|
def test_truncated_iommu_spec_rejected(self):
|
|
self.put_cells("soc@0/some-device/iommus", 0x9C)
|
|
with self.assertRaisesRegex(ValueError, "invalid IOMMU arguments"):
|
|
self.generate()
|
|
|
|
def test_unexpected_iommu_cells_rejected(self):
|
|
self.put_cells("soc@0/iommu@16c0000/#iommu-cells", 2)
|
|
with self.assertRaisesRegex(ValueError, "IOMMU argument"):
|
|
self.generate()
|
|
|
|
def test_duplicate_phandle_rejected(self):
|
|
self.put_cells("soc@0/another-device/phandle", 0x29)
|
|
with self.assertRaisesRegex(ValueError, "duplicate phandle"):
|
|
self.generate()
|
|
|
|
def test_wrong_clock_rejected(self):
|
|
self.put_cells("soc@0/ipa@14780000/clocks", 0x29, 0x45)
|
|
with self.assertRaisesRegex(ValueError, "RPM IPA core clock"):
|
|
self.generate()
|
|
|
|
def test_clock_provider_cells_rejected(self):
|
|
self.put_cells("soc@0/rpm-cc/#clock-cells", 2)
|
|
with self.assertRaisesRegex(ValueError, "clock provider"):
|
|
self.generate()
|
|
|
|
def test_existing_test_device_rejected(self):
|
|
(self.root / "soc@0/platina-ipa-dma-test@147c0000").mkdir()
|
|
with self.assertRaisesRegex(ValueError, "test node already exists"):
|
|
self.generate()
|
|
|
|
def test_malformed_cells_rejected(self):
|
|
self.put("soc@0/ipa@14780000/clocks", b"\x00")
|
|
with self.assertRaisesRegex(ValueError, "invalid cells"):
|
|
self.generate()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|