Compare commits

...

3 Commits

Author SHA1 Message Date
b4b6908d69 Test arch_cpu.sh to 100% and take it off the allowlist (91 -> 90)
Some checks are pending
Pre-commit checks / pre-commit (push) Waiting to run
Shell tests / shell-tests (push) Waiting to run
Shell tests / arch-tests (push) Waiting to run
57/57 lines, measured through run_all.sh and confirmed a second time at
--min 100 so a shortfall would exit non-zero. check_shell_coverage.sh
passes with the exemption removed.

28 assertions over 14 cases: no cpufreq at all, every core already
tuned, the mixed case where only some cores lag, cpupower absent /
unconfigured / already configured, and all three I/O scheduler targets
(none for NVMe, mq-deadline for SATA SSD, bfq for spinning disks).

The sysfs reads and the two /etc write targets are now behind overrides
defaulting to the real paths, so the tests can present hardware this
host does not have -- a rotational disk -- without touching anything.

One assertion initially passed for the wrong reason: _t_hide keeps
$FAKE_BIN on PATH by design, so the harness's own cpupower stub still
satisfied has_cmd and the "not installed" branch never ran. Unstubbing
before hiding is now explicit, and the case fails if that is lost.

This also settles arch_sysctl.sh's diagnosis: it uses this same
harness, so the harness is not why it cannot be measured.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-22 21:14:57 +02:00
7c14cfca61 Test arch_sysctl.sh and open the optimize_arch_desktop lib family
23 assertions over 8 cases covering both tweak_vm_sysctl and
tweak_network_sysctl: the skip path, the write-when-the-drop-in-is-
missing path that a naive "nothing to do" check gets wrong, the
value-differs path, an unreadable-sysctl path, and the tcp_bbr guard.

arch_desktop_harness.sh is the third family harness, supplying the
globals and apply_tweak that live in optimize_arch_desktop.sh rather
than in any lib. arch_cpu.sh and arch_hardware.sh will reuse it.

SYSCTL_DROPIN_DIR defaults to the real /etc/sysctl.d, matching the
seam ubuntu_perf_more.sh and arch_perf_fixes.sh already carry; the
suite runs un-jailed in ci_mirror.sh and CI, so a bind mount would
protect nothing. Both real drop-ins keep their Mar 2 mtimes.

_t_run lands in lib_test_core.sh because `out="$(func)"` forks a
subshell and kcov never registers a lib whose first execution happens
inside one -- measured as 0 lines via $( ) against 54 lines via a
direct call.

arch_sysctl.sh STAYS on the coverage allowlist: it still reports "kcov
instrumented no lines" through the jail, while ubuntu_perf_more.sh
measures 32/32 in the same worktree and the same invocation. The tests
are real and green; the coverage number is not yet obtainable, and the
exemption may only come off once it is.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-22 20:54:47 +02:00
afe6ac3a33 Reformat three fixes libs with shfmt ahead of coverage work
shfmt runs on every staged shell file and rewrites drifted libs, which
moves coverage denominators and invalidates measurements taken minutes
earlier. Landing the reformat first makes every number measured from
here the number that survives pre-commit.

thorium_repairs.sh converts from 2-space indent to tabs; the other two
only lose runs of blank lines. `git diff -w` shows no token changed,
shellcheck is clean, and the 20-file suite stays green.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-22 20:22:23 +02:00
14 changed files with 807 additions and 142 deletions

View File

@ -0,0 +1,18 @@
{
"title": "Clear arch_cpu.sh from the shell coverage allowlist",
"objective": "Bring arch_cpu.sh to 100% measured line coverage through tests/run_all.sh and remove its allowlist exemption, taking the allowlist from 91 entries to 90.",
"acceptance_criteria": [
"The jail reports arch_cpu.sh at 100.00% measured through tests/run_all.sh, not through a single test file.",
"A second measurement at --min 100 exits 0, so a shortfall would be a non-zero exit rather than a number to read.",
"With the allowlist line removed, check_shell_coverage.sh on arch_cpu.sh prints 'every checked shell library meets the coverage bar'.",
"Both functions are covered across every branch: no cpufreq at all, all cores already tuned, a mixed set where only some cores lag, cpupower absent, cpupower present and unconfigured, cpupower already configured, and all three I/O scheduler targets (none for NVMe, mq-deadline for SSD, bfq for HDD).",
"arch_cpu.sh's production behaviour is unchanged: every new override defaults to the real path it replaced.",
"The whole suite stays green and shellcheck reports nothing, with zero suppressions."
],
"out_of_scope": [
"arch_sysctl.sh's kcov registration failure, which is tracked separately and stays on the allowlist.",
"Changing the coverage instrument, which is scheduled after the eight libs.",
"arch_hardware.sh, the third lib of this family, which reuses this harness in a later commit."
],
"verifier": "timeout 900s bash meta/scripts/shell_coverage_jail.sh --subject linux_configuration/scripts/single_use/fixes/lib/tests/run_all.sh --measure arch_cpu.sh --min 100 --fail-on-case-error -- \"\" (expects 57/57 = 100.00%, exit 0), followed by bash meta/scripts/check_shell_coverage.sh on the lib with its allowlist line removed."
}

View File

@ -0,0 +1,19 @@
{
"title": "Test arch_sysctl.sh and open the optimize_arch_desktop lib family",
"objective": "Give arch_sysctl.sh a real test suite covering both of its sysctl-tuning functions, and add the third family harness so arch_cpu.sh and arch_hardware.sh can reuse it, as the first of the eight untested fixes/lib libraries.",
"acceptance_criteria": [
"test_arch_sysctl.sh exercises both tweak_vm_sysctl and tweak_network_sysctl across every branch: already-tuned-with-drop-in (skip), already-tuned-without-drop-in (write), value-differs (write and reload), sysctl-read-failure, and the tcp_bbr modprobe guard.",
"The whole suite stays green: run_all.sh reports every test file passing, including the 20 that predate this change.",
"shellcheck reports nothing on the new and modified files, with zero suppressions added anywhere.",
"No write reaches /etc: the two real sysctl drop-ins keep their pre-existing mtimes after the suite runs.",
"arch_sysctl.sh's production behaviour is unchanged -- SYSCTL_DROPIN_DIR defaults to the real /etc/sysctl.d.",
"arch_sysctl.sh stays on meta/shell-coverage-allowlist.txt, because it is not yet measurable through run_all.sh; the allowlist line may only be removed once the jail reports a real percentage."
],
"out_of_scope": [
"Removing arch_sysctl.sh from the coverage allowlist while its measurement still fails.",
"Changing the coverage instrument (meta/scripts/lib/shell_coverage_lines.py), which is scheduled after the eight libs.",
"Refactoring pacman_hook_stall_harness.sh onto lib_test_core.sh.",
"Touching arch_cpu.sh or arch_hardware.sh, which reuse this harness in later commits."
],
"verifier": "bash linux_configuration/scripts/single_use/fixes/lib/tests/run_all.sh (all test files pass, arch_sysctl reports 23 passed / 0 failed), plus shellcheck on the four touched shell files, plus stat on /etc/sysctl.d/9[01]-*.conf showing unchanged mtimes."
}

View File

@ -0,0 +1,51 @@
{
"intent": "Test arch_cpu.sh to 100% line coverage and take it off the shell coverage allowlist, clearing the second of the eight untested fixes/lib libraries.",
"scope": [
"linux_configuration/scripts/single_use/fixes/lib/arch_cpu.sh (test seams only)",
"linux_configuration/scripts/single_use/fixes/lib/tests/test_arch_cpu.sh (new)",
"linux_configuration/scripts/single_use/fixes/lib/tests/arch_desktop_harness.sh (sysfs helpers)",
"meta/shell-coverage-allowlist.txt (one line removed)",
"Non-goal: arch_sysctl.sh's measurement problem, which this commit deliberately leaves untouched"
],
"changes": [
"Added CPU_SYSFS_ROOT, BLOCK_SYSFS_ROOT, UDEV_RULES_DIR and CPUPOWER_CONF_FILE overrides to arch_cpu.sh, each defaulting to the real path so production behaviour is unchanged",
"Added _t_make_cpu, _t_make_block, _t_sched and _t_udev to arch_desktop_harness.sh so a case can present hardware this host does not have, such as a rotational disk",
"Added test_arch_cpu.sh: 28 assertions over 14 cases covering both functions, including the mixed-governor case, all three I/O scheduler targets, and the already-configured cpupower path",
"Removed arch_cpu.sh from meta/shell-coverage-allowlist.txt, taking it from 91 to 90 entries"
],
"verification": [
{
"command": "shell_coverage_jail.sh --subject .../tests/run_all.sh --measure arch_cpu.sh --min 1 --fail-on-case-error",
"result": "pass",
"evidence": "arch_cpu.sh: 57/57 lines = 100.00%"
},
{
"command": "shell_coverage_jail.sh ... --measure arch_cpu.sh --min 100 --fail-on-case-error",
"result": "pass",
"evidence": "arch_cpu.sh: 57/57 lines = 100.00%, exit 0, so a shortfall would have been a non-zero exit."
},
{
"command": "bash meta/scripts/check_shell_coverage.sh .../fixes/lib/arch_cpu.sh (after removing the allowlist line)",
"result": "pass",
"evidence": "check_shell_coverage.sh: every checked shell library meets the coverage bar"
},
{
"command": "bash linux_configuration/scripts/single_use/fixes/lib/tests/run_all.sh",
"result": "pass",
"evidence": "All fixes lib test files passed; arch_cpu: 28 passed, 0 failed."
},
{
"command": "shellcheck arch_cpu.sh test_arch_cpu.sh arch_desktop_harness.sh",
"result": "pass",
"evidence": "No findings, zero suppressions."
}
],
"risks": [
"A test asserting cpupower is absent initially passed for the wrong reason: _t_hide keeps $FAKE_BIN on PATH, so the harness's own default stub still satisfied has_cmd. Fixed by unstubbing before hiding, and the assertion now fails if that ordering is lost.",
"The measurement of arch_cpu.sh through the same harness that arch_sysctl.sh uses shows the harness is not the cause of arch_sysctl.sh's unmeasurability"
],
"rollback": [
"git revert the commit, then re-add the arch_cpu.sh line to meta/shell-coverage-allowlist.txt",
"Re-run check_shell_coverage.sh to confirm the gate passes again with the exemption restored"
]
}

View File

@ -0,0 +1,57 @@
{
"intent": "Add a test suite for arch_sysctl.sh and the shared harness for the optimize_arch_desktop.sh lib family, covering both sysctl-tuning functions across every branch.",
"scope": [
"linux_configuration/scripts/single_use/fixes/lib/arch_sysctl.sh (SYSCTL_DROPIN_DIR override only)",
"linux_configuration/scripts/single_use/fixes/lib/tests/arch_desktop_harness.sh (new)",
"linux_configuration/scripts/single_use/fixes/lib/tests/test_arch_sysctl.sh (new)",
"linux_configuration/scripts/single_use/fixes/lib/tests/lib_test_core.sh (_t_run primitive)",
"Non-goal: removing arch_sysctl.sh from the coverage allowlist -- see risks, the lib is not yet measurable through run_all.sh"
],
"changes": [
"Added SYSCTL_DROPIN_DIR to arch_sysctl.sh, defaulting to the real /etc/sysctl.d so production behaviour is unchanged; it exists so tests never write to /etc, which matters because run_all.sh runs un-jailed in ci_mirror.sh and in CI",
"Added arch_desktop_harness.sh, the third family harness, supplying the DRY_RUN/AGGRESSIVE/TWEAKS_* globals and the apply_tweak helper that live in the entry script optimize_arch_desktop.sh rather than in any lib",
"Added test_arch_sysctl.sh: 23 assertions over 8 cases covering both functions' skip path, write-when-drop-in-missing path, value-differs path, sysctl-failure path, and tweak_network_sysctl's modprobe guard",
"Added _t_run to lib_test_core.sh: runs the subject in the current shell and captures output via a file, because command substitution forks a subshell and kcov then never registers the sourced lib"
],
"verification": [
{
"command": "bash linux_configuration/scripts/single_use/fixes/lib/tests/test_arch_sysctl.sh",
"result": "pass",
"evidence": "arch_sysctl: 23 passed, 0 failed"
},
{
"command": "bash linux_configuration/scripts/single_use/fixes/lib/tests/run_all.sh",
"result": "pass",
"evidence": "All fixes lib test files passed; 21 test files green including the new one."
},
{
"command": "shellcheck lib_test_core.sh arch_desktop_harness.sh test_arch_sysctl.sh arch_sysctl.sh",
"result": "pass",
"evidence": "No findings, zero suppressions. The SC2034 on $out was fixed by exporting it, matching the existing treatment of cross-file globals in lib_test_core.sh."
},
{
"command": "ls -la /etc/sysctl.d/90-desktop-performance.conf /etc/sysctl.d/91-desktop-network.conf",
"result": "pass",
"evidence": "Both still dated Mar 2, i.e. untouched by the suite: the SYSCTL_DROPIN_DIR override kept every write inside the throwaway tmpdir."
},
{
"command": "kcov --include-pattern=arch_sysctl.sh <dir> ./g1.sh (direct call, no command substitution)",
"result": "pass",
"evidence": "arch_sysctl.sh instrumented 54 lines when the function is called directly, versus 0 lines when first called inside $( ). This is what motivated _t_run."
},
{
"command": "shell_coverage_jail.sh --measure arch_sysctl.sh --subject .../run_all.sh",
"result": "fail",
"evidence": "'kcov instrumented no lines' persists through the jail even after the _t_run change, while the control lib ubuntu_perf_more.sh measures 32/32 = 100.00% in the same worktree and same jail invocation. The lib is therefore NOT yet measurable and its allowlist line is deliberately left in place."
}
],
"risks": [
"arch_sysctl.sh remains on the coverage allowlist despite having 23 passing assertions, because it cannot yet be measured through run_all.sh; the tests are real but the coverage number is unknown",
"_t_run changes the calling convention for future lib tests; existing test files are untouched and still green",
"The SYSCTL_DROPIN_DIR override adds a test seam to production code, the same seam ubuntu_perf_more.sh and arch_perf_fixes.sh already carry"
],
"rollback": [
"git revert the commit; arch_sysctl.sh returns to hardcoded /etc/sysctl.d paths and the two new test files disappear",
"Re-run tests/run_all.sh to confirm the remaining 20 test files are still green"
]
}

View File

@ -0,0 +1,43 @@
{
"intent": "Normalize shfmt formatting of three fixes/lib shell libraries before writing tests against them, so that coverage denominators measured later are the ones that survive pre-commit.",
"scope": [
"linux_configuration/scripts/single_use/fixes/lib/thorium_repairs.sh",
"linux_configuration/scripts/single_use/fixes/lib/hosts_guard_migrate.sh",
"linux_configuration/scripts/single_use/fixes/lib/arch_cpu.sh",
"Non-goal: any behavioural change; this is formatting only"
],
"changes": [
"Ran shfmt -w on the three libs shfmt -l reported as drifted; thorium_repairs.sh converted from 2-space indent to tabs",
"Collapsed runs of three blank lines to one in arch_cpu.sh and hosts_guard_migrate.sh (shfmt's own normalization)"
],
"verification": [
{
"command": "git diff -w -- arch_cpu.sh hosts_guard_migrate.sh",
"result": "pass",
"evidence": "Only blank-line collapsing (3 -> 1) appears; no token changed. thorium_repairs.sh is empty under -w, i.e. pure indent conversion."
},
{
"command": "shellcheck thorium_repairs.sh hosts_guard_migrate.sh arch_cpu.sh",
"result": "pass",
"evidence": "No findings, zero suppressions."
},
{
"command": "bash linux_configuration/scripts/single_use/fixes/lib/tests/run_all.sh",
"result": "pass",
"evidence": "All fixes lib test files passed; ubuntu_perf_more: 24 passed, 0 failed. 20 test files green."
},
{
"command": "wc -l on all 8 target libs",
"result": "pass",
"evidence": "Post-format: thorium_repairs 179, hosts_guard_migrate 159, arch_cpu 124, ubuntu_perf_fixes 215, arch_hardware 202, nvidia_config 180, hosts_guard_rollback 141, arch_sysctl 122. All under the 250-line cap."
}
],
"risks": [
"shfmt reformatting changes coverage denominators; doing it before any measurement is precisely what removes that risk for the upcoming test work",
"thorium_repairs.sh's indent change is large in diff terms (294 lines) despite being semantically inert"
],
"rollback": [
"git revert the commit; the libs return to their prior indentation",
"Re-run tests/run_all.sh to confirm the suite is still green after rollback"
]
}

View File

@ -10,7 +10,10 @@
# ===================================================================
tweak_cpu_governor() {
local gov_files
gov_files=$(find /sys/devices/system/cpu -maxdepth 3 -name scaling_governor 2>/dev/null || true)
# CPU_SYSFS_ROOT and the two write targets below default to the real
# locations and are overridden only by the test harness, which runs
# un-jailed in ci_mirror.sh and in CI.
gov_files=$(find "${CPU_SYSFS_ROOT:-/sys/devices/system/cpu}" -maxdepth 3 -name scaling_governor 2>/dev/null || true)
if [[ -z $gov_files ]]; then
log_warn "No CPU governor sysfs files found — skipping."
@ -37,7 +40,7 @@ tweak_cpu_governor() {
done
# Make it persistent via a sysctl-style drop-in using udev rule
local udev_rule="/etc/udev/rules.d/60-cpu-governor-performance.rules"
local udev_rule="${UDEV_RULES_DIR:-/etc/udev/rules.d}/60-cpu-governor-performance.rules"
if [[ ! -f $udev_rule ]]; then
cat >"$udev_rule" <<'UDEVEOF'
# Set CPU governor to performance on all cores at boot
@ -46,7 +49,7 @@ UDEVEOF
fi
# Also install cpupower hook as a more reliable persistence method
local cpupower_conf="/etc/default/cpupower"
local cpupower_conf="${CPUPOWER_CONF_FILE:-/etc/default/cpupower}"
if has_cmd cpupower; then
if [[ ! -f $cpupower_conf ]] || ! grep -q "^governor='performance'" "$cpupower_conf" 2>/dev/null; then
mkdir -p "$(dirname "$cpupower_conf")"
@ -68,7 +71,8 @@ tweak_io_scheduler() {
local changed=false
local block_dev
for block_dev in /sys/block/sd* /sys/block/nvme* /sys/block/vd*; do
local block_root="${BLOCK_SYSFS_ROOT:-/sys/block}"
for block_dev in "$block_root"/sd* "$block_root"/nvme* "$block_root"/vd*; do
[[ -d $block_dev ]] || continue
local sched_file="$block_dev/queue/scheduler"
[[ -f $sched_file ]] || continue
@ -100,7 +104,7 @@ tweak_io_scheduler() {
done
# Persist via udev rule
local udev_rule="/etc/udev/rules.d/60-io-scheduler.rules"
local udev_rule="${UDEV_RULES_DIR:-/etc/udev/rules.d}/60-io-scheduler.rules"
if [[ ! -f $udev_rule ]]; then
cat >"$udev_rule" <<'IOEOF'
# NVMe: no scheduler (multi-queue hardware handles it)
@ -119,8 +123,6 @@ IOEOF
return 0
}
# ===================================================================
# Apply all tweaks
# ===================================================================

View File

@ -9,7 +9,9 @@
# 3. Memory & swap tuning via sysctl
# ===================================================================
tweak_vm_sysctl() {
local dropin="/etc/sysctl.d/90-desktop-performance.conf"
# SYSCTL_DROPIN_DIR defaults to the real directory and is overridden only
# by the test harness, which runs un-jailed in ci_mirror.sh and in CI.
local dropin="${SYSCTL_DROPIN_DIR:-/etc/sysctl.d}/90-desktop-performance.conf"
# Desktop workloads: low swappiness, aggressive VFS caching, tuned dirty ratios
local -A params=(
@ -62,7 +64,7 @@ VMEOF
# 4. Network: TCP BBR + fastopen + buffer tuning
# ===================================================================
tweak_network_sysctl() {
local dropin="/etc/sysctl.d/91-desktop-network.conf"
local dropin="${SYSCTL_DROPIN_DIR:-/etc/sysctl.d}/91-desktop-network.conf"
# Check if BBR module is available
if ! modprobe tcp_bbr 2>/dev/null; then

View File

@ -33,8 +33,6 @@ validate_requirements() {
fi
}
install_plugins() {
run mkdir -p "$PLUGIN_INSTALL_DIR"
local src

View File

@ -0,0 +1,149 @@
#!/usr/bin/env bash
# lib/tests/arch_desktop_harness.sh — shared setup for the arch desktop
# optimization lib tests (arch_sysctl.sh, arch_cpu.sh, arch_hardware.sh).
#
# Sourced, not executed. Builds on lib_test_core.sh and adds the pieces these
# three libs read from their entry script, optimize_arch_desktop.sh:
#
# * DRY_RUN, AGGRESSIVE, TWEAKS_APPLIED and TWEAKS_SKIPPED;
# * apply_tweak, redefined verbatim from the entry script -- it lives there
# rather than in any lib, the same arrangement arch_perf_harness.sh
# handles with add_finding/add_action;
# * the real log_*/has_cmd helpers, via scripts/lib/common.sh.
#
# NOT to be confused with arch_perf_harness.sh, which serves a different entry
# script (diagnose_arch_performance.sh) and a different set of libs. The two
# families were mis-grouped in an earlier handoff; the distinct names are the
# fix for that.
#
# Every absolute write target of these libs is behind an override defaulting
# to the real location, because run_all.sh runs UN-jailed in ci_mirror.sh and
# in CI, where a bind mount would protect nothing.
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"
# shellcheck source=../../../../lib/common.sh
. "${REPO_ROOT}/linux_configuration/scripts/lib/common.sh"
# --- globals and helpers owned by optimize_arch_desktop.sh ------------------
# Read by the libs under test, never by this harness, so static analysis
# cannot see the use; export makes the intent explicit.
export SYSCTL_DROPIN_DIR="${TEST_TMPDIR}/sysctl.d"
export UDEV_RULES_DIR="${TEST_TMPDIR}/udev.rules.d"
export CPUPOWER_CONF_FILE="${TEST_TMPDIR}/cpupower"
# arch_cpu.sh reads CPU and block-device state from sysfs; the tests build a
# fake tree under these roots so a case can present hardware this host does
# not have (a rotational disk, a core not on the performance governor).
export CPU_SYSFS_ROOT="${TEST_TMPDIR}/sys_cpu"
export BLOCK_SYSFS_ROOT="${TEST_TMPDIR}/sys_block"
export SYSTEMD_UNIT_DIR="${TEST_TMPDIR}/systemd_units"
export JOURNALD_CONF_DIR="${TEST_TMPDIR}/journald.conf.d"
export DRY_RUN="false"
export AGGRESSIVE="false"
export INTERACTIVE_MODE="false"
TWEAKS_APPLIED=0
TWEAKS_SKIPPED=0
# Verbatim from optimize_arch_desktop.sh.
apply_tweak() {
local description="$1"
shift
echo ""
log_info "$description"
if [[ $DRY_RUN == "true" ]]; then
echo " [dry-run] Would run: $*"
return 0
fi
if [[ $INTERACTIVE_MODE == "true" ]]; then
if ! ask_yes_no " Apply this optimization?"; then
log_warn "Skipped."
((TWEAKS_SKIPPED++)) || true
return 0
fi
fi
if "$@"; then
log_ok "Done."
((TWEAKS_APPLIED++)) || true
else
log_error "Failed (non-fatal, continuing)."
fi
}
# --- external tool stubs ----------------------------------------------------
_arch_desktop_default_stubs() {
local tool
for tool in sysctl modprobe udevadm cpupower systemctl nvidia-smi \
lsblk lscpu journalctl pacman; do
_t_stub "$tool" 'exit 0'
done
}
# arch_desktop_reset — start a test group from "nothing has happened yet".
arch_desktop_reset() {
_t_reset_calls
TWEAKS_APPLIED=0
TWEAKS_SKIPPED=0
DRY_RUN="false"
AGGRESSIVE="false"
INTERACTIVE_MODE="false"
export DRY_RUN AGGRESSIVE INTERACTIVE_MODE
rm -rf "${SYSCTL_DROPIN_DIR}" "${UDEV_RULES_DIR}" "${SYSTEMD_UNIT_DIR}" \
"${JOURNALD_CONF_DIR}" "${CPU_SYSFS_ROOT}" "${BLOCK_SYSFS_ROOT}"
mkdir -p "${SYSCTL_DROPIN_DIR}" "${UDEV_RULES_DIR}" "${SYSTEMD_UNIT_DIR}" \
"${JOURNALD_CONF_DIR}" "${CPU_SYSFS_ROOT}" "${BLOCK_SYSFS_ROOT}"
rm -f "${CPUPOWER_CONF_FILE}"
_t_full_path
_arch_desktop_default_stubs
}
# _t_make_cpu N GOVERNOR — create N fake cores whose scaling_governor reads
# GOVERNOR. The layout mirrors the real one closely enough for the lib's
# `find -maxdepth 3 -name scaling_governor` to reach it.
_t_make_cpu() {
local count="$1" governor="$2" i dir
for ((i = 0; i < count; i++)); do
dir="${CPU_SYSFS_ROOT}/cpu${i}/cpufreq"
mkdir -p "$dir"
printf '%s\n' "$governor" >"${dir}/scaling_governor"
done
}
# _t_make_block NAME ROTATIONAL SCHEDULER — create one fake block device.
# SCHEDULER is written in the kernel's own format, with the active entry in
# brackets, because that is what the lib parses.
_t_make_block() {
local name="$1" rotational="$2" scheduler="$3" dir
dir="${BLOCK_SYSFS_ROOT}/${name}/queue"
mkdir -p "$dir"
printf '%s\n' "$rotational" >"${dir}/rotational"
printf '%s\n' "$scheduler" >"${dir}/scheduler"
}
# _t_sched NAME — the scheduler file's contents for a fake device.
_t_sched() {
cat "${BLOCK_SYSFS_ROOT}/$1/queue/scheduler" 2>/dev/null || true
}
# _t_udev FILE — the contents of a udev rule written this round.
_t_udev() {
cat "${UDEV_RULES_DIR}/$1" 2>/dev/null || true
}
# _t_dropin FILE — the contents of a sysctl drop-in written this round.
_t_dropin() {
cat "${SYSCTL_DROPIN_DIR}/$1" 2>/dev/null || true
}
arch_desktop_reset

View File

@ -195,6 +195,28 @@ _t_full_path() {
export LIB_TEST_ORIG_PATH="${PATH#"${FAKE_BIN}:"}"
# _t_run FUNC [ARG...] — run FUNC in THE CURRENT SHELL, putting its combined
# output in $out and returning its exit status.
#
# Deliberately not `out="$(func)"`. Command substitution forks a subshell, and
# kcov does not register a sourced file whose first execution happens inside
# one: the lib then reports "kcov instrumented no lines" and cannot be
# measured at all, even though every assertion against it passes. Capturing
# through a file keeps the call in the current shell, so the lib is
# registered. Measured on arch_sysctl.sh: 0 lines via $( ), 54 lines via this.
# $out is the output of the most recent _t_run, read by the assertions at
# every call site. Exported for the same reason the other cross-file globals
# here are: the readers live in other files, so static analysis cannot see
# the use from this one.
export out=""
_t_run() {
local rc=0
"$@" >"${TEST_TMPDIR}/run_out" 2>&1 || rc=$?
out="$(cat "${TEST_TMPDIR}/run_out")"
return "$rc"
}
# _t_calls — print everything the stubs recorded this round.
_t_calls() {
cat "${DEV}/calls" 2>/dev/null || true

View File

@ -0,0 +1,160 @@
#!/usr/bin/env bash
# lib/tests/test_arch_cpu.sh — tests for arch_cpu.sh.
#
# Both functions read hardware state from sysfs and write persistence rules,
# so every case builds a fake sysfs tree under $CPU_SYSFS_ROOT /
# $BLOCK_SYSFS_ROOT first. That is what lets a case present hardware this
# host does not have -- a rotational disk, or a core that is not already on
# the performance governor.
#
# Calls go through _t_run rather than `out="$(...)"`: command substitution
# forks a subshell, and kcov does not register a lib whose first execution
# happens inside one.
set -uo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=arch_desktop_harness.sh
. "${SCRIPT_DIR}/arch_desktop_harness.sh"
# shellcheck source=../arch_cpu.sh
. "${FIXES_DIR}/lib/arch_cpu.sh"
printf '\n-- tweak_cpu_governor --\n'
# Case 1: no governor files at all (a VM, or a kernel without cpufreq).
arch_desktop_reset
_t_run tweak_cpu_governor
_t_eq "0" "$?" "tweak_cpu_governor: returns 0 with no governor files"
_t_contains "$out" "No CPU governor sysfs files found" \
"tweak_cpu_governor: warns when cpufreq is absent"
_t_eq "" "$(_t_udev 60-cpu-governor-performance.rules)" \
"tweak_cpu_governor: writes no udev rule when there is nothing to tune"
# Case 2: every core already on performance -> skip without writing.
arch_desktop_reset
_t_make_cpu 4 performance
_t_run tweak_cpu_governor
_t_contains "$out" "already on 'performance' governor" \
"tweak_cpu_governor: reports the skip when all cores are tuned"
_t_eq "" "$(_t_udev 60-cpu-governor-performance.rules)" \
"tweak_cpu_governor: writes no udev rule when skipping"
# Case 3: cores on powersave -> every core is switched and the rule written.
arch_desktop_reset
_t_make_cpu 3 powersave
# _t_hide keeps $FAKE_BIN on PATH, so the default stub has to go first or
# has_cmd still finds cpupower and the "not installed" branch never runs.
_t_unstub cpupower
_t_hide cpupower
_t_run tweak_cpu_governor
_t_eq "performance" "$(cat "${CPU_SYSFS_ROOT}/cpu0/cpufreq/scaling_governor")" \
"tweak_cpu_governor: switches cpu0 to performance"
_t_eq "performance" "$(cat "${CPU_SYSFS_ROOT}/cpu2/cpufreq/scaling_governor")" \
"tweak_cpu_governor: switches the last core too"
_t_contains "$(_t_udev 60-cpu-governor-performance.rules)" "scaling_governor" \
"tweak_cpu_governor: writes the persistence udev rule"
_t_eq "" "$(cat "${CPUPOWER_CONF_FILE}" 2>/dev/null || true)" \
"tweak_cpu_governor: writes no cpupower config when cpupower is absent"
_t_full_path
# Case 4: only SOME cores need changing -- the mixed case, which the
# all_performance loop must break out of on the first mismatch.
arch_desktop_reset
_t_make_cpu 2 performance
mkdir -p "${CPU_SYSFS_ROOT}/cpu2/cpufreq"
printf 'powersave\n' >"${CPU_SYSFS_ROOT}/cpu2/cpufreq/scaling_governor"
_t_unstub cpupower
_t_hide cpupower
_t_run tweak_cpu_governor
_t_eq "performance" "$(cat "${CPU_SYSFS_ROOT}/cpu2/cpufreq/scaling_governor")" \
"tweak_cpu_governor: switches the one core that lagged"
_t_lacks "$out" "already on 'performance'" \
"tweak_cpu_governor: does not claim a skip when one core differed"
_t_full_path
# Case 5: cpupower present and unconfigured -> config written and unit enabled.
arch_desktop_reset
_t_make_cpu 1 powersave
_t_stub cpupower 'exit 0'
_t_run tweak_cpu_governor
_t_contains "$(cat "${CPUPOWER_CONF_FILE}")" "governor='performance'" \
"tweak_cpu_governor: writes the cpupower default"
_t_contains "$(_t_calls)" "systemctl enable cpupower.service" \
"tweak_cpu_governor: enables the cpupower unit"
# Case 6: cpupower present and ALREADY configured -> left alone, not re-enabled.
arch_desktop_reset
_t_make_cpu 1 powersave
_t_stub cpupower 'exit 0'
printf "governor='performance'\n" >"${CPUPOWER_CONF_FILE}"
_t_run tweak_cpu_governor
_t_lacks "$(_t_calls)" "systemctl enable cpupower.service" \
"tweak_cpu_governor: does not re-enable when already configured"
printf '\n-- tweak_io_scheduler --\n'
# Case 7: no block devices -> the udev rule is still written, and the
# "already optimal" line reports that nothing changed.
arch_desktop_reset
_t_run tweak_io_scheduler
_t_eq "0" "$?" "tweak_io_scheduler: returns 0 with no block devices"
_t_contains "$out" "All I/O schedulers already optimal" \
"tweak_io_scheduler: reports nothing changed"
_t_contains "$(_t_udev 60-io-scheduler.rules)" "mq-deadline" \
"tweak_io_scheduler: writes the persistence udev rule regardless"
# Case 8: an NVMe drive wants 'none'.
arch_desktop_reset
_t_make_block nvme0n1 0 '[mq-deadline] none'
_t_run tweak_io_scheduler
_t_eq "none" "$(_t_sched nvme0n1)" "tweak_io_scheduler: sets NVMe to none"
_t_contains "$out" "scheduler changed from 'mq-deadline' to 'none'" \
"tweak_io_scheduler: logs the NVMe change"
# Case 9: a SATA SSD (rotational=0) wants mq-deadline.
arch_desktop_reset
_t_make_block sda 0 '[none] mq-deadline bfq'
_t_run tweak_io_scheduler
_t_eq "mq-deadline" "$(_t_sched sda)" "tweak_io_scheduler: sets SSD to mq-deadline"
# Case 10: a spinning disk (rotational=1) wants bfq.
arch_desktop_reset
_t_make_block sdb 1 '[mq-deadline] bfq none'
_t_run tweak_io_scheduler
_t_eq "bfq" "$(_t_sched sdb)" "tweak_io_scheduler: sets HDD to bfq"
# Case 11: a device already on its target is left alone.
arch_desktop_reset
_t_make_block nvme1n1 0 'mq-deadline [none]'
_t_run tweak_io_scheduler
_t_contains "$out" "already using 'none' scheduler" \
"tweak_io_scheduler: reports an already-optimal device"
_t_contains "$out" "All I/O schedulers already optimal" \
"tweak_io_scheduler: counts it as no change"
# Case 12: several devices of different kinds in one pass.
arch_desktop_reset
_t_make_block nvme0n1 0 '[mq-deadline] none'
_t_make_block sda 0 '[bfq] mq-deadline'
_t_make_block sdb 1 '[mq-deadline] bfq'
_t_run tweak_io_scheduler
_t_eq "none" "$(_t_sched nvme0n1)" "tweak_io_scheduler: NVMe handled in a mixed pass"
_t_eq "mq-deadline" "$(_t_sched sda)" "tweak_io_scheduler: SSD handled in a mixed pass"
_t_eq "bfq" "$(_t_sched sdb)" "tweak_io_scheduler: HDD handled in a mixed pass"
# Case 13: a directory without a queue/scheduler file is skipped, not fatal.
arch_desktop_reset
mkdir -p "${BLOCK_SYSFS_ROOT}/sdc"
_t_run tweak_io_scheduler
_t_eq "0" "$?" "tweak_io_scheduler: skips a device with no scheduler file"
# Case 14: an existing udev rule is not overwritten.
arch_desktop_reset
printf 'CUSTOM RULE\n' >"${UDEV_RULES_DIR}/60-io-scheduler.rules"
_t_run tweak_io_scheduler
_t_eq "CUSTOM RULE" "$(_t_udev 60-io-scheduler.rules)" \
"tweak_io_scheduler: leaves an existing udev rule alone"
printf '\narch_cpu: %d passed, %d failed\n' "$PASS" "$FAIL"
[[ $FAIL -eq 0 ]]

View File

@ -0,0 +1,145 @@
#!/usr/bin/env bash
# lib/tests/test_arch_sysctl.sh — tests for arch_sysctl.sh.
#
# Both functions share a shape: probe every parameter with `sysctl -n`, set
# needs_update when any current value differs from the wanted one, skip when
# nothing differs AND the drop-in already exists, otherwise write the drop-in
# and reload. The cases below walk each arm of that shape for both functions,
# plus tweak_network_sysctl's modprobe guard.
set -uo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=arch_desktop_harness.sh
. "${SCRIPT_DIR}/arch_desktop_harness.sh"
# shellcheck source=../arch_sysctl.sh
. "${FIXES_DIR}/lib/arch_sysctl.sh"
printf '\n-- tweak_vm_sysctl --\n'
# A sysctl stub that reports every parameter as already at its wanted value,
# so needs_update stays false. Values are keyed by the parameter name in $2
# (sysctl is called as `sysctl -n KEY`).
_stub_sysctl_tuned() {
_t_stub_stdin sysctl <<'STUB'
case "$2" in
vm.swappiness) echo 10 ;;
vm.vfs_cache_pressure) echo 50 ;;
vm.dirty_ratio) echo 15 ;;
vm.dirty_background_ratio) echo 5 ;;
vm.dirty_writeback_centisecs) echo 1500 ;;
vm.page-cluster) echo 0 ;;
net.core.default_qdisc) echo fq ;;
net.ipv4.tcp_congestion_control) echo bbr ;;
net.ipv4.tcp_fastopen) echo 3 ;;
net.core.rmem_max) echo 16777216 ;;
net.core.wmem_max) echo 16777216 ;;
net.ipv4.tcp_rmem) printf '4096\t1048576\t16777216\n' ;;
net.ipv4.tcp_wmem) printf '4096\t1048576\t16777216\n' ;;
net.ipv4.tcp_mtu_probing) echo 1 ;;
*) exit 0 ;;
esac
STUB
}
# Case 1: values already tuned AND the drop-in exists -> skip without writing.
arch_desktop_reset
_stub_sysctl_tuned
: >"${SYSCTL_DROPIN_DIR}/90-desktop-performance.conf"
_t_run tweak_vm_sysctl
_t_eq "0" "$?" "tweak_vm_sysctl: returns 0 when already tuned"
_t_contains "$out" "already tuned" "tweak_vm_sysctl: reports the skip"
_t_eq "" "$(_t_dropin 90-desktop-performance.conf)" \
"tweak_vm_sysctl: leaves the existing drop-in untouched"
_t_lacks "$(_t_calls)" "sysctl --system" \
"tweak_vm_sysctl: does not reload when skipping"
# Case 2: values already tuned but NO drop-in file -> must still write it.
# This is the arm that a naive "nothing to do" check would wrongly skip.
arch_desktop_reset
_stub_sysctl_tuned
_t_run tweak_vm_sysctl
_t_contains "$(_t_dropin 90-desktop-performance.conf)" "vm.swappiness = 10" \
"tweak_vm_sysctl: writes the drop-in when it is missing"
_t_lacks "$out" "already tuned" \
"tweak_vm_sysctl: does not report a skip when the drop-in is absent"
# Case 3: a value differs -> write the drop-in and reload.
arch_desktop_reset
_t_stub_stdin sysctl <<'STUB'
case "$2" in
vm.swappiness) echo 60 ;;
*) exit 0 ;;
esac
STUB
_t_run tweak_vm_sysctl
dropin="$(_t_dropin 90-desktop-performance.conf)"
_t_contains "$dropin" "vm.swappiness = 10" "tweak_vm_sysctl: writes swappiness"
_t_contains "$dropin" "vm.vfs_cache_pressure = 50" \
"tweak_vm_sysctl: writes vfs_cache_pressure"
_t_contains "$dropin" "vm.page-cluster = 0" "tweak_vm_sysctl: writes page-cluster"
_t_contains "$dropin" "managed by optimize_arch_desktop.sh" \
"tweak_vm_sysctl: stamps the drop-in as managed"
_t_contains "$(_t_calls)" "sysctl --system" "tweak_vm_sysctl: reloads sysctl"
# Case 4: sysctl failing outright (unknown key) still reaches the write path.
arch_desktop_reset
_t_stub sysctl 'exit 1'
_t_run tweak_vm_sysctl
_t_eq "0" "$?" "tweak_vm_sysctl: returns 0 when sysctl -n fails"
_t_contains "$(_t_dropin 90-desktop-performance.conf)" "vm.dirty_ratio = 15" \
"tweak_vm_sysctl: writes the drop-in when current values are unreadable"
printf '\n-- tweak_network_sysctl --\n'
# Case 5: the tcp_bbr module is unavailable -> warn and return without writing.
arch_desktop_reset
_t_stub modprobe 'exit 1'
_t_run tweak_network_sysctl
_t_eq "0" "$?" "tweak_network_sysctl: returns 0 when tcp_bbr is unavailable"
_t_contains "$out" "tcp_bbr kernel module unavailable" \
"tweak_network_sysctl: warns about the missing module"
_t_eq "" "$(_t_dropin 91-desktop-network.conf)" \
"tweak_network_sysctl: writes nothing without tcp_bbr"
# Case 6: already tuned AND drop-in present -> skip. The tcp_rmem/tcp_wmem
# values come back tab-separated from the kernel, which is why the lib
# normalizes both sides through xargs before comparing; this case is what
# proves that normalization works.
arch_desktop_reset
_stub_sysctl_tuned
: >"${SYSCTL_DROPIN_DIR}/91-desktop-network.conf"
_t_run tweak_network_sysctl
_t_contains "$out" "already tuned" \
"tweak_network_sysctl: skips when tab-separated values match"
_t_lacks "$(_t_calls)" "sysctl --system" \
"tweak_network_sysctl: does not reload when skipping"
# Case 7: already tuned but no drop-in -> write it.
arch_desktop_reset
_stub_sysctl_tuned
_t_run tweak_network_sysctl
_t_contains "$(_t_dropin 91-desktop-network.conf)" "net.ipv4.tcp_congestion_control = bbr" \
"tweak_network_sysctl: writes the drop-in when it is missing"
# Case 8: a value differs -> write and reload.
arch_desktop_reset
_t_stub_stdin sysctl <<'STUB'
case "$2" in
net.ipv4.tcp_congestion_control) echo cubic ;;
*) exit 0 ;;
esac
STUB
_t_run tweak_network_sysctl
dropin="$(_t_dropin 91-desktop-network.conf)"
_t_contains "$dropin" "net.core.default_qdisc = fq" \
"tweak_network_sysctl: writes the qdisc"
_t_contains "$dropin" "net.ipv4.tcp_rmem = 4096 1048576 16777216" \
"tweak_network_sysctl: writes the receive buffers"
_t_contains "$dropin" "net.ipv4.tcp_mtu_probing = 1" \
"tweak_network_sysctl: writes mtu probing"
_t_contains "$(_t_calls)" "sysctl --system" "tweak_network_sysctl: reloads sysctl"
printf '\narch_sysctl: %d passed, %d failed\n' "$PASS" "$FAIL"
[[ $FAIL -eq 0 ]]

View File

@ -7,173 +7,173 @@
# Fix 1: Handle corrupted Local State file (most common crash cause)
fix_local_state() {
log_info "Checking Local State file..."
local local_state="$THORIUM_CONFIG_DIR/Local State"
log_info "Checking Local State file..."
local local_state="$THORIUM_CONFIG_DIR/Local State"
if [[ -f $local_state ]]; then
# Check if it's valid JSON
if ! python3 -c "import json; json.load(open('$local_state'))" 2> /dev/null; then
log_warn "Local State file appears corrupted"
backup_if_exists "$local_state"
else
# Even if valid JSON, back it up as it can still cause crashes
log_info "Local State exists - backing up (common crash source)"
backup_if_exists "$local_state"
fi
else
log_info "No Local State file found (OK for fresh install)"
fi
if [[ -f $local_state ]]; then
# Check if it's valid JSON
if ! python3 -c "import json; json.load(open('$local_state'))" 2>/dev/null; then
log_warn "Local State file appears corrupted"
backup_if_exists "$local_state"
else
# Even if valid JSON, back it up as it can still cause crashes
log_info "Local State exists - backing up (common crash source)"
backup_if_exists "$local_state"
fi
else
log_info "No Local State file found (OK for fresh install)"
fi
}
# Fix 2: Clear singleton lock files
fix_singleton_locks() {
log_info "Clearing singleton lock files..."
local locks=(
"$THORIUM_CONFIG_DIR/SingletonLock"
"$THORIUM_CONFIG_DIR/SingletonSocket"
"$THORIUM_CONFIG_DIR/SingletonCookie"
)
log_info "Clearing singleton lock files..."
local locks=(
"$THORIUM_CONFIG_DIR/SingletonLock"
"$THORIUM_CONFIG_DIR/SingletonSocket"
"$THORIUM_CONFIG_DIR/SingletonCookie"
)
local cleared=0
for lock in "${locks[@]}"; do
if remove_if_exists "$lock"; then
((cleared++)) || true
fi
done
local cleared=0
for lock in "${locks[@]}"; do
if remove_if_exists "$lock"; then
((cleared++)) || true
fi
done
if [[ $cleared -eq 0 ]]; then
log_info "No stale lock files found"
fi
if [[ $cleared -eq 0 ]]; then
log_info "No stale lock files found"
fi
}
# Fix 3: Clear GPU cache
fix_gpu_cache() {
log_info "Clearing GPU cache..."
local gpu_paths=(
"$THORIUM_CONFIG_DIR/GPUCache"
"$THORIUM_CONFIG_DIR/Default/GPUCache"
"$THORIUM_CONFIG_DIR/ShaderCache"
"$THORIUM_CONFIG_DIR/Default/ShaderCache"
)
log_info "Clearing GPU cache..."
local gpu_paths=(
"$THORIUM_CONFIG_DIR/GPUCache"
"$THORIUM_CONFIG_DIR/Default/GPUCache"
"$THORIUM_CONFIG_DIR/ShaderCache"
"$THORIUM_CONFIG_DIR/Default/ShaderCache"
)
local cleared=0
for cache in "${gpu_paths[@]}"; do
if remove_if_exists "$cache"; then
((cleared++)) || true
fi
done
local cleared=0
for cache in "${gpu_paths[@]}"; do
if remove_if_exists "$cache"; then
((cleared++)) || true
fi
done
if [[ $cleared -eq 0 ]]; then
log_info "No GPU cache to clear"
fi
if [[ $cleared -eq 0 ]]; then
log_info "No GPU cache to clear"
fi
}
# Fix 4: Clear crash reports (can accumulate and cause issues)
fix_crash_reports() {
log_info "Clearing old crash reports..."
local crash_dir="$THORIUM_CONFIG_DIR/Crash Reports"
log_info "Clearing old crash reports..."
local crash_dir="$THORIUM_CONFIG_DIR/Crash Reports"
if [[ -d $crash_dir ]]; then
local crash_count
crash_count=$(find "$crash_dir" -type f 2> /dev/null | wc -l)
if [[ $crash_count -gt 0 ]]; then
if [[ $DRY_RUN == true ]]; then
echo " [dry-run] Would clear $crash_count crash report(s)"
else
rm -rf "$crash_dir"
log_ok "Cleared $crash_count crash report(s)"
fi
fi
fi
if [[ -d $crash_dir ]]; then
local crash_count
crash_count=$(find "$crash_dir" -type f 2>/dev/null | wc -l)
if [[ $crash_count -gt 0 ]]; then
if [[ $DRY_RUN == true ]]; then
echo " [dry-run] Would clear $crash_count crash report(s)"
else
rm -rf "$crash_dir"
log_ok "Cleared $crash_count crash report(s)"
fi
fi
fi
}
# Fix 5: Aggressive cleaning (optional)
fix_aggressive() {
if [[ $AGGRESSIVE != true ]]; then
return
fi
if [[ $AGGRESSIVE != true ]]; then
return
fi
log_warn "Applying aggressive fixes (may lose some site data)..."
log_warn "Applying aggressive fixes (may lose some site data)..."
local aggressive_paths=(
"$THORIUM_CONFIG_DIR/Default/Service Worker"
"$THORIUM_CONFIG_DIR/Default/Cache"
"$THORIUM_CONFIG_DIR/Default/Code Cache"
"$THORIUM_CONFIG_DIR/Default/IndexedDB"
"$THORIUM_CONFIG_DIR/BrowserMetrics"
"$THORIUM_CONFIG_DIR/component_crx_cache"
)
local aggressive_paths=(
"$THORIUM_CONFIG_DIR/Default/Service Worker"
"$THORIUM_CONFIG_DIR/Default/Cache"
"$THORIUM_CONFIG_DIR/Default/Code Cache"
"$THORIUM_CONFIG_DIR/Default/IndexedDB"
"$THORIUM_CONFIG_DIR/BrowserMetrics"
"$THORIUM_CONFIG_DIR/component_crx_cache"
)
for path in "${aggressive_paths[@]}"; do
remove_if_exists "$path"
done
for path in "${aggressive_paths[@]}"; do
remove_if_exists "$path"
done
# Backup potentially corrupted databases
local db_files=(
"$THORIUM_CONFIG_DIR/Default/Web Data"
"$THORIUM_CONFIG_DIR/Default/History"
)
# Backup potentially corrupted databases
local db_files=(
"$THORIUM_CONFIG_DIR/Default/Web Data"
"$THORIUM_CONFIG_DIR/Default/History"
)
for db in "${db_files[@]}"; do
if [[ -f $db ]]; then
log_info "Checking database: $(basename "$db")"
# Simple corruption check - if sqlite3 can't open it, back it up
if command -v sqlite3 &> /dev/null; then
if ! sqlite3 "$db" "PRAGMA integrity_check;" &> /dev/null; then
log_warn "Database may be corrupted: $(basename "$db")"
backup_if_exists "$db"
fi
fi
fi
done
for db in "${db_files[@]}"; do
if [[ -f $db ]]; then
log_info "Checking database: $(basename "$db")"
# Simple corruption check - if sqlite3 can't open it, back it up
if command -v sqlite3 &>/dev/null; then
if ! sqlite3 "$db" "PRAGMA integrity_check;" &>/dev/null; then
log_warn "Database may be corrupted: $(basename "$db")"
backup_if_exists "$db"
fi
fi
fi
done
}
# Test if Thorium starts successfully
test_thorium() {
if [[ $TEST_AFTER != true ]]; then
return
fi
if [[ $TEST_AFTER != true ]]; then
return
fi
log_info "Testing Thorium startup..."
log_info "Testing Thorium startup..."
if [[ $DRY_RUN == true ]]; then
echo " [dry-run] Would test thorium-browser startup"
return
fi
if [[ $DRY_RUN == true ]]; then
echo " [dry-run] Would test thorium-browser startup"
return
fi
# Start Thorium in background
thorium-browser &> /dev/null &
local pid=$!
# Start Thorium in background
thorium-browser &>/dev/null &
local pid=$!
# Wait a few seconds and check if it's still running
sleep 4
# Wait a few seconds and check if it's still running
sleep 4
if kill -0 "$pid" 2> /dev/null; then
log_ok "Thorium started successfully! (PID: $pid)"
echo -e "${GREEN}Fix successful!${NC} Thorium is now running."
if kill -0 "$pid" 2>/dev/null; then
log_ok "Thorium started successfully! (PID: $pid)"
echo -e "${GREEN}Fix successful!${NC} Thorium is now running."
# Offer to keep it running or kill it
read -r -p "Keep browser running? [Y/n] " response
case "$response" in
[nN]*)
kill "$pid" 2> /dev/null || true
log_info "Browser closed"
;;
*)
log_info "Browser left running"
;;
esac
else
log_error "Thorium still crashing after fixes"
echo -e "${RED}Standard fixes did not resolve the issue.${NC}"
echo ""
echo "Try these additional steps:"
echo " 1. Run with --aggressive flag for deeper cleaning"
echo " 2. Test with fresh profile: thorium-browser --user-data-dir=/tmp/thorium-test"
echo " 3. Reinstall: yay -S thorium-browser-bin"
echo " 4. Check NVIDIA drivers: nvidia-smi"
exit 1
fi
# Offer to keep it running or kill it
read -r -p "Keep browser running? [Y/n] " response
case "$response" in
[nN]*)
kill "$pid" 2>/dev/null || true
log_info "Browser closed"
;;
*)
log_info "Browser left running"
;;
esac
else
log_error "Thorium still crashing after fixes"
echo -e "${RED}Standard fixes did not resolve the issue.${NC}"
echo ""
echo "Try these additional steps:"
echo " 1. Run with --aggressive flag for deeper cleaning"
echo " 2. Test with fresh profile: thorium-browser --user-data-dir=/tmp/thorium-test"
echo " 3. Reinstall: yay -S thorium-browser-bin"
echo " 4. Check NVIDIA drivers: nvidia-smi"
exit 1
fi
}
# Main execution

View File

@ -73,7 +73,6 @@ linux_configuration/scripts/single_use/features/lib/website_build.sh
linux_configuration/scripts/single_use/features/lib/wg_firewall.sh
linux_configuration/scripts/single_use/features/lib/wg_keys.sh
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_sysctl.sh
linux_configuration/scripts/single_use/fixes/lib/bt_adapter.sh