Skip to content

Conversation

@jra3
Copy link
Collaborator

@jra3 jra3 commented Nov 17, 2025

Summary

This PR adds comprehensive testing for hardware bus type inference functions to address issue #161. The implementation follows a four-phase approach covering all device patterns, drivers, and real-world cloud provider scenarios.

What Changed

New Test File

  • internal/hardware/graph/bus_inference_test.go (715 lines)
    • 17 test functions covering all four phases
    • 100+ individual test cases
    • Comprehensive device pattern coverage

Test Coverage by Phase

Phase 1: Core Disk Bus Type Pattern Tests

  • NVMe Patterns: Base devices, partitions, multiple namespaces (nvme0n1, nvme1n2p1)
  • SATA/SCSI Patterns: All device names including extended (sda-sdz, sdaa, etc.)
  • IDE Patterns: Legacy disk controllers (hda, hdb, hdc, hdd)
  • VirtIO Patterns: KVM/QEMU (vda, vdb) and Xen (xvda, xvdb) virtual disks
  • Unknown Patterns: Loop devices, device mapper, MD RAID, eMMC, network block, optical drives
  • Edge Cases: Case sensitivity, substring matching, empty strings

Phase 2: Network Driver Detection Tests

  • Virtual Interfaces: Loopback, bridge, VLAN, bonding
  • VirtIO Drivers: virtio_net, virtio_pci variants
  • USB Drivers: Drivers with "usb" in name (usbnet, usb_ethernet)
    • Documents limitation: r8152, asix, ax88179 not detected (no "usb" substring)
  • PCI Drivers: Intel (e1000, igb, ixgbe, i40e, ice), Broadcom, Realtek, Mellanox, AWS ENA, VMware vmxnet3, wireless (iwlwifi, ath9k)

Phase 3: Bus Connection Relationship Tests

  • All Bus Type Enums: PCI, PCIe, USB, SATA, NVMe, SAS, IDE, SCSI, VirtIO, Unknown
  • Bus Address Formatting: PCI addresses (0000:00:1f.2), USB locations (1-1.2)
  • Relationship Validation: Proper subject/object/predicate structure
  • Protobuf Verification: Successful unmarshaling of ConnectedTo predicates

Phase 4: Real-World Device Pattern Validation

  • AWS EC2: NVMe EBS volumes, instance store, Xen paravirtual (xvda)
  • GCP: Persistent disks (sda), local NVMe SSDs
  • Azure: Managed disks (sda), premium NVMe
  • VMware: Paravirtual SCSI (sda), IDE (hda)
  • Container Environments: Loop devices, device mapper
  • Cloud Network Adapters: AWS ENA, GCP VirtIO, Azure Mellanox, VMware vmxnet3
  • Physical Servers: Large disk arrays (27+ disks), mixed NVMe/SATA configurations

Test Statistics

  • 17 test functions organized by phase
  • 100+ individual test cases covering all scenarios
  • All device patterns from issue test: Improve bus type inference testing coverage #161 implemented
  • All bus types validated with enum mapping
  • Cloud providers (AWS, GCP, Azure, VMware) comprehensively covered

Test Results

Coverage Improvement:

  • Before: 70.9%
  • After: 75.1%
  • Improvement: +4.2 percentage points ✅

All tests passing:

ok      github.com/antimetal/agent/internal/hardware/graph     13.869s coverage: 75.1% of statements

Key Findings

The tests document current implementation behavior:

  • ✅ Comprehensive device pattern detection (NVMe, SATA, IDE, VirtIO)
  • ✅ Virtual interface detection working correctly
  • ✅ VirtIO driver detection working correctly
  • ⚠️ USB driver detection limitation: Only detects drivers with "usb" substring
    • Drivers like r8152, asix, ax88179 default to PCI
    • Tests document this as current behavior vs ideal behavior

Success Criteria Met

✅ Achieve comprehensive coverage for bus inference functions
✅ Test all documented device naming patterns
✅ Cover all supported bus types
✅ Validate unknown device fallback behavior
✅ Test relationship creation for all bus types

Testing

# Run all tests
go test ./internal/hardware/graph/...

# Run with coverage
go test ./internal/hardware/graph/... -cover

# Run specific bus inference tests
go test ./internal/hardware/graph/... -run "Infer|BusInference"

Closes #161

Implement all 4 testing phases specified in issue #161 for hardware
graph bus type inference validation. Tests cover device naming patterns,
driver detection, relationship creation, and real-world cloud provider
device patterns.

Phase 1 (Core Disk Bus Type Patterns):
- NVMe device patterns (nvme0n1, nvme1n2p1, etc)
- SATA/SCSI device patterns (sda, sdb1, sdaa, etc)
- IDE device patterns (hda, hdb, hdc, hdd)
- VirtIO/Xen patterns (vda, xvda with partitions)
- Unknown device patterns (loop, dm, md, mmcblk, etc)
- Case sensitivity and substring matching edge cases

Phase 2 (Network Driver Detection):
- Virtual interface types (loopback, bridge, vlan, bond)
- VirtIO network drivers (virtio_net, virtio_pci)
- USB driver detection with documented limitations
- PCI driver patterns for Intel, Broadcom, Realtek, Mellanox, AWS ENA,
  VMware vmxnet3, and wireless drivers

Phase 3 (Bus Connection Relationships):
- All bus type enum mappings (PCI, PCIe, USB, SATA, NVMe, SAS, IDE,
  SCSI, VirtIO, Unknown)
- Bus address formatting validation
- Relationship structure verification
- Protobuf unmarshaling validation

Phase 4 (Real-World Device Patterns):
- AWS EC2 devices (NVMe EBS, instance store, Xen paravirtual)
- GCP devices (persistent disks, local SSDs)
- Azure devices (managed disks, NVMe)
- VMware devices (SCSI, IDE)
- Container environments (loop devices, device mapper)
- Cloud provider network adapters (AWS ENA, GCP VirtIO, Azure Mellanox,
  VMware vmxnet3)
- Physical server disk patterns (large arrays, mixed NVMe/SATA)

Test implementation includes 17 test functions with 100+ individual test
cases. Tests document current USB driver detection limitations and
validate unknown device fallback behavior. Coverage improvement:
70.9% to 75.1% (+4.2%).

Closes #161

Co-Authored-By: Claude <[email protected]>
Signed-off-by: John Allen <[email protected]>
@jra3 jra3 requested a review from haq204 November 17, 2025 16:15
@jra3 jra3 marked this pull request as ready for review November 17, 2025 16:15
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.

test: Improve bus type inference testing coverage

2 participants