Skip to content

refactor: table-driven DIMM format parsing with tests#654

Merged
harp-intel merged 5 commits intomainfrom
refactor/dimm-parse-table-driven
Mar 3, 2026
Merged

refactor: table-driven DIMM format parsing with tests#654
harp-intel merged 5 commits intomainfrom
refactor/dimm-parse-table-driven

Conversation

@harp-intel
Copy link
Contributor

Summary

  • Replace cascading if-else in getDIMMParseInfo and switch in getDIMMSocketSlot with a unified dimmFormats table where each entry holds pre-compiled regexes, match predicates, and extraction functions
  • Fix regex bugs where [\d+] matched a single character instead of multi-digit numbers (affected Quanta GNR, Birchstream, and Forest City formats)
  • Add descriptive dimmType names (dimmTypeInspurICX, dimmTypeQuantaGNR, etc.) replacing opaque dimmType0dimmType16
  • Add 66 characterization tests covering all 17 DIMM formats, ordering edge cases, and multi-digit regression cases

Test plan

  • All 66 new DIMM tests pass (go test ./internal/extract/ -run "TestGetDIMM|TestDeriveDIMMInfoOther")
  • Full test suite passes (make test) with zero failures
  • Verify on real hardware with various DIMM configurations (Dell, HPE, SuperMicro, etc.)

🤖 Generated with Claude Code

Replace the cascading if-else in getDIMMParseInfo and switch in
getDIMMSocketSlot with a unified dimmFormats table. Each entry holds
pre-compiled regexes, match predicates, and extraction functions.

- Fix regex bugs: [\d+] matched single char, not multi-digit numbers
- Add descriptive dimmType names (dimmTypeInspurICX, dimmTypeQuantaGNR, etc.)
- Add 66 characterization tests covering all 17 formats, ordering
  edge cases, and multi-digit regression cases

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Harper, Jason M <jason.m.harper@intel.com>
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 PR refactors the DIMM format detection and parsing logic in internal/extract/dimm.go to use a table-driven approach. It also fixes regex bugs where [\d+] was incorrectly used (matching a single character from the set \d, + rather than one-or-more digits) in some patterns, adds descriptive names for the previously opaque dimmType0dimmType16 constants, and adds 66 new characterization tests.

Changes:

  • Replace cascading if-else/switch in getDIMMParseInfo and getDIMMSocketSlot with a unified dimmFormats table containing pre-compiled regexes, match predicates, and extraction functions
  • Add descriptive dimmType constant names with backward-compatible aliases for the old dimmType0dimmType16 names
  • Add a comprehensive test file (dimm_test.go) with 66 test cases covering all 17 DIMM formats, ordering edge cases, and multi-digit regression cases

Reviewed changes

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

File Description
internal/extract/dimm.go Main refactor: replaces cascading if-else with dimmFormats table, adds new descriptive constants and aliases, introduces dimmFormat struct
internal/extract/dimm_test.go New file: 66 test cases across TestGetDIMMParseInfo, TestGetDIMMSocketSlot, and TestDeriveDIMMInfoOther

harp-intel and others added 3 commits March 3, 2026 12:50
Update all test references from dimmType0-16 to descriptive names
(dimmTypeInspurICX, dimmTypeQuantaGNR, etc.) and remove the backward
compatibility aliases from dimm.go.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Exercise the return nil, nil path (line 597) where the first DIMM
identifies a format but a subsequent DIMM fails to match it.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
For formats requiring both bankLocPat and locPat to match (matchBoth),
getDIMMSocketSlot now requires both matches to be non-nil before calling
extractFunc. Previously, a partial match (one nil, one non-nil) would
pass a nil slice to extractFunc, causing an index-out-of-range panic.

This is realistic in deriveDIMMInfoOther where the format is identified
from dimms[0] but applied to all subsequent DIMM rows.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@harp-intel harp-intel merged commit bbfee59 into main Mar 3, 2026
5 checks passed
@harp-intel harp-intel deleted the refactor/dimm-parse-table-driven branch March 3, 2026 23:38
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