tools/testing/selftests/power_supply/test_power_supply_properties.sh
Source file repositories/reference/linux-study-clean/tools/testing/selftests/power_supply/test_power_supply_properties.sh
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/power_supply/test_power_supply_properties.sh- Extension
.sh- Size
- 3583 bytes
- Lines
- 115
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: tools
- Status
- atlas-only
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
#
# Copyright (c) 2022, 2024 Collabora Ltd
#
# This test validates the power supply uAPI: namely, the files in sysfs and
# lines in uevent that expose the power supply properties.
#
# By default all power supplies available are tested. Optionally the name of a
# power supply can be passed as a parameter to test only that one instead.
DIR="$(dirname "$(readlink -f "$0")")"
. "${DIR}"/../kselftest/ktap_helpers.sh
. "${DIR}"/helpers.sh
count_tests() {
SUPPLIES=$1
# This needs to be updated every time a new test is added.
NUM_TESTS=33
total_tests=0
for i in $SUPPLIES; do
total_tests=$((total_tests + NUM_TESTS))
done
echo "$total_tests"
}
ktap_print_header
SYSFS_SUPPLIES=/sys/class/power_supply/
if [ $# -eq 0 ]; then
supplies=$(ls "$SYSFS_SUPPLIES")
else
supplies=$1
fi
ktap_set_plan "$(count_tests "$supplies")"
for DEVNAME in $supplies; do
ktap_print_msg Testing device "$DEVNAME"
if [ ! -d "$SYSFS_SUPPLIES"/"$DEVNAME" ]; then
ktap_test_fail "$DEVNAME".exists
ktap_exit_fail_msg Device does not exist
fi
ktap_test_pass "$DEVNAME".exists
test_uevent_prop NAME "$DEVNAME"
test_sysfs_prop type
SUPPLY_TYPE=$(cat "$SYSFS_SUPPLIES"/"$DEVNAME"/type)
# This fails on kernels < 5.8 (needs 2ad3d74e3c69f)
test_uevent_prop TYPE "$SUPPLY_TYPE"
test_sysfs_prop_optional usb_type
test_sysfs_prop_optional_range online 0 2
test_sysfs_prop_optional_range present 0 1
test_sysfs_prop_optional_list status "Unknown","Charging","Discharging","Not charging","Full"
# Capacity is reported as percentage, thus any value less than 0 and
# greater than 100 are not allowed.
test_sysfs_prop_optional_range capacity 0 100 "%"
Annotation
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.