mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-24 07:06:21 +01:00
Compare commits
3 Commits
503ba1fcca
...
0e9cc0ce95
| Author | SHA1 | Date | |
|---|---|---|---|
| 0e9cc0ce95 | |||
| 4cfc3fdde1 | |||
| 98ca3ac56a |
@ -0,0 +1,17 @@
|
||||
{
|
||||
"title": "Test bt_pairing.sh to 100% and clear it from the shell-coverage allowlist",
|
||||
"objective": "Cover the second of the sixteen untested linux_configuration/scripts/single_use/fixes/lib libs. bt_pairing.sh is the first in the family whose code writes outside its own process -- a sysfs power/control file and a udev rule under /etc -- so the contract is to reach 100% without ever letting the suite touch either, given that lib/tests/run_all.sh runs UN-jailed in ci_mirror.sh and in CI.",
|
||||
"acceptance_criteria": [
|
||||
"bt_pairing.sh measures 100.00% through lib/tests/run_all.sh, twice, the second run at --min 100 with exit 0.",
|
||||
"check_shell_coverage.sh exits 0 for bt_pairing.sh with its allowlist line removed, i.e. with no exemption.",
|
||||
"A bare (un-jailed) run of run_all.sh leaves /etc/udev/rules.d/50-bluetooth-no-autosuspend.rules with its original 2026-02-21 mtime, and leaves the power/control values of the probed USB devices unchanged.",
|
||||
"Every test file stays under the repo's 250-line cap.",
|
||||
"pre-commit passes on all changed files with no suppression added -- no # shellcheck disable, no noqa."
|
||||
],
|
||||
"out_of_scope": [
|
||||
"Bind-mounting /etc in the jail to make the udev write safe. Rejected: run_all.sh runs un-jailed in ci_mirror.sh and CI, so a bind mount would protect only the coverage run.",
|
||||
"Refactoring pacman_hook_stall_harness.sh onto the new lib_test_core.sh. Its six libs are already gated at 100% with no exemption.",
|
||||
"The remaining fourteen untested fixes/lib libs, which land in later commits."
|
||||
],
|
||||
"verifier": "bash linux_configuration/scripts/single_use/fixes/lib/tests/run_all.sh (expects all files passing, 11 + 20 for the two bt_pairing files), plus bash meta/scripts/shell_coverage_jail.sh --subject linux_configuration/scripts/single_use/fixes/lib/tests/run_all.sh --measure bt_pairing.sh --min 100 --fail-on-case-error -- \"\" (expects 65/65 = 100.00% and exit 0), plus bash meta/scripts/check_shell_coverage.sh linux_configuration/scripts/single_use/fixes/lib/bt_pairing.sh (expects exit 0), plus stat -c '%y' /etc/udev/rules.d/50-bluetooth-no-autosuspend.rules (expects 2026-02-21)."
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
{
|
||||
"intent": "Test linux_configuration/scripts/single_use/fixes/lib/bt_pairing.sh to 100% line coverage and take it off the shell-coverage allowlist, second of the 16 untested fixes/lib libs.",
|
||||
"scope": [
|
||||
"linux_configuration/scripts/single_use/fixes/lib/tests/test_bt_pairing.sh and test_bt_pairing_usb.sh (new, 11 + 20 = 31 assertions; split across two files to stay under the 250-line cap, which run_all.sh's test_*.sh glob makes free)",
|
||||
"linux_configuration/scripts/single_use/fixes/lib/bt_pairing.sh (one line: UDEV_RULES_DIR override)",
|
||||
"linux_configuration/scripts/single_use/fixes/lib/tests/bt_harness.sh (stub udevadm, which was reaching the real binary)",
|
||||
"meta/shell-coverage-allowlist.txt (one line removed)",
|
||||
"Non-goal: bind-mounting /etc to make the udev write safe -- rejected, see risks"
|
||||
],
|
||||
"changes": [
|
||||
"Added test_bt_pairing.sh covering remove_stale_pairing (empty TARGET_MAC, paired-but-not-connected, paired-and-connected, not-paired, and device-unknown) and restart_bluetooth (both arms of the FIXES_APPLIED guard); added test_bt_pairing_usb.sh covering fix_usb_autosuspend (no bluetooth device, unparseable USB ID, no matching sysfs path, control already 'on', and control 'auto') and _disable_usb_autosuspend directly, including both arms of its idempotence guard and the different-vendor rewrite.",
|
||||
"Added a UDEV_RULES_DIR override to bt_pairing.sh:_disable_usb_autosuspend so the test suite can redirect the udev rule write out of /etc. Production default is unchanged: ${UDEV_RULES_DIR:-/etc/udev/rules.d}.",
|
||||
"Added udevadm to the harness's default stub list. It was NOT stubbed before, so `udevadm control --reload-rules` was reaching the real binary on the host -- the 'a prepended stub dir cannot hide a real binary' trap, caught by an assertion on the recorded call rather than by inspection.",
|
||||
"fix_usb_autosuspend globs the real /sys/bus/usb/devices/*/ with no env override, so each branch is driven through the stubbed lsusb output instead: ffff:ffff matches no device on any machine and exercises the not-found arm, while 046d:c077 (control=on) and 046d:0825 (control=auto) are read-only probes of devices present on this host, each guarded so it self-skips if that stops holding.",
|
||||
"Removed linux_configuration/scripts/single_use/fixes/lib/bt_pairing.sh from meta/shell-coverage-allowlist.txt."
|
||||
],
|
||||
"verification": [
|
||||
{
|
||||
"command": "bash linux_configuration/scripts/single_use/fixes/lib/tests/run_all.sh",
|
||||
"result": "pass",
|
||||
"evidence": "test_bt_pairing.sh: 11 passed, 0 failed; test_bt_pairing_usb.sh: 20 passed, 0 failed; test_bt_report.sh: 24 passed, 0 failed. All fixes lib test files passed, so the eight pre-existing pacman_hook_stall suites stay green."
|
||||
},
|
||||
{
|
||||
"command": "bash meta/scripts/shell_coverage_jail.sh --subject linux_configuration/scripts/single_use/fixes/lib/tests/run_all.sh --measure bt_pairing.sh --min 1 --fail-on-case-error -- \"\"",
|
||||
"result": "pass",
|
||||
"evidence": "bt_pairing.sh: 65/65 lines = 100.00%, up from 55/65 = 84.62% before _disable_usb_autosuspend's body (lines 112-126) was covered. No 'outside kcov's line set' lines reported."
|
||||
},
|
||||
{
|
||||
"command": "bash meta/scripts/shell_coverage_jail.sh --subject linux_configuration/scripts/single_use/fixes/lib/tests/run_all.sh --measure bt_pairing.sh --min 100 --fail-on-case-error -- \"\"",
|
||||
"result": "pass",
|
||||
"evidence": "bt_pairing.sh: 65/65 lines = 100.00%, exit code 0. Second matching run at the --min 100 bar, re-run after the two-file split to confirm the split did not change the line set."
|
||||
},
|
||||
{
|
||||
"command": "bash meta/scripts/check_shell_coverage.sh linux_configuration/scripts/single_use/fixes/lib/bt_pairing.sh",
|
||||
"result": "pass",
|
||||
"evidence": "'check_shell_coverage.sh: every checked shell library meets the coverage bar', exit 0, with the allowlist line already removed so the lib had no exemption."
|
||||
},
|
||||
{
|
||||
"command": "stat -c '%y' /etc/udev/rules.d/50-bluetooth-no-autosuspend.rules",
|
||||
"result": "pass",
|
||||
"evidence": "2026-02-21 21:51:36, unchanged after a bare (un-jailed) run of run_all.sh -- the file is a real artifact of a past production run, six months old. /sys/bus/usb/devices/1-10 and 1-11 power/control still read 'auto' and 'on'. This is the check that proves the suite is safe where it actually runs un-jailed; the jail cannot give it."
|
||||
}
|
||||
],
|
||||
"risks": [
|
||||
"Bind-mounting /etc was considered and rejected. lib/tests/run_all.sh runs UN-jailed in ci_mirror.sh (the pre-push hook) and in the shell-tests workflow, as its own header states, so a --bind would have made only the coverage run safe and left every bare run writing to the real root-owned udev rule. The UDEV_RULES_DIR override follows the precedent pacman_hook_stall_harness.sh set with PACMAN_LOG/CACHE_DIR/PACMAN_LOCK.",
|
||||
"Two fix_usb_autosuspend cases read real sysfs devices (046d:c077 and 046d:0825) because the /sys path is hardcoded in the lib. Both are read-only and each is wrapped in a guard that turns the case into a pass with an explicit SKIP note if the host's power/control value changes, so the suite cannot silently start asserting nothing.",
|
||||
"The coverage runs were made in a detached worktree, because a second Claude session is writing to this repo concurrently and the jail aborts on any working-tree delta during a run."
|
||||
],
|
||||
"rollback": [
|
||||
"git revert the commit; that restores the bt_pairing.sh allowlist line, removes the UDEV_RULES_DIR override and deletes the test file together.",
|
||||
"After rollback, run bash linux_configuration/scripts/single_use/fixes/lib/tests/run_all.sh and confirm the remaining suites pass, then bash meta/scripts/check_shell_coverage.sh to confirm the gate is green with bt_pairing.sh exempt again."
|
||||
]
|
||||
}
|
||||
53
docs/superpowers/evidence/bt-report-coverage-2026-08-22.json
Normal file
53
docs/superpowers/evidence/bt-report-coverage-2026-08-22.json
Normal file
@ -0,0 +1,53 @@
|
||||
{
|
||||
"intent": "Test linux_configuration/scripts/single_use/fixes/lib/bt_report.sh to 100% line coverage and take it off the shell-coverage allowlist, continuing the fixes/lib coverage campaign.",
|
||||
"scope": [
|
||||
"linux_configuration/scripts/single_use/fixes/lib/tests/lib_test_core.sh (new shared assertion/sandbox primitives)",
|
||||
"linux_configuration/scripts/single_use/fixes/lib/tests/bt_harness.sh (new fix_bluetooth.sh family harness)",
|
||||
"linux_configuration/scripts/single_use/fixes/lib/tests/test_bt_report.sh (new, 24 assertions)",
|
||||
"meta/shell-coverage-allowlist.txt (one line removed)",
|
||||
"Non-goal: refactoring pacman_hook_stall_harness.sh, whose six libs are already gated at 100% with no exemption",
|
||||
"Non-goal: the remaining 15 untested fixes/lib libs, handled in later commits"
|
||||
],
|
||||
"changes": [
|
||||
"Added lib_test_core.sh: PASS/FAIL tally, _t_eq/_t_contains/_t_lacks assertions, a mktemp -d sandbox wiped on EXIT, a FAKE_BIN stub dir on PATH, and _t_stub/_t_unstub. _t_unstub runs `hash -r`, because removing a stub file alone does not drop bash's cached executable path.",
|
||||
"Added bt_harness.sh: sources lib_test_core.sh, sources the real scripts/lib/common.sh for the production log_*/has_cmd helpers (verified inert at source time), and redefines _btctl and apply_fix verbatim from fix_bluetooth.sh since those live in the entry script rather than in any lib.",
|
||||
"Added _t_only_path, which drops PATH to FAKE_BIN alone: every tool these libs call (usbreset, pactl, lsusb, ...) genuinely exists on this host, so a prepended stub dir cannot exercise a 'not installed' branch.",
|
||||
"Added test_bt_report.sh covering show_instructions (both the known-MAC and <MAC>-placeholder branches) and dump_diagnostics (populated output, the (none loaded)/(rfkill not available) fallbacks, the empty-TARGET_MAC skip, and the (device not known) arm).",
|
||||
"Removed linux_configuration/scripts/single_use/fixes/lib/bt_report.sh from meta/shell-coverage-allowlist.txt."
|
||||
],
|
||||
"verification": [
|
||||
{
|
||||
"command": "bash linux_configuration/scripts/single_use/fixes/lib/tests/run_all.sh",
|
||||
"result": "pass",
|
||||
"evidence": "test_bt_report.sh: 24 passed, 0 failed. All fixes lib test files passed -- the eight pre-existing pacman_hook_stall suites stay green alongside the new file."
|
||||
},
|
||||
{
|
||||
"command": "bash meta/scripts/shell_coverage_jail.sh --subject linux_configuration/scripts/single_use/fixes/lib/tests/run_all.sh --measure bt_report.sh --min 1 --fail-on-case-error -- \"\"",
|
||||
"result": "pass",
|
||||
"evidence": "bt_report.sh: 37/37 lines = 100.00%. Measured through run_all.sh, the subject is_covered() builds. No 'outside kcov's line set' lines were reported, so the figure covers every statement kcov instrumented."
|
||||
},
|
||||
{
|
||||
"command": "bash meta/scripts/shell_coverage_jail.sh --subject linux_configuration/scripts/single_use/fixes/lib/tests/run_all.sh --measure bt_report.sh --min 100 --fail-on-case-error -- \"\"",
|
||||
"result": "pass",
|
||||
"evidence": "bt_report.sh: 37/37 lines = 100.00%, exit code 0. Second matching run at the --min 100 bar, so a shortfall would have been a non-zero exit rather than a number to misread."
|
||||
},
|
||||
{
|
||||
"command": "bash meta/scripts/check_shell_coverage.sh linux_configuration/scripts/single_use/fixes/lib/bt_report.sh",
|
||||
"result": "pass",
|
||||
"evidence": "'check_shell_coverage.sh: every checked shell library meets the coverage bar', exit 0, run with the allowlist line already removed so the lib had no exemption."
|
||||
},
|
||||
{
|
||||
"command": "jscpd --pattern '**/*.sh' --min-lines 14 --min-tokens 25 --threshold 2 (the pre-commit hook's exact flags)",
|
||||
"result": "pass",
|
||||
"evidence": "444 files, 27 clones, 933 duplicated lines = 1.6%, under the 2% threshold. The hook already excludes **/lib/tests/** and **/tests/**, so the shared-core harness design carries no duplication risk."
|
||||
}
|
||||
],
|
||||
"risks": [
|
||||
"bt_harness.sh copies _btctl and apply_fix from fix_bluetooth.sh, so a change to either in the entry script would leave the harness stale. This is the same trade-off pacman_hook_stall_harness.sh already makes with log_size, and is preferable to moving those helpers into a lib, which would reintroduce a cross-file-global seam.",
|
||||
"The three coverage runs were executed in a detached git worktree under the scratchpad, because a second Claude session was concurrently writing to this repo (phone_focus_mode/config.sh, focus_owner/) and the jail aborts on any working-tree delta during a run. The measurement subject and libs were identical to HEAD; only the tree's isolation differed."
|
||||
],
|
||||
"rollback": [
|
||||
"git revert the commit; that restores the bt_report.sh line in meta/shell-coverage-allowlist.txt and deletes the three new test files together.",
|
||||
"After rollback, run bash linux_configuration/scripts/single_use/fixes/lib/tests/run_all.sh and confirm the eight pacman_hook_stall suites still pass, then bash meta/scripts/check_shell_coverage.sh to confirm the gate is green with bt_report.sh exempt again."
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
{
|
||||
"intent": "Let a newly installed lyricanki appear on the phone. Focus Owner hides every package absent from the allowlist, so lyricanki installed as installed=true hidden=true: missing from the launcher and from `pm list packages`, and `am start` reported the activity did not exist even though dumpsys listed its MAIN/LAUNCHER filter.",
|
||||
"scope": [
|
||||
"phone_focus_mode/config.sh - add com.kuhy.lyricanki to WHITELIST",
|
||||
"focus_owner/assets/policy.json - regenerated, never hand-edited",
|
||||
"Non-goal: night curfew. lyricanki is a day-list app only.",
|
||||
"Non-goal: any change to enforcement logic."
|
||||
],
|
||||
"changes": [
|
||||
"Added com.kuhy.lyricanki to the 'kuhy's own apps' block of WHITELIST, alphabetically.",
|
||||
"Regenerated policy.json via `python3 -m python_pkg.focus_policy --redact-home`; the diff is the single added entry in allowed_packages.",
|
||||
"Dropped com.android.launcher3 and com.android.camera2 from SYSTEM_NEVER_DISABLE. Both are strict supersets of entries already present (com.android.launcher, com.android.camera) and that list is prefix-matched, so coverage is unchanged; this kept config.sh under the 250-line cap without weakening the policy. com.android.settings was NOT removed: its only shorter match is com.android.se, an accidental substring rather than intent."
|
||||
],
|
||||
"verification": [
|
||||
{
|
||||
"command": "python3 -c \"json ... never_disable_prefixes coverage check\"",
|
||||
"result": "pass",
|
||||
"evidence": "launcher3 covered: True, camera2 covered: True, settings covered: True - prefix semantics identical before and after the two removals."
|
||||
},
|
||||
{
|
||||
"command": "bash ~/.claude/scripts/phone_deploy.sh ~/testsAndMisc/focus_owner --release",
|
||||
"result": "pass",
|
||||
"evidence": "release signer 9dcc2e6c...f846 matched the installed APK's signer, so `adb install -r` was an in-place upgrade with no uninstall. 'Success'."
|
||||
},
|
||||
{
|
||||
"command": "adb shell dpm list-owners",
|
||||
"result": "pass",
|
||||
"evidence": "User 0: admin=com.kuhy.focus_owner/.FocusDeviceAdminReceiver,DeviceOwner - Device Owner survived the upgrade."
|
||||
},
|
||||
{
|
||||
"command": "adb shell dumpsys package <pkg> | grep hidden",
|
||||
"result": "pass",
|
||||
"evidence": "com.kuhy.lyricanki hidden=false (was true). Regression spot-checks: com.kuhy.workout_app hidden=false, org.fossify.phone hidden=false."
|
||||
}
|
||||
],
|
||||
"risks": [
|
||||
"Reinstalling the Device Owner app is unrecoverable if the signature ever differs: DO cannot be re-provisioned on an unrooted Pixel without a factory reset. Mitigated by comparing the keystore's SHA-256 against the installed APK's before building, and by pulling the live versionCode 2 APK as a rollback artifact first.",
|
||||
"A misparsed allowlist could hide the dialer or launcher. Checked explicitly after install rather than assuming."
|
||||
],
|
||||
"rollback": [
|
||||
"adb install -r <scratchpad>/focus_owner-installed-vc2.apk (pulled from the device before the upgrade; same signer, so it reinstalls in place).",
|
||||
"git revert the config.sh + policy.json commit and regenerate.",
|
||||
"After rollback confirm: dpm list-owners still reports DeviceOwner, and org.fossify.phone is hidden=false."
|
||||
]
|
||||
}
|
||||
@ -11,6 +11,7 @@
|
||||
"com.kuhy.diet_guard_app",
|
||||
"com.kuhy.focus_owner",
|
||||
"com.kuhy.home_inventory",
|
||||
"com.kuhy.lyricanki",
|
||||
"com.kuhy.untools",
|
||||
"com.kuhy.wake_alarm_sync",
|
||||
"com.kuhy.workout_app",
|
||||
@ -65,7 +66,6 @@
|
||||
"android",
|
||||
"com.android.bluetooth",
|
||||
"com.android.camera",
|
||||
"com.android.camera2",
|
||||
"com.android.captiveportallogin",
|
||||
"com.android.certinstaller",
|
||||
"com.android.contacts",
|
||||
@ -76,7 +76,6 @@
|
||||
"com.android.inputmethod",
|
||||
"com.android.keychain",
|
||||
"com.android.launcher",
|
||||
"com.android.launcher3",
|
||||
"com.android.location",
|
||||
"com.android.messaging",
|
||||
"com.android.mms",
|
||||
|
||||
@ -114,14 +114,17 @@ _disable_usb_autosuspend() {
|
||||
local product="$3"
|
||||
|
||||
# Immediate fix
|
||||
echo "on" > "$power_control"
|
||||
echo "on" >"$power_control"
|
||||
|
||||
# Persistent udev rule
|
||||
local rule_file="/etc/udev/rules.d/50-bluetooth-no-autosuspend.rules"
|
||||
# Persistent udev rule. UDEV_RULES_DIR defaults to the real directory and
|
||||
# is only overridden by the test suite, which cannot be allowed to write
|
||||
# to /etc: lib/tests/run_all.sh runs UN-jailed in ci_mirror.sh and in CI,
|
||||
# so a bind mount would protect the coverage run and nothing else.
|
||||
local rule_file="${UDEV_RULES_DIR:-/etc/udev/rules.d}/50-bluetooth-no-autosuspend.rules"
|
||||
local rule="ACTION==\"add\", SUBSYSTEM==\"usb\", ATTR{idVendor}==\"$vendor\", ATTR{idProduct}==\"$product\", ATTR{power/control}=\"on\""
|
||||
|
||||
if [[ ! -f $rule_file ]] || ! grep -qF "$vendor" "$rule_file" 2>/dev/null; then
|
||||
echo "$rule" > "$rule_file"
|
||||
echo "$rule" >"$rule_file"
|
||||
udevadm control --reload-rules 2>/dev/null || true
|
||||
log_info "Created persistent udev rule: $rule_file"
|
||||
fi
|
||||
|
||||
138
linux_configuration/scripts/single_use/fixes/lib/tests/bt_harness.sh
Executable file
138
linux_configuration/scripts/single_use/fixes/lib/tests/bt_harness.sh
Executable file
@ -0,0 +1,138 @@
|
||||
#!/usr/bin/env bash
|
||||
# lib/tests/bt_harness.sh — shared setup for the fix_bluetooth.sh lib tests
|
||||
# (bt_report.sh, bt_adapter.sh, bt_pairing.sh, bt_audio.sh).
|
||||
#
|
||||
# Sourced, not executed. Builds on lib_test_core.sh (tmpdir, $FAKE_BIN on
|
||||
# PATH, the _t_* assertions) and adds the three things the bt libs need:
|
||||
#
|
||||
# 1. the real log_*/has_cmd helpers, by sourcing scripts/lib/common.sh --
|
||||
# it is inert at source time (a load guard, two exports and three
|
||||
# sub-sources), so the libs get the exact helpers they see in production
|
||||
# rather than reimplementations that could drift;
|
||||
# 2. _btctl and apply_fix, which live in fix_bluetooth.sh itself rather
|
||||
# than in any lib. Redefined here verbatim from the entry script so the
|
||||
# libs resolve them exactly as they do when sourced for real -- the same
|
||||
# approach pacman_hook_stall_harness.sh takes with log_size;
|
||||
# 3. stubs for the external tools the bt libs shell out to.
|
||||
#
|
||||
# Every tool these libs call (dmesg, wget, lsusb, modprobe, pactl, usbreset,
|
||||
# bluetoothctl, rfkill...) genuinely exists on an Arch desktop, so a
|
||||
# PREPENDED stub dir cannot exercise a "not installed" branch. _t_only_path
|
||||
# below drops PATH to $FAKE_BIN alone for exactly those cases.
|
||||
set -uo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
FIXES_DIR="$(cd "${SCRIPT_DIR}/../.." && pwd)"
|
||||
REPO_ROOT="$(cd "${FIXES_DIR}/../../../.." && pwd)"
|
||||
|
||||
# shellcheck source=lib_test_core.sh
|
||||
. "${SCRIPT_DIR}/lib_test_core.sh"
|
||||
|
||||
# Real logging/has_cmd/ask_yes_no helpers, as the entry script gets them.
|
||||
# shellcheck source=../../../../lib/common.sh
|
||||
. "${REPO_ROOT}/linux_configuration/scripts/lib/common.sh"
|
||||
|
||||
# --- pieces that live in fix_bluetooth.sh, not in a lib ---------------------
|
||||
|
||||
# Verbatim from fix_bluetooth.sh: bluetoothctl returns empty when driven with
|
||||
# `-- <cmd>`, so the real script pipes the command in on stdin.
|
||||
_btctl() {
|
||||
echo "$*" | bluetoothctl 2>/dev/null
|
||||
}
|
||||
|
||||
FIXES_APPLIED=0
|
||||
FIXES_SKIPPED=0
|
||||
INTERACTIVE_MODE="false"
|
||||
|
||||
# Verbatim from fix_bluetooth.sh. The libs call apply_fix for every mutating
|
||||
# action, so it is the seam most assertions read: $DEV/fixes records the
|
||||
# description of each fix that actually ran.
|
||||
apply_fix() {
|
||||
local description="$1"
|
||||
shift
|
||||
|
||||
echo ""
|
||||
log_info "$description"
|
||||
printf '%s\n' "$description" >>"${DEV}/fixes"
|
||||
|
||||
if [[ $INTERACTIVE_MODE == "true" ]]; then
|
||||
if ! ask_yes_no " Apply this fix?"; then
|
||||
log_warn "Skipped."
|
||||
((FIXES_SKIPPED++)) || true
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
if "$@"; then
|
||||
log_ok "Done."
|
||||
((FIXES_APPLIED++)) || true
|
||||
else
|
||||
log_error "Failed (non-fatal, continuing)."
|
||||
fi
|
||||
}
|
||||
|
||||
# --- external tool stubs ----------------------------------------------------
|
||||
|
||||
# Default every tool the bt libs touch to a quiet success. Individual tests
|
||||
# re-stub the one tool they care about via _t_stub.
|
||||
_bt_default_stubs() {
|
||||
local tool
|
||||
for tool in dmesg wget curl lsusb modprobe dbus-send pactl wpctl \
|
||||
bluetoothctl rfkill lsmod usbreset systemctl journalctl sudo id \
|
||||
udevadm; do
|
||||
_t_stub "$tool" 'exit 0'
|
||||
done
|
||||
# `id -u <user>` feeds _run_as_user's XDG_RUNTIME_DIR path.
|
||||
_t_stub id 'echo 1000'
|
||||
# sudo -u <user> VAR=... <cmd> ... -- drop sudo's own arguments and exec
|
||||
# the wrapped command, so _run_as_user reaches the stubbed tool. Held in
|
||||
# a quoted heredoc: every $ in here belongs to the stub, not to us.
|
||||
local sudo_body
|
||||
sudo_body="$(
|
||||
cat <<'SUDO_BODY'
|
||||
shift 2 2>/dev/null || true
|
||||
while [[ "${1:-}" == *=* ]]; do shift; done
|
||||
[[ $# -gt 0 ]] || exit 0
|
||||
exec "$@"
|
||||
SUDO_BODY
|
||||
)"
|
||||
_t_stub sudo "$sudo_body"
|
||||
}
|
||||
|
||||
# _t_only_path — restrict PATH to $FAKE_BIN plus coreutils, so a tool absent
|
||||
# from $FAKE_BIN is genuinely "not installed" as far as has_cmd/command -v is
|
||||
# concerned. Used for the has_cmd false branches.
|
||||
_t_only_path() {
|
||||
PATH="${FAKE_BIN}"
|
||||
hash -r
|
||||
}
|
||||
|
||||
# _t_full_path — restore the prepended-stub PATH set up by lib_test_core.sh.
|
||||
_t_full_path() {
|
||||
PATH="${FAKE_BIN}:${LIB_TEST_ORIG_PATH}"
|
||||
hash -r
|
||||
}
|
||||
|
||||
export LIB_TEST_ORIG_PATH="${PATH#"${FAKE_BIN}:"}"
|
||||
|
||||
# bt_reset — start a test group from "nothing has happened yet".
|
||||
bt_reset() {
|
||||
_t_reset_calls
|
||||
: >"${DEV}/fixes"
|
||||
FIXES_APPLIED=0
|
||||
FIXES_SKIPPED=0
|
||||
INTERACTIVE_MODE="false"
|
||||
TARGET_MAC="F8:5C:7E:0E:50:6B"
|
||||
_t_full_path
|
||||
_bt_default_stubs
|
||||
}
|
||||
|
||||
# _t_fixes — the descriptions of the fixes apply_fix ran this round.
|
||||
_t_fixes() {
|
||||
cat "${DEV}/fixes" 2>/dev/null || true
|
||||
}
|
||||
|
||||
# TARGET_MAC is read by the bt libs under test, never by this harness, so
|
||||
# static analysis cannot see the use. export makes the intent explicit.
|
||||
export TARGET_MAC="F8:5C:7E:0E:50:6B"
|
||||
bt_reset
|
||||
112
linux_configuration/scripts/single_use/fixes/lib/tests/lib_test_core.sh
Executable file
112
linux_configuration/scripts/single_use/fixes/lib/tests/lib_test_core.sh
Executable file
@ -0,0 +1,112 @@
|
||||
#!/usr/bin/env bash
|
||||
# lib/tests/lib_test_core.sh — assertion + sandbox primitives shared by the
|
||||
# per-family harnesses in this directory.
|
||||
#
|
||||
# Sourced, not executed. Provides exactly the pieces every family needs and
|
||||
# nothing family-specific: a PASS/FAIL tally, the _t_* assertions, a
|
||||
# throwaway $TEST_TMPDIR wiped on EXIT, and a $FAKE_BIN stub directory
|
||||
# prepended to PATH.
|
||||
#
|
||||
# Deliberately does NOT touch pacman_hook_stall_harness.sh, which predates it
|
||||
# and whose six libs are already off the coverage allowlist -- i.e. gated at
|
||||
# 100% with no exemption. Refactoring that harness to sit on top of this one
|
||||
# would put banked work at risk for no coverage gain.
|
||||
set -uo pipefail
|
||||
|
||||
PASS=0
|
||||
FAIL=0
|
||||
|
||||
_t_pass() {
|
||||
PASS=$((PASS + 1))
|
||||
printf ' OK: %s\n' "$1"
|
||||
}
|
||||
|
||||
_t_fail() {
|
||||
FAIL=$((FAIL + 1))
|
||||
printf ' FAIL: %s\n' "$1"
|
||||
}
|
||||
|
||||
_t_eq() {
|
||||
local want="$1" got="$2" what="$3"
|
||||
if [[ "$got" == "$want" ]]; then
|
||||
_t_pass "$what"
|
||||
else
|
||||
_t_fail "$what (want '${want}', got '${got}')"
|
||||
fi
|
||||
}
|
||||
|
||||
# _t_contains HAYSTACK NEEDLE WHAT — substring assertion.
|
||||
_t_contains() {
|
||||
local haystack="$1" needle="$2" what="$3"
|
||||
if [[ "$haystack" == *"$needle"* ]]; then
|
||||
_t_pass "$what"
|
||||
else
|
||||
_t_fail "$what (expected to contain '${needle}', got: ${haystack})"
|
||||
fi
|
||||
}
|
||||
|
||||
# _t_lacks HAYSTACK NEEDLE WHAT — negative substring assertion.
|
||||
_t_lacks() {
|
||||
local haystack="$1" needle="$2" what="$3"
|
||||
if [[ "$haystack" != *"$needle"* ]]; then
|
||||
_t_pass "$what"
|
||||
else
|
||||
_t_fail "$what (expected NOT to contain '${needle}', got: ${haystack})"
|
||||
fi
|
||||
}
|
||||
|
||||
TEST_TMPDIR="$(mktemp -d)"
|
||||
trap 'rm -rf "${TEST_TMPDIR}"' EXIT
|
||||
|
||||
readonly DEV="${TEST_TMPDIR}/device"
|
||||
readonly FAKE_BIN="${TEST_TMPDIR}/fake_bin"
|
||||
mkdir -p "${DEV}" "${FAKE_BIN}"
|
||||
: >"${DEV}/calls"
|
||||
|
||||
export PATH="${FAKE_BIN}:${PATH}"
|
||||
|
||||
# _t_stub NAME BODY — write an executable stub NAME into $FAKE_BIN whose body
|
||||
# is BODY, then drop bash's cached path for NAME.
|
||||
#
|
||||
# Every stub records its own invocation into $DEV/calls before running BODY,
|
||||
# so _t_calls works uniformly without each stub repeating the boilerplate.
|
||||
_t_stub() {
|
||||
local name="$1" body="$2"
|
||||
# The recording preamble is written with a quoted heredoc so $0 and $@
|
||||
# reach the stub file unexpanded and expand when the STUB runs. Using
|
||||
# $0/$@ rather than the stub's literal name is what keeps this a plain
|
||||
# heredoc with nothing for the writer to interpolate.
|
||||
cat >"${FAKE_BIN}/${name}" <<'STUB_PREAMBLE'
|
||||
#!/usr/bin/env bash
|
||||
printf '%s %s\n' "${0##*/}" "$*" >>"${LIB_TEST_DEV}/calls"
|
||||
STUB_PREAMBLE
|
||||
printf '%s\n' "$body" >>"${FAKE_BIN}/${name}"
|
||||
chmod +x "${FAKE_BIN}/${name}"
|
||||
hash -r
|
||||
}
|
||||
|
||||
# _t_unstub NAME... — remove stubs and drop bash's cached executable paths.
|
||||
#
|
||||
# `rm` alone does NOT hide a stub: bash caches the resolved location of every
|
||||
# command it has run, so a later call re-executes the deleted file's path and
|
||||
# fails with "No such file or directory" instead of falling through to the
|
||||
# real binary. `hash -r` is the part that matters.
|
||||
_t_unstub() {
|
||||
local name
|
||||
for name in "$@"; do
|
||||
rm -f "${FAKE_BIN}/${name}"
|
||||
done
|
||||
hash -r
|
||||
}
|
||||
|
||||
# _t_calls — print everything the stubs recorded this round.
|
||||
_t_calls() {
|
||||
cat "${DEV}/calls" 2>/dev/null || true
|
||||
}
|
||||
|
||||
# _t_reset_calls — start a fresh recording window.
|
||||
_t_reset_calls() {
|
||||
: >"${DEV}/calls"
|
||||
}
|
||||
|
||||
export LIB_TEST_DEV="${DEV}"
|
||||
98
linux_configuration/scripts/single_use/fixes/lib/tests/test_bt_pairing.sh
Executable file
98
linux_configuration/scripts/single_use/fixes/lib/tests/test_bt_pairing.sh
Executable file
@ -0,0 +1,98 @@
|
||||
#!/usr/bin/env bash
|
||||
# Tests for lib/bt_pairing.sh: remove_stale_pairing, restart_bluetooth and
|
||||
# fix_usb_autosuspend.
|
||||
set -uo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# shellcheck source=bt_harness.sh
|
||||
. "${SCRIPT_DIR}/bt_harness.sh"
|
||||
|
||||
# shellcheck source=../bt_pairing.sh
|
||||
. "${FIXES_DIR}/lib/bt_pairing.sh"
|
||||
|
||||
# _btctl_info BODY — stub bluetoothctl so `_btctl info <mac>` returns BODY.
|
||||
_btctl_info() {
|
||||
local body="$1"
|
||||
local stub
|
||||
stub="$(
|
||||
cat <<'BTCTL_HEAD'
|
||||
read -r cmd rest
|
||||
if [[ "$cmd" == "info" ]]; then
|
||||
cat "${LIB_TEST_DEV}/btctl_info"
|
||||
fi
|
||||
exit 0
|
||||
BTCTL_HEAD
|
||||
)"
|
||||
printf '%s\n' "$body" >"${DEV}/btctl_info"
|
||||
_t_stub bluetoothctl "$stub"
|
||||
}
|
||||
|
||||
# --- remove_stale_pairing ---------------------------------------------------
|
||||
|
||||
bt_reset
|
||||
TARGET_MAC=""
|
||||
out="$(remove_stale_pairing)"
|
||||
_t_eq "" "$out" "remove_stale_pairing: no output when TARGET_MAC is empty"
|
||||
_t_eq "" "$(_t_fixes)" "remove_stale_pairing: applies no fix when TARGET_MAC is empty"
|
||||
|
||||
# Paired but not connected — the stale-pairing case the function exists for.
|
||||
bt_reset
|
||||
TARGET_MAC="AA:BB:CC:DD:EE:FF"
|
||||
_btctl_info "Device AA:BB:CC:DD:EE:FF JBL
|
||||
Paired: yes
|
||||
Connected: no"
|
||||
out="$(remove_stale_pairing 2>&1)"
|
||||
_t_contains "$out" "stale pairing" \
|
||||
"remove_stale_pairing: warns when the device is paired but not connected"
|
||||
_t_contains "$out" "Removing stale pairing for AA:BB:CC:DD:EE:FF" \
|
||||
"remove_stale_pairing: applies the removal fix for a stale pairing"
|
||||
|
||||
# Paired AND connected — healthy, nothing to do.
|
||||
bt_reset
|
||||
TARGET_MAC="AA:BB:CC:DD:EE:FF"
|
||||
_btctl_info "Device AA:BB:CC:DD:EE:FF JBL
|
||||
Paired: yes
|
||||
Connected: yes"
|
||||
out="$(remove_stale_pairing 2>&1)"
|
||||
_t_contains "$out" "paired and connected" \
|
||||
"remove_stale_pairing: reports a healthy device as paired and connected"
|
||||
_t_lacks "$out" "Removing stale pairing" \
|
||||
"remove_stale_pairing: applies no fix when the device is connected"
|
||||
|
||||
# Known to the adapter but not paired at all.
|
||||
bt_reset
|
||||
TARGET_MAC="AA:BB:CC:DD:EE:FF"
|
||||
_btctl_info "Device AA:BB:CC:DD:EE:FF JBL
|
||||
Paired: no
|
||||
Connected: no"
|
||||
out="$(remove_stale_pairing 2>&1)"
|
||||
_t_contains "$out" "not currently paired" \
|
||||
"remove_stale_pairing: reports an unpaired device as not paired"
|
||||
_t_lacks "$out" "Removing stale pairing" \
|
||||
"remove_stale_pairing: applies no fix when the device is not paired"
|
||||
|
||||
# Device entirely unknown to bluetoothctl.
|
||||
bt_reset
|
||||
TARGET_MAC="11:22:33:44:55:66"
|
||||
_btctl_info "No default controller available"
|
||||
out="$(remove_stale_pairing 2>&1)"
|
||||
_t_contains "$out" "Fresh pairing needed" \
|
||||
"remove_stale_pairing: asks for fresh pairing when the device is unknown"
|
||||
|
||||
# --- restart_bluetooth ------------------------------------------------------
|
||||
|
||||
bt_reset
|
||||
FIXES_APPLIED=0
|
||||
out="$(restart_bluetooth 2>&1)"
|
||||
_t_contains "$out" "skipping service restart" \
|
||||
"restart_bluetooth: skips the restart when no fixes were applied"
|
||||
|
||||
bt_reset
|
||||
FIXES_APPLIED=2
|
||||
out="$(restart_bluetooth 2>&1)"
|
||||
_t_contains "$out" "Restarting bluetooth.service" \
|
||||
"restart_bluetooth: restarts the service when fixes were applied"
|
||||
|
||||
echo
|
||||
echo "bt_pairing (stale pairing + restart): ${PASS} passed, ${FAIL} failed"
|
||||
((FAIL == 0))
|
||||
173
linux_configuration/scripts/single_use/fixes/lib/tests/test_bt_pairing_usb.sh
Executable file
173
linux_configuration/scripts/single_use/fixes/lib/tests/test_bt_pairing_usb.sh
Executable file
@ -0,0 +1,173 @@
|
||||
#!/usr/bin/env bash
|
||||
# Tests for lib/bt_pairing.sh: fix_usb_autosuspend and
|
||||
# _disable_usb_autosuspend, split from test_bt_pairing.sh for the 250-line cap.
|
||||
set -uo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# shellcheck source=bt_harness.sh
|
||||
. "${SCRIPT_DIR}/bt_harness.sh"
|
||||
|
||||
# shellcheck source=../bt_pairing.sh
|
||||
. "${FIXES_DIR}/lib/bt_pairing.sh"
|
||||
|
||||
# --- fix_usb_autosuspend ----------------------------------------------------
|
||||
#
|
||||
# This function globs the REAL /sys/bus/usb/devices/*/ -- the path is
|
||||
# hardcoded, with no env override to point elsewhere. Rather than bind-mount
|
||||
# or write anything, each case drives the branch it wants through the stubbed
|
||||
# `lsusb` output:
|
||||
#
|
||||
# * a vendor:product of ffff:ffff matches no device on any machine, so the
|
||||
# loop runs to exhaustion and takes the "could not find sysfs path" arm;
|
||||
# * a vendor:product that IS present on this host reaches the power/control
|
||||
# read, and _disable_usb_autosuspend is stubbed IN A SUBSHELL for those
|
||||
# cases so the udev rule and the sysfs write never happen.
|
||||
#
|
||||
# A top-level redefinition would shadow the real function for every later
|
||||
# assertion, so each override is confined to its own subshell.
|
||||
|
||||
# _lsusb_line TEXT — stub lsusb to emit a single line of TEXT.
|
||||
_lsusb_line() {
|
||||
printf '%s\n' "$1" >"${DEV}/lsusb_out"
|
||||
local body
|
||||
body="$(
|
||||
cat <<'LSUSB_BODY'
|
||||
cat "${LIB_TEST_DEV}/lsusb_out"
|
||||
LSUSB_BODY
|
||||
)"
|
||||
_t_stub lsusb "$body"
|
||||
}
|
||||
|
||||
# No bluetooth device in lsusb at all: the function returns before any lookup.
|
||||
bt_reset
|
||||
_t_stub lsusb 'echo "Bus 001 Device 002: ID 046d:c077 Logitech, Inc. Mouse"'
|
||||
out="$(fix_usb_autosuspend 2>&1)"
|
||||
_t_contains "$out" "Checking USB autosuspend" \
|
||||
"fix_usb_autosuspend: announces the check"
|
||||
_t_eq "" "$(_t_fixes)" \
|
||||
"fix_usb_autosuspend: applies no fix when lsusb lists no bluetooth device"
|
||||
|
||||
# A bluetooth line with no parseable ID: the usb_id guard returns early.
|
||||
bt_reset
|
||||
_lsusb_line "Bus 001 Device 003: Bluetooth adapter with no id field"
|
||||
out="$(fix_usb_autosuspend 2>&1)"
|
||||
_t_eq "" "$(_t_fixes)" \
|
||||
"fix_usb_autosuspend: applies no fix when the bluetooth line has no ID"
|
||||
|
||||
# A well-formed ID that matches no real device: the sysfs scan finds nothing.
|
||||
bt_reset
|
||||
_lsusb_line "Bus 001 Device 004: ID ffff:ffff Bluetooth Device"
|
||||
out="$(fix_usb_autosuspend 2>&1)"
|
||||
_t_contains "$out" "Could not find sysfs path" \
|
||||
"fix_usb_autosuspend: warns when no sysfs device matches the USB ID"
|
||||
_t_eq "" "$(_t_fixes)" \
|
||||
"fix_usb_autosuspend: applies no fix when the sysfs path is not found"
|
||||
|
||||
# A device whose power/control is already "on" needs no change. 046d:c077 is
|
||||
# present on this host with control=on; skipped if that ever stops holding.
|
||||
bt_reset
|
||||
if grep -qx "on" /sys/bus/usb/devices/1-11/power/control 2>/dev/null; then
|
||||
_lsusb_line "Bus 001 Device 005: ID 046d:c077 Bluetooth Device"
|
||||
out="$(fix_usb_autosuspend 2>&1)"
|
||||
_t_contains "$out" "already disabled" \
|
||||
"fix_usb_autosuspend: reports autosuspend already disabled when control is on"
|
||||
_t_eq "" "$(_t_fixes)" \
|
||||
"fix_usb_autosuspend: applies no fix when control is already on"
|
||||
else
|
||||
_t_pass "fix_usb_autosuspend: SKIP already-on case (1-11 control is not 'on' here)"
|
||||
fi
|
||||
|
||||
# _record_disable ARGS... — stand-in for the real writer, recording only.
|
||||
_record_disable() {
|
||||
printf 'disable_called %s\n' "$*" >>"${DEV}/fixes"
|
||||
}
|
||||
|
||||
# A device whose power/control is "auto" gets the fix. _disable_usb_autosuspend
|
||||
# is replaced INSIDE the subshell so this case proves the arguments handed to
|
||||
# the writer without letting the real writer touch /sys or /etc; the real
|
||||
# writer gets its own direct tests further down. The redefinition must stay in
|
||||
# the subshell, since a top-level one would shadow the real function for every
|
||||
# later assertion in this file.
|
||||
bt_reset
|
||||
if grep -qx "auto" /sys/bus/usb/devices/1-10/power/control 2>/dev/null; then
|
||||
_lsusb_line "Bus 001 Device 006: ID 046d:0825 Bluetooth Device"
|
||||
# _record_disable is defined at top level (so it is plainly a called
|
||||
# function) but only BOUND to the writer's name inside the subshell.
|
||||
out="$(
|
||||
eval '_disable_usb_autosuspend() { _record_disable "$@"; }'
|
||||
fix_usb_autosuspend 2>&1
|
||||
)"
|
||||
_t_contains "$out" "USB autosuspend is enabled" \
|
||||
"fix_usb_autosuspend: warns when autosuspend is enabled"
|
||||
_t_contains "$out" "Disabling USB autosuspend" \
|
||||
"fix_usb_autosuspend: applies the disable fix when control is auto"
|
||||
_t_contains "$(_t_fixes)" "disable_called /sys/bus/usb/devices/1-10/power/control 046d 0825" \
|
||||
"fix_usb_autosuspend: passes the control path, vendor and product to the writer"
|
||||
else
|
||||
_t_pass "fix_usb_autosuspend: SKIP auto case (1-10 control is not 'auto' here)"
|
||||
fi
|
||||
|
||||
# --- _disable_usb_autosuspend ----------------------------------------------
|
||||
#
|
||||
# Called directly, with the REAL body running. Both of its writes are
|
||||
# redirected out of the way rather than stubbed:
|
||||
#
|
||||
# * the sysfs power/control file is already a parameter, so a tmpdir file
|
||||
# covers it;
|
||||
# * the udev rule path is the UDEV_RULES_DIR override the lib exposes for
|
||||
# exactly this. A bind mount was rejected: run_all.sh runs UN-jailed in
|
||||
# ci_mirror.sh and in CI, so binding /etc would make the coverage run
|
||||
# safe and leave every bare run writing to the real file.
|
||||
#
|
||||
# udevadm is already stubbed by _bt_default_stubs.
|
||||
|
||||
bt_reset
|
||||
control_file="${TEST_TMPDIR}/power_control"
|
||||
rules_dir="${TEST_TMPDIR}/udev_rules"
|
||||
rule_file="${rules_dir}/50-bluetooth-no-autosuspend.rules"
|
||||
rm -rf "$rules_dir"
|
||||
mkdir -p "$rules_dir"
|
||||
echo "auto" >"$control_file"
|
||||
|
||||
out="$(UDEV_RULES_DIR="$rules_dir" \
|
||||
_disable_usb_autosuspend "$control_file" "046d" "0825" 2>&1)"
|
||||
|
||||
_t_eq "on" "$(cat "$control_file")" \
|
||||
"_disable_usb_autosuspend: writes 'on' to the sysfs power/control file"
|
||||
_t_contains "$out" "Created persistent udev rule" \
|
||||
"_disable_usb_autosuspend: reports creating the udev rule"
|
||||
_t_contains "$(cat "$rule_file")" 'ATTR{idVendor}=="046d"' \
|
||||
"_disable_usb_autosuspend: writes the vendor into the udev rule"
|
||||
_t_contains "$(cat "$rule_file")" 'ATTR{idProduct}=="0825"' \
|
||||
"_disable_usb_autosuspend: writes the product into the udev rule"
|
||||
_t_contains "$(cat "$rule_file")" 'ATTR{power/control}="on"' \
|
||||
"_disable_usb_autosuspend: pins power/control to on in the udev rule"
|
||||
_t_contains "$(_t_calls)" "udevadm control --reload-rules" \
|
||||
"_disable_usb_autosuspend: reloads udev rules after writing"
|
||||
|
||||
# Second call with the rule already present for this vendor: the guard must
|
||||
# skip the rewrite, so the existing file survives untouched.
|
||||
bt_reset
|
||||
printf '%s\n' "# pre-existing rule for 046d" >"$rule_file"
|
||||
echo "auto" >"$control_file"
|
||||
out="$(UDEV_RULES_DIR="$rules_dir" \
|
||||
_disable_usb_autosuspend "$control_file" "046d" "0825" 2>&1)"
|
||||
_t_eq "# pre-existing rule for 046d" "$(cat "$rule_file")" \
|
||||
"_disable_usb_autosuspend: leaves an existing rule for the same vendor alone"
|
||||
_t_lacks "$out" "Created persistent udev rule" \
|
||||
"_disable_usb_autosuspend: does not claim to create a rule that already existed"
|
||||
_t_eq "on" "$(cat "$control_file")" \
|
||||
"_disable_usb_autosuspend: still writes power/control on the idempotent path"
|
||||
|
||||
# A rule file that exists but covers a DIFFERENT vendor must be rewritten.
|
||||
bt_reset
|
||||
printf '%s\n' "# rule for some other vendor 1234" >"$rule_file"
|
||||
echo "auto" >"$control_file"
|
||||
out="$(UDEV_RULES_DIR="$rules_dir" \
|
||||
_disable_usb_autosuspend "$control_file" "046d" "0825" 2>&1)"
|
||||
_t_contains "$(cat "$rule_file")" 'ATTR{idVendor}=="046d"' \
|
||||
"_disable_usb_autosuspend: rewrites a rule file that covers a different vendor"
|
||||
|
||||
echo
|
||||
echo "bt_pairing (usb autosuspend): ${PASS} passed, ${FAIL} failed"
|
||||
((FAIL == 0))
|
||||
118
linux_configuration/scripts/single_use/fixes/lib/tests/test_bt_report.sh
Executable file
118
linux_configuration/scripts/single_use/fixes/lib/tests/test_bt_report.sh
Executable file
@ -0,0 +1,118 @@
|
||||
#!/usr/bin/env bash
|
||||
# Tests for lib/bt_report.sh: show_instructions and dump_diagnostics.
|
||||
set -uo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# shellcheck source=bt_harness.sh
|
||||
. "${SCRIPT_DIR}/bt_harness.sh"
|
||||
|
||||
# shellcheck source=../bt_report.sh
|
||||
. "${FIXES_DIR}/lib/bt_report.sh"
|
||||
|
||||
# --- show_instructions ------------------------------------------------------
|
||||
|
||||
bt_reset
|
||||
TARGET_MAC="AA:BB:CC:DD:EE:FF"
|
||||
out="$(show_instructions)"
|
||||
_t_contains "$out" "Next Steps" "show_instructions: prints the Next Steps header"
|
||||
_t_contains "$out" "PAIRING mode" "show_instructions: tells the user to enter pairing mode"
|
||||
_t_contains "$out" "pair AA:BB:CC:DD:EE:FF" \
|
||||
"show_instructions: interpolates TARGET_MAC into the pair command"
|
||||
_t_contains "$out" "trust AA:BB:CC:DD:EE:FF" \
|
||||
"show_instructions: interpolates TARGET_MAC into the trust command"
|
||||
_t_contains "$out" "connect AA:BB:CC:DD:EE:FF" \
|
||||
"show_instructions: interpolates TARGET_MAC into the connect command"
|
||||
_t_lacks "$out" "pair <MAC>" \
|
||||
"show_instructions: omits the placeholder form when a MAC is known"
|
||||
_t_contains "$out" "journalctl -u bluetooth -f" \
|
||||
"show_instructions: points at the bluetooth journal on failure"
|
||||
|
||||
# With no MAC known, the placeholder branch runs instead.
|
||||
bt_reset
|
||||
TARGET_MAC=""
|
||||
out="$(show_instructions)"
|
||||
_t_contains "$out" "pair <MAC>" \
|
||||
"show_instructions: falls back to the <MAC> placeholder when TARGET_MAC is empty"
|
||||
_t_contains "$out" "note its MAC address" \
|
||||
"show_instructions: tells the user to note the MAC when none is known"
|
||||
_t_lacks "$out" "trust AA:BB" \
|
||||
"show_instructions: does not emit a concrete MAC when TARGET_MAC is empty"
|
||||
|
||||
# --- dump_diagnostics -------------------------------------------------------
|
||||
|
||||
bt_reset
|
||||
TARGET_MAC="AA:BB:CC:DD:EE:FF"
|
||||
# _btctl pipes the command in on stdin, so the stub dispatches on what it
|
||||
# reads there. Quoted heredoc: the $ belong to the stub, not to this file.
|
||||
btctl_body="$(
|
||||
cat <<'BTCTL_BODY'
|
||||
read -r cmd rest
|
||||
case "$cmd" in
|
||||
show) echo "Controller AA:11 [bluetoothctl]"; echo " Powered: yes" ;;
|
||||
devices) echo "Device AA:BB:CC:DD:EE:FF JBL Charge 5" ;;
|
||||
info) echo " Connected: yes" ;;
|
||||
esac
|
||||
exit 0
|
||||
BTCTL_BODY
|
||||
)"
|
||||
_t_stub bluetoothctl "$btctl_body"
|
||||
# `lsmod | grep -i bluetooth` matches on the module NAME, so the fixture has
|
||||
# to carry a row whose text actually contains "bluetooth" -- bare "btusb" is
|
||||
# filtered out by the lib's own grep, exactly as it would be in production.
|
||||
_t_stub lsmod '
|
||||
echo "btusb 73728 0"
|
||||
echo "bluetooth 995328 9 btrtl,btmtk,btintel,btbcm,btusb"
|
||||
'
|
||||
_t_stub rfkill 'echo "0 bluetooth hci0 unblocked unblocked"'
|
||||
_t_stub journalctl 'echo "bluetoothd[1]: Bluetooth daemon"'
|
||||
|
||||
out="$(dump_diagnostics)"
|
||||
_t_contains "$out" "=== Diagnostic Summary ===" "dump_diagnostics: prints the summary header"
|
||||
_t_contains "$out" "--- Bluetooth adapter ---" "dump_diagnostics: prints the adapter section"
|
||||
_t_contains "$out" "Powered: yes" "dump_diagnostics: includes bluetoothctl show output"
|
||||
_t_lacks "$out" "[bluetoothctl]" \
|
||||
"dump_diagnostics: filters the [bluetoothctl] prompt noise out of show output"
|
||||
_t_contains "$out" "Device AA:BB:CC:DD:EE:FF" "dump_diagnostics: lists known devices"
|
||||
_t_contains "$out" "bluetooth 995328" \
|
||||
"dump_diagnostics: reports loaded bluetooth kernel modules"
|
||||
_t_lacks "$out" "(none loaded)" \
|
||||
"dump_diagnostics: omits the '(none loaded)' fallback when a module matches"
|
||||
_t_contains "$out" "--- rfkill status ---" "dump_diagnostics: prints the rfkill section"
|
||||
_t_contains "$out" "--- Device info: AA:BB:CC:DD:EE:FF ---" \
|
||||
"dump_diagnostics: dumps info for the target device when a MAC is set"
|
||||
_t_contains "$out" "Bluetooth daemon" "dump_diagnostics: includes recent journal entries"
|
||||
|
||||
# Empty results still print their section, via the `|| echo`/`|| true` arms.
|
||||
bt_reset
|
||||
TARGET_MAC=""
|
||||
_t_stub bluetoothctl 'exit 0'
|
||||
_t_stub lsmod 'echo "ext4 1000 0"'
|
||||
_t_stub rfkill 'exit 1'
|
||||
_t_stub journalctl 'exit 1'
|
||||
|
||||
out="$(dump_diagnostics)"
|
||||
_t_contains "$out" "(none loaded)" \
|
||||
"dump_diagnostics: reports '(none loaded)' when no bluetooth module matches"
|
||||
_t_contains "$out" "(rfkill not available)" \
|
||||
"dump_diagnostics: reports rfkill unavailable when the command fails"
|
||||
_t_lacks "$out" "--- Device info:" \
|
||||
"dump_diagnostics: skips the device-info section when TARGET_MAC is empty"
|
||||
|
||||
# A device the adapter does not know about takes the `|| echo` arm.
|
||||
bt_reset
|
||||
TARGET_MAC="11:22:33:44:55:66"
|
||||
btctl_body="$(
|
||||
cat <<'BTCTL_INFO_FAILS'
|
||||
read -r cmd rest
|
||||
[[ "$cmd" == "info" ]] && exit 1
|
||||
exit 0
|
||||
BTCTL_INFO_FAILS
|
||||
)"
|
||||
_t_stub bluetoothctl "$btctl_body"
|
||||
out="$(dump_diagnostics)"
|
||||
_t_contains "$out" "(device not known)" \
|
||||
"dump_diagnostics: reports an unknown device when bluetoothctl info fails"
|
||||
|
||||
echo
|
||||
echo "bt_report: ${PASS} passed, ${FAIL} failed"
|
||||
((FAIL == 0))
|
||||
@ -81,8 +81,6 @@ linux_configuration/scripts/single_use/fixes/lib/arch_perf_report.sh
|
||||
linux_configuration/scripts/single_use/fixes/lib/arch_sysctl.sh
|
||||
linux_configuration/scripts/single_use/fixes/lib/bt_adapter.sh
|
||||
linux_configuration/scripts/single_use/fixes/lib/bt_audio.sh
|
||||
linux_configuration/scripts/single_use/fixes/lib/bt_pairing.sh
|
||||
linux_configuration/scripts/single_use/fixes/lib/bt_report.sh
|
||||
linux_configuration/scripts/single_use/fixes/lib/hosts_guard_migrate.sh
|
||||
linux_configuration/scripts/single_use/fixes/lib/hosts_guard_rollback.sh
|
||||
linux_configuration/scripts/single_use/fixes/lib/nvidia_config.sh
|
||||
|
||||
@ -123,6 +123,7 @@ com.kunzisoft.keepass.libre
|
||||
# --- kuhy's own apps ---
|
||||
com.kuhy.diet_guard_app
|
||||
com.kuhy.home_inventory
|
||||
com.kuhy.lyricanki
|
||||
com.kuhy.untools
|
||||
com.kuhy.wake_alarm_sync
|
||||
com.kuhy.workout_app
|
||||
@ -204,7 +205,6 @@ pl.infakt.infakt
|
||||
# just the filter. Must outrank every enforcement branch.
|
||||
com.celzero.bravedns
|
||||
com.android.launcher
|
||||
com.android.launcher3
|
||||
com.android.settings
|
||||
com.android.systemui
|
||||
com.android.phone
|
||||
@ -224,7 +224,6 @@ com.android.vpndialogs
|
||||
com.android.se
|
||||
com.android.emergency
|
||||
com.android.camera
|
||||
com.android.camera2
|
||||
com.android.documentsui
|
||||
com.android.externalstorage
|
||||
com.android.keychain
|
||||
|
||||
Loading…
Reference in New Issue
Block a user