Repository navigation
Description
Summary
Several classes in oshi-common combine command execution with output parsing in a single method, making the parsing logic untestable without running the actual command. This limits test coverage to ~58% — the parsing branches (error handling, edge cases, platform-specific formats) can only be exercised on real hardware with the right conditions.
The project already has an established pattern for separating these concerns. For example, LinuxCentralProcessor provides:
readTopologyFromCpuinfo()— runs the commandreadTopologyFromCpuinfo(List<String> lines)— parses the output (testable with fixture data)
This pattern should be applied more broadly. The refactoring is mechanical: extract the parsing into a package-private static method that accepts List<String> (or String), and have the public method call the command then delegate.
Benefits
- Testable with fixture data: representative command output from Linux, macOS, and Windows can be committed as test resources or inline strings, enabling deterministic cross-platform tests
- No new dependencies: no mocking framework needed
- No public API changes: the public methods remain unchanged
- Incremental: each method is a small, independent PR
Fixture data strategy
Real command output can be captured from actual hardware and used as test fixtures:
- Linux:
lspci -vnnm,dmidecode --type 17,dmidecode -t system,dmidecode -t bios,who,lscpu -p=cpu,node,lscpu,lshw -C display,lshw -C system,lshw -class processor,vcgencmd version,netstatvariants - macOS:
system_profiler SPDisplaysDataType,sw_vers,who(uses different date format than Linux) - Windows: mostly uses WMI/COM rather than command-line parsing, so fewer candidates here
Fixtures can be stored as List.of(...) inline in tests or as resource files under src/test/resources/.
Methods to refactor
Linux — oshi-common drivers (highest priority)
-
AbstractGlobalMemory.getPhysicalMemory()— parsesdmidecode --type 17output (27 missed lines) -
LinuxGraphicsCard.getGraphicsCardsFromLspci()— parseslspci -vnnmoutput (~40 missed lines) -
LinuxGraphicsCard.queryLspciMemorySize()— parseslspci -v -soutput -
LinuxOperatingSystem.queryFamilyVersionCodenameFromReleaseFiles()— parses release files -
LinuxOperatingSystem.getParentPidsFromProcFiles()— parses/proc/[pid]/stat -
LinuxCentralProcessor.mapNumaNodesFromLscpu()— parseslscpu -p=cpu,node -
LinuxCentralProcessor.mapCachesFromLscpu()— parseslscpucache lines -
LinuxFileSystemmount/filesystem parsing — parses/proc/self/mountsanddfoutput -
LinuxOSProcess—taskset -paffinity mask parsing -
Dmidecode.querySerialNumber()— parsesdmidecode -t system -
Dmidecode.queryUUID()— parsesdmidecode -t system -
Dmidecode.queryBiosNameRev()— parsesdmidecode -t bios -
Lshwstatic initializer andqueryCpuCapacity()— parseslshwoutput -
Who.matchLinux()(linux) — already has the parsing separated but it is private; make package-private -
LinuxFirmware.queryVcGenCmd()— parsesvcgencmd version(Raspberry Pi)
macOS — oshi-common drivers
-
MacGraphicsCard.parseGraphicsCards()— parsessystem_profiler SPDisplaysDataType -
MacOperatingSystemversion detection — parsessw_vers -
MacCentralProcessor— parsessysctloutput for topology
Unix shared drivers
-
Who.matchUnix()— already package-private, just needs test fixtures for variouswhodate formats -
NetStat.queryTcpnetstat()— parsesnetstat -n -p tcp -
NetStat.queryNetstat()— parsesnetstat -n -
NetStat.queryTcpStats()/queryUdpStats()— parsesnetstat -svariants -
Xrandr/Xwininfo— parses X11 display info
Already done (reference examples)
- ✅
LinuxCentralProcessor.readTopologyFromCpuinfo(List<String>) - ✅
LinuxCentralProcessor.readTopologyFromSysfs(String path) - ✅
LinuxCentralProcessor.getSystemLoadAverage(int, String) - ✅
LinuxCentralProcessor.queryMaxFreqFromCpuFreqPath(String) - ✅
LinuxInstalledApps.parseLinuxAppInfo(List<String>)
Suggested approach
Each PR should:
- Add a package-private overload that accepts the parsed input (
List<String>orString) - Have the existing public method delegate to it
- Add tests with fixture data covering the key branches
- No public API changes, no new dependencies
PRs can be organized by file or by platform — whatever is easiest to review.
Activity
coderabbitai commentedon Apr 23, 2026
🔗 Related PRs
#3188 - Improve Linux test coverage in oshi-common [merged]
#3199 - Extract macOS parsing logic for testability [closed]
#3201 - Extract parsing logic from dmidecode/lscpu/vcgencmd commands [closed]
#3202 - Extract parsing logic from lspci/lshw commands [closed]
#3203 - Extract parsing from Who, LinuxOSProcess, LinuxOperatingSystem [closed]
📝 Issue Planner
Check the box below or use the
@coderabbitai plancommand to generate an implementation plan and prompts that you can use with your favorite coding assistant.🧪 Issue enrichment is currently in open beta.
To disable automatic issue enrichment, add the following to your
.coderabbit.yaml:💬 Have feedback or questions? Drop into our discord!
Extract macOS parsing logic for testability (#3189) (#3199)
Extract parsing logic from dmidecode/lscpu/vcgencmd commands (#3201)
Extract parsing logic from lspci/lshw commands (#3189) (#3202)
Extract parsing from Who, LinuxOSProcess, LinuxOperatingSystem (#3189) (
Extract parsing from NetStat and Xrandr commands (#3189) (#3204)
Extract /proc/[pid]/stat parsing and add LinuxFileSystem tests (#3189) (