Files
logpile/internal/parser/vendors/nvidia/inventory_log_test.go
Michael Chus 77e25ddc02 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>
2026-02-10 22:57:50 +03:00

84 lines
2.0 KiB
Go

package nvidia
import (
"os"
"path/filepath"
"strings"
"testing"
"git.mchus.pro/mchus/logpile/internal/parser"
)
func TestParseInventoryLog(t *testing.T) {
// Test with the real archive
archivePath := filepath.Join("../../../../example", "A514359X5A09844_logs-20260115-151707.tar")
// Check if file exists
if _, err := os.Stat(archivePath); os.IsNotExist(err) {
t.Skip("Test archive not found, skipping test")
}
// Extract files from archive
files, err := parser.ExtractArchive(archivePath)
if err != nil {
t.Fatalf("Failed to extract archive: %v", err)
}
// Find inventory/output.log
var inventoryLog *parser.ExtractedFile
for _, f := range files {
if strings.Contains(f.Path, "inventory/output.log") {
inventoryLog = &f
break
}
}
if inventoryLog == nil {
t.Fatal("inventory/output.log not found")
}
content := string(inventoryLog.Content)
// 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)
matches := devnameRegex.FindAllStringSubmatch(line, -1)
t.Logf(" Found %d devname matches", len(matches))
for _, match := range matches {
if len(match) == 3 {
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)
if serialCount == 0 {
t.Error("Expected to find GPU serial numbers, but found none")
}
}
func min(a, b int) int {
if a < b {
return a
}
return b
}