Skip to content

Commit

Permalink
Add test cases from @jaesivsm
Browse files Browse the repository at this point in the history
Add a new test file, test_acpi.sh, for testing acpi battery and
temperature info on Linux.
  • Loading branch information
Rycieos committed Dec 22, 2020
1 parent cf8989f commit cef9cb1
Show file tree
Hide file tree
Showing 5 changed files with 308 additions and 0 deletions.
72 changes: 72 additions & 0 deletions tests/test_acpi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@

# Error on unset variables
set -u

# Load Linux version of _lp_battery()
uname() { printf 'Linux'; }

. ../liquidprompt --no-activate
unset -f uname

LP_ENABLE_BATT=1

typeset -a battery_outputs battery_statuses battery_values temp_outputs temp_values

# Add test cases to these arrays like below

# Linux 4.19.0-10-amd64 #1 SMP Debian 4.19.132-1 (2020-07-24) x86_64 GNU/Linux Debian 10 (buster)
battery_outputs+=(
""
)
battery_statuses+=(4)
battery_values+=("")
temp_outputs+=(
"Thermal 0: ok, 23.0 degrees C"
)
temp_values+=(23)


function test_acpi_battery {

acpi() {
printf '%s\n' "$__battery_output"
}

for (( index=0; index < ${#battery_values[@]}; index++ )); do
__battery_output=${battery_outputs[$index]}

LP_BATTERY_THRESHOLD=100
_lp_battery
assertEquals "ACPI battery below returns at index ${index}" "${battery_statuses[$index]}" "$?"
assertEquals "ACPI battery value at index ${index}" "${battery_values[$index]}" "$lp_battery"

_status=${battery_statuses[$index]}
(( _status < 4 )) && _status=$(( _status + 1 ))

LP_BATTERY_THRESHOLD=0
_lp_battery
assertEquals "ACPI battery above returns at index ${index}" "$_status" "$?"
assertEquals "ACPI battery value at index ${index}" "${battery_values[$index]}" "$lp_battery"
done
}

function test_acpi_temperature {

acpi() {
printf '%s\n' "$__temp_output"
}

for (( index=0; index < ${#temp_values[@]}; index++ )); do
__temp_output=${temp_outputs[$index]}
local lp_temperature=0
__lp_temp_acpi
assertEquals "ACPI temperature output at index ${index}" "${temp_values[$index]}" "$lp_temperature"
done
}

if [ -n "${ZSH_VERSION-}" ]; then
SHUNIT_PARENT="$0"
setopt shwordsplit ksh_arrays
fi

. ./shunit2
18 changes: 18 additions & 0 deletions tests/test_connection.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,24 @@ ps_outputs+=(
)
values+=(tel)

# Linux 5.4.0-58-generic #64-Ubuntu SMP Wed Dec 9 08:16:25 UTC 2020 x86_64 GNU/Linux Ubuntu 20.04.1 LTS
who_outputs+=(
""
)
ps_outputs+=(
"bash"
)
values+=(lcl)

# Linux 4.9.0-13-amd64 #1 SMP Debian 4.9.228-1 (2020-07-05) x86_64 GNU/Linux Debian 9.13 (stretch)
who_outputs+=(
"user pts/75 Dec 22 10:39 (10.0.0.117)"
)
ps_outputs+=(
"bash"
)
values+=(tel)


function test_connection {

Expand Down
9 changes: 9 additions & 0 deletions tests/test_detached_sessions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ screen_outputs+=(
)
screen_values+=(1)

# Linux 4.9.0-13-amd64 #1 SMP Debian 4.9.228-1 (2020-07-05) x86_64 GNU/Linux Debian 9.13 (stretch)
screen_outputs+=(
"There is a screen on:""
30133.pts-6.hostnam (08/03/20 09:10:09) (Attached)
1 Socket in /run/screen/S-user.""
"
)
screen_values+=(0)


function test_screen_sessions {

Expand Down
203 changes: 203 additions & 0 deletions tests/test_sensors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,209 @@ temp1:
)
values+=(25)

# Linux 5.4.0-58-generic #64-Ubuntu SMP Wed Dec 9 08:16:25 UTC 2020 x86_64 GNU/Linux Ubuntu 20.04.1 LTS
outputs+=(
"ath10k_hwmon-pci-0200
Adapter: PCI adapter
temp1:
temp1_input: 47.000
coretemp-isa-0000
Adapter: ISA adapter
Package id 0:
temp1_input: 68.000
temp1_max: 100.000
temp1_crit: 100.000
temp1_crit_alarm: 0.000
Core 0:
temp2_input: 68.000
temp2_max: 100.000
temp2_crit: 100.000
temp2_crit_alarm: 0.000
Core 1:
temp3_input: 67.000
temp3_max: 100.000
temp3_crit: 100.000
temp3_crit_alarm: 0.000
Core 2:
temp4_input: 66.000
temp4_max: 100.000
temp4_crit: 100.000
temp4_crit_alarm: 0.000
Core 3:
temp5_input: 65.000
temp5_max: 100.000
temp5_crit: 100.000
temp5_crit_alarm: 0.000
BAT0-acpi-0
Adapter: ACPI interface
in0:
in0_input: 12.642
curr1:
curr1_input: 0.001
dell_smm-virtual-0
Adapter: Virtual device
fan1:
fan1_input: 4921.000
fan2:
fan2_input: 4921.000
pch_skylake-virtual-0
Adapter: Virtual device
temp1:
temp1_input: 55.500
acpitz-acpi-0
Adapter: ACPI interface
temp1:
temp1_input: 25.000
temp1_crit: 107.000
"
)
values+=(68)

# Linux 4.9.0-13-amd64 #1 SMP Debian 4.9.228-1 (2020-07-05) x86_64 GNU/Linux Debian 9.13 (stretch)
outputs+=(
"coretemp-isa-0000
Adapter: ISA adapter
Physical id 0:
temp1_input: 51.000
temp1_max: 74.000
temp1_crit: 94.000
temp1_crit_alarm: 0.000
Core 0:
temp2_input: 46.000
temp2_max: 74.000
temp2_crit: 94.000
temp2_crit_alarm: 0.000
Core 1:
temp3_input: 52.000
temp3_max: 74.000
temp3_crit: 94.000
temp3_crit_alarm: 0.000
Core 2:
temp4_input: 48.000
temp4_max: 74.000
temp4_crit: 94.000
temp4_crit_alarm: 0.000
Core 3:
temp5_input: 43.000
temp5_max: 74.000
temp5_crit: 94.000
temp5_crit_alarm: 0.000
"
)
values+=(52)

# Linux 4.9.78-xxxx-std-ipv6-64 #2 SMP Wed Jan 24 10:27:15 CET 2018 x86_64 GNU/Linux Debian 10 (buster)
outputs+=(
"coretemp-isa-0000
Adapter: ISA adapter
Core 0:
temp2_input: 48.000
temp2_crit: 100.000
temp2_crit_alarm: 0.000
Core 1:
temp3_input: 47.000
temp3_crit: 100.000
temp3_crit_alarm: 0.000
w83627dhg-isa-0290
Adapter: ISA adapter
Vcore:
in0_input: 1.032
in0_min: 0.000
in0_max: 1.744
in0_alarm: 0.000
in1:
in1_input: 1.008
in1_min: 2.024
in1_max: 1.056
in1_alarm: 1.000
AVCC:
in2_input: 3.376
in2_min: 2.976
in2_max: 3.632
in2_alarm: 0.000
+3.3V:
in3_input: 3.376
in3_min: 2.976
in3_max: 3.632
in3_alarm: 0.000
in4:
in4_input: 1.016
in4_min: 1.240
in4_max: 0.232
in4_alarm: 1.000
in5:
in5_input: 1.512
in5_min: 1.760
in5_max: 0.576
in5_alarm: 1.000
in6:
in6_input: 1.080
in6_min: 0.664
in6_max: 0.048
in6_alarm: 1.000
3VSB:
in7_input: 3.392
in7_min: 2.976
in7_max: 3.632
in7_alarm: 0.000
Vbat:
in8_input: 3.264
in8_min: 2.704
in8_max: 3.632
in8_alarm: 0.000
fan1:
fan1_input: 0.000
fan1_min: 10546.000
fan1_alarm: 1.000
fan1_div: 128.000
fan2:
fan2_input: 0.000
fan2_min: 10546.000
fan2_alarm: 1.000
fan2_div: 128.000
fan3:
fan3_input: 0.000
fan3_min: 10546.000
fan3_alarm: 1.000
fan3_div: 128.000
fan4:
fan4_input: 0.000
fan4_min: 10546.000
fan4_alarm: 1.000
fan4_div: 128.000
fan5:
fan5_input: 0.000
fan5_min: 10546.000
fan5_alarm: 1.000
fan5_div: 128.000
temp1:
temp1_input: 44.000
temp1_max: 3.000
temp1_max_hyst: 64.000
temp1_alarm: 0.000
temp1_type: 1.000
temp1_offset: 0.000
temp3:
temp3_input: 44.500
temp3_max: 80.000
temp3_max_hyst: 75.000
temp3_alarm: 0.000
temp3_type: 1.000
temp3_offset: 0.000
cpu0_vid:
cpu0_vid: 0.000
intrusion0:
intrusion0_alarm: 1.000
"
)
values+=(48)


function test_sensors {

Expand Down
6 changes: 6 additions & 0 deletions tests/test_terminal_device.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ tty_outputs+=(
)
values+=("ttys135")

# Linux 4.9.0-13-amd64 #1 SMP Debian 4.9.228-1 (2020-07-05) x86_64 GNU/Linux Debian 9.13 (stretch)
tty_outputs+=(
"/dev/pts/75"
)
values+=("75")


function test_terminal_device {

Expand Down

0 comments on commit cef9cb1

Please sign in to comment.