Skip to content

batt: distinguish AC line status values - #498

Merged
laffer1 merged 1 commit into
stable/4.1from
stable-4.1-batt-acline-status
Sep 3, 2026
Merged

batt: distinguish AC line status values#498
laffer1 merged 1 commit into
stable/4.1from
stable-4.1-batt-acline-status

Conversation

@laffer1

@laffer1 laffer1 commented Sep 3, 2026

Copy link
Copy Markdown
Member

Summary

  • report AC-line value 0 as battery power and value 1 as plugged in
  • diagnose the kernel sentinel value -1 as unknown and reject other values
  • flush captured stdout in the test child before _exit()
  • add regression coverage for offline, unknown, and invalid AC-line values

Testing

  • bmake -C usr.bin/batt clean all
  • kyua test -k /usr/obj/usr/src/amd64.amd64/usr.bin/batt/tests/Kyuafile (9/9 passed)
  • git diff --cached --check -- usr.bin/batt

The 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:

  • Distinguish battery-powered, plugged-in, unknown, and invalid AC-line status values in batt output.

Bug Fixes:

  • Treat the kernel AC-line sentinel value -1 as an explicit error instead of reporting a charging or drained state.

Enhancements:

  • Flush captured child-process stdout before exiting to ensure test output is preserved.

Tests:

  • Add regression coverage for battery-power, unknown, and invalid AC-line statuses.

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>
Copilot AI lite review requested due to automatic review settings September 3, 2026 23:17
@sourcery-ai

sourcery-ai Bot commented Sep 3, 2026

Copy link
Copy Markdown

Reviewer's Guide

The 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 classification

flowchart 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]
Loading

File-Level Changes

Change Details Files
Explicitly classify every AC-line sysctl value and fail on unknown or invalid states.
  • Map 0 to battery-power output and 1 to plugged-in output.
  • Treat -1 as an unknown-state error and reject all other values.
  • Preserve existing size and availability validation before classification.
usr.bin/batt/batt.c
Expand regression coverage for AC-line state handling and make child-process output capture reliable.
  • Flush captured stdout before exiting the test child.
  • Add tests for offline, kernel-sentinel unknown, and invalid AC-line values, including exit status and diagnostics.
  • Register the new tests in the ATF test program.
usr.bin/batt/tests/batt_test.c

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@laffer1
laffer1 merged commit 9763a2d into stable/4.1 Sep 3, 2026
5 of 6 checks passed
@laffer1
laffer1 deleted the stable-4.1-batt-acline-status branch September 3, 2026 23:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 switch over AC-line status (0=battery, 1=plugged in, -1=unknown/error, other=error).
  • Flush child-process stdout in 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.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants