Skip to content

Commit

Permalink
bat.d/thinkpad{-legacy}: unit tests for feature-detection edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
linrunner committed Dec 19, 2021
1 parent b09c98e commit 1680d9f
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 0 deletions.
31 changes: 31 additions & 0 deletions unit-tests/charge-thresholds_thinkpad
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,34 @@ $ sudo tlp-stat -b -- X_THRESH_SIMULATE_READERR=1 | grep -E 'charge_(control|beh
/sys/class/power_supply/BAT0/charge_control_start_threshold = (not available) [%]
/sys/class/power_supply/BAT0/charge_control_end_threshold = (not available) [%]
/sys/class/power_supply/BAT0/charge_behaviour = [auto] inhibit-charge force-discharge
$ # --- Feature Detection Edge Cases
$ sudo ./kmod-helper acpi_call restore
$ sudo ./kmod-helper acpi_call enable
$ sudo tlp-stat -b -- NATACPI_ENABLE=0 | head -8 | tail -5
Plugin: thinkpad
Supported features: charge thresholds, recalibration
Driver usage:
* natacpi (thinkpad_acpi) = inactive (disabled by configuration)
* tpacpi-bat (acpi_call) = active (charge thresholds, recalibration)
$ sudo ./kmod-helper acpi_call disable
$ sudo tlp-stat -b -- NATACPI_ENABLE=0 | head -8 | tail -5
Plugin: thinkpad
Supported features: none available
Driver usage:
* natacpi (thinkpad_acpi) = inactive (disabled by configuration)
* tpacpi-bat (acpi_call) = inactive (kernel module 'acpi_call' load error)
$ sudo ./kmod-helper acpi_call enable
$ sudo ./kmod-helper acpi_call remove
$ sudo tlp-stat -b -- NATACPI_ENABLE=0 | head -8 | tail -5
Plugin: thinkpad
Supported features: none available
Driver usage:
* natacpi (thinkpad_acpi) = inactive (disabled by configuration)
* tpacpi-bat (acpi_call) = inactive (kernel module 'acpi_call' not installed)
$ sudo ./kmod-helper acpi_call restore
$ sudo tlp-stat -b -- NATACPI_ENABLE=0 TPACPI_ENABLE=0 | head -8 | tail -5
Plugin: thinkpad
Supported features: none available
Driver usage:
* natacpi (thinkpad_acpi) = inactive (disabled by configuration)
* tpacpi-bat (acpi_call) = inactive (disabled by configuration)
32 changes: 32 additions & 0 deletions unit-tests/charge-thresholds_thinkpad-legacy
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,35 @@ $ sudo tlp-stat -b -- X_THRESH_SIMULATE_READERR=1 | grep -E 'charge_thresh|disch
/sys/devices/platform/smapi/BAT0/start_charge_thresh = (not available) [%]
/sys/devices/platform/smapi/BAT0/stop_charge_thresh = (not available) [%]
/sys/devices/platform/smapi/BAT0/force_discharge = 0
$ # --- Feature Detection Edge Cases
$ sudo ./kmod-helper tp_smapi restore
$ sudo ./kmod-helper tp_smapi enable
$ sudo tlp-stat -b | head -7 | tail -4
Plugin: thinkpad-legacy
Supported features: charge thresholds, recalibration
Driver usage:
* tp-smapi (tp_smapi) = active (status, charge thresholds, recalibration)
$ sudo tlp-stat -b -- NATACPI_ENABLE=0 | head -7 | tail -4
Plugin: thinkpad-legacy
Supported features: charge thresholds, recalibration
Driver usage:
* tp-smapi (tp_smapi) = active (status, charge thresholds, recalibration)
$ sudo tlp-stat -b -- NATACPI_ENABLE=0 TPACPI_ENABLE=0 | head -7 | tail -4
Plugin: thinkpad-legacy
Supported features: charge thresholds, recalibration
Driver usage:
* tp-smapi (tp_smapi) = active (status, charge thresholds, recalibration)
$ sudo ./kmod-helper tp_smapi disable
$ sudo tlp-stat -b | head -7 | tail -4
Plugin: thinkpad-legacy
Supported features: none available
Driver usage:
* tp-smapi (tp_smapi) = inactive (kernel module 'tp_smapi' load error)
$ sudo ./kmod-helper tp_smapi enable
$ sudo ./kmod-helper tp_smapi remove
$ sudo tlp-stat -b | head -7 | tail -4
Plugin: thinkpad-legacy
Supported features: none available
Driver usage:
* tp-smapi (tp_smapi) = inactive (kernel module 'tp_smapi' not installed)
$ sudo ./kmod-helper tp_smapi restore
59 changes: 59 additions & 0 deletions unit-tests/kmod-helper
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/sh
# Kernel module helper for battery care testing: disable/remove DKMS modules
# $1: module name
# $2: disable/enable/remove/restore

# Constants
KILLFILE=/etc/modprobe.d/kmod-helper.conf

# Functions
unload_kmod () { # $1: module name
modprobe -r "$1"
}

# MAIN

if [ "$1" != "acpi_call" ] && [ "$1" != "tp_smapi" ]; then
echo "Error: unknown kernel module \"$1\"." 1>&2
exit 1
fi

kernel=$(uname -r)
module=$1
modfile="/lib/modules/${kernel}/updates/dkms/${module}.ko"
modsave="${modfile}-save"

case "$2" in
disable)
unload_kmod "$module"
echo "install ${module} killmod" > $KILLFILE
;;

enable)
rm -f "$KILLFILE"
;;

remove)
unload_kmod "$module"
if [ -f "$modfile" ]; then
mv "$modfile" "$modsave"
else
exit 2
fi
;;

restore)
if [ -f "$modsave" ]; then
mv "$modsave" "$modfile"
else
exit 2
fi
;;

*)
echo "Error: unknown action \"$2\"." 1>&2
exit 1
;;
esac

exit 0

0 comments on commit 1680d9f

Please sign in to comment.