#!/usr/bin/env python3 """Offline regression checks for Nokia 8000 4G (nokia-sparkler) bring-up.""" import os import re import shutil import subprocess import sys import unittest BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) def read_text(rel_path): with open(os.path.join(BASE_DIR, rel_path), "r", encoding="utf-8") as handle: return handle.read() class TestSparklerPort(unittest.TestCase): def test_deviceinfo_and_initfs(self): deviceinfo = read_text("devices/nokia-sparkler/deviceinfo") for expected in ( 'deviceinfo_codename="nokia-sparkler"', 'deviceinfo_dtb="qcom-msm8909-nokia-sparkler"', 'deviceinfo_drm="true"', 'deviceinfo_flash_offset_base="0x80000000"', 'deviceinfo_flash_offset_kernel="0x00008000"', 'deviceinfo_flash_offset_ramdisk="0x02700000"', 'deviceinfo_flash_offset_tags="0x02500000"', ): self.assertIn(expected, deviceinfo) initfs = read_text("devices/nokia-sparkler/modules-initfs").splitlines() for mod in ("pm8916-lbc", "pm8916-bms-vm", "panel-mipi-dbi", "matrix_keypad", "matrix_keymap"): self.assertIn(mod, initfs) def _assert_dts_invariants(self, text): for expected in ( 'model = "Nokia 8000 4G";', 'compatible = "nokia,sparkler", "qcom,msm8909";', 'qcom,msm-id = <0xf5 0x00>;', 'qcom,board-id = <0x08 0x100>;', 'qcom,pmic-id = <0x1000d 0x00 0x00 0x00>;', 'reg = <0x80000000 0x20000000>;', 'sound@7702000', 'audio-codec@f000', 'audio-codec@771c000', 'vibrator@c000', 'apr {', '0x500d4', '0x100007f', '0x205000e', '0x301009e', ): self.assertIn(expected, text) for forbidden in ('0x5008b', '0x10002b8', '0x20501be', '0x30102b9', 'cd-gpios', 'broken-cd'): self.assertNotIn(forbidden, text) mm3 = re.search(r'dai-link-multimedia3\s*\{[^}]*status\s*=\s*"disabled";', text, re.S) self.assertIsNotNone(mm3, "dai-link-multimedia3 must be disabled") vib = re.search(r'vibrator@c000\s*\{[^}]*status\s*=\s*"disabled";', text, re.S) self.assertIsNotNone(vib, "vibrator@c000 must be disabled on sparkler (157 Hz haptic audio)") star = re.search(r'key-star\s*\{[^}]*gpios\s*=\s*<0x27 0x5a 0x01>;[^}]*linux,code\s*=\s*<0x20a>;', text, re.S) self.assertIsNotNone(star, "key-star on gpio90 (0x5a) must map to KEY_NUMERIC_STAR (0x20a)") resin = re.search(r'resin\s*\{[^}]*compatible\s*=\s*"qcom,pm8941-resin";[^}]*linux,code\s*=\s*<0x20b>;', text, re.S) self.assertIsNotNone(resin, "pm8941_resin must map to KEY_NUMERIC_POUND (0x20b)") sdhci_ext = re.search(r'sdhci@7864000\s*\{[^}]*non-removable;', text, re.S) self.assertIsNotNone(sdhci_ext, "sdhci@7864000 must set non-removable;") def test_dts_and_compiled_dtb_invariants(self): dts = read_text("devices/nokia-sparkler/qcom-msm8909-nokia-sparkler.dts") self._assert_dts_invariants(dts) for cpu_idx in range(4): m = re.search( rf'cpu@{cpu_idx}\s*\{{[^}}]*clock-frequency\s*=\s*<1094400000>;', dts, re.S, ) self.assertIsNotNone(m, f"cpu@{cpu_idx} must set clock-frequency = <1094400000>;") dtc = shutil.which("dtc") if dtc is None: return for dtb_rel in ( "devices/nokia-sparkler/qcom-msm8909-nokia-sparkler.dtb", "prebuilt/kernel-6.12.1-msm8916/dtbs/qcom-msm8909-nokia-sparkler.dtb", ): dtb_path = os.path.join(BASE_DIR, dtb_rel) self.assertTrue(os.path.isfile(dtb_path), "missing compiled DTB: " + dtb_rel) with open(dtb_path, "rb") as handle: raw_dtb = handle.read() # 1094400000 Hz in big-endian u32 is 0x413b3800 ("A;8\0" in ASCII) self.assertGreaterEqual(raw_dtb.count(b"\x41\x3b\x38\x00"), 4, dtb_rel) dec = subprocess.check_output([dtc, "-q", "-I", "dtb", "-O", "dts", dtb_path], text=True) dec = dec.replace(r"\0", '", "') self._assert_dts_invariants(dec) null_joined = dec.replace('"nokia,sparkler", "qcom,msm8909"', r'"nokia,sparkler\0qcom,msm8909"') self.assertIn(r'compatible = "nokia,sparkler\0qcom,msm8909";', null_joined) self._assert_dts_invariants(null_joined.replace(r"\0", '", "')) def test_smp_cpufreq_haptic_audio_and_camera_fixes(self): patch_0013 = read_text("patches/kernel/0013-msm8909-early-scm-smp-cpufreq.patch") for expected in ( "early_virt", "qcom_scm_set_boot_addr_mc", "cpu_present(cpu)", "clock-frequency = <1094400000>;", ): self.assertIn(expected, patch_0013) build_k = read_text("scripts/build-kernel-audio.sh") self.assertIn("0013-msm8909-early-scm-smp-cpufreq.patch", build_k) sysmap = read_text("prebuilt/kernel-6.12.1-msm8916/System.map") self.assertIn(" qcom_scm_set_boot_addr_mc\n", sysmap) vib_c = read_text("src/dwm-plugins/sxmo_vibrate.c") for expected in ( "is_haptic_audio_device", "vibrate_haptic_audio", "157.0", "nokia,sparkler", "SND_PCM_FORMAT_FLOAT_LE", "pa_sw_volume_to_linear", "HAPTIC_REF_RX3_VOL", ): self.assertIn(expected, vib_c) for script_rel in ("scripts/build-dwm-plugins.sh", "scripts/build-sxmo-x11.sh"): build_s = read_text(script_rel) for expected in ("alsa", "libpulse", "pulseaudio-dev"): self.assertIn(expected, build_s, script_rel) cam_c = read_text("src/msm8905-cam/msm8905-cam.c") for expected in ( 'of_machine_is_compatible("nokia,sparkler")', "row_buf", "msm8905_cam_demosaic(cam->raw_dma_buf, dst_rgb, cam->rotate_180);", ): self.assertIn(expected, cam_c) def test_dual_gpio_torch_driver_and_module(self): torch_src = read_text("src/leds-msm8905-torch/leds-msm8905-torch.c") for expected in ( '#define MSM8905_TLMM_GPIO31_PHYS 0x0101f000UL', 'of_machine_is_compatible("nokia,sparkler")', 'of_machine_is_compatible("nokia,leo")', 'is_sparkler_dual_gpio_torch', 'GPIO_32/GPIO_31 (BC847BS)', ): self.assertIn(expected, torch_src) ko_path = os.path.join(BASE_DIR, "prebuilt/kernel-6.12.1-msm8916/leds/leds-msm8905-torch.ko") ko_zst = ko_path + ".zst" self.assertTrue(os.path.isfile(ko_path), "missing leds-msm8905-torch.ko") self.assertTrue(os.path.isfile(ko_zst), "missing leds-msm8905-torch.ko.zst") with open(ko_path, "rb") as handle: raw_ko = handle.read() self.assertIn(b"GPIO_32/GPIO_31 (BC847BS)", raw_ko) modinfo = shutil.which("modinfo") if modinfo is not None: out = subprocess.check_output([modinfo, "-F", "vermagic", ko_path], text=True).strip() self.assertEqual(out, "6.12.1-msm8916 SMP preempt mod_unload ARMv7 p2v8") deps = subprocess.check_output([modinfo, "-F", "depends", ko_path], text=True).strip() self.assertEqual(deps, "") def test_flash_release_and_boot_validators_wired(self): flash_py = read_text("flash-edl.py") for expected in ( 'BOOT_IMAGE_DEVICES = ("nokia-beatles", "nokia-coconut", "nokia-sparkler")', 'UNLOCK_DEFAULT_DEVICES = ("nokia-beatles", "nokia-coconut", "nokia-sparkler", "nokia-leo")', 'EDL_STAR_HASH_DEVICES = ("nokia-sparkler", "nokia-leo")', 'SPARKLER_LK2ND_IMAGE = "images/boot-lk2nd-nokia-sparkler-display.img"', '"nokia-sparkler": SPARKLER_LK2ND_IMAGE', ): self.assertIn(expected, flash_py) import importlib.util flash_spec = importlib.util.spec_from_file_location( "flash_edl", os.path.join(BASE_DIR, "flash-edl.py"), ) flash_mod = importlib.util.module_from_spec(flash_spec) flash_spec.loader.exec_module(flash_mod) self.assertEqual(flash_mod.edl_button_combo_hint("nokia-sparkler"), "* + #") self.assertEqual(flash_mod.edl_button_combo_hint("nokia-leo"), "* + #") self.assertEqual(flash_mod.edl_button_combo_hint("nokia-argon"), "D-Pad Up + D-Pad Down") self.assertEqual(flash_mod.edl_button_combo_hint("nokia-beatles"), "D-Pad Up + D-Pad Down") self.assertEqual(flash_mod.edl_button_combo_hint("nokia-coconut"), "D-Pad Up + D-Pad Down") manual_md = read_text("MANUAL.md") self.assertIn("`*` + `#`", manual_md) prep_sh = read_text("prepare-release.sh") for expected in ( 'DISPLAY_IMAGE="images/boot-lk2nd-nokia-sparkler-display.img"', 'BOOT_IMAGE="images/boot-bananarchy-nokia-sparkler.img"', 'scripts/check-lk2nd-sparkler.py', './scripts/build-lk2nd-sparkler.sh', ): self.assertIn(expected, prep_sh) sys.path.insert(0, os.path.join(BASE_DIR, "scripts")) import importlib bootimg_mod = importlib.import_module("check-beatles-bootimg") bootfs_mod = importlib.import_module("sync-beatles-bootfs") self.assertIn("nokia-sparkler", bootimg_mod.DEVICE_MODELS) self.assertEqual(bootimg_mod.DEVICE_MODELS["nokia-sparkler"], "Nokia 8000 4G") spec = bootimg_mod.DEVICE_SPECS["nokia-sparkler"] self.assertEqual(spec["addrs"], (0x80008000, 0x82700000, 0x82500000)) self.assertEqual(bootfs_mod.DEVICE_DTB_NAMES["nokia-sparkler"], "qcom-msm8909-nokia-sparkler.dtb") if __name__ == "__main__": unittest.main()