mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-10 20:07:04 +01:00
Test arch_perf_probes.sh to 100%: allowlist 93 -> 92
Sixth of the 16 untested fixes/lib libs, and the first with no dead branch to
fix -- the whole job was test-writing. 43 assertions across two files;
93/93 = 100.00% through run_all.sh, twice, the second at --min 100 (exit 0),
then cleared with the real gate confirming and no exemption.
The one genuine gap was check_memory_pressure's high-swap branch (lines
158-159), which fires only when swap is heavily used WHILE RAM is still
available -- a state this host does not happen to be in. The lib reads the
absolute /proc/meminfo, but every read goes through `awk`, so stubbing awk
supplies controlled figures without touching /proc: the stub answers on the
pattern being matched and execs the real awk for anything else. Both
directions are covered, including RAM genuinely exhausted, which must NOT be
flagged because it is not the stutter signature.
Everything else here is branch coverage of probes whose inputs are external
commands: failed systemd units, ACPI error counts, a CPU-hungry Xorg,
governors all-performance vs one-powersave vs unsupported, thermal
throttling excerpts, the TLP/power-profiles-daemon conflict in all three
combinations, and storage health with and without fstrim/smartctl.
lib_test_core.sh gains _t_stub_cat. "Print this fixture file" is by far the
commonest stub shape, and writing it inline forces every call site to embed
a literal ${LIB_TEST_DEV} that must not expand at write time -- SC2016 on
every use. Passing the fixture NAME as data removes the class outright, and
two earlier bluetooth test files are simplified onto it. All 21 test files
and three harnesses now lint clean with no suppression anywhere.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
c309c95f5a
commit
fa7b05da74
@ -0,0 +1,17 @@
|
||||
{
|
||||
"title": "Test arch_perf_probes.sh to 100% and clear it from the shell-coverage allowlist",
|
||||
"objective": "Cover the sixth of the sixteen untested fixes/lib libs, the diagnostic-probe half of diagnose_arch_performance.sh. Unlike the two libs before it this one contains no dead branch, so the whole job is test-writing: reaching the swap-pressure branch that depends on /proc/meminfo, and the governor branches that depend on a real /sys tree.",
|
||||
"acceptance_criteria": [
|
||||
"arch_perf_probes.sh measures 100.00% (93/93) through lib/tests/run_all.sh, twice, the second run at --min 100 with exit 0.",
|
||||
"check_shell_coverage.sh exits 0 for arch_perf_probes.sh with its allowlist line removed, i.e. with no exemption.",
|
||||
"The check_memory_pressure swap branch is genuinely exercised with controlled figures, not skipped because this host happens to swap.",
|
||||
"Every file in fixes/lib/tests stays under the repo's 250-line cap and passes shellcheck with no suppression added.",
|
||||
"The five libs cleared earlier in the session still pass the gate."
|
||||
],
|
||||
"out_of_scope": [
|
||||
"Any change to arch_perf_probes.sh itself.",
|
||||
"bt_adapter.sh, still exempt at 98.55% for the backslash-continued assignment flavour of defect (a).",
|
||||
"The remaining ten untested fixes/lib libs."
|
||||
],
|
||||
"verifier": "bash linux_configuration/scripts/single_use/fixes/lib/tests/run_all.sh (expects all 21 files passing, 16 + 27 for the two arch_perf_probes files), plus bash meta/scripts/shell_coverage_jail.sh --subject linux_configuration/scripts/single_use/fixes/lib/tests/run_all.sh --measure arch_perf_probes.sh --min 100 --fail-on-case-error -- \"\" (expects 93/93 = 100.00% and exit 0), plus bash meta/scripts/check_shell_coverage.sh linux_configuration/scripts/single_use/fixes/lib/arch_perf_probes.sh (expects exit 0)."
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
{
|
||||
"intent": "Test linux_configuration/scripts/single_use/fixes/lib/arch_perf_probes.sh to 100% line coverage and take it off the shell-coverage allowlist, sixth of the 16 untested fixes/lib libs.",
|
||||
"scope": [
|
||||
"linux_configuration/scripts/single_use/fixes/lib/tests/test_arch_perf_probes.sh (new, 16 assertions)",
|
||||
"linux_configuration/scripts/single_use/fixes/lib/tests/test_arch_perf_probes_health.sh (new, 27 assertions)",
|
||||
"linux_configuration/scripts/single_use/fixes/lib/tests/lib_test_core.sh (new _t_stub_cat helper)",
|
||||
"linux_configuration/scripts/single_use/fixes/lib/tests/test_bt_pairing_usb.sh and test_bt_adapter_reset.sh (simplified onto _t_stub_cat)",
|
||||
"meta/shell-coverage-allowlist.txt (one line removed)",
|
||||
"Non-goal: any change to arch_perf_probes.sh itself -- unlike the two libs before it, this one had no dead branch"
|
||||
],
|
||||
"changes": [
|
||||
"Added test_arch_perf_probes.sh covering collect_basics (a quiet machine, failed systemd units, frequent ACPI errors, a CPU-hungry Xorg, and the load-average threshold) and check_cpu_governor (all cores on performance, one core left on powersave, and no governor files at all).",
|
||||
"Added test_arch_perf_probes_health.sh covering check_thermal_state (sensors present and clean, throttling messages excerpted, sensors absent), check_power_services (both daemons enabled, neither enabled, exactly one enabled), check_storage_health (healthy disk, disabled fstrim.timer, missing smartctl), and check_memory_pressure (heavy swap with RAM free, heavy swap with RAM exhausted, and a swapless machine).",
|
||||
"The high-swap branch is reached by stubbing awk rather than /proc/meminfo, which the lib reads by absolute path: every meminfo read goes through awk, so the stub answers on the pattern being matched and execs the real awk for every other call. That closed lines 158-159, the only genuine test gap in the lib.",
|
||||
"Added _t_stub_cat to lib_test_core.sh: the commonest stub shape is 'print this fixture file', and writing it inline forced every call site to embed a literal ${LIB_TEST_DEV} that must not expand at write time. Passing the fixture name as data removes that whole class of SC2016 with no suppression, and two earlier bluetooth test files were simplified onto it.",
|
||||
"Removed linux_configuration/scripts/single_use/fixes/lib/arch_perf_probes.sh from meta/shell-coverage-allowlist.txt."
|
||||
],
|
||||
"verification": [
|
||||
{
|
||||
"command": "bash linux_configuration/scripts/single_use/fixes/lib/tests/run_all.sh",
|
||||
"result": "pass",
|
||||
"evidence": "arch_perf_probes (basics/governor): 16 passed; arch_perf_probes (health): 27 passed; both 0 failed. All 21 test files in the directory pass, so the five cleared libs and the eight pacman_hook_stall suites stay green after _t_stub_cat landed."
|
||||
},
|
||||
{
|
||||
"command": "bash meta/scripts/shell_coverage_jail.sh --subject linux_configuration/scripts/single_use/fixes/lib/tests/run_all.sh --measure arch_perf_probes.sh --min 1 --fail-on-case-error -- \"\"",
|
||||
"result": "pass",
|
||||
"evidence": "arch_perf_probes.sh: 93/93 lines = 100.00%, up from 91/93 = 97.85% before the check_memory_pressure swap branch 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 arch_perf_probes.sh --min 100 --fail-on-case-error -- \"\"",
|
||||
"result": "pass",
|
||||
"evidence": "arch_perf_probes.sh: 93/93 lines = 100.00%, exit code 0. Second matching run at the --min 100 bar."
|
||||
},
|
||||
{
|
||||
"command": "bash meta/scripts/check_shell_coverage.sh on arch_perf_probes.sh, arch_perf_report.sh and bt_audio.sh",
|
||||
"result": "pass",
|
||||
"evidence": "'check_shell_coverage.sh: every checked shell library meets the coverage bar', exit 0, with the arch_perf_probes.sh allowlist line already removed so it had no exemption. The other two are included to confirm the libs cleared in c309c95f did not regress."
|
||||
},
|
||||
{
|
||||
"command": "shellcheck on every file in fixes/lib/tests",
|
||||
"result": "pass",
|
||||
"evidence": "All 21 test files plus the three harnesses lint clean, with no suppression added anywhere in this commit."
|
||||
}
|
||||
],
|
||||
"risks": [
|
||||
"check_cpu_governor and collect_basics read absolute paths (/sys/devices/system/cpu via find, /proc/loadavg) that have no environment override, so those cases are driven by stubbing the command the lib shells out to (find, getconf, ps, systemctl, journalctl). The load-average case additionally self-skips with an explicit note if this host's 1-minute load happens to sit below 1, so it cannot silently start asserting nothing.",
|
||||
"The awk stub used for the swap cases execs /usr/bin/awk for any pattern it does not recognise. If the lib later reads a new /proc/meminfo field, the stub will fall through to the real awk and the fabricated figures will silently stop applying to that field rather than failing loudly."
|
||||
],
|
||||
"rollback": [
|
||||
"git revert the commit; that restores the arch_perf_probes.sh allowlist line and deletes the two test files 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 arch_perf_probes.sh exempt again."
|
||||
]
|
||||
}
|
||||
@ -106,6 +106,19 @@ exit 0"
|
||||
_t_stub "$name" "$body"
|
||||
}
|
||||
|
||||
# _t_stub_cat NAME FIXTURE — stub NAME so it prints the contents of
|
||||
# $DEV/FIXTURE, a file the test writes beforehand.
|
||||
#
|
||||
# The commonest stub shape by far, and the one that otherwise forces every
|
||||
# caller to embed a literal ${LIB_TEST_DEV} that must not expand at write
|
||||
# time. Passing the fixture NAME as data keeps every call site quote-free.
|
||||
_t_stub_cat() {
|
||||
local name="$1" fixture="$2"
|
||||
_t_stub_stdin "$name" <<STUB_CAT
|
||||
cat "\${LIB_TEST_DEV}/${fixture}"
|
||||
STUB_CAT
|
||||
}
|
||||
|
||||
# _t_stub_stdin NAME — stub NAME with a multi-line body read from stdin.
|
||||
#
|
||||
# The body is data, not code this file evaluates, so a `$1` or `${VAR}` in it
|
||||
|
||||
119
linux_configuration/scripts/single_use/fixes/lib/tests/test_arch_perf_probes.sh
Executable file
119
linux_configuration/scripts/single_use/fixes/lib/tests/test_arch_perf_probes.sh
Executable file
@ -0,0 +1,119 @@
|
||||
#!/usr/bin/env bash
|
||||
# Tests for lib/arch_perf_probes.sh: collect_basics and check_cpu_governor.
|
||||
set -uo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# shellcheck source=arch_perf_harness.sh
|
||||
. "${SCRIPT_DIR}/arch_perf_harness.sh"
|
||||
|
||||
# shellcheck source=../arch_perf_probes.sh
|
||||
. "${FIXES_DIR}/lib/arch_perf_probes.sh"
|
||||
|
||||
# --- collect_basics ---------------------------------------------------------
|
||||
|
||||
# A quiet machine: every section is logged, and nothing is flagged.
|
||||
arch_reset
|
||||
_t_stub uname 'echo "Linux kuhy-pc 7.1.9-arch1-1"'
|
||||
_t_stub uptime 'echo " 12:00:00 up 2:00, 1 user, load average: 0.10, 0.20, 0.30"'
|
||||
_t_stub free 'echo "Mem: 32Gi 8Gi 24Gi"'
|
||||
_t_stub swapon 'exit 0'
|
||||
_t_stub lscpu 'echo "CPU(s): 16"'
|
||||
_t_stub df 'echo "/dev/nvme0n1p2 100G 40G 60G 40% /"'
|
||||
_t_stub systemd-analyze 'echo "Startup finished in 3.2s"'
|
||||
_t_stub systemctl 'exit 0'
|
||||
_t_stub journalctl 'exit 0'
|
||||
_t_stub getconf 'echo 16'
|
||||
_t_stub ps 'echo " PID COMMAND %CPU %MEM"'
|
||||
collect_basics
|
||||
report="$(_t_report)"
|
||||
_t_contains "$report" "=== Kernel ===" "collect_basics: logs the kernel section"
|
||||
_t_contains "$report" "=== Uptime ===" "collect_basics: logs the uptime section"
|
||||
_t_contains "$report" "=== Memory ===" "collect_basics: logs the memory section"
|
||||
_t_contains "$report" "=== Boot Time ===" "collect_basics: logs the boot time section"
|
||||
_t_contains "$report" "=== Failed Units ===" "collect_basics: logs the failed units section"
|
||||
_t_contains "$report" "=== Top CPU Processes ===" \
|
||||
"collect_basics: logs the top CPU processes snapshot"
|
||||
_t_eq "" "$(_t_findings)" "collect_basics: flags nothing on a quiet machine"
|
||||
|
||||
# Failed units, frequent ACPI errors and a busy Xorg are each flagged.
|
||||
arch_reset
|
||||
_t_stub getconf 'echo 16'
|
||||
_t_stub_stdin systemctl <<'STUB_BODY'
|
||||
if [[ "$*" == *"--failed --no-legend"* ]]; then
|
||||
echo "foo.service loaded failed failed Foo"
|
||||
echo "bar.service loaded failed failed Bar"
|
||||
fi
|
||||
exit 0
|
||||
STUB_BODY
|
||||
_t_stub_stdin journalctl <<'STUB_BODY'
|
||||
for _ in 1 2 3 4 5 6; do
|
||||
echo "kernel: ACPI Error: something went wrong"
|
||||
done
|
||||
exit 0
|
||||
STUB_BODY
|
||||
_t_stub_stdin ps <<'STUB_BODY'
|
||||
if [[ "$*" == *"-C Xorg"* ]]; then
|
||||
echo " 45.0"
|
||||
exit 0
|
||||
fi
|
||||
echo " PID COMMAND %CPU %MEM"
|
||||
STUB_BODY
|
||||
collect_basics
|
||||
findings="$(_t_findings)"
|
||||
_t_contains "$findings" "systemd units are failed (2)" \
|
||||
"collect_basics: flags failed systemd units and counts them"
|
||||
_t_contains "$findings" "ACPI errors detected" \
|
||||
"collect_basics: flags frequent ACPI errors"
|
||||
_t_contains "$findings" "Xorg is using high CPU (45%)" \
|
||||
"collect_basics: flags a CPU-hungry Xorg"
|
||||
|
||||
# A load average at or above the thread count is flagged. /proc/loadavg is
|
||||
# read directly by the lib, so the case is driven by a low CPU count instead.
|
||||
arch_reset
|
||||
_t_stub getconf 'echo 1'
|
||||
_t_stub systemctl 'exit 0'
|
||||
_t_stub journalctl 'exit 0'
|
||||
_t_stub ps 'echo none'
|
||||
collect_basics
|
||||
if [[ $(awk '{print int($1)}' /proc/loadavg) -ge 1 ]]; then
|
||||
_t_contains "$(_t_findings)" "load average is at/above CPU thread count" \
|
||||
"collect_basics: flags a load average at or above the thread count"
|
||||
else
|
||||
_t_pass "collect_basics: SKIP load case (this host's 1-minute load is below 1)"
|
||||
fi
|
||||
|
||||
# --- check_cpu_governor -----------------------------------------------------
|
||||
|
||||
# The lib runs `find /sys/devices/system/cpu`, a real path with no override,
|
||||
# so `find` is stubbed to control which governor files it reports.
|
||||
arch_reset
|
||||
mkdir -p "${TEST_TMPDIR}/gov"
|
||||
echo "performance" >"${TEST_TMPDIR}/gov/cpu0"
|
||||
echo "performance" >"${TEST_TMPDIR}/gov/cpu1"
|
||||
printf '%s\n%s\n' "${TEST_TMPDIR}/gov/cpu0" "${TEST_TMPDIR}/gov/cpu1" >"${DEV}/gov_list"
|
||||
_t_stub_cat find gov_list
|
||||
check_cpu_governor
|
||||
_t_contains "$(_t_report)" "CPU governor summary: performance:2" \
|
||||
"check_cpu_governor: summarises the governors in use"
|
||||
_t_eq "" "$(_t_findings)" "check_cpu_governor: flags nothing when every core is on performance"
|
||||
|
||||
# A core left on powersave is the condition the probe exists for.
|
||||
arch_reset
|
||||
echo "powersave" >"${TEST_TMPDIR}/gov/cpu1"
|
||||
_t_stub_cat find gov_list
|
||||
check_cpu_governor
|
||||
_t_contains "$(_t_findings)" "governor includes 'powersave'" \
|
||||
"check_cpu_governor: flags a core left on the powersave governor"
|
||||
|
||||
# No governor files at all: an action, not a finding, and no hang.
|
||||
arch_reset
|
||||
: >"${DEV}/gov_list"
|
||||
_t_stub_cat find gov_list
|
||||
check_cpu_governor
|
||||
_t_contains "$(_t_actions)" "CPU governor files not found" \
|
||||
"check_cpu_governor: records an action when no governor files exist"
|
||||
_t_eq "" "$(_t_findings)" "check_cpu_governor: records no finding when governors are unsupported"
|
||||
|
||||
echo
|
||||
echo "arch_perf_probes (basics/governor): ${PASS} passed, ${FAIL} failed"
|
||||
((FAIL == 0))
|
||||
@ -0,0 +1,189 @@
|
||||
#!/usr/bin/env bash
|
||||
# Tests for lib/arch_perf_probes.sh: check_thermal_state, check_power_services,
|
||||
# check_storage_health and check_memory_pressure.
|
||||
# Split from test_arch_perf_probes.sh for the 250-line cap.
|
||||
set -uo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# shellcheck source=arch_perf_harness.sh
|
||||
. "${SCRIPT_DIR}/arch_perf_harness.sh"
|
||||
|
||||
# shellcheck source=../arch_perf_probes.sh
|
||||
. "${FIXES_DIR}/lib/arch_perf_probes.sh"
|
||||
|
||||
# --- check_thermal_state ----------------------------------------------------
|
||||
|
||||
# sensors present and dmesg clean: the section is logged, nothing flagged.
|
||||
arch_reset
|
||||
_t_stub sensors 'echo "Core 0: +45.0C"'
|
||||
_t_stub dmesg 'echo "usb 1-1: new high-speed USB device"'
|
||||
check_thermal_state
|
||||
_t_contains "$(_t_report)" "=== Temperatures (sensors) ===" \
|
||||
"check_thermal_state: logs the sensors output when sensors is installed"
|
||||
_t_eq "" "$(_t_findings)" "check_thermal_state: flags nothing when dmesg is clean"
|
||||
|
||||
# Throttling messages in dmesg are flagged and excerpted into the report.
|
||||
arch_reset
|
||||
_t_stub sensors 'echo "Core 0: +95.0C"'
|
||||
_t_stub dmesg 'echo "CPU2: Core temperature above threshold, cpu clock throttled"'
|
||||
check_thermal_state
|
||||
_t_contains "$(_t_findings)" "thermal/throttling related messages" \
|
||||
"check_thermal_state: flags throttling messages in the kernel log"
|
||||
_t_contains "$(_t_report)" "=== Thermal/Throttling dmesg excerpts ===" \
|
||||
"check_thermal_state: excerpts the throttling lines into the report"
|
||||
|
||||
# sensors absent: an action recommending lm_sensors. The host may have a real
|
||||
# sensors binary, so _t_hide takes it off PATH.
|
||||
arch_reset
|
||||
_t_unstub sensors
|
||||
_t_hide sensors
|
||||
_t_stub dmesg 'echo "nothing interesting"'
|
||||
check_thermal_state
|
||||
_t_full_path
|
||||
_t_contains "$(_t_actions)" "Install lm_sensors" \
|
||||
"check_thermal_state: recommends lm_sensors when sensors is missing"
|
||||
|
||||
# --- check_power_services ---------------------------------------------------
|
||||
|
||||
# Both daemons enabled: the classic conflict.
|
||||
arch_reset
|
||||
_t_stub systemctl 'exit 0'
|
||||
check_power_services
|
||||
_t_contains "$(_t_report)" "Power services: tlp=true, power-profiles-daemon=true" \
|
||||
"check_power_services: records both daemons as enabled"
|
||||
_t_contains "$(_t_findings)" "Both TLP and power-profiles-daemon are enabled" \
|
||||
"check_power_services: flags the TLP/ppd conflict"
|
||||
|
||||
# Neither enabled: an action, not a finding.
|
||||
arch_reset
|
||||
_t_stub systemctl 'exit 1'
|
||||
check_power_services
|
||||
_t_contains "$(_t_report)" "Power services: tlp=false, power-profiles-daemon=false" \
|
||||
"check_power_services: records both daemons as disabled"
|
||||
_t_contains "$(_t_actions)" "No power management daemon is enabled" \
|
||||
"check_power_services: recommends enabling a power daemon when none is"
|
||||
_t_eq "" "$(_t_findings)" "check_power_services: flags nothing when neither daemon runs"
|
||||
|
||||
# Exactly one enabled is the healthy case: neither finding nor action.
|
||||
arch_reset
|
||||
_t_stub_stdin systemctl <<'STUB_BODY'
|
||||
[[ "$*" == *"power-profiles-daemon"* ]] && exit 0
|
||||
exit 1
|
||||
STUB_BODY
|
||||
check_power_services
|
||||
_t_contains "$(_t_report)" "tlp=false, power-profiles-daemon=true" \
|
||||
"check_power_services: records a single enabled daemon"
|
||||
_t_eq "" "$(_t_findings)" "check_power_services: flags nothing when only one daemon is enabled"
|
||||
_t_eq "" "$(_t_actions)" "check_power_services: recommends nothing when one daemon is enabled"
|
||||
|
||||
# --- check_storage_health ---------------------------------------------------
|
||||
|
||||
arch_reset
|
||||
_t_stub lsblk 'echo "nvme0n1 Samsung 990 0 1T disk"'
|
||||
_t_stub fstrim 'echo "/: 12 GiB (trimmed)"'
|
||||
_t_stub systemctl 'exit 0'
|
||||
_t_stub smartctl 'echo "SMART overall-health self-assessment test result: PASSED"'
|
||||
_t_stub findmnt 'echo "/dev/nvme0n1p2"'
|
||||
check_storage_health
|
||||
_t_contains "$(_t_report)" "=== Block Devices ===" \
|
||||
"check_storage_health: logs the block device list"
|
||||
_t_contains "$(_t_report)" "=== fstrim dry-run ===" \
|
||||
"check_storage_health: logs the fstrim dry run when fstrim is present"
|
||||
_t_contains "$(_t_actions)" "fstrim.timer is enabled" \
|
||||
"check_storage_health: records an enabled fstrim.timer as good"
|
||||
_t_eq "" "$(_t_findings)" "check_storage_health: flags nothing on a healthy disk"
|
||||
|
||||
# fstrim.timer disabled is a finding; smartctl missing is an action.
|
||||
arch_reset
|
||||
_t_stub lsblk 'echo "sda disk"'
|
||||
_t_stub systemctl 'exit 1'
|
||||
_t_unstub smartctl
|
||||
_t_hide smartctl fstrim
|
||||
check_storage_health
|
||||
_t_full_path
|
||||
_t_contains "$(_t_findings)" "fstrim.timer is not enabled" \
|
||||
"check_storage_health: flags a disabled fstrim.timer"
|
||||
_t_contains "$(_t_actions)" "Install smartmontools" \
|
||||
"check_storage_health: recommends smartmontools when smartctl is missing"
|
||||
|
||||
# --- check_memory_pressure --------------------------------------------------
|
||||
|
||||
# /proc/meminfo is read directly by the lib and cannot be redirected, so this
|
||||
# asserts on the shape of the result rather than on fabricated numbers.
|
||||
arch_reset
|
||||
check_memory_pressure
|
||||
report="$(_t_report)"
|
||||
if grep -q '^SwapTotal: *0 ' /proc/meminfo; then
|
||||
_t_lacks "$report" "Swap usage:" \
|
||||
"check_memory_pressure: reports no swap usage when the host has no swap"
|
||||
else
|
||||
_t_contains "$report" "Swap usage:" \
|
||||
"check_memory_pressure: records swap usage when the host has swap"
|
||||
fi
|
||||
if [[ -f /proc/pressure/memory ]]; then
|
||||
_t_contains "$report" "=== Memory PSI ===" \
|
||||
"check_memory_pressure: logs the kernel memory pressure counters"
|
||||
else
|
||||
_t_lacks "$report" "=== Memory PSI ===" \
|
||||
"check_memory_pressure: omits the PSI section when the kernel lacks it"
|
||||
fi
|
||||
|
||||
# The high-swap branch: swap heavily used while RAM is still available. The
|
||||
# lib reads the absolute /proc/meminfo, but every read goes through `awk`, so
|
||||
# stubbing awk supplies controlled figures without touching /proc. The stub
|
||||
# answers on the pattern the lib greps for, and defers to the real awk for
|
||||
# any other call (check_thermal_state and collect_basics use it too).
|
||||
arch_reset
|
||||
_t_stub_stdin awk <<'STUB_BODY'
|
||||
case "$1" in
|
||||
*MemTotal*) echo 32000000 ;;
|
||||
*MemAvailable*) echo 20000000 ;;
|
||||
*SwapTotal*) echo 8000000 ;;
|
||||
*SwapFree*) echo 2000000 ;;
|
||||
*) exec /usr/bin/awk "$@" ;;
|
||||
esac
|
||||
STUB_BODY
|
||||
check_memory_pressure
|
||||
_t_contains "$(_t_report)" "Swap usage: 75%" \
|
||||
"check_memory_pressure: computes the swap usage percentage"
|
||||
_t_contains "$(_t_findings)" "High swap usage while RAM is still available" \
|
||||
"check_memory_pressure: flags heavy swapping while RAM is free"
|
||||
_t_contains "$(_t_actions)" "lowering swappiness" \
|
||||
"check_memory_pressure: recommends lowering swappiness"
|
||||
|
||||
# Heavy swap use with RAM genuinely exhausted is NOT the stutter signature,
|
||||
# so it must not be flagged.
|
||||
arch_reset
|
||||
_t_stub_stdin awk <<'STUB_BODY'
|
||||
case "$1" in
|
||||
*MemTotal*) echo 32000000 ;;
|
||||
*MemAvailable*) echo 500000 ;;
|
||||
*SwapTotal*) echo 8000000 ;;
|
||||
*SwapFree*) echo 2000000 ;;
|
||||
*) exec /usr/bin/awk "$@" ;;
|
||||
esac
|
||||
STUB_BODY
|
||||
check_memory_pressure
|
||||
_t_contains "$(_t_report)" "Swap usage: 75%" \
|
||||
"check_memory_pressure: still records the percentage when RAM is exhausted"
|
||||
_t_eq "" "$(_t_findings)" \
|
||||
"check_memory_pressure: does not flag swapping when RAM is genuinely full"
|
||||
|
||||
# A machine with no swap at all skips the whole swap section.
|
||||
arch_reset
|
||||
_t_stub_stdin awk <<'STUB_BODY'
|
||||
case "$1" in
|
||||
*MemTotal*) echo 32000000 ;;
|
||||
*MemAvailable*) echo 20000000 ;;
|
||||
*SwapTotal*) echo 0 ;;
|
||||
*SwapFree*) echo 0 ;;
|
||||
*) exec /usr/bin/awk "$@" ;;
|
||||
esac
|
||||
STUB_BODY
|
||||
check_memory_pressure
|
||||
_t_lacks "$(_t_report)" "Swap usage:" \
|
||||
"check_memory_pressure: reports no swap usage on a swapless machine"
|
||||
|
||||
echo
|
||||
echo "arch_perf_probes (health): ${PASS} passed, ${FAIL} failed"
|
||||
((FAIL == 0))
|
||||
@ -21,25 +21,13 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# _btctl_list TEXT — stub bluetoothctl so `_btctl list` emits TEXT.
|
||||
_btctl_list() {
|
||||
printf '%s\n' "$1" >"${DEV}/btctl_out"
|
||||
local body
|
||||
body="$(
|
||||
cat <<'BTCTL_BODY'
|
||||
cat "${LIB_TEST_DEV}/btctl_out"
|
||||
BTCTL_BODY
|
||||
)"
|
||||
_t_stub bluetoothctl "$body"
|
||||
_t_stub_cat bluetoothctl btctl_out
|
||||
}
|
||||
|
||||
# _lsusb_line TEXT — stub lsusb to emit 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"
|
||||
_t_stub_cat lsusb lsusb_out
|
||||
}
|
||||
|
||||
# _record_reload ARGS... — stand-in for the real btusb reloader.
|
||||
|
||||
@ -29,13 +29,7 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# _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"
|
||||
_t_stub_cat lsusb lsusb_out
|
||||
}
|
||||
|
||||
# No bluetooth device in lsusb at all: the function returns before any lookup.
|
||||
|
||||
@ -76,7 +76,6 @@ linux_configuration/scripts/single_use/features/lib/wg_sshd.sh
|
||||
linux_configuration/scripts/single_use/fixes/lib/arch_cpu.sh
|
||||
linux_configuration/scripts/single_use/fixes/lib/arch_hardware.sh
|
||||
linux_configuration/scripts/single_use/fixes/lib/arch_perf_fixes.sh
|
||||
linux_configuration/scripts/single_use/fixes/lib/arch_perf_probes.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/hosts_guard_migrate.sh
|
||||
|
||||
Loading…
Reference in New Issue
Block a user