tools/testing/selftests/power_supply/helpers.sh
Source file repositories/reference/linux-study-clean/tools/testing/selftests/power_supply/helpers.sh
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/power_supply/helpers.sh- Extension
.sh- Size
- 3464 bytes
- Lines
- 179
- 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
SYSFS_SUPPLIES=/sys/class/power_supply
calc() {
awk "BEGIN { print $* }";
}
test_sysfs_prop() {
PROP="$1"
VALUE="$2" # optional
PROP_PATH="$SYSFS_SUPPLIES"/"$DEVNAME"/"$PROP"
TEST_NAME="$DEVNAME".sysfs."$PROP"
if [ -z "$VALUE" ]; then
ktap_test_result "$TEST_NAME" [ -f "$PROP_PATH" ]
else
ktap_test_result "$TEST_NAME" grep -q "$VALUE" "$PROP_PATH"
fi
}
to_human_readable_unit() {
VALUE="$1"
UNIT="$2"
case "$VALUE" in
*[!0-9]* ) return ;; # Not a number
esac
if [ "$UNIT" = "uA" ]; then
new_unit="mA"
div=1000
elif [ "$UNIT" = "uV" ]; then
new_unit="V"
div=1000000
elif [ "$UNIT" = "uAh" ]; then
new_unit="Ah"
div=1000000
elif [ "$UNIT" = "uW" ]; then
new_unit="mW"
div=1000
elif [ "$UNIT" = "uWh" ]; then
new_unit="Wh"
div=1000000
else
return
fi
value_converted=$(calc "$VALUE"/"$div")
echo "$value_converted" "$new_unit"
}
_check_sysfs_prop_available() {
PROP=$1
PROP_PATH="$SYSFS_SUPPLIES"/"$DEVNAME"/"$PROP"
TEST_NAME="$DEVNAME".sysfs."$PROP"
if [ ! -e "$PROP_PATH" ] ; then
ktap_test_skip "$TEST_NAME"
return 1
fi
if ! cat "$PROP_PATH" >/dev/null; then
ktap_print_msg "Failed to read"
ktap_test_fail "$TEST_NAME"
return 1
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.