Files
logpile/internal/parser/vendors/pciids/pciids_lookup_test.go
T
Mikhail ChusavitinandClaude Opus 5.5 b4b15e58a2 feat(parser): linux-generic content-driven parser and RAR archive support
Field bundles from ad-hoc service scripts (first sample: Giga G894-SD3 .rar
with dmidecode/lscpu/lspci/nvme/lsblk output, no fixed layout). ADL-078:
- linux-generic: recognizes utility output by content, merges records by
  stable key, low detect confidence (20-30) below all vendor parsers
- pciids.LookupByDescription: resolve a textual lspci description back to
  vendor/device IDs and manufacturer/model
- archive: accept .rar via the in-repo internal/rar5 reader (RAR 5 / RAR 7,
  single volume, solid; encrypted, multi-volume, SFX and RAR 4.x rejected),
  same per-file and total limits as tar/zip
- UI: .rar in the upload accept list

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-02 15:00:38 +03:00

84 lines
2.3 KiB
Go

package pciids
import (
"os"
"path/filepath"
"sync"
"testing"
)
func TestLookupByDescription(t *testing.T) {
dir := t.TempDir()
idsPath := filepath.Join(dir, "pci.ids")
content := "" +
"fff0 Example Devices\n" +
"\t0001 Widget 100 [W100]\n" +
"\t0002 Twin Port Adapter\n" +
"\t0003 Twin Port Adapter\n" +
"fff1 Example Devices, Inc. [EXD]\n" +
"\t0010 Gadget\n"
if err := os.WriteFile(idsPath, []byte(content), 0o644); err != nil {
t.Fatalf("write pci.ids: %v", err)
}
t.Setenv("LOGPILE_PCI_IDS_PATH", idsPath)
reset := func() {
loadOnce = sync.Once{}
reverseOnce = sync.Once{}
vendors = nil
devices = nil
}
reset()
t.Cleanup(reset)
cases := []struct {
name string
description string
wantOK bool
wantVendor int
wantDevice int
wantName string
wantModel string
}{
{
name: "unique device name",
description: "Example Devices Widget 100 [W100]",
wantOK: true, wantVendor: 0xfff0, wantDevice: 0x0001,
wantName: "Example Devices", wantModel: "Widget 100 [W100]",
},
{
name: "longest vendor name wins",
description: "Example Devices, Inc. [EXD] Gadget",
wantOK: true, wantVendor: 0xfff1, wantDevice: 0x0010,
wantName: "Example Devices, Inc. [EXD]", wantModel: "Gadget",
},
{
name: "lspci placeholder carries the device id",
description: "Example Devices Device 0abc",
wantOK: true, wantVendor: 0xfff0, wantDevice: 0x0abc,
wantName: "Example Devices", wantModel: "Device 0abc",
},
{
name: "ambiguous device name keeps the id unknown",
description: "Example Devices Twin Port Adapter",
wantOK: true, wantVendor: 0xfff0, wantDevice: 0,
wantName: "Example Devices", wantModel: "Twin Port Adapter",
},
{
name: "vendor name must end at a word boundary",
description: "Example DevicesX Widget",
wantOK: false, wantModel: "Example DevicesX Widget",
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
vendorID, deviceID, vendorName, deviceName, ok := LookupByDescription(tc.description)
if ok != tc.wantOK || vendorID != tc.wantVendor || deviceID != tc.wantDevice ||
vendorName != tc.wantName || deviceName != tc.wantModel {
t.Fatalf("LookupByDescription(%q) = %04x:%04x %q %q ok=%v", tc.description, vendorID, deviceID, vendorName, deviceName, ok)
}
})
}
}