mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-13 20:50:47 +01:00
Two levels of pure taxonomy carrying no information, and a 2-directory
cap leaves no room for them. Categories now sit directly under
linux_configuration/: features, fixes, utils, misc, fresh-install,
installers, diagnostics, gaming, boot_recovery, periodic_background, lib,
meta, tests. A script's own lib/ and tests/ are exempt from the cap, so
those stay put.
Depth violations 248 -> 139; roughly 40 of the remainder are inside
digital_wellbeing and hosts, deferred until the guard-lib repoint.
The moves are the easy half. What breaks is every path that counted
levels, and three classes of it had to be found by resolving paths rather
than reading diffs:
- 52 relative `source` lines for lib/common.sh and lib/android.sh. The
correct prefix differs per file: 40 were ../../ and 12 were ../../../,
so a blanket replace would have fixed one set and broken the other.
- REPO_ROOT in 7 fixes/lib/tests harnesses and setup_syncyomi_guard.sh,
each walking up four levels from a directory now two levels shallower.
This caused a real regression -- the fixes suite went red with
"log_warn: command not found" -- caught by running it and comparing
against the pre-move baseline worktree.
- conftest.py's sys.path entries, which took the pytest gate down with
14 collection errors, and the `# shellcheck source=` directives, which
took shellcheck down with SC1091.
16 symlinks in $HOME broke, including the entire i3blocks bar. All
repointed, and cpu_monitor/memory/disk/time/volume were run to confirm
they emit real output rather than merely resolving.
Verified: 1798 tests pass at 100% coverage, 8 of 9 lib/tests suites pass
(the ninth needs the coverage jail, identically at baseline), pre-commit
is clean, and the two untracked secret configs are still ignored after
their gitignore paths changed.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJrqKERAo5QUeEHWS5Asgp
103 lines
4.2 KiB
Bash
Executable File
103 lines
4.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# lib/tests/test_nvidia_config.sh — tests for nvidia_config.sh's backup_file,
|
|
# configure_xorg and configure_gcc_workaround.
|
|
#
|
|
# install_pyroveil lives in test_nvidia_config_pyroveil.sh, split out to hold
|
|
# every file under the 250-line cap.
|
|
#
|
|
# 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=nvidia_config_harness.sh
|
|
. "${SCRIPT_DIR}/nvidia_config_harness.sh"
|
|
|
|
# shellcheck source=../nvidia_config.sh
|
|
. "${FIXES_DIR}/lib/nvidia_config.sh"
|
|
|
|
printf '\n-- backup_file --\n'
|
|
|
|
# Case 1: a file that does not exist is not backed up, and that is not an error.
|
|
nvidia_reset
|
|
_t_run backup_file "${TEST_TMPDIR}/absent"
|
|
_t_eq "0" "$?" "backup_file: returns 0 for a missing file"
|
|
_t_lacks "$out" "Backed up" "backup_file: says nothing about a missing file"
|
|
|
|
# Case 2: an existing file is copied aside and the original left in place.
|
|
nvidia_reset
|
|
printf 'ORIGINAL\n' >"${XORG_CONF}"
|
|
_t_run backup_file "${XORG_CONF}"
|
|
_t_contains "$out" "Backed up" "backup_file: reports the backup"
|
|
_t_eq "1" "$(_t_backups "${XORG_CONF}")" "backup_file: writes exactly one backup"
|
|
_t_eq "ORIGINAL" "$(cat "${XORG_CONF}")" "backup_file: leaves the original in place"
|
|
|
|
printf '\n-- configure_xorg --\n'
|
|
|
|
# Case 3: a fresh machine -> the drop-in dir is created and the config written
|
|
# with RenderAccel TRUE. Setting it false forces software rendering and pins
|
|
# Xorg at 30%+ CPU, which is why the value is asserted rather than assumed.
|
|
nvidia_reset
|
|
rm -rf "${XORG_CONF_D}"
|
|
_t_run configure_xorg
|
|
conf="$(_t_nvidia_conf)"
|
|
_t_contains "$conf" 'Option "RenderAccel" "true"' \
|
|
"configure_xorg: enables RenderAccel"
|
|
_t_lacks "$conf" '"RenderAccel" "false"' \
|
|
"configure_xorg: never writes the software-rendering value"
|
|
_t_contains "$conf" 'Driver "nvidia"' "configure_xorg: selects the nvidia driver"
|
|
_t_contains "$conf" 'Identifier "NVIDIA Card"' "configure_xorg: names the device section"
|
|
_t_contains "$out" "Created" "configure_xorg: reports what it created"
|
|
|
|
# Case 4: an existing xorg.conf is backed up before anything is written.
|
|
nvidia_reset
|
|
printf 'OLD XORG\n' >"${XORG_CONF}"
|
|
_t_run configure_xorg
|
|
_t_eq "1" "$(_t_backups "${XORG_CONF}")" "configure_xorg: backs up an existing xorg.conf"
|
|
_t_eq "OLD XORG" "$(cat "${XORG_CONF}")" "configure_xorg: does not overwrite xorg.conf itself"
|
|
|
|
# Case 5: an existing 20-nvidia.conf is backed up too, then replaced.
|
|
nvidia_reset
|
|
printf 'OLD NVIDIA CONF\n' >"${XORG_CONF_D}/20-nvidia.conf"
|
|
_t_run configure_xorg
|
|
_t_eq "1" "$(_t_backups "${XORG_CONF_D}/20-nvidia.conf")" \
|
|
"configure_xorg: backs up an existing nvidia drop-in"
|
|
_t_contains "$(_t_nvidia_conf)" "RenderAccel" \
|
|
"configure_xorg: replaces the drop-in with the managed one"
|
|
|
|
printf '\n-- configure_gcc_workaround --\n'
|
|
|
|
# Case 6: a profile without the variable -> appended.
|
|
nvidia_reset
|
|
printf '# existing profile\n' >"${PROFILE_FILE}"
|
|
_t_run configure_gcc_workaround
|
|
profile="$(_t_profile_text)"
|
|
_t_contains "$profile" "export IGNORE_CC_MISMATCH=1" \
|
|
"configure_gcc_workaround: exports the variable"
|
|
_t_contains "$profile" "# existing profile" \
|
|
"configure_gcc_workaround: appends rather than replacing the profile"
|
|
_t_contains "$profile" "Added by nvidia_troubleshoot.sh" \
|
|
"configure_gcc_workaround: stamps the addition"
|
|
_t_contains "$out" "Added IGNORE_CC_MISMATCH=1" "configure_gcc_workaround: reports the change"
|
|
|
|
# Case 7: already present -> not appended a second time. Running the fix twice
|
|
# must not grow /etc/profile without bound.
|
|
nvidia_reset
|
|
printf 'export IGNORE_CC_MISMATCH=1\n' >"${PROFILE_FILE}"
|
|
_t_run configure_gcc_workaround
|
|
_t_contains "$out" "already configured" "configure_gcc_workaround: reports the skip"
|
|
_t_eq "1" "$(grep -c 'IGNORE_CC_MISMATCH' "${PROFILE_FILE}")" \
|
|
"configure_gcc_workaround: does not duplicate the export"
|
|
|
|
# Case 8: the profile is backed up before being modified.
|
|
nvidia_reset
|
|
printf '# profile\n' >"${PROFILE_FILE}"
|
|
_t_run configure_gcc_workaround
|
|
_t_eq "1" "$(_t_backups "${PROFILE_FILE}")" \
|
|
"configure_gcc_workaround: backs up the profile first"
|
|
|
|
printf '\nnvidia_config (xorg/gcc): %d passed, %d failed\n' "$PASS" "$FAIL"
|
|
[[ $FAIL -eq 0 ]]
|