batt: distinguish AC line status values - #499
Conversation
Report battery power only for an offline AC line and diagnose unknown or invalid statuses. Add regression coverage for each AC line status path. AI-Assisted-by: GPT-5.6 (Codex) Signed-off-by: Lucas Holt <luke@foolishgames.com>
Reviewer's GuideThe PR replaces the previous fallback AC-line handling with an explicit switch that distinguishes battery power, plugged-in, unknown, and invalid values, and adds ATF regression coverage for the new behavior. Flow diagram for AC-line status handlingflowchart TD
A[Read AC line status] --> B{AC line value}
B -->|0| C[Print System running on battery power]
B -->|1| D[Print System plugged in]
B -->|-1| E[Exit with AC line status unknown]
B -->|Other| F[Exit with unexpected AC line status value]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Claude finished @laffer1's task in 1m 45s —— View job Review: batt: distinguish AC line status values (#499, merged)
No specific question was included in the trigger comment beyond the PR description, so here is a code review of the merged changes per repo review guidelines (correctness, malloc/free symmetry, bounds checking, style(9), security). Correctness — verified against the kernel side I cross-checked the new switch in
So the new mapping — Bounds/size checks: The malloc/free: Style: The new AC-line branch uses an Security: No injection, overflow, or format-string issues. Tests: The new ATF cases ( Overall: no correctness, memory-safety, or style(9) issues found in the shipped diff. |
There was a problem hiding this comment.
🟢 Approval recommended
The change is narrowly scoped, handles the sysctl value domain explicitly, and includes targeted regression coverage for the new behaviors.
Pull request overview
This PR improves usr.bin/batt’s interpretation of the hw.acpi.acline sysctl by distinguishing the supported AC-line status values (0/1), explicitly handling the kernel sentinel -1, and rejecting any other unexpected values; it also adds regression tests to cover the new behavior.
Changes:
- Update
batt -toutput to report AC-line status0as “System running on battery power” and1as “System plugged in”. - Treat AC-line status
-1as “unknown” (exit 1) and reject other values as unexpected (exit 1). - Add ATF regression tests for battery power, unknown, and invalid AC-line status values.
File summaries
| File | Description |
|---|---|
| usr.bin/batt/batt.c | Switch-based handling of hw.acpi.acline with explicit mapping for 0/1, sentinel -1 error, and default rejection of other values. |
| usr.bin/batt/tests/batt_test.c | Adds regression test cases for AC-line values 0 (battery), -1 (unknown), and 2 (invalid), and registers them in the test plan. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Summary
Master already flushes the test child output via
exit(), so this PR does not duplicate the stable-branch harness fix.Testing
bmake -C usr.bin/batt clean allkyua test -k /usr/obj/usr/src/amd64.amd64/usr.bin/batt/tests/Kyuafile(9/9 passed)git diff --cached --check -- usr.bin/battThe repository C-analysis scripts were invoked. Their
\.c$filter skipped clang-tidy and Splint, so both were also run manually. Splint cannot parse the current system headers; clang-tidy/cppcheck reported pre-existing diagnostics in batt and its test harness, with no diagnostic specific to the new AC-line switch.AI-Assisted-by: GPT-5.6 (Codex)
Summary by Sourcery
Distinguish supported AC-line status values and handle sentinel or invalid values explicitly.
New Features:
Bug Fixes:
Tests: