Skip to content

Commit 58c3d7f

Browse files
committed
Enhance battery care unit-tests
* Simulations can run on hardware with BAT0+BAT1 * Cache credentials for sudo before actual tests
1 parent 97d54d9 commit 58c3d7f

11 files changed

Lines changed: 109 additions & 97 deletions

unit-tests/charge-thresholds_cros-ec-v2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ $ sudo tlp setcharge XYZZY ABCDE ${batb} -- ${xinc} 2>&1 | sed -r "s/${batb}/BAT
9696
Error: battery BATB not present.
9797
$ #
9898
$ # --- tlp-stat
99-
$ sudo tlp-stat -b -- ${xinc} | grep "charge_control_end_threshold" | sed -r "s/${bata}/BATA/"
99+
$ sudo tlp-stat -b -- ${xinc} | grep "${bata}/charge_control_end_threshold" | sed -r "s/${bata}/BATA/"
100100
/sys/class/power_supply/BATA/charge_control_end_threshold = 100 [%]
101-
$ sudo tlp-stat -b -- ${xinc} X_THRESH_SIMULATE_READERR=1 | grep "charge_control_end_threshold" | sed -r "s/${bata}/BATA/"
101+
$ sudo tlp-stat -b -- ${xinc} X_THRESH_SIMULATE_READERR=1 | grep "${bata}/charge_control_end_threshold" | sed -r "s/${bata}/BATA/"
102102
/sys/class/power_supply/BATA/charge_control_end_threshold = (not available) [%]
103103
$ #
104104
$ # --- Reset test machine to configured thresholds

unit-tests/charge-thresholds_simulate1

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ TLP started in AC mode (auto).
1919
$ sudo tlp start -- X_BAT_PLUGIN_SIMULATE=asus START_CHARGE_THRESH_BAT0="0" STOP_CHARGE_THRESH_BAT0="0" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
2020
Error in configuration at STOP_CHARGE_THRESH_BAT0="0": not specified, invalid or out of range (1..100). Battery skipped.
2121
TLP started in AC mode (auto).
22-
$ sudo tlp start -- X_BAT_PLUGIN_SIMULATE=asus START_CHARGE_THRESH_BAT0="0" STOP_CHARGE_THRESH_BAT0="101" START_CHARGE_THRESH_BAT$
22+
$ sudo tlp start -- X_BAT_PLUGIN_SIMULATE=asus START_CHARGE_THRESH_BAT0="0" STOP_CHARGE_THRESH_BAT0="101" START_CHARGE_THRESH_BAT= STOP_CHARGE_THRESH_BAT1=
2323
Error in configuration at STOP_CHARGE_THRESH_BAT0="101": not specified, invalid or out of range (1..100). Battery skipped.
2424
TLP started in AC mode (auto).
2525
$ sudo tlp start -- X_BAT_PLUGIN_SIMULATE=asus START_CHARGE_THRESH_BAT0="95" STOP_CHARGE_THRESH_BAT0="86" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
@@ -90,17 +90,17 @@ Setting temporary charge threshold for BAT0:
9090
$ sudo tlp setcharge DEF DEF -- X_BAT_PLUGIN_SIMULATE=asus
9191
Setting temporary charge threshold for BAT0:
9292
stop = 100
93-
$ sudo tlp setcharge BAT1 -- X_BAT_PLUGIN_SIMULATE=asus
94-
Error: battery BAT1 not present.
95-
$ sudo tlp setcharge 0 3 BAT1 -- X_BAT_PLUGIN_SIMULATE=asus
96-
Error: battery BAT1 not present.
97-
$ sudo tlp setcharge XYZZY ABCDE BAT1 -- X_BAT_PLUGIN_SIMULATE=asus
98-
Error: battery BAT1 not present.
93+
$ sudo tlp setcharge BAT2 -- X_BAT_PLUGIN_SIMULATE=asus
94+
Error: battery BAT2 not present.
95+
$ sudo tlp setcharge 0 3 BAT2 -- X_BAT_PLUGIN_SIMULATE=asus
96+
Error: battery BAT2 not present.
97+
$ sudo tlp setcharge XYZZY ABCDE BAT2 -- X_BAT_PLUGIN_SIMULATE=asus
98+
Error: battery BAT2 not present.
9999
$ #
100100
$ # --- tlp-stat
101-
$ sudo tlp-stat -b -- X_BAT_PLUGIN_SIMULATE=asus | grep "charge_control_end_threshold"
101+
$ sudo tlp-stat -b -- X_BAT_PLUGIN_SIMULATE=asus | grep "BAT0/charge_control_end_threshold"
102102
/sys/class/power_supply/BAT0/charge_control_end_threshold = 100 [%]
103-
$ sudo tlp-stat -b -- X_BAT_PLUGIN_SIMULATE=asus X_THRESH_SIMULATE_READERR=1 | grep "charge_control_end_threshold"
103+
$ sudo tlp-stat -b -- X_BAT_PLUGIN_SIMULATE=asus X_THRESH_SIMULATE_READERR=1 | grep "BAT0/charge_control_end_threshold"
104104
/sys/class/power_supply/BAT0/charge_control_end_threshold = (not available) [%]
105105
$ #
106106
$ # +++ Huawei ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@@ -197,12 +197,12 @@ Setting temporary charge thresholds:
197197
$ sudo tlp setcharge 95 95 -- -- X_BAT_PLUGIN_SIMULATE=huawei X_THRESH_SIMULATE_START="95" X_THRESH_SIMULATE_STOP="95"
198198
Setting temporary charge thresholds:
199199
start = 95, stop = 95 (Error: write failed)
200-
$ sudo tlp setcharge BAT1 -- X_BAT_PLUGIN_SIMULATE=huawei
201-
Error: battery BAT1 not present.
202-
$ sudo tlp setcharge 0 3 BAT1 -- X_BAT_PLUGIN_SIMULATE=huawei
203-
Error: battery BAT1 not present.
204-
$ sudo tlp setcharge XYZZY ABCDE BAT1 -- X_BAT_PLUGIN_SIMULATE=huawei
205-
Error: battery BAT1 not present.
200+
$ sudo tlp setcharge BAT2 -- X_BAT_PLUGIN_SIMULATE=huawei
201+
Error: battery BAT2 not present.
202+
$ sudo tlp setcharge 0 3 BAT2 -- X_BAT_PLUGIN_SIMULATE=huawei
203+
Error: battery BAT2 not present.
204+
$ sudo tlp setcharge XYZZY ABCDE BAT2 -- X_BAT_PLUGIN_SIMULATE=huawei
205+
Error: battery BAT2 not present.
206206
$ #
207207
$ # --- tlp-stat
208208
$ sudo tlp-stat -b -- X_BAT_PLUGIN_SIMULATE=huawei X_THRESH_SIMULATE_START="0" X_THRESH_SIMULATE_STOP="0" | grep "charge_control_thresholds"
@@ -255,10 +255,10 @@ Setting temporary charge threshold for all batteries:
255255
$ sudo tlp setcharge DEF DEF -- X_BAT_PLUGIN_SIMULATE=lenovo X_THRESH_SIMULATE_STOP="0"
256256
Setting temporary charge threshold for all batteries:
257257
conservation mode = 0 (no change)
258-
$ sudo tlp setcharge 42 24 BAT1 -- X_BAT_PLUGIN_SIMULATE=lenovo
259-
Error: battery BAT1 not present.
260-
$ sudo tlp setcharge 2 -- X_BAT_PLUGIN_SIMULATE=lenovo
261-
Error: battery 2 not present.
258+
$ sudo tlp setcharge 42 24 BAT2 -- X_BAT_PLUGIN_SIMULATE=lenovo
259+
Error: battery BAT2 not present.
260+
$ sudo tlp setcharge BAT2 -- X_BAT_PLUGIN_SIMULATE=lenovo
261+
Error: battery BAT2 not present.
262262
$ #
263263
$ # --- tlp-stat
264264
$ sudo tlp-stat -b -- X_BAT_PLUGIN_SIMULATE=lenovo | grep "conservation_mode"
@@ -305,15 +305,15 @@ $ sudo tlp setcharge ABCDE XYZZY -- X_BAT_PLUGIN_SIMULATE=lg
305305
Error: stop charge threshold (XYZZY) for battery BAT0 not specified or invalid (must be 80 or 100). Aborted.
306306
$ sudo tlp setcharge DEF DEF -- X_THRESH_SIMULATE_READERR="1"
307307
Error: could not read current charge threshold(s) for battery BAT0. Aborted.
308-
$ sudo tlp setcharge 42 80 BAT1 -- X_BAT_PLUGIN_SIMULATE=lg X_SOC_CHECK=0
309-
Error: battery BAT1 not present.
310-
$ sudo tlp setcharge 2 -- X_BAT_PLUGIN_SIMULATE=lg
311-
Error: battery 2 not present.
308+
$ sudo tlp setcharge 42 80 BAT2 -- X_BAT_PLUGIN_SIMULATE=lg X_SOC_CHECK=0
309+
Error: battery BAT2 not present.
310+
$ sudo tlp setcharge BAT2 -- X_BAT_PLUGIN_SIMULATE=lg
311+
Error: battery BAT2 not present.
312312
$ #
313313
$ # --- tlp-stat
314-
$ sudo tlp-stat -b -- X_BAT_PLUGIN_SIMULATE=lg | grep "charge_control_end_threshold"
314+
$ sudo tlp-stat -b -- X_BAT_PLUGIN_SIMULATE=lg | grep "BAT0/charge_control_end_threshold"
315315
/sys/class/power_supply/BAT0/charge_control_end_threshold = 100 [%]
316-
$ sudo tlp-stat -b -- X_BAT_PLUGIN_SIMULATE=lg X_THRESH_SIMULATE_READERR=1 | grep "charge_control_end_threshold"
316+
$ sudo tlp-stat -b -- X_BAT_PLUGIN_SIMULATE=lg X_THRESH_SIMULATE_READERR=1 | grep "BAT0/charge_control_end_threshold"
317317
/sys/class/power_supply/BAT0/charge_control_end_threshold = (not available) [%]
318318
$ #
319319
$ # ---
@@ -356,10 +356,10 @@ $ sudo tlp setcharge ABCDE XYZZY -- X_BAT_PLUGIN_SIMULATE=lg-legacy
356356
Error: care limit (XYZZY) not specified or invalid (must be 80 or 100). Aborted.
357357
$ sudo tlp setcharge DEF DEF -- X_BAT_PLUGIN_SIMULATE=lg-legacy X_THRESH_SIMULATE_READERR="1"
358358
Error: could not read current care limit. Aborted.
359-
$ sudo tlp setcharge 42 80 BAT1 -- X_BAT_PLUGIN_SIMULATE=lg-legacy
360-
Error: battery BAT1 not present.
361-
$ sudo tlp setcharge 2 -- X_BAT_PLUGIN_SIMULATE=lg-legacy
362-
Error: battery 2 not present.
359+
$ sudo tlp setcharge 42 80 BAT2 -- X_BAT_PLUGIN_SIMULATE=lg-legacy
360+
Error: battery BAT2 not present.
361+
$ sudo tlp setcharge BAT2 -- X_BAT_PLUGIN_SIMULATE=lg-legacy
362+
Error: battery BAT2 not present.
363363
$ #
364364
$ # --- tlp-stat
365365
$ sudo tlp-stat -b -- X_BAT_PLUGIN_SIMULATE=lg-legacy | grep "battery_care_limit"

unit-tests/charge-thresholds_simulate2

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,18 @@ Setting temporary charge thresholds for battery BAT0:
7070
start = 100 (due to hardware constraint)
7171
$ sudo tlp setcharge DEF DEF -- X_BAT_PLUGIN_SIMULATE=macbook X_THRESH_SIMULATE_READERR="1"
7272
Error: could not read current stop charge threshold for battery BAT0. Aborted.
73-
$ sudo tlp setcharge BAT1 -- X_BAT_PLUGIN_SIMULATE=macbook
74-
Error: battery BAT1 not present.
75-
$ sudo tlp setcharge 0 3 BAT1 -- X_BAT_PLUGIN_SIMULATE=macbook
76-
Error: battery BAT1 not present.
77-
$ sudo tlp setcharge XYZZY ABCDE BAT1 -- X_BAT_PLUGIN_SIMULATE=macbook
78-
Error: battery BAT1 not present.
73+
$ sudo tlp setcharge BAT2 -- X_BAT_PLUGIN_SIMULATE=macbook
74+
Error: battery BAT2 not present.
75+
$ sudo tlp setcharge 0 3 BAT2 -- X_BAT_PLUGIN_SIMULATE=macbook
76+
Error: battery BAT2 not present.
77+
$ sudo tlp setcharge XYZZY ABCDE BAT2 -- X_BAT_PLUGIN_SIMULATE=macbook
78+
Error: battery BAT2 not present.
7979
$ #
8080
$ # --- tlp-stat
81-
$ sudo tlp-stat -b -- X_BAT_PLUGIN_SIMULATE=macbook X_THRESH_SIMULATE_START=100 | grep -E 'charge_control'
81+
$ sudo tlp-stat -b -- X_BAT_PLUGIN_SIMULATE=macbook X_THRESH_SIMULATE_START=100 | grep -E 'BAT0/charge_control'
8282
/sys/class/power_supply/BAT0/charge_control_start_threshold = 100 [%]
8383
/sys/class/power_supply/BAT0/charge_control_end_threshold = 100 [%]
84-
$ sudo tlp-stat -b -- X_BAT_PLUGIN_SIMULATE=macbook X_THRESH_SIMULATE_READERR=1 | grep -E 'charge_control'
84+
$ sudo tlp-stat -b -- X_BAT_PLUGIN_SIMULATE=macbook X_THRESH_SIMULATE_READERR=1 | grep -E 'BAT0/charge_control'
8585
/sys/class/power_supply/BAT0/charge_control_start_threshold = (not available) [%]
8686
/sys/class/power_supply/BAT0/charge_control_end_threshold = (not available) [%]
8787
$ #
@@ -182,18 +182,18 @@ $ sudo tlp setcharge 95 96 -- X_BAT_PLUGIN_SIMULATE=msi X_SOC_CHECK=0
182182
Setting temporary charge thresholds for battery BAT0:
183183
stop = 96 (no change)
184184
start = 86 (no change)
185-
$ sudo tlp setcharge BAT1 -- X_BAT_PLUGIN_SIMULATE=msi
186-
Error: battery BAT1 not present.
187-
$ sudo tlp setcharge 0 3 BAT1 -- X_BAT_PLUGIN_SIMULATE=msi
188-
Error: battery BAT1 not present.
189-
$ sudo tlp setcharge XYZZY ABCDE BAT1 -- X_BAT_PLUGIN_SIMULATE=msi
190-
Error: battery BAT1 not present.
185+
$ sudo tlp setcharge BAT2 -- X_BAT_PLUGIN_SIMULATE=msi
186+
Error: battery BAT2 not present.
187+
$ sudo tlp setcharge 0 3 BAT2 -- X_BAT_PLUGIN_SIMULATE=msi
188+
Error: battery BAT2 not present.
189+
$ sudo tlp setcharge XYZZY ABCDE BAT2 -- X_BAT_PLUGIN_SIMULATE=msi
190+
Error: battery BAT2 not present.
191191
$ #
192192
$ # --- tlp-stat
193-
$ sudo tlp-stat -b -- X_BAT_PLUGIN_SIMULATE=msi | grep -E 'charge_control'
193+
$ sudo tlp-stat -b -- X_BAT_PLUGIN_SIMULATE=msi | grep -E 'BAT0/charge_control'
194194
/sys/class/power_supply/BAT0/charge_control_start_threshold = 86 [%]
195195
/sys/class/power_supply/BAT0/charge_control_end_threshold = 96 [%]
196-
$ sudo tlp-stat -b -- X_BAT_PLUGIN_SIMULATE=msi X_THRESH_SIMULATE_READERR=1 | grep -E 'charge_control'
196+
$ sudo tlp-stat -b -- X_BAT_PLUGIN_SIMULATE=msi X_THRESH_SIMULATE_READERR=1 | grep -E 'BAT0/charge_control'
197197
/sys/class/power_supply/BAT0/charge_control_start_threshold = (not available) [%]
198198
/sys/class/power_supply/BAT0/charge_control_end_threshold = (not available) [%]
199199
$ #
@@ -236,10 +236,10 @@ Setting temporary charge threshold for all batteries:
236236
$ sudo tlp setcharge DEF DEF -- X_BAT_PLUGIN_SIMULATE=samsung X_THRESH_SIMULATE_STOP="0"
237237
Setting temporary charge threshold for all batteries:
238238
life extender = 0 (no change)
239-
$ sudo tlp setcharge 42 24 BAT1 -- X_BAT_PLUGIN_SIMULATE=samsung
240-
Error: battery BAT1 not present.
241-
$ sudo tlp setcharge 2 -- X_BAT_PLUGIN_SIMULATE=samsung
242-
Error: battery 2 not present.
239+
$ sudo tlp setcharge 42 24 BAT2 -- X_BAT_PLUGIN_SIMULATE=samsung
240+
Error: battery BAT2 not present.
241+
$ sudo tlp setcharge BAT2 -- X_BAT_PLUGIN_SIMULATE=samsung
242+
Error: battery BAT2 not present.
243243
$ #
244244
$ # --- tlp-stat
245245
$ sudo tlp-stat -b -- X_BAT_PLUGIN_SIMULATE=samsung | grep "battery_life_extender"
@@ -305,8 +305,8 @@ Setting temporary charge threshold for all batteries:
305305
$ sudo tlp setcharge DEF DEF -- X_BAT_PLUGIN_SIMULATE=sony X_THRESH_SIMULATE_STOP="0" X_SOC_CHECK=0
306306
Setting temporary charge threshold for all batteries:
307307
care limiter = 100 (no change)
308-
$ sudo tlp setcharge 42 24 BAT1 -- X_BAT_PLUGIN_SIMULATE=sony
309-
Error: battery BAT1 not present.
308+
$ sudo tlp setcharge 42 24 BAT2 -- X_BAT_PLUGIN_SIMULATE=sony
309+
Error: battery BAT2 not present.
310310
$ sudo tlp setcharge 2 -- X_BAT_PLUGIN_SIMULATE=sony
311311
Error: battery 2 not present.
312312
$ #
@@ -405,18 +405,18 @@ $ sudo tlp setcharge DEF DEF -- X_BAT_PLUGIN_SIMULATE=system76
405405
Setting temporary charge thresholds for battery BAT0:
406406
start = 90
407407
stop = 100
408-
$ sudo tlp setcharge BAT1 -- X_BAT_PLUGIN_SIMULATE=system76
409-
Error: battery BAT1 not present.
410-
$ sudo tlp setcharge 0 3 BAT1 -- X_BAT_PLUGIN_SIMULATE=system76
411-
Error: battery BAT1 not present.
412-
$ sudo tlp setcharge XYZZY ABCDE BAT1 -- X_BAT_PLUGIN_SIMULATE=system76
413-
Error: battery BAT1 not present.
408+
$ sudo tlp setcharge BAT2 -- X_BAT_PLUGIN_SIMULATE=system76
409+
Error: battery BAT2 not present.
410+
$ sudo tlp setcharge 0 3 BAT2 -- X_BAT_PLUGIN_SIMULATE=system76
411+
Error: battery BAT2 not present.
412+
$ sudo tlp setcharge XYZZY ABCDE BAT2 -- X_BAT_PLUGIN_SIMULATE=system76
413+
Error: battery BAT2 not present.
414414
$ #
415415
$ # --- tlp-stat
416-
$ sudo tlp-stat -b -- X_BAT_PLUGIN_SIMULATE=system76 | grep -E 'charge_control'
416+
$ sudo tlp-stat -b -- X_BAT_PLUGIN_SIMULATE=system76 | grep -E 'BAT0/charge_control'
417417
/sys/class/power_supply/BAT0/charge_control_start_threshold = 90 [%]
418418
/sys/class/power_supply/BAT0/charge_control_end_threshold = 100 [%]
419-
$ sudo tlp-stat -b -- X_BAT_PLUGIN_SIMULATE=system76 X_THRESH_SIMULATE_READERR=1 | grep -E 'charge_control'
419+
$ sudo tlp-stat -b -- X_BAT_PLUGIN_SIMULATE=system76 X_THRESH_SIMULATE_READERR=1 | grep -E 'BAT0/charge_control'
420420
/sys/class/power_supply/BAT0/charge_control_start_threshold = (not available) [%]
421421
/sys/class/power_supply/BAT0/charge_control_end_threshold = (not available) [%]
422422
$ #
@@ -462,13 +462,13 @@ Setting temporary charge threshold for battery BAT0:
462462
$ sudo tlp setcharge DEF DEF -- X_BAT_PLUGIN_SIMULATE=toshiba
463463
Setting temporary charge threshold for battery BAT0:
464464
stop = 100
465-
$ sudo tlp setcharge 42 80 BAT1 -- X_BAT_PLUGIN_SIMULATE=toshiba
466-
Error: battery BAT1 not present.
467-
$ sudo tlp setcharge 2 -- X_BAT_PLUGIN_SIMULATE=toshiba
468-
Error: battery 2 not present.
465+
$ sudo tlp setcharge 42 80 BAT2 -- X_BAT_PLUGIN_SIMULATE=toshiba
466+
Error: battery BAT2 not present.
467+
$ sudo tlp setcharge BAT2 -- X_BAT_PLUGIN_SIMULATE=toshiba
468+
Error: battery BAT2 not present.
469469
$ #
470470
$ # --- tlp-stat
471-
$ sudo tlp-stat -b -- X_BAT_PLUGIN_SIMULATE=toshiba | grep -E 'charge_control'
471+
$ sudo tlp-stat -b -- X_BAT_PLUGIN_SIMULATE=toshiba | grep -E 'BAT0/charge_control'
472472
/sys/class/power_supply/BAT0/charge_control_end_threshold = 100 [%]
473473
$ #
474474
$ # --- Reset test machine to configured thresholds

unit-tests/test-bc_all-simulate.sh

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,9 @@ readonly TESTLIB="./test-func"
66
exit 70
77
}
88

9+
cache_root_cred
910
start_report
1011

11-
if [ -d /sys/class/power_supply/BAT0/ ] \
12-
&& [ -d /sys/class/power_supply/BAT1/ ]; then
13-
printf "%s -- Error: do not run this test on hardware that has BAT0 *and* BAT1.\n\n" "${0##*/}" 1>&2
14-
report_test "${0##*/}"
15-
report_line "not run"
16-
print_report
17-
fi
18-
1912
run_clitest charge-thresholds_simulate1
2013
run_clitest charge-thresholds_simulate2
2114

unit-tests/test-bc_all.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ readonly TESTLIB="./test-func"
66
exit 70
77
}
88

9+
cache_root_cred
910
start_report
1011

1112
./test-bc_thinkpad.sh

unit-tests/test-bc_cros-ec-all-simulate.sh

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,21 @@ readonly TESTLIB="./test-func"
66
exit 70
77
}
88

9+
cache_root_cred
910
start_report
1011

11-
if [ -d /sys/class/power_supply/BAT0/ ]; then
12-
if [ -d /sys/class/power_supply/BAT1/ ]; then
13-
printf "%s -- Error: do not run this test on hardware that has BAT0 *and* BAT1.\n\n" "${0##*/}" 1>&2
14-
report_test "${0##*/}"
15-
report_line "not run"
16-
print_report
17-
exit 1
18-
fi
12+
if bat_present BAT0; then
1913
export bata=BAT0
20-
export batb=BAT1
21-
elif [ -d /sys/class/power_supply/BAT1/ ]; then
14+
export batb=BAT2
15+
elif bat_present BAT1; then
2216
export bata=BAT1
23-
export batb=BAT0
17+
export batb=BAT2
2418
else
25-
echo "Error: neither BAT0 nor BAT1 exists." 1>&2
19+
# shellcheck disable=SC2059
20+
printf "${ANSI_RED}Error:${ANSI_BLACK} neither BAT0 nor BAT1 exists.\n\n"
21+
report_test "${0##*/}"
22+
report_line "${ANSI_RED}FAIL:${ANSI_BLACK} not run - neither BAT0 nor BAT1 exists"
23+
print_report
2624
exit 1
2725
fi
2826

unit-tests/test-bc_cros-ec-v2.sh

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,21 @@ readonly TESTLIB="./test-func"
66
exit 70
77
}
88

9+
cache_root_cred
910
start_report
1011

11-
if [ -d /sys/class/power_supply/BAT0/ ]; then
12+
if bat_present BAT0; then
1213
export bata=BAT0
13-
export batb=BAT1
14-
elif [ -d /sys/class/power_supply/BAT1/ ]; then
14+
export batb=BAT2
15+
elif bat_present BAT1; then
1516
export bata=BAT1
16-
export batb=BAT0
17+
export batb=BAT2
1718
else
18-
echo "Error: neither BAT0 nor BAT1 exists." 1>&2
19+
# shellcheck disable=SC2059
20+
printf "${ANSI_RED}Error:${ANSI_BLACK} neither BAT0 nor BAT1 exists.\n\n"
21+
report_test "${0##*/}"
22+
report_line "${ANSI_RED}FAIL:${ANSI_BLACK} not run - neither BAT0 nor BAT1 exists"
23+
print_report
1924
exit 1
2025
fi
2126

unit-tests/test-bc_cros-ec-v3.sh

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,21 @@ readonly TESTLIB="./test-func"
66
exit 70
77
}
88

9+
cache_root_cred
910
start_report
1011

11-
if [ -d /sys/class/power_supply/BAT0/ ]; then
12+
if bat_present BAT0; then
1213
export bata=BAT0
13-
export batb=BAT1
14-
elif [ -d /sys/class/power_supply/BAT1/ ]; then
14+
export batb=BAT2
15+
elif bat_present BAT1; then
1516
export bata=BAT1
16-
export batb=BAT0
17+
export batb=BAT2
1718
else
18-
echo "Error: neither BAT0 nor BAT1 exists." 1>&2
19+
# shellcheck disable=SC2059
20+
printf "${ANSI_RED}Error:${ANSI_BLACK} neither BAT0 nor BAT1 exists.\n\n"
21+
report_test "${0##*/}"
22+
report_line "${ANSI_RED}FAIL:${ANSI_BLACK} not run - neither BAT0 nor BAT1 exists"
23+
print_report
1924
exit 1
2025
fi
2126

unit-tests/test-bc_dell-simulate.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ readonly TESTLIB="./test-func"
66
exit 70
77
}
88

9+
cache_root_cred
910
start_report
1011

1112
export xinc="X_BAT_PLUGIN_SIMULATE=dell"

unit-tests/test-func

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ on_ac () {
133133
upower -i /org/freedesktop/UPower/devices/line_power_AC 2> /dev/null | grep -qE 'online:\s+yes'
134134
}
135135

136+
bat_present () {
137+
# Check for battery
138+
# $1: battery name
139+
# rc: 0=present/1=absent
140+
141+
[ "$(read_sysf "/sys/class/power_supply/$1/present")" = "1" ]
142+
}
143+
136144
run_clitest () {
137145
# Run clitest script and record result line to file
138146
# $1: script filepath
@@ -185,7 +193,7 @@ report_line () {
185193
# $1: text
186194
if [ -f "$_report_file" ]; then
187195
# note: use output string in format for proper ansi esc sequence interpolation
188-
# shellcheck disable=SC2059 ###
196+
# shellcheck disable=SC2059
189197
printf "$1\n" >> "$_report_file"
190198
fi
191199
}

0 commit comments

Comments
 (0)