Files
bananarchy/scripts/test-lk2nd-beatles-port.py
T

164 lines
7.4 KiB
Python
Executable File

#!/usr/bin/env python3
"""Host tests for the source-built nokia-beatles lk2nd port.
Runs the image validator, compiles the shared C panel-init walker against the
actual byte streams extracted from the shipped QCDT DTB, and checks that the
repository wiring (build script, patch, flasher) still points at the port.
"""
import os
import shutil
import subprocess
import sys
import tempfile
BASE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
PINNED = "cf45aefd22d744b2bf9b39455afae697ce430063"
def run(cmd, **kwargs):
return subprocess.run(cmd, cwd=BASE, capture_output=True, text=True, **kwargs)
def check(condition, message):
if not condition:
print("FAIL: %s" % message)
return False
print("[ok] %s" % message)
return True
def main():
ok = True
validator = os.path.join(BASE, "scripts", "check-lk2nd-beatles.py")
build = os.path.join(BASE, "scripts", "build-lk2nd-beatles.sh")
patch = os.path.join(BASE, "bootloader", "lk2nd", "nokia-beatles.patch")
header = os.path.join(BASE, "bootloader", "lk2nd", "spi-panel-init.h")
test_c = os.path.join(BASE, "bootloader", "lk2nd", "test_spi_panel_init.c")
variants = (
("images/boot-lk2nd-nokia-beatles.img", 0, 0),
("images/boot-lk2nd-nokia-beatles-diagnostic.img", 1, 0),
("images/boot-lk2nd-nokia-beatles-display.img", 0, 1),
)
for image, fastboot, display in variants:
ok &= check(os.path.isfile(os.path.join(BASE, image)), "%s exists" % image)
if not os.path.isfile(os.path.join(BASE, image)):
continue
cmd = [sys.executable, validator, "--image", image,
"--expect-fastboot", str(fastboot),
"--expect-display", str(display)]
r = subprocess.run(cmd, cwd=BASE, capture_output=True, text=True)
for line in r.stdout.strip().split("\n"):
if line:
print(line)
ok &= check(r.returncode == 0,
"%s passes structural validation" % os.path.basename(image))
if r.returncode != 0:
print(r.stderr.strip())
for path, label in ((build, "build-lk2nd-beatles.sh"),
(patch, "nokia-beatles.patch"),
(header, "spi-panel-init.h"),
(test_c, "test_spi_panel_init.c"),
(os.path.join(BASE, "bootloader", "lk2nd", "Dockerfile"),
"toolchain Dockerfile")):
ok &= check(os.path.isfile(path), "%s exists" % label)
script = open(build).read()
ok &= check(PINNED in script, "build script pins upstream commit %s" % PINNED)
ok &= check("LK2ND_FORCE_FASTBOOT=1" in script and "lk2nd.no-display" in script,
"build script can produce the forced-fastboot no-display diagnostic image")
ok &= check("lk2nd.display=on" in script and "--expect-display" in script,
"build script can produce and validate the SPI display image")
ok &= check("--force-panel-init" in script,
"build script supports forcing the panel init replay")
ok &= check('--with-display' in script and 'WITH_DISPLAY' in script,
"build script can re-enable the SPI display")
ok &= check("make TOOLCHAIN_PREFIX=arm-none-eabi-" in script and
"MKBOOTIMG_CMDLINE=" in script,
"build script uses the cross toolchain and beatles cmdline")
patch_text = open(patch).read()
ok &= check("lk2nd/device/dts/lk2nd.dtsi" in patch_text and
"nokia-beatles.dtsi" in patch_text and
"msm8905-qrd-skub.dts" in patch_text and
"lk2nd,panel-init" in patch_text and
"mdss_spi_panel_init_commands" in patch_text,
"patch contains the /cpus fix, device node, panel init data and driver hook")
ok &= check("oem scan-boot" in patch_text,
"patch contains the oem scan-boot extlinux probe")
ok &= check("oem scan-dtb" in patch_text,
"patch contains the oem scan-dtb kernel DTB probe")
ok &= check("lk2nd/ramoops/ramoops.c" in patch_text,
"patch contains the always-on ramoops console fix")
ok &= check("oem display-init" in patch_text,
"patch contains the runtime SPI display probe")
ok &= check("lk2nd.display=on" in patch_text,
"patch contains the boot-time display option")
ok &= check("platform/msm_shared/reboot.c" in patch_text and
"beatles low-bit reboot cookie" in patch_text,
"patch contains the low-bit lk2nd menu reboot cookie")
ok &= check("QUP_FIFO_TIMEOUT" in patch_text and "CLK_POLL_TIMEOUT" in patch_text,
"patch bounds QUP and clock register polls")
ok &= check("lk2nd/device/2nd/spi-display.c" in patch_text,
"patch contains the safe SPI display init")
ok &= check("app/aboot/aboot.c" in patch_text and
"scan-only: final kernel cmdline/DTB ready" in patch_text,
"patch stages the final DTB after lk2nd DT updates")
ok &= check("No valid pstore console" in patch_text,
"patch validates and bounds the ramoops console")
ok &= check("SPI panel fallback from QCDT" in patch_text,
"patch supports chain-loaded SPI panel probes")
ok &= check("per-word SPEW log" in patch_text,
"patch removes the QUP FIFO log flood")
ok &= check("lk2nd/fastboot/fetch.c" in patch_text and
"aligned read exceeds partition" in patch_text,
"patch makes oem read-partition block-safe")
flasher = open(os.path.join(BASE, "flash-edl.py")).read()
ok &= check("headless" not in flasher.lower(),
"flasher no longer describes a headless lk2nd")
ok &= check("images/boot-lk2nd-nokia-beatles-display.img" in flasher,
"flasher defaults to the display-enabled beatles lk2nd image")
ok &= check('target_names = ("boot", "recovery", "lk2nd")' in flasher,
"flasher refreshes the separate lk2nd partition")
ok &= check('"--lk2nd-image"' in flasher and "args.lk2nd_image" in flasher,
"flasher can override the beatles lk2nd image for diagnostics")
preflight = open(os.path.join(BASE, "scripts", "check-rebuild.sh")).read()
ok &= check("check-lk2nd-beatles.py" in preflight,
"check-rebuild.sh validates the beatles lk2nd image")
gcc = shutil.which("gcc") or shutil.which("cc")
if gcc:
with tempfile.TemporaryDirectory() as tmp:
streams = os.path.join(tmp, "panel_streams.h")
r = subprocess.run([sys.executable, validator,
"--image", "images/boot-lk2nd-nokia-beatles.img",
"--emit-streams-header", streams],
cwd=BASE, capture_output=True, text=True)
ok &= check(r.returncode == 0, "panel init streams extracted from QCDT DTB")
if r.returncode == 0:
binary = os.path.join(tmp, "test_spi_panel_init")
r = run([gcc, "-std=c11", "-Wall", "-Wextra", "-Werror",
"-I", tmp, "-I", os.path.join(BASE, "bootloader", "lk2nd"),
"-o", binary, test_c])
ok &= check(r.returncode == 0,
"host C unit test compiles against the shared parser header")
if r.returncode == 0:
print(r.stderr.strip())
r = run([binary])
print(r.stdout.strip())
print(r.stderr.strip())
ok &= check(r.returncode == 0,
"host C unit test accepts the GC9305 v2 init stream")
else:
print("[skip] no host C compiler; C unit test skipped")
print("[%s] nokia-beatles lk2nd port tests" % ("ok" if ok else "FAIL"))
return 0 if ok else 1
if __name__ == "__main__":
sys.exit(main())