#!/usr/bin/env bats load test_helper # system/hardware.sh on a fake machine under $HARDWARE_ROOT, with fake pacman, # yay, sudo and systemctl setup() { common_setup export COREDESKTOP="$REPO" export HARDWARE_ROOT="$BATS_TEST_TMPDIR/root" R="$HARDWARE_ROOT" mkdir -p "$R/sys/class/ieee80211" "$R/sys/class/power_supply" "$R/sys/bus/pci/devices" \ "$R/proc" "$R/etc/conf.d" "$R/usr/share/zoneinfo/Europe" printf '# Countries\nUS\t+404251-0740023\tAmerica/New_York\nDE\t+5230+01322\tEurope/Berlin\n' \ > "$R/usr/share/zoneinfo/zone.tab" touch "$R/usr/share/zoneinfo/Europe/Berlin" ln -s "$R/usr/share/zoneinfo/Europe/Berlin" "$R/etc/localtime" printf '#WIRELESS_REGDOM="DE"\n#WIRELESS_REGDOM="US"\n' > "$R/etc/conf.d/wireless-regdom" cpu AuthenticAMD 25 33 stub pacman 'exit 1' stub yay stub sudo '"$@"' stub systemctl '[ "$1" != is-enabled ]' } cpu() { printf 'processor\t: 0\nvendor_id\t: %s\ncpu family\t: %s\nmodel\t\t: %s\n' "$1" "$2" "$3" > "$R/proc/cpuinfo" } wifi() { mkdir -p "$R/sys/class/ieee80211/phy0"; } battery() { mkdir -p "$R/sys/class/power_supply/BAT0"; } pci() { mkdir -p "$R/sys/bus/pci/devices/$1" echo "0x$2" > "$R/sys/bus/pci/devices/$1/vendor" echo "0x$3" > "$R/sys/bus/pci/devices/$1/device" } @test "hardware.sh sets the Wi-Fi country from the time zone" { wifi run bash "$REPO/system/hardware.sh" [ "$status" -eq 0 ] called yay -S --noconfirm --answerdiff=None --answeredit=None --answerclean=None wireless-regdb grep -qx 'WIRELESS_REGDOM="DE"' "$R/etc/conf.d/wireless-regdom" } @test "hardware.sh leaves a Wi-Fi country that's set" { wifi echo 'WIRELESS_REGDOM="FR"' >> "$R/etc/conf.d/wireless-regdom" run bash "$REPO/system/hardware.sh" [ "$status" -eq 0 ] [ "$(grep -c '^WIRELESS_REGDOM' "$R/etc/conf.d/wireless-regdom")" -eq 1 ] } @test "hardware.sh says so when the time zone has no country" { wifi ln -sfn "$R/usr/share/zoneinfo/UTC" "$R/etc/localtime" run bash "$REPO/system/hardware.sh" [ "$status" -eq 0 ] [[ "$output" == *"Couldn't tell the country"* ]] refute grep -q '^WIRELESS_REGDOM' "$R/etc/conf.d/wireless-regdom" } @test "hardware.sh does nothing for Wi-Fi without it" { run bash "$REPO/system/hardware.sh" [ "$status" -eq 0 ] not_called yay refute grep -q '^WIRELESS_REGDOM' "$R/etc/conf.d/wireless-regdom" } @test "hardware.sh runs thermald and intel-lpmd on a newer Intel laptop" { battery cpu GenuineIntel 6 170 run bash "$REPO/system/hardware.sh" [ "$status" -eq 0 ] called yay -S --noconfirm --answerdiff=None --answeredit=None --answerclean=None thermald called yay -S --noconfirm --answerdiff=None --answeredit=None --answerclean=None intel-lpmd called systemctl enable thermald.service called systemctl enable intel_lpmd.service } @test "hardware.sh runs only thermald on an older Intel laptop" { battery cpu GenuineIntel 6 142 run bash "$REPO/system/hardware.sh" [ "$status" -eq 0 ] called systemctl enable thermald.service uncalled systemctl enable intel_lpmd.service } @test "hardware.sh leaves Intel desktops and AMD laptops alone" { cpu GenuineIntel 6 170 run bash "$REPO/system/hardware.sh" not_called systemctl battery cpu AuthenticAMD 25 33 run bash "$REPO/system/hardware.sh" not_called systemctl } @test "hardware.sh turns off Wi-Fi 7 on an Intel BE200" { pci 0000:00:14.3 8086 272b run bash "$REPO/system/hardware.sh" [ "$status" -eq 0 ] grep -qx 'options iwlwifi disable_11be=Y' "$R/etc/modprobe.d/iwlwifi-disable-eht.conf" } @test "hardware.sh leaves other Wi-Fi cards on Wi-Fi 7" { pci 0000:00:14.3 8086 7e40 run bash "$REPO/system/hardware.sh" [ "$status" -eq 0 ] [ ! -e "$R/etc/modprobe.d/iwlwifi-disable-eht.conf" ] }