Files
matrix-screen-controller/核桃派软件源代码/tests/test_kernel_recovery.py
T

181 lines
8.0 KiB
Python

from pathlib import Path
import pytest
from scripts.axp313a_kernel_health import (
HealthError,
check_cpufreq,
check_driver_pair,
check_kernel_messages,
)
from scripts.render_dual_kernel_boot import BootScriptError, render
BOOT_SOURCE = '''# DO NOT EDIT THIS FILE
setenv docker_optimizations "on"
setenv bootargs "root=/dev/mmcblk1p2"
if test "${docker_optimizations}" = "on"; then setenv bootargs "${bootargs} cgroup_enable=memory swapaccount=1"; fi
if mmc dev 1; then
load ${devtype} ${devnum} ${fdt_addr_r} ${prefix}${fdtfile_emmc}.dtb
else
load ${devtype} ${devnum} ${fdt_addr_r} ${prefix}${fdtfile}.dtb
fi
if test "${overlay_error}" = "true"; then
load ${devtype} ${devnum} ${fdt_addr_r} ${prefix}${fdtfile}.dtb
fi
load ${devtype} ${devnum} ${kernel_addr_r} ${prefix}Image
'''
def test_dual_kernel_boot_consumes_health_marker_and_keeps_original_paths():
managed = render(BOOT_SOURCE)
assert "fatrm ${devtype} ${devnum} ${prefix}matrix-kernel-good" in managed
assert 'setenv matrix_kernel_file "Image-matrix-axp313a1"' in managed
assert 'setenv matrix_dtb_suffix "-matrix-axp313a1"' in managed
assert "matrix_kernel_candidate=1 panic=10" in managed
assert "${prefix}${fdtfile}${matrix_dtb_suffix}.dtb" in managed
assert "${prefix}${matrix_kernel_file}" in managed
assert 'setenv matrix_kernel_file "Image"' in managed
assert 'setenv matrix_dtb_suffix ""' in managed
def test_dual_kernel_boot_refuses_to_stack_management_blocks():
with pytest.raises(BootScriptError, match="already candidate-managed"):
render(render(BOOT_SOURCE))
def test_cpufreq_health_requires_policy0_all_cpus_and_performance(tmp_path):
policy = tmp_path / "cpufreq" / "policy0"
policy.mkdir(parents=True)
(policy / "affected_cpus").write_text("0 1 2 3\n", encoding="ascii")
(policy / "scaling_available_governors").write_text(
"powersave performance schedutil\n", encoding="ascii"
)
deferred = tmp_path / "devices_deferred"
deferred.write_text("", encoding="utf-8")
check_cpufreq(policy.parent, deferred)
deferred.write_text("platform cpufreq-dt\n", encoding="utf-8")
with pytest.raises(HealthError, match="still deferred"):
check_cpufreq(policy.parent, deferred)
def driver_status(frames: int, misses: int = 0) -> dict:
return {
"screen": {
"driver": "walnutpi-h618-hub75",
"driver_status": {
"actual_refresh_rate_hz": 97.5,
"panel_scan_rate_hz": 97.5,
"completed_frames": frames,
"completed_scans": frames,
"scans_per_frame": 1,
"deadline_misses": misses,
"oe_pulse_faults": 0,
"oe_forced_blanks": 0,
"driver_error": None,
"oe_timing_error": None,
"safeoff_error": None,
"cpu_affinity": 3,
"cpu_affinity_active": True,
"realtime_priority": 50,
"realtime_priority_active": True,
"memory_locked": True,
},
},
}
def test_candidate_health_accepts_only_progressing_equal_gpio_counters():
check_driver_pair(driver_status(1000), driver_status(1200))
stalled = driver_status(1000)
with pytest.raises(HealthError, match="stalled or unequal"):
check_driver_pair(stalled, stalled)
def test_candidate_health_rejects_axp313a_dcdc_boot_errors():
check_kernel_messages("axp20x-regulator: regulator probe completed\n")
with pytest.raises(HealthError, match="regulator logged a boot error"):
check_kernel_messages(
"axp20x-regulator axp20x-regulator: Error setting dcdc frequency: -22\n"
)
def test_kernel_scripts_pin_release_commits_and_preserve_original_boot_files():
source_root = Path(__file__).resolve().parents[1]
build = (source_root / "scripts/build_axp313a_kernel.sh").read_text(encoding="utf-8")
install = (source_root / "scripts/install_axp313a_kernel.sh").read_text(encoding="utf-8")
capture = (source_root / "scripts/capture_axp313a_state.sh").read_text(encoding="utf-8")
dts_patch = (source_root / "kernel/patches/0004-walnutpi-axp313a-dts.patch").read_text(
encoding="utf-8"
)
dldo_patch = (
source_root / "kernel/patches/0005-walnutpi-axp313a-preserve-dldo1.patch"
).read_text(encoding="utf-8")
uwe_patch = (
source_root / "kernel/patches/0006-walnutpi-uwe5622-out-of-tree-build.patch"
).read_text(encoding="utf-8")
realtek_patch = (
source_root / "kernel/patches/0007-walnutpi-enabled-realtek-out-of-tree-build.patch"
).read_text(encoding="utf-8")
rtl8192_patch = (
source_root / "kernel/patches/0008-walnutpi-rtl8192eu-out-of-tree-build.patch"
).read_text(encoding="utf-8")
rtl8812_patch = (
source_root / "kernel/patches/0009-walnutpi-rtl8812au-out-of-tree-build.patch"
).read_text(encoding="utf-8")
rtl8812_phydm_patch = (
source_root / "kernel/patches/0010-walnutpi-rtl8812au-phydm-out-of-tree-build.patch"
).read_text(encoding="utf-8")
rtl88x2cs_topdir_patch = (
source_root / "kernel/patches/0011-walnutpi-rtl88x2cs-topdir-out-of-tree-build.patch"
).read_text(encoding="utf-8")
emmc_dts_patch = (
source_root / "kernel/patches/0012-walnutpi-emmc-axp313a-dts.patch"
).read_text(encoding="utf-8")
dcdc_frequency_patch = (
source_root / "kernel/patches/0013-walnutpi-axp313a-fixed-dcdc-frequency.patch"
).read_text(encoding="utf-8")
unit = (source_root / "systemd/matrix-axp313a-health.service").read_text(encoding="utf-8")
assert "30ff3fd5cf45417622b447a12e7a947402ffe34d" in build
assert "75c8cb2f4cb218aaf4ea68cab08d6dbc96eeae15.patch" in build
assert "60fd7eb89670d2636ac3156881acbd103c6eba6a.patch" in build
assert "4628b804555773daa982d9578d89fe04fcdde374.patch" in build
assert "/boot/boot.cmd.matrix-original" in install
assert "/boot/boot.scr.matrix-original" in install
assert "KERNEL_RELEASE" in build
assert "verify_dtb" in install
assert "dldo1 3300000 3300000 vcc3v3" in install
assert "cpu_supply" in install and "dcdc2_phandle" in install
assert "+\t\t\t\tregulator-min-microvolt = <1100000>;" in dts_patch
assert "reg_dldo1: dldo1" in dldo_patch
assert "regulator-min-microvolt = <3300000>" in dldo_patch
assert "0005-walnutpi-axp313a-preserve-dldo1.patch" in build
assert "0006-walnutpi-uwe5622-out-of-tree-build.patch" in build
assert "$(srctree)/drivers/net/wireless/uwe5622/unisocwcn" in uwe_patch
assert "0007-walnutpi-enabled-realtek-out-of-tree-build.patch" in build
for directory in ("rtl8189fs", "rtl8723ds", "rtl8723du", "rtl8811cu", "rtl88x2cs"):
assert f"$(srctree)/drivers/net/wireless/{directory}" in realtek_patch
assert "0008-walnutpi-rtl8192eu-out-of-tree-build.patch" in build
assert "$(srctree)/drivers/net/wireless/rtl8192eu" in rtl8192_patch
assert "0009-walnutpi-rtl8812au-out-of-tree-build.patch" in build
assert "$(srctree)/drivers/net/wireless/rtl8812au" in rtl8812_patch
assert "0010-walnutpi-rtl8812au-phydm-out-of-tree-build.patch" in build
assert "$(srctree)/drivers/net/wireless/rtl8812au/hal/phydm" in rtl8812_phydm_patch
assert "0011-walnutpi-rtl88x2cs-topdir-out-of-tree-build.patch" in build
assert "$(srctree)/drivers/net/wireless/rtl88x2cs/rtl8822c.mk" in rtl88x2cs_topdir_patch
assert "0012-walnutpi-emmc-axp313a-dts.patch" in build
assert "sun50i-h616-walnutpi-1b-emmc.dts" in emmc_dts_patch
assert "x-powers,axp313a" in emmc_dts_patch
assert "reg_dldo1: dldo1" in emmc_dts_patch
assert "0013-walnutpi-axp313a-fixed-dcdc-frequency.patch" in build
assert "+\t\tif (dcdcfreq != 0)" in dcdc_frequency_patch
assert "-\t\tif (dcdcfreq != 3000000)" in dcdc_frequency_patch
assert "/var/lib/matrix-screen-controller" in capture
assert "state output directory must not exist" in capture
assert "ConditionKernelCommandLine=matrix_kernel_candidate=1" in unit