Skip to content

Cover Linux command and file parsing via seam extraction - #3514

Merged
dbwiddis merged 2 commits into
oshi:masterfrom
dbwiddis:linux-parse-coverage2
Jul 22, 2026
Merged

dbwiddis merged 2 commits into
oshi:masterfrom
dbwiddis:linux-parse-coverage2

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Jul 22, 2026 •

Copy link
Copy Markdown
Member

Summary

Coverage-driven (from Codecov cross-OS missed-line data): add unit coverage for previously-untested Linux command/file parsing, extracting seams where acquire+parse was inline and grounding fixtures in documented Linux formats.

  • LinuxGraphicsCard — the lshw -C display parse was inline and unseamed. Extract getGraphicsCardsFromLshw(List, factory, drmLookup) (mirroring the existing lspci seam) and add a two-card fixture grounded in real lshw -C display output (memory-range VRAM math). Also cover two lspci gaps: a Vendor line without a [hex] id (raw-text fallback) and output that ends mid-card with no trailing blank line (last-card flush).
  • LinuxOperatingSystem — extract parseServices(systemctl, running, initDir) (the systemctl list-unit-files scan plus the /etc/init .conf upstart fallback) and getReleaseFilename(etcPath) (the /etc *-release/*-version scan). Fixtures are grounded in real systemctl list-unit-files columns, upstart .conf files, and the /etc scan: the enabled/dedup-by-name-and-short-name path, the init-dir fallback, the missing-init-dir branch, a distrib-file match, excluded os/lsb/system-release files, and the release/issue fallbacks. The /etc/init fallback now guards on listFiles() == null instead of exists() && isDirectory() — behavior-preserving, and it closes a latent NPE from iterating listFiles() without a null check.
  • LinuxCgroupInfo — extract static resolveV1ControllerPath(selfCgroup, controller) parsing /proc/self/cgroup. Fixtures grounded in a real hybrid (v1 + unified) cgroup file cover a comma-separated-controller exact match, a single controller, a not-found default, and a v2-only unified line whose controllers field is empty.

Deliberately left alone (not cleanly seamable): queryFamilyVersionCodenameFromReleaseFiles (interleaves several real file reads), the LinuxFileSystem mount-table loop / NFS / TCP probing (file-I/O + network), and queryBitness.

Testing

  • oshi-common full gate green: spotless, checkstyle, install + forbiddenapis, javadoc.
  • New/updated tests pass. SysPath-dependent cgroup assertions and the LinuxOperatingSystem file/command tests run on Linux CI (where cross-OS coverage is collected) and skip elsewhere.

No CHANGELOG entry — test/coverage plus behavior-preserving extractions.

Summary by CodeRabbit

  • Bug Fixes
    • Improved Linux graphics card discovery and parsing from lshw, including incomplete vendor metadata and lspci output without a trailing blank line.
    • Improved Linux graphics card VRAM totals, version handling, and driver/device details.
    • Improved Linux cgroup v1 controller path resolution for hybrid and unified cgroup layouts.
    • Improved Linux service discovery and release-file detection with safer directory-scoped fallbacks.
  • Tests
    • Added unit test coverage for graphics card parsing, cgroup path resolution, service discovery, and release-file selection scenarios.

Coverage-driven from Codecov cross-OS missed-line data: add unit coverage
for previously-untested Linux command and file parsing, extracting seams
where acquire+parse was inline and grounding fixtures in documented formats.

- LinuxGraphicsCard: extract getGraphicsCardsFromLshw(List, factory, drmLookup)
  from the inline `lshw -C display` parse; add fixtures for the two-card lshw
  path and two lspci gaps (vendor line without a "[hex]" id -> raw fallback;
  output with no trailing blank line -> last-card flush).
- LinuxOperatingSystem: extract parseServices(systemctl, running, initDir)
  (systemctl list-unit-files + /etc/init .conf fallback) and
  getReleaseFilename(etcPath) (/etc *-release/*-version scan). Fixtures cover
  the systemctl enabled/dedup path, the upstart .conf fallback, the missing
  init-dir branch, distrib-file match, excluded os/lsb/system-release files,
  and the release/issue fallbacks. The /etc/init fallback now guards on
  listFiles() == null (behavior-preserving; also closes a latent NPE from
  iterating listFiles() without a null check).
- LinuxCgroupInfo: extract static resolveV1ControllerPath(selfCgroup,
  controller) parsing /proc/self/cgroup; fixtures cover a comma-controller
  exact match, a single controller, a not-found default, and a v2-only
  unified line.

No CHANGELOG entry: test/coverage plus behavior-preserving extractions.
@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: bc2a7bfd-a053-4050-a6fd-119cdfe838d8

📥 Commits

Reviewing files that changed from the base of the PR and between 5405769 and abcc0aa.

📒 Files selected for processing (3)
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOperatingSystem.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxGraphicsCardTest.java
  • oshi-common/src/test/java/oshi/software/common/os/linux/LinuxOperatingSystemTest.java
🚧 Files skipped from review as they are similar to previous changes (3)
  • oshi-common/src/test/java/oshi/software/common/os/linux/LinuxOperatingSystemTest.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOperatingSystem.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxGraphicsCardTest.java
📜 Recent review details
⏰ Context from checks skipped due to timeout. (7)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Analyze (java)
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Test JDK 26, ubuntu-latest

📝 Walkthrough

Walkthrough

Linux platform parsing was refactored into testable helpers for graphics DRM data, cgroup controller paths, release files, and service enumeration. New tests cover parser fallbacks, incomplete input, hybrid cgroup layouts, temporary directories, and empty results.

Changes

Graphics parsing

Layer / File(s) Summary
Graphics parser injection and edge cases
oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGraphicsCard.java, oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxGraphicsCardTest.java
The lshw parser accepts injected DRM lookup logic. Tests cover vendor parsing, final-card flushing, lshw metadata, VRAM totals, missing versions, and empty input.

Cgroup controller resolution

Layer / File(s) Summary
Controller path helper and coverage
oshi-common/src/main/java/oshi/software/common/os/linux/LinuxCgroupInfo.java, oshi-common/src/test/java/oshi/software/common/os/linux/LinuxCgroupInfoV1DispatchTest.java
Controller path parsing moves to a static helper, with tests for hybrid cgroup entries, fallback paths, and unified-only lines.

Linux operating-system parsing

Layer / File(s) Summary
Release filename fallback resolution
oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOperatingSystem.java, oshi-common/src/test/java/oshi/software/common/os/linux/LinuxOperatingSystemTest.java
Release lookup uses a directory-scoped helper and tests distro-specific, release, and issue fallbacks.
Service enumeration helper
oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOperatingSystem.java, oshi-common/src/test/java/oshi/software/common/os/linux/LinuxOperatingSystemTest.java
Service parsing handles systemctl units, running-service deduplication, init configuration fallback, and missing directories with focused tests.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

  • oshi/oshi#3202: Refactors Linux graphics parsing to inject DRM metadata lookup.
  • oshi/oshi#3239: Expands tests for Linux cgroup controller path parsing.

Poem

I hop through lshw, where bright GPUs gleam,
Parse cgroups neatly beside the stream.
Services settle, release files align,
Tests catch each edge in a burrow so fine.
Squeak, says the rabbit: the helpers now shine!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main theme: extracting seams to cover Linux command and file parsing.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.47619% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.92%. Comparing base (1d9a27a) to head (abcc0aa).

Files with missing lines Patch % Lines
...oshi/software/common/os/linux/LinuxCgroupInfo.java 0.00% 1 Missing ⚠️
...software/common/os/linux/LinuxOperatingSystem.java 94.11% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3514      +/-   ##
============================================
+ Coverage     77.72%   77.92%   +0.19%     
  Complexity       83       83              
============================================
  Files           694      694              
  Lines         24246    24249       +3     
  Branches       4028     4029       +1     
============================================
+ Hits          18846    18895      +49     
+ Misses         3184     3131      -53     
- Partials       2216     2223       +7     
Flag Coverage Δ
linux 34.69% <90.47%> (+0.25%) ⬆️
macos 35.55% <9.52%> (+0.12%) ⬆️
windows 42.73% <9.52%> (+0.15%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxGraphicsCardTest.java (1)

323-327: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert the missing-version expectation.

The comment says the second card should have UNKNOWN version information, but the test never checks it. Add an assertion so regressions that leak the first card’s version into the second card are detected.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxGraphicsCardTest.java`
around lines 323 - 327, Add an assertion in LinuxGraphicsCardTest for the second
card variable intel, verifying its version is UNKNOWN as documented by the
existing comment. Keep the existing name, vendor, and VRAM assertions unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOperatingSystem.java`:
- Around line 565-574: Update the systemctl parsing loop in LinuxOperatingSystem
so systemctlFound is set whenever an enabled .service row is successfully
parsed, before checking running services or deduplicating names. Preserve
stopped-service creation behavior, and add coverage for a case where the only
enabled unit is already running to ensure /etc/init fallback is not used.

---

Nitpick comments:
In
`@oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxGraphicsCardTest.java`:
- Around line 323-327: Add an assertion in LinuxGraphicsCardTest for the second
card variable intel, verifying its version is UNKNOWN as documented by the
existing comment. Keep the existing name, vendor, and VRAM assertions unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 515b6fdd-faf2-4d61-8b37-12cf92728e71

📥 Commits

Reviewing files that changed from the base of the PR and between 1d9a27a and 5405769.

📒 Files selected for processing (6)
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGraphicsCard.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxCgroupInfo.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOperatingSystem.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxGraphicsCardTest.java
  • oshi-common/src/test/java/oshi/software/common/os/linux/LinuxCgroupInfoV1DispatchTest.java
  • oshi-common/src/test/java/oshi/software/common/os/linux/LinuxOperatingSystemTest.java
📜 Review details
⏰ Context from checks skipped due to timeout. (8)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 26, ubuntu-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, ubuntu-latest
  • GitHub Check: Analyze (java)
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.

Applied to files:

  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGraphicsCard.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxCgroupInfo.java
📚 Learning: 2026-07-06T19:25:59.225Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3432
File: oshi-common/src/main/java/oshi/util/ExceptionUtil.java:26-56
Timestamp: 2026-07-06T19:25:59.225Z
Learning: In this repo’s SLF4J 1.x-compatible logging code, do not flag cases where a logger call uses SLF4J 1.6+ implicit-cause handling—e.g., `log.error("...{}", value, t)` (or similar with a single `{}` placeholder) where `t` is passed as the final/trailing argument. SLF4J will attach `t` as the log event’s cause with the full stack trace; this is equivalent to SLF4J 2.x’s fluent `atLevel(...).setCause(t).log(...)` and is intentionally used to preserve SLF4J 1.x runtime compatibility.

Applied to files:

  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGraphicsCard.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxCgroupInfo.java
🪛 ast-grep (0.44.1)
oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOperatingSystem.java

[warning] 517-517: Prevent path traversal
Context: new File(etc, "issue")
Note: [CWE-22] Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'). Security best practice.

(path-traversal-java)

🔇 Additional comments (4)
oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGraphicsCard.java (1)

299-300: LGTM!

Also applies to: 311-312, 326-326, 357-357

oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxGraphicsCardTest.java (1)

271-292: LGTM!

Also applies to: 298-310, 311-322, 328-334

oshi-common/src/main/java/oshi/software/common/os/linux/LinuxCgroupInfo.java (1)

204-214: LGTM!

oshi-common/src/test/java/oshi/software/common/os/linux/LinuxCgroupInfoV1DispatchTest.java (1)

16-26: LGTM!

Also applies to: 143-184

- parseServices: mark systemctlFound as soon as an enabled .service row is
  parsed (before the running-check/dedup) so the /etc/init fallback runs only
  when systemctl produced no enabled units. Fixes a latent case where every
  enabled unit is already running would spuriously trigger the fallback. Add a
  test covering that case.
- LinuxGraphicsCardTest: assert the second lshw card's version is UNKNOWN, as
  the existing comment documents.
@dbwiddis
dbwiddis merged commit 7227287 into oshi:master Jul 22, 2026
16 checks passed
@dbwiddis
dbwiddis deleted the linux-parse-coverage2 branch July 22, 2026 02:15
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.

1 participant