|
5 | 5 | "path/filepath"
|
6 | 6 | "strings"
|
7 | 7 | "testing"
|
| 8 | + |
| 9 | + "github.com/opencontainers/runc/libcontainer/configs" |
8 | 10 | )
|
9 | 11 |
|
10 | 12 | func TestIntelRdtSetL3CacheSchema(t *testing.T) {
|
@@ -98,30 +100,148 @@ func TestIntelRdtSetMemBwScSchema(t *testing.T) {
|
98 | 100 | }
|
99 | 101 |
|
100 | 102 | func TestApply(t *testing.T) {
|
101 |
| - helper := NewIntelRdtTestUtil(t) |
102 |
| - |
103 | 103 | const closID = "test-clos"
|
104 |
| - |
105 |
| - helper.config.IntelRdt.ClosID = closID |
106 |
| - intelrdt := newManager(helper.config, "", helper.IntelRdtPath) |
107 |
| - if err := intelrdt.Apply(1234); err == nil { |
108 |
| - t.Fatal("unexpected success when applying pid") |
| 104 | + // TC-1: failure because non-pre-existing CLOS |
| 105 | + { |
| 106 | + helper := NewIntelRdtTestUtil(t) |
| 107 | + helper.config.IntelRdt = &configs.IntelRdt{ |
| 108 | + ClosID: closID, |
| 109 | + } |
| 110 | + |
| 111 | + intelrdt := newManager(helper.config, "", "") |
| 112 | + if err := intelrdt.Apply(1234); err == nil { |
| 113 | + t.Fatal("unexpected success when applying pid") |
| 114 | + } |
| 115 | + closPath := filepath.Join(intelRdtRoot, closID) |
| 116 | + if _, err := os.Stat(closPath); err == nil { |
| 117 | + t.Fatal("closid dir should not exist") |
| 118 | + } |
109 | 119 | }
|
110 |
| - if _, err := os.Stat(filepath.Join(helper.IntelRdtPath, closID)); err == nil { |
111 |
| - t.Fatal("closid dir should not exist") |
| 120 | + // TC-2: CLOS dir should be created if some schema has been specified |
| 121 | + { |
| 122 | + helper := NewIntelRdtTestUtil(t) |
| 123 | + helper.config.IntelRdt = &configs.IntelRdt{ |
| 124 | + ClosID: closID, |
| 125 | + L3CacheSchema: "L3:0=f", |
| 126 | + } |
| 127 | + |
| 128 | + intelrdt := newManager(helper.config, "", "") |
| 129 | + if err := intelrdt.Apply(1235); err != nil { |
| 130 | + t.Fatalf("Apply() failed: %v", err) |
| 131 | + } |
| 132 | + |
| 133 | + closPath := filepath.Join(intelRdtRoot, closID) |
| 134 | + pids, err := getIntelRdtParamString(closPath, "tasks") |
| 135 | + if err != nil { |
| 136 | + t.Fatalf("failed to read tasks file: %v", err) |
| 137 | + } |
| 138 | + if pids != "1235" { |
| 139 | + t.Fatalf("unexpected tasks file, expected '1235', got %q", pids) |
| 140 | + } |
112 | 141 | }
|
113 |
| - |
114 |
| - // Dir should be created if some schema has been specified |
115 |
| - intelrdt.config.IntelRdt.L3CacheSchema = "L3:0=f" |
116 |
| - if err := intelrdt.Apply(1235); err != nil { |
117 |
| - t.Fatalf("Apply() failed: %v", err) |
| 142 | + // TC-3: clos and monitoring group should be created if EnableMonitoring is true |
| 143 | + { |
| 144 | + helper := NewIntelRdtTestUtil(t) |
| 145 | + helper.config.IntelRdt = &configs.IntelRdt{ |
| 146 | + EnableMonitoring: true, |
| 147 | + } |
| 148 | + id := "aaaa-bbbb" |
| 149 | + |
| 150 | + intelrdt := newManager(helper.config, id, "") |
| 151 | + if err := intelrdt.Apply(1236); err != nil { |
| 152 | + t.Fatalf("Apply() failed: %v", err) |
| 153 | + } |
| 154 | + |
| 155 | + closPath := filepath.Join(intelRdtRoot, id) |
| 156 | + pids, err := getIntelRdtParamString(closPath, "tasks") |
| 157 | + if err != nil { |
| 158 | + t.Fatalf("failed to read tasks file: %v", err) |
| 159 | + } |
| 160 | + if pids != "1236" { |
| 161 | + t.Fatalf("unexpected tasks file, expected '1236', got %q", pids) |
| 162 | + } |
118 | 163 | }
|
| 164 | +} |
119 | 165 |
|
120 |
| - pids, err := getIntelRdtParamString(intelrdt.GetPath(), "tasks") |
121 |
| - if err != nil { |
122 |
| - t.Fatalf("failed to read tasks file: %v", err) |
| 166 | +func TestDestroy(t *testing.T) { |
| 167 | + const closID = "test-clos" |
| 168 | + |
| 169 | + // TC-1: per-container CLOS dir should be removed |
| 170 | + { |
| 171 | + helper := NewIntelRdtTestUtil(t) |
| 172 | + id := "abcd-efgh" |
| 173 | + |
| 174 | + intelrdt := newManager(helper.config, id, "") |
| 175 | + if err := intelrdt.Apply(1234); err != nil { |
| 176 | + t.Fatalf("Apply() failed: %v", err) |
| 177 | + } |
| 178 | + closPath := filepath.Join(intelRdtRoot, id) |
| 179 | + if _, err := os.Stat(closPath); err != nil { |
| 180 | + t.Fatal("CLOS dir should exist") |
| 181 | + } |
| 182 | + if err := intelrdt.Destroy(); err != nil { |
| 183 | + t.Fatalf("Destroy() failed: %v", err) |
| 184 | + } |
| 185 | + if _, err := os.Stat(closPath); err == nil { |
| 186 | + t.Fatal("CLOS dir should not exist") |
| 187 | + } |
| 188 | + } |
| 189 | + // TC-2: pre-existing CLOS should not be removed |
| 190 | + { |
| 191 | + helper := NewIntelRdtTestUtil(t) |
| 192 | + helper.config.IntelRdt = &configs.IntelRdt{ |
| 193 | + ClosID: closID, |
| 194 | + } |
| 195 | + |
| 196 | + closPath := filepath.Join(intelRdtRoot, closID) |
| 197 | + if err := os.MkdirAll(closPath, 0o755); err != nil { |
| 198 | + t.Fatal(err) |
| 199 | + } |
| 200 | + |
| 201 | + intelrdt := newManager(helper.config, "", "") |
| 202 | + if err := intelrdt.Apply(1234); err != nil { |
| 203 | + t.Fatalf("Apply() failed: %v", err) |
| 204 | + } |
| 205 | + if _, err := os.Stat(closPath); err != nil { |
| 206 | + t.Fatal("CLOS dir should exist") |
| 207 | + } |
| 208 | + if err := intelrdt.Destroy(); err != nil { |
| 209 | + t.Fatalf("Destroy() failed: %v", err) |
| 210 | + } |
| 211 | + if _, err := os.Stat(closPath); err != nil { |
| 212 | + t.Fatal("CLOS dir should exist") |
| 213 | + } |
123 | 214 | }
|
124 |
| - if pids != "1235" { |
125 |
| - t.Fatalf("unexpected tasks file, expected '1235', got %q", pids) |
| 215 | + // TC-3: per-container MON dir in pre-existing CLOS should be removed |
| 216 | + { |
| 217 | + helper := NewIntelRdtTestUtil(t) |
| 218 | + helper.config.IntelRdt = &configs.IntelRdt{ |
| 219 | + ClosID: closID, |
| 220 | + EnableMonitoring: true, |
| 221 | + } |
| 222 | + id := "abcd-efgh" |
| 223 | + |
| 224 | + closPath := filepath.Join(intelRdtRoot, closID) |
| 225 | + if err := os.MkdirAll(closPath, 0o755); err != nil { |
| 226 | + t.Fatal(err) |
| 227 | + } |
| 228 | + |
| 229 | + intelrdt := newManager(helper.config, id, "") |
| 230 | + if err := intelrdt.Apply(1234); err != nil { |
| 231 | + t.Fatalf("Apply() failed: %v", err) |
| 232 | + } |
| 233 | + monPath := filepath.Join(closPath, "mon_groups", id) |
| 234 | + if _, err := os.Stat(monPath); err != nil { |
| 235 | + t.Fatal("MON dir should exist") |
| 236 | + } |
| 237 | + if err := intelrdt.Destroy(); err != nil { |
| 238 | + t.Fatalf("Destroy() failed: %v", err) |
| 239 | + } |
| 240 | + if _, err := os.Stat(closPath); err != nil { |
| 241 | + t.Fatalf("CLOS dir should exist: %f", err) |
| 242 | + } |
| 243 | + if _, err := os.Stat(monPath); err == nil { |
| 244 | + t.Fatal("MON dir should not exist") |
| 245 | + } |
126 | 246 | }
|
127 | 247 | }
|
0 commit comments