mirror of
https://github.com/dikeckaan/mu300-linux.git
synced 2026-12-06 08:03:36 +00:00
- Windows (fixes #7): a clone with core.autocrlf=true checked the device scripts out as CRLF, and Android's sh ran none of android-install.sh ("unexpected 'do'"), with an empty log. .gitattributes keeps text LF on every system; install.ps1 pushes scripts through PushUnix, and build-boot-image.py writes init, ueventd-perms.sh and the module orders with LF, for clones made before. Checked on Windows: 5 of 5 scripts CRLF on main, 0 now. - Wi-Fi (#8): the vendor driver had no dump_station, so iw, iwinfo assoclist and LuCI's Associated Stations were empty although hostapd had the clients; nor get_channel ("Channel: 0"). dump_station lists the firmware's peer table entries of the AP (address only: the firmware gives no signal or counters), get_channel returns what cfg80211 kept from start_ap. Mainline copy and a 5.4 patch; the channel checked on the F50 under 6.18. - A U30 Air restarted every ten minutes after mu300-linux from Android: boot_b's device segment, which mu300-update keeps, still held an old experiment's --trial-guard. The generic segment carries an empty guard file that replaces it; an experiment's guard goes last, into a segment of its own. Checked on the U30 Air. - mu300-nfc on|off: ZTE's NFC switch is bit 5 of the tag's configuration byte 0x3bf (found by reading the chip with the switch on and off); set, phones get nothing. mu300-nfc says so. Checked on the U30 Air. - Tests: CRLF inputs, no plain adb push of scripts, the empty guard, NFC on/off. FINDINGS 33g, 33h. Fixes #7 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AeuDBrAce8rrgSJDbFJQGN
119 lines
5.8 KiB
Python
119 lines
5.8 KiB
Python
"""Checks over every script without running it: syntax under each shell that runs it, executable bits, and rules
|
|
that past bugs taught (see each test)."""
|
|
import re
|
|
import shutil
|
|
import subprocess
|
|
import unittest
|
|
|
|
from helpers import BIN, TOP, shells
|
|
|
|
OPENWRT = TOP / 'openwrt' / 'overlay'
|
|
|
|
|
|
def shebang(p):
|
|
try:
|
|
with open(p, 'rb') as f:
|
|
first = f.readline()
|
|
except OSError:
|
|
return ''
|
|
return first.decode(errors='replace').strip() if first.startswith(b'#!') else ''
|
|
|
|
|
|
def shell_scripts():
|
|
"""(path, 'sh'|'bash') of every shell script the project ships or runs."""
|
|
cands = list(BIN.iterdir()) + list((TOP / 'tools').glob('*.sh')) + [
|
|
TOP / 'install.sh', TOP / 'uninstall.sh', TOP / 'boot' / 'init', TOP / 'rootfs' / 'assemble.sh',
|
|
TOP / 'kernel' / 'build-all.sh', TOP / 'tools' / 'i18n.sh', TOP / 'tools' / 'self-update.sh',
|
|
TOP / 'tools' / 'linux-mode.sh', TOP / 'android-vendor' / 'ueventd-perms.sh']
|
|
cands += [p for p in OPENWRT.rglob('*') if p.is_file()]
|
|
out = []
|
|
for p in sorted(set(cands)):
|
|
if not p.is_file():
|
|
continue
|
|
sb = shebang(p)
|
|
if 'bash' in sb:
|
|
out.append((p, 'bash'))
|
|
elif sb.endswith('sh') or 'rc.common' in sb or (not sb and p.suffix == '.sh'):
|
|
out.append((p, 'sh'))
|
|
return out
|
|
|
|
|
|
class Syntax(unittest.TestCase):
|
|
def test_every_script_parses(self):
|
|
sh_shells = [s for s in shells() if s[0] != 'bash'] or shells()
|
|
scripts = shell_scripts()
|
|
self.assertGreater(len(scripts), 40)
|
|
for p, kind in scripts:
|
|
if kind == 'bash' and not shutil.which('bash'):
|
|
continue
|
|
for s in ([['bash']] if kind == 'bash' else sh_shells):
|
|
with self.subTest(script=str(p.relative_to(TOP)), shell=' '.join(s)):
|
|
r = subprocess.run(s + ['-n', str(p)], capture_output=True, text=True)
|
|
self.assertEqual(r.returncode, 0, r.stderr)
|
|
|
|
def test_device_programs_are_executable(self):
|
|
for p in BIN.iterdir():
|
|
if p.is_file() and shebang(p):
|
|
with self.subTest(p=p.name):
|
|
self.assertTrue(p.stat().st_mode & 0o111, 'not executable')
|
|
|
|
|
|
class Rules(unittest.TestCase):
|
|
def test_powershell_device_commands_have_no_double_quotes(self):
|
|
# Windows PowerShell 5.1 drops the double quotes inside an argument to a native program: `tr -d "\000"`
|
|
# reached the device as tr -d \000 ("delete the character 0"), and every empty region was "not empty".
|
|
# A command for the device (SuDo, adb shell) may therefore contain no `" and no "".
|
|
for name in ('install.ps1', 'uninstall.ps1'):
|
|
for n, line in enumerate((TOP / name).read_text().splitlines(), 1):
|
|
code = line.split('#', 1)[0] if not line.lstrip().startswith('#') else ''
|
|
if re.search(r'\bSuDo(ToFile)?\s+"|adb shell\s+"', code) and ('`"' in code or '""' in code):
|
|
self.fail(f'{name}:{n}: double quote inside a device command: {line.strip()}')
|
|
|
|
def test_powershell_scripts_are_ascii(self):
|
|
# Windows PowerShell 5.1 reads a file without a BOM as ANSI: non-ASCII text in the script is garbled
|
|
for name in ('install.ps1', 'uninstall.ps1'):
|
|
data = (TOP / name).read_bytes()
|
|
bad = [i for i, b in enumerate(data) if b > 127]
|
|
self.assertFalse(bad, f'{name}: non-ASCII byte at offset {bad[:1]}')
|
|
|
|
def test_windows_pushes_text_with_lf(self):
|
|
# a CRLF clone pushed its scripts as they were and Android's sh ran none of them (issue #7): the Windows
|
|
# installers send text files through PushUnix, never a plain adb push
|
|
for name in ('install.ps1', 'uninstall.ps1'):
|
|
for n, line in enumerate((TOP / name).read_text().splitlines(), 1):
|
|
if 'adb push' in line:
|
|
self.assertNotRegex(line, r'\.(sh|prop)\b|mu300-linux"|\$f"', f'{name}:{n}')
|
|
self.assertIn('eol=lf', (TOP / '.gitattributes').read_text())
|
|
|
|
def test_single_quoted_scripts_have_no_apostrophes(self):
|
|
# A script handed to `sh -c '...'` (docker run) ends at its first apostrophe: "the U30 Air's charger" in a
|
|
# comment there broke OpenWrt's build at release time, while every parser still saw balanced quotes.
|
|
for name in ('openwrt/build-rootfs.sh', 'tools/make-release.sh'):
|
|
lines = (TOP / name).read_text().splitlines()
|
|
for n, line in enumerate(lines):
|
|
if not line.rstrip().endswith("-c '"):
|
|
continue
|
|
for m in range(n + 1, len(lines)):
|
|
if "'" in lines[m]:
|
|
self.assertTrue(lines[m].rstrip().endswith("'") and lines[m].count("'") == 1,
|
|
f'{name}:{m + 1}: an apostrophe inside the script of line {n + 1}')
|
|
break
|
|
|
|
def test_init_finds_partitions_after_the_modules(self):
|
|
# the eMMC driver is one of the vendor modules: misc and boot_b cannot be found before they are loaded
|
|
init = (TOP / 'boot' / 'init').read_text()
|
|
calls = [l.strip() for l in init.splitlines() if l.strip() in ('load_vendor_modules', 'find_partitions')]
|
|
self.assertEqual(calls, ['load_vendor_modules', 'find_partitions'])
|
|
|
|
def test_every_device_has_its_files(self):
|
|
# a device the installers know needs its module order; its modules come from kernel/build-<device>.sh
|
|
for dev in ('u30air',):
|
|
self.assertTrue((TOP / 'boot' / f'module-order-{dev}.txt').is_file())
|
|
self.assertTrue((TOP / 'kernel' / f'{dev}.fragment').is_file())
|
|
self.assertIn(dev, (TOP / 'install.sh').read_text())
|
|
self.assertIn(dev, (TOP / 'install.ps1').read_text())
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|