mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-12-02 02:13:41 +08:00
Verify Isolated Panda Fault Test Builds
This commit is contained in:
+26
-21
@@ -20,46 +20,51 @@ def word(w):
|
||||
class TestBuild(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
# debug and release build in copies, board/obj is left alone
|
||||
# Build each profile in its own source copy.
|
||||
files = [f for f in subprocess.check_output(["git", "ls-files"], cwd=ROOT, encoding="utf8").split() if os.path.isfile(os.path.join(ROOT, f))]
|
||||
env = {k: v for k, v in os.environ.items() if k not in ("RELEASE", "CERT")}
|
||||
env = {k: v for k, v in os.environ.items() if k not in ("RELEASE", "CERT", "PANDA_FAULT_INJECTION")}
|
||||
cls.tmp = {}
|
||||
for release in (False, True):
|
||||
for profile in ("debug", "faulttest", "release"):
|
||||
tmp = tempfile.TemporaryDirectory()
|
||||
cls.addClassCleanup(tmp.cleanup)
|
||||
d = cls.tmp[release] = tmp.name
|
||||
d = cls.tmp[profile] = tmp.name
|
||||
for f in files:
|
||||
os.makedirs(os.path.dirname(f"{d}/{f}"), exist_ok=True)
|
||||
shutil.copy2(f"{ROOT}/{f}", f"{d}/{f}")
|
||||
release_env = {"RELEASE": "1", "CERT": f"{d}/board/crypto/certs/debug"} if release else {}
|
||||
subprocess.check_call([sys.executable, "-B", "-m", "SCons", "-u", "board/obj/panda_h7.bin.signed", "board/obj/bootstub.panda_h7.bin"], cwd=d, env=env | release_env,
|
||||
build_env = {}
|
||||
if profile == "release":
|
||||
build_env = {"RELEASE": "1", "CERT": f"{d}/board/crypto/certs/debug"}
|
||||
elif profile == "faulttest":
|
||||
build_env = {"PANDA_FAULT_INJECTION": "1"}
|
||||
subprocess.check_call([sys.executable, "-B", "-m", "SCons", "-u", "board/obj/panda_h7.bin.signed", "board/obj/bootstub.panda_h7.bin"], cwd=d, env=env | build_env,
|
||||
stdout=subprocess.DEVNULL)
|
||||
|
||||
def _read(self, release, fn):
|
||||
with open(f"{self.tmp[release]}/board/obj/{fn}", "rb") as f:
|
||||
def _read(self, profile, fn):
|
||||
with open(f"{self.tmp[profile]}/board/obj/{fn}", "rb") as f:
|
||||
return f.read()
|
||||
|
||||
def _has_symbol(self, release, elf, name):
|
||||
# the pip toolchain has no nm, symbol names are null terminated in the ELF string table
|
||||
return f"\0{name}\0".encode() in self._read(release, f"panda_h7/{elf}")
|
||||
def _has_symbol(self, profile, elf, name):
|
||||
# Symbols in the ELF string table are null terminated.
|
||||
return f"\0{name}\0".encode() in self._read(profile, f"panda_h7/{elf}")
|
||||
|
||||
def test_release_has_no_debug_features(self):
|
||||
# each is only compiled with ALLOW_DEBUG, the debug build checks the name still exists
|
||||
for sym in ("self_test_inject", "relay_readback_inject", "stop_mode_requested"):
|
||||
assert self._has_symbol(False, "main.elf", sym), sym
|
||||
assert not self._has_symbol(True, "main.elf", sym), sym
|
||||
for profile in self.tmp:
|
||||
with self.subTest(profile=profile):
|
||||
assert self._has_symbol(profile, "main.elf", "stop_mode_requested") == (profile != "release")
|
||||
for symbol in ("self_test_inject", "relay_readback_inject"):
|
||||
assert self._has_symbol(profile, "main.elf", symbol) == (profile == "faulttest"), symbol
|
||||
|
||||
def test_only_bootstub_programs_flash(self):
|
||||
for release in (False, True):
|
||||
for profile in self.tmp:
|
||||
for func in ("flash_unlock", "flash_erase_sector", "flash_write_word"):
|
||||
assert self._has_symbol(release, "bootstub.elf", func), func
|
||||
assert not self._has_symbol(release, "main.elf", func), func
|
||||
assert not any(word(k) in self._read(release, "panda_h7/main.bin") for k in FLASH_KEYS)
|
||||
assert self._has_symbol(profile, "bootstub.elf", func), func
|
||||
assert not self._has_symbol(profile, "main.elf", func), func
|
||||
assert not any(word(k) in self._read(profile, "panda_h7/main.bin") for k in FLASH_KEYS)
|
||||
|
||||
def test_option_bytes_never_unlocked(self):
|
||||
for release in (False, True):
|
||||
for profile in self.tmp:
|
||||
for fn in ("panda_h7/main.bin", "bootstub.panda_h7.bin"):
|
||||
assert not any(word(k) in self._read(release, fn) for k in OPT_KEYS), (release, fn)
|
||||
assert not any(word(k) in self._read(profile, fn) for k in OPT_KEYS), (profile, fn)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user