Skip to content

test(hardware): add comprehensive unit tests for NUMA distance relationships#245

Closed
jra3 wants to merge 3 commits into
mainfrom
feat/issue-162
Closed

test(hardware): add comprehensive unit tests for NUMA distance relationships#245
jra3 wants to merge 3 commits into
mainfrom
feat/issue-162

Conversation

@jra3
Copy link
Copy Markdown
Collaborator

@jra3 jra3 commented Nov 17, 2025

Summary

This PR adds comprehensive unit tests for NUMA distance relationship creation to address issue #162. The implementation achieves 100% coverage for the previously untested createNUMADistanceRelationship function with 60+ test cases covering all NUMA topology scenarios found in production servers and cloud instances.

What Changed

New Test File

  • internal/hardware/graph/numa_distance_test.go (646 lines)
    • 12 comprehensive test functions
    • 60+ individual test cases
    • Complete coverage of all NUMA patterns

Test Coverage by Phase

Phase 1: Basic Functionality Tests

  • Basic Relationship Creation: Subject/object reference validation, successful creation
  • Predicate Marshaling: Protobuf marshaling/unmarshaling of NUMAAffinity predicate
  • Type Descriptor: Proper relationship type and kind validation
  • Distance Preservation: Verify distance values are correctly stored

Phase 2: Distance Values & Validation

  • Distance Value Range: Local (10), remote same-socket (20), remote cross-socket (40), zero, maximum (255), negative (-1)
  • Nil Reference Handling: Nil source node, nil target node, both nil (no panics)
  • Self-Referential: Node-to-itself relationships (typical local distance=10)
  • Large Node IDs: Support for systems with many NUMA nodes (up to 255)
  • Edge Cases: Zero distance, negative distance, very large distances

Phase 3: Real-World NUMA Topology Scenarios

  • Dual-Socket Topology: Standard 2x2 distance matrix (Intel/AMD servers)
  • Quad-Socket Topology: 4x4 distance matrix with multi-hop distances
  • AMD EPYC Topology: Chiplet architecture (intra-socket=10-12, inter-socket=32)
  • Intel Xeon Topology: Uniform cross-socket distances (typically 21)
  • Eight-Socket Topology: Large server configurations with multi-hop distances
  • Single-Node Systems: Cloud instances and small servers
  • Cloud Provider Patterns: AWS c5.metal (2 nodes), GCP n2 (1 node), Azure L-series (4 nodes)
  • Bidirectional Symmetry: Verify symmetric distance relationships
  • Asymmetric Distances: Support for rare asymmetric NUMA configurations

Test Statistics

  • 12 test functions covering all phases
  • 60+ individual test cases for comprehensive coverage
  • All NUMA architectures (Intel Xeon, AMD EPYC, cloud instances)
  • All topology sizes (1, 2, 4, 8 NUMA nodes)
  • Distance matrix validation for common server configurations

Coverage Achievement

createNUMADistanceRelationship Function:

  • Before: 0% coverage (completely untested)
  • After: 100% coverage ✅

Overall Package:

  • Before: 70.9%
  • After: 72.2%
  • Improvement: +1.3 percentage points ✅

All tests passing:

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

Success Criteria Met

✅ Achieve 100% coverage for createNUMADistanceRelationship
✅ Test all NUMA distance scenarios
✅ Validate proper predicate creation
✅ Test error handling and edge cases
✅ Cover real-world NUMA topologies (Intel, AMD, cloud providers)

Testing

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

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

# Run specific NUMA distance tests
go test ./internal/hardware/graph/... -run "CreateNUMADistanceRelationship"

Closes #162

Related

jra3 and others added 3 commits November 17, 2025 11:18
Add linux-tools-generic package to GitHub Actions build dependencies
to provide bpftool utility required by generate-vmlinux target.

The ARM64 build job was failing when ebpf/scripts/generate_vmlinux.sh
attempted to convert kernel BTF to vmlinux.h header file. The script
requires bpftool which was not available in the build environment.

Update package installation in three workflow jobs:
- Generation Check job
- Build Agent Binary jobs (amd64 and arm64)
- Build Test Artifacts job
…onships

Add 604 lines of unit tests for createNUMADistanceRelationship function,
achieving 100% coverage for NUMA distance relationship creation (previously
0% coverage). Tests verify correctness across all real-world NUMA topologies
found in production servers and cloud instances.

Test implementation covers three phases from issue #162:

Phase 1: Basic functionality tests validate relationship creation,
predicate marshaling/unmarshaling, type descriptors, and reference handling.

Phase 2: Distance value validation tests cover all typical NUMA distances
(local=10, remote=20, far=40), edge cases (zero, maximum, negative values),
nil reference handling, and self-referential relationships.

Phase 3: Real-world NUMA topology scenarios test dual-socket servers,
quad-socket configurations, AMD EPYC chiplet architectures, Intel Xeon
topologies, eight-socket systems, single-node cloud instances, and cloud
provider patterns (AWS c5.metal, GCP n2, Azure L-series). Tests validate
bidirectional symmetry and asymmetric distance support.

Coverage improvement: 70.9% to 72.2% (+1.3%)
createNUMADistanceRelationship: 0% to 100% coverage

Closes #162

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: John Allen <john@antimetal.com>
Fix errcheck lint errors by capturing error returns in NotPanics
callbacks.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@jra3 jra3 marked this pull request as ready for review December 4, 2025 16:39
@jra3 jra3 requested a review from haq204 December 4, 2025 18:30
@jra3 jra3 closed this Jan 30, 2026
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: Add unit tests for NUMA distance relationship creation

1 participant