Fix NVIDIA GPU serial number format extraction
Extract decimal serial numbers from devname parameters (e.g., "SXM5_SN_1653925027099") instead of hex PCIe Device Serial Numbers. This provides the correct GPU serial numbers as they appear in NVIDIA diagnostics tooling. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
+18
-22
@@ -39,9 +39,10 @@ func TestParseInventoryLog(t *testing.T) {
|
||||
|
||||
content := string(inventoryLog.Content)
|
||||
|
||||
// Test devname regex
|
||||
// Test devname regex - this extracts both slot mapping and serial numbers
|
||||
t.Log("Testing devname extraction:")
|
||||
lines := strings.Split(content, "\n")
|
||||
serialCount := 0
|
||||
for i, line := range lines {
|
||||
if strings.Contains(line, "devname=") && strings.Contains(line, "fieldiag") {
|
||||
t.Logf("Line %d: Found fieldiag command", i)
|
||||
@@ -49,34 +50,29 @@ func TestParseInventoryLog(t *testing.T) {
|
||||
t.Logf(" Found %d devname matches", len(matches))
|
||||
for _, match := range matches {
|
||||
if len(match) == 3 {
|
||||
t.Logf(" PCI: %s -> Slot: %s", match[1], match[2])
|
||||
pciBDF := match[1]
|
||||
slotName := match[2]
|
||||
t.Logf(" PCI: %s -> Slot: %s", pciBDF, slotName)
|
||||
|
||||
// Extract serial number from slot name
|
||||
if strings.HasPrefix(slotName, "SXM") {
|
||||
parts := strings.Split(slotName, "_")
|
||||
if len(parts) == 3 && parts[1] == "SN" {
|
||||
serial := parts[2]
|
||||
t.Logf(" Serial: %s", serial)
|
||||
serialCount++
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
t.Logf("\nTotal GPU serials extracted: %d", serialCount)
|
||||
|
||||
// Test lspci regex
|
||||
t.Log("\nTesting lspci BDF extraction:")
|
||||
serialCount := 0
|
||||
bdfCount := 0
|
||||
for i, line := range lines {
|
||||
// Check for lines that look like lspci headers
|
||||
if strings.Contains(line, "3D controller") && strings.Contains(line, "NVIDIA") {
|
||||
t.Logf("Line %d: Potential lspci line: %q (starts with: %q)", i, line[:min(80, len(line))], line[:min(10, len(line))])
|
||||
if match := pciBDFRegex.FindStringSubmatch(line); len(match) > 1 {
|
||||
bdfCount++
|
||||
t.Logf(" -> Matched BDF: %s", match[1])
|
||||
} else {
|
||||
t.Logf(" -> NO MATCH")
|
||||
}
|
||||
}
|
||||
if match := gpuSerialRegex.FindStringSubmatch(line); len(match) > 1 {
|
||||
serialCount++
|
||||
}
|
||||
if serialCount == 0 {
|
||||
t.Error("Expected to find GPU serial numbers, but found none")
|
||||
}
|
||||
t.Logf("\nTotal BDFs found: %d", bdfCount)
|
||||
t.Logf("Total serials found: %d", serialCount)
|
||||
}
|
||||
|
||||
func min(a, b int) int {
|
||||
|
||||
Reference in New Issue
Block a user