Skip to content

Conversation

@harp-intel
Copy link
Contributor

This pull request improves the robustness of the cache parsing logic for lscpu output, ensuring compatibility with both modern and legacy formats where numeric fields may be represented as strings. It also adds comprehensive tests to validate correct parsing across various scenarios.

Parsing improvements for lscpu cache output

  • Added support for legacy lscpu output formats by introducing a new lscpuCacheEntryLegacy struct in table_helpers_cache.go, allowing the parser to handle cases where numeric fields are returned as strings.
  • Updated the parseLscpuCacheOutput function to first attempt parsing with the modern format, and if that fails, to fall back to the legacy format. Legacy string fields are converted to integers, with invalid or empty strings defaulting to zero.

Testing enhancements

  • Added testify assertions and requirements to table_helpers_cache_test.go for more expressive and reliable test checks.
  • Introduced a new TestParseLscpuCacheOutput function in table_helpers_cache_test.go, covering a wide range of input scenarios including modern and legacy formats, empty fields, invalid number strings, empty input, invalid JSON, and empty caches arrays.

Signed-off-by: Harper, Jason M <jason.m.harper@intel.com>
@harp-intel harp-intel linked an issue Oct 30, 2025 that may be closed by this pull request
@harp-intel harp-intel requested a review from Copilot October 30, 2025 22:26
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request enhances the lscpu cache parsing functionality to support both modern and legacy formats of lscpu output. The key improvement is adding fallback logic to handle older versions of lscpu that return numeric fields as strings instead of integers.

  • Introduces a new lscpuCacheEntryLegacy struct to handle string-based numeric fields from older lscpu versions
  • Updates parseLscpuCacheOutput function with fallback parsing logic that tries modern format first, then legacy format
  • Adds comprehensive test coverage for various scenarios including modern format, legacy format, empty fields, invalid numbers, and error cases

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
internal/report/table_helpers_cache.go Adds legacy struct and fallback parsing logic with string-to-integer conversion
internal/report/table_helpers_cache_test.go Adds testify imports and comprehensive test suite for both modern and legacy parsing scenarios

@harp-intel harp-intel merged commit 8a131ba into main Oct 31, 2025
5 checks passed
@harp-intel harp-intel deleted the legacycache branch October 31, 2025 01:11
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.

Cache data not reported

2 participants