Repository navigation
lscpu: add --sysroot and test fixtures - #718
Merged
Merged
Conversation
Thread a system root through all sysfs and procfs reads so lscpu can run against a fake tree. Add integration tests that exercise proc/cpuinfo, topology, caches, frequency boost, vulnerabilities and JSON output through --sysroot.
sylvestre
reviewed
Nov 27, 2026
Address review comments: assert fields on the matching output line, parse JSON entries before checking values, return an error instead of panicking for an invalid sysroot, and simplify the sysroot argument definition.
Contributor
Author
|
Thanks for the review! All six comments are addressed in f43d930. |
Contributor
|
Thanks for your PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
#717
Add
-s/--sysroottolscpuand thread the system root through every sysfs/procfs read. This makes it possible to runlscpuagainst a fake filesystem tree in tests and matches the util-linux--sysrootoption.The default behavior without
--sysrootis unchanged: the root defaults to/.Relation to #528
#528 also adds
--sysroot, but additionally introduces a shareduulinuxcrate and changeslsmem. This PR contains only thelscpuportion so it can be reviewed and tested independently.If #528 is preferred as-is, this PR can be closed.
Changes
-s, --sysroot <directory>to thelscpuCLI.system_path(root, path)helper insysfs.rs:Path::joindiscarding the root when given an absolute path/behavior unchanged/proc/cpuinfo/sys/devices/system/cpu/online/sys/devices/system/cpu/cpuN/topology/*/sys/devices/system/cpu/cpuN/cache/index*/*/sys/devices/system/cpu/vulnerabilities/*/sys/devices/system/cpu/cpufreq/boost/sys/kernel/cpu_byteorderTestSysCpu, a fake sysfs/procfs fixture built withtempfile::TempDir.test_sysroot_outputandtest_sysroot_json.The fixture deliberately uses values that are unlikely to match the host (
TestVendor,Big Endian,boost=0,fake_vuln) so the tests fail if any read accidentally bypasses--sysroot.Behavior
Before:
After:
lscpuwithout--sysrootstill reads from/.Follow-ups
lscpu: panic on aarch64-linux #494:lscpupanic on incomplete sysfs datalscpu: implement --hexlscpu: fix topology for multi-socket and offline CPUs