|
| 1 | +//go:build windows |
| 2 | + |
| 3 | +package jobcontainers |
| 4 | + |
| 5 | +import ( |
| 6 | + "context" |
| 7 | + "strings" |
| 8 | + "testing" |
| 9 | + |
| 10 | + specs "github.com/opencontainers/runtime-spec/specs-go" |
| 11 | +) |
| 12 | + |
| 13 | +func TestSpecToLimits_CPUAffinity_Group0MaskSet(t *testing.T) { |
| 14 | + s := &specs.Spec{ |
| 15 | + Windows: &specs.Windows{ |
| 16 | + Resources: &specs.WindowsResources{ |
| 17 | + CPU: &specs.WindowsCPUResources{ |
| 18 | + Affinity: []specs.WindowsCPUGroupAffinity{ |
| 19 | + {Mask: 0x3, Group: 0}, |
| 20 | + }, |
| 21 | + }, |
| 22 | + }, |
| 23 | + }, |
| 24 | + } |
| 25 | + |
| 26 | + limits, err := specToLimits(context.Background(), "cid", s) |
| 27 | + if err != nil { |
| 28 | + t.Fatalf("specToLimits failed: %v", err) |
| 29 | + } |
| 30 | + if limits.CPUAffinity != 0x3 { |
| 31 | + t.Fatalf("unexpected cpu affinity: got %d want %d", limits.CPUAffinity, uint64(0x3)) |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +func TestSpecToLimits_CPUAffinity_MultiGroupRejected(t *testing.T) { |
| 36 | + s := &specs.Spec{ |
| 37 | + Windows: &specs.Windows{ |
| 38 | + Resources: &specs.WindowsResources{ |
| 39 | + CPU: &specs.WindowsCPUResources{ |
| 40 | + Affinity: []specs.WindowsCPUGroupAffinity{ |
| 41 | + {Mask: 0x1, Group: 0}, |
| 42 | + {Mask: 0x1, Group: 1}, |
| 43 | + }, |
| 44 | + }, |
| 45 | + }, |
| 46 | + }, |
| 47 | + } |
| 48 | + |
| 49 | + _, err := specToLimits(context.Background(), "cid", s) |
| 50 | + if err == nil { |
| 51 | + t.Fatal("expected error for multiple affinity entries") |
| 52 | + } |
| 53 | + if !strings.Contains(err.Error(), "multiple processor groups") { |
| 54 | + t.Fatalf("unexpected error: %v", err) |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +func TestSpecToLimits_CPUAffinity_NonZeroGroupRejected(t *testing.T) { |
| 59 | + s := &specs.Spec{ |
| 60 | + Windows: &specs.Windows{ |
| 61 | + Resources: &specs.WindowsResources{ |
| 62 | + CPU: &specs.WindowsCPUResources{ |
| 63 | + Affinity: []specs.WindowsCPUGroupAffinity{ |
| 64 | + {Mask: 0x1, Group: 1}, |
| 65 | + }, |
| 66 | + }, |
| 67 | + }, |
| 68 | + }, |
| 69 | + } |
| 70 | + |
| 71 | + _, err := specToLimits(context.Background(), "cid", s) |
| 72 | + if err == nil { |
| 73 | + t.Fatal("expected error for non-zero affinity group") |
| 74 | + } |
| 75 | + if !strings.Contains(err.Error(), "processor group") { |
| 76 | + t.Fatalf("unexpected error: %v", err) |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +func TestSpecToLimits_CPUAffinity_ZeroMaskRejected(t *testing.T) { |
| 81 | + s := &specs.Spec{ |
| 82 | + Windows: &specs.Windows{ |
| 83 | + Resources: &specs.WindowsResources{ |
| 84 | + CPU: &specs.WindowsCPUResources{ |
| 85 | + Affinity: []specs.WindowsCPUGroupAffinity{ |
| 86 | + {Mask: 0, Group: 0}, |
| 87 | + }, |
| 88 | + }, |
| 89 | + }, |
| 90 | + }, |
| 91 | + } |
| 92 | + |
| 93 | + _, err := specToLimits(context.Background(), "cid", s) |
| 94 | + if err == nil { |
| 95 | + t.Fatal("expected error for zero affinity mask") |
| 96 | + } |
| 97 | + if !strings.Contains(err.Error(), "mask must be non-zero") { |
| 98 | + t.Fatalf("unexpected error: %v", err) |
| 99 | + } |
| 100 | +} |
0 commit comments