|
| 1 | +//go:build windows |
| 2 | + |
| 3 | +package builder |
| 4 | + |
| 5 | +import ( |
| 6 | + "testing" |
| 7 | + |
| 8 | + hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2" |
| 9 | + "github.com/Microsoft/hcsshim/internal/vm" |
| 10 | +) |
| 11 | + |
| 12 | +func TestNUMASettings(t *testing.T) { |
| 13 | + b, cs := newBuilder(t, vm.Linux) |
| 14 | + virtualNodeCount := uint8(2) |
| 15 | + maxSizePerNode := uint64(4096) |
| 16 | + numaProcessors := &hcsschema.NumaProcessors{ |
| 17 | + CountPerNode: hcsschema.Range{Max: 4}, |
| 18 | + NodePerSocket: 1, |
| 19 | + } |
| 20 | + numa := &hcsschema.Numa{ |
| 21 | + VirtualNodeCount: virtualNodeCount, |
| 22 | + PreferredPhysicalNodes: []int64{0, 1}, |
| 23 | + Settings: []hcsschema.NumaSetting{ |
| 24 | + { |
| 25 | + VirtualNodeNumber: 0, |
| 26 | + PhysicalNodeNumber: 0, |
| 27 | + VirtualSocketNumber: 0, |
| 28 | + CountOfProcessors: 2, |
| 29 | + CountOfMemoryBlocks: 1024, |
| 30 | + MemoryBackingType: hcsschema.MemoryBackingType_VIRTUAL, |
| 31 | + }, |
| 32 | + { |
| 33 | + VirtualNodeNumber: 1, |
| 34 | + PhysicalNodeNumber: 1, |
| 35 | + VirtualSocketNumber: 1, |
| 36 | + CountOfProcessors: 2, |
| 37 | + CountOfMemoryBlocks: 1024, |
| 38 | + MemoryBackingType: hcsschema.MemoryBackingType_PHYSICAL, |
| 39 | + }, |
| 40 | + }, |
| 41 | + MaxSizePerNode: maxSizePerNode, |
| 42 | + } |
| 43 | + |
| 44 | + b.Numa().SetNUMAProcessorsSettings(numaProcessors) |
| 45 | + b.Numa().SetNUMASettings(numa) |
| 46 | + |
| 47 | + gotProcessors := cs.VirtualMachine.ComputeTopology.Processor.NumaProcessorsSettings |
| 48 | + if gotProcessors == nil { |
| 49 | + t.Fatal("NUMA processor settings not applied") |
| 50 | + } |
| 51 | + if gotProcessors.CountPerNode.Max != 4 { |
| 52 | + t.Fatalf("CountPerNode.Max = %d, want %d", gotProcessors.CountPerNode.Max, 4) |
| 53 | + } |
| 54 | + if gotProcessors.NodePerSocket != 1 { |
| 55 | + t.Fatalf("NodePerSocket = %d, want %d", gotProcessors.NodePerSocket, 1) |
| 56 | + } |
| 57 | + |
| 58 | + gotNUMA := cs.VirtualMachine.ComputeTopology.Numa |
| 59 | + if gotNUMA == nil { |
| 60 | + t.Fatal("NUMA settings not applied") |
| 61 | + } |
| 62 | + if gotNUMA.VirtualNodeCount != virtualNodeCount { |
| 63 | + t.Fatalf("VirtualNodeCount = %d, want %d", gotNUMA.VirtualNodeCount, virtualNodeCount) |
| 64 | + } |
| 65 | + if gotNUMA.MaxSizePerNode != maxSizePerNode { |
| 66 | + t.Fatalf("MaxSizePerNode = %d, want %d", gotNUMA.MaxSizePerNode, maxSizePerNode) |
| 67 | + } |
| 68 | + if len(gotNUMA.PreferredPhysicalNodes) != 2 || gotNUMA.PreferredPhysicalNodes[0] != 0 || gotNUMA.PreferredPhysicalNodes[1] != 1 { |
| 69 | + t.Fatalf("PreferredPhysicalNodes = %v, want [0 1]", gotNUMA.PreferredPhysicalNodes) |
| 70 | + } |
| 71 | + if len(gotNUMA.Settings) != 2 { |
| 72 | + t.Fatalf("Settings length = %d, want %d", len(gotNUMA.Settings), 2) |
| 73 | + } |
| 74 | + |
| 75 | + first := gotNUMA.Settings[0] |
| 76 | + if first.VirtualNodeNumber != 0 || first.PhysicalNodeNumber != 0 || first.VirtualSocketNumber != 0 { |
| 77 | + t.Fatal("first NUMA setting node/socket numbers not applied as expected") |
| 78 | + } |
| 79 | + if first.CountOfProcessors != 2 || first.CountOfMemoryBlocks != 1024 { |
| 80 | + t.Fatal("first NUMA setting processor/memory counts not applied as expected") |
| 81 | + } |
| 82 | + if first.MemoryBackingType != hcsschema.MemoryBackingType_VIRTUAL { |
| 83 | + t.Fatalf("first NUMA setting MemoryBackingType = %s, want %s", first.MemoryBackingType, hcsschema.MemoryBackingType_VIRTUAL) |
| 84 | + } |
| 85 | + |
| 86 | + second := gotNUMA.Settings[1] |
| 87 | + if second.VirtualNodeNumber != 1 || second.PhysicalNodeNumber != 1 || second.VirtualSocketNumber != 1 { |
| 88 | + t.Fatal("second NUMA setting node/socket numbers not applied as expected") |
| 89 | + } |
| 90 | + if second.CountOfProcessors != 2 || second.CountOfMemoryBlocks != 1024 { |
| 91 | + t.Fatal("second NUMA setting processor/memory counts not applied as expected") |
| 92 | + } |
| 93 | + if second.MemoryBackingType != hcsschema.MemoryBackingType_PHYSICAL { |
| 94 | + t.Fatalf("second NUMA setting MemoryBackingType = %s, want %s", second.MemoryBackingType, hcsschema.MemoryBackingType_PHYSICAL) |
| 95 | + } |
| 96 | +} |
0 commit comments