batt: distinguish AC line status values - #498
Conversation
Report battery power only for an offline AC line, diagnose unknown and invalid statuses, and add regression coverage. Flush test output before the child exits so successful output can be asserted. AI-Assisted-by: GPT-5.6 (Codex) Signed-off-by: Lucas Holt <luke@foolishgames.com>
Reviewer's GuideThe PR replaces ambiguous AC-line handling with explicit 0/1/-1/invalid classification and adds ATF regression tests for each new behavior, while flushing child stdout to ensure captured output is deterministic. Flow diagram for AC-line status classificationflowchart TD
A[Read AC line status] --> B{acline 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
|
There was a problem hiding this comment.
🟢 Approval recommended
The behavior change is small, consistent with kernel semantics (including -1), and is covered by targeted regression tests.
Pull request overview
Updates batt(1) to handle hw.acpi.acline values explicitly, distinguishing battery vs plugged-in states, treating the kernel sentinel -1 as “unknown”, and rejecting other unexpected values; also strengthens the test harness to reliably capture child stdout output.
Changes:
- Replace the previous “non-1” fallback message with a
switchover AC-line status (0=battery, 1=plugged in, -1=unknown/error, other=error). - Flush child-process
stdoutin the test runner before_exit()so buffered output (notably non-newline outputs) is not lost. - Add regression tests covering offline (0), unknown (-1), and invalid (2) AC-line values.
File summaries
| File | Description |
|---|---|
| usr.bin/batt/batt.c | Implements explicit AC-line status handling via switch (acline) including unknown (-1) and invalid-value rejection. |
| usr.bin/batt/tests/batt_test.c | Ensures stdout is flushed before _exit() and adds test cases for battery/unknown/invalid AC-line status behavior. |
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
_exit()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
Handle AC-line status values explicitly and add regression coverage for valid, unknown, and invalid states.
New Features:
Bug Fixes:
Enhancements:
Tests: