github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/mergeCode/runc/libcontainer/cgroups/fs/blkio_test.go (about) 1 // +build linux 2 3 package fs 4 5 import ( 6 "strconv" 7 "testing" 8 9 "github.com/opencontainers/runc/libcontainer/cgroups" 10 "github.com/opencontainers/runc/libcontainer/configs" 11 ) 12 13 const ( 14 sectorsRecursiveContents = `8:0 1024` 15 serviceBytesRecursiveContents = `8:0 Read 100 16 8:0 Write 200 17 8:0 Sync 300 18 8:0 Async 500 19 8:0 Total 500 20 Total 500` 21 servicedRecursiveContents = `8:0 Read 10 22 8:0 Write 40 23 8:0 Sync 20 24 8:0 Async 30 25 8:0 Total 50 26 Total 50` 27 queuedRecursiveContents = `8:0 Read 1 28 8:0 Write 4 29 8:0 Sync 2 30 8:0 Async 3 31 8:0 Total 5 32 Total 5` 33 serviceTimeRecursiveContents = `8:0 Read 173959 34 8:0 Write 0 35 8:0 Sync 0 36 8:0 Async 173959 37 8:0 Total 17395 38 Total 17395` 39 waitTimeRecursiveContents = `8:0 Read 15571 40 8:0 Write 0 41 8:0 Sync 0 42 8:0 Async 15571 43 8:0 Total 15571` 44 mergedRecursiveContents = `8:0 Read 5 45 8:0 Write 10 46 8:0 Sync 0 47 8:0 Async 0 48 8:0 Total 15 49 Total 15` 50 timeRecursiveContents = `8:0 8` 51 throttleServiceBytes = `8:0 Read 11030528 52 8:0 Write 23 53 8:0 Sync 42 54 8:0 Async 11030528 55 8:0 Total 11030528 56 252:0 Read 11030528 57 252:0 Write 23 58 252:0 Sync 42 59 252:0 Async 11030528 60 252:0 Total 11030528 61 Total 22061056` 62 throttleServiced = `8:0 Read 164 63 8:0 Write 23 64 8:0 Sync 42 65 8:0 Async 164 66 8:0 Total 164 67 252:0 Read 164 68 252:0 Write 23 69 252:0 Sync 42 70 252:0 Async 164 71 252:0 Total 164 72 Total 328` 73 ) 74 75 func appendBlkioStatEntry(blkioStatEntries *[]cgroups.BlkioStatEntry, major, minor, value uint64, op string) { 76 *blkioStatEntries = append(*blkioStatEntries, cgroups.BlkioStatEntry{Major: major, Minor: minor, Value: value, Op: op}) 77 } 78 79 func TestBlkioSetWeight(t *testing.T) { 80 helper := NewCgroupTestUtil("blkio", t) 81 defer helper.cleanup() 82 83 const ( 84 weightBefore = 100 85 weightAfter = 200 86 ) 87 88 helper.writeFileContents(map[string]string{ 89 "blkio.weight": strconv.Itoa(weightBefore), 90 }) 91 92 helper.CgroupData.config.Resources.BlkioWeight = weightAfter 93 blkio := &BlkioGroup{} 94 if err := blkio.Set(helper.CgroupPath, helper.CgroupData.config); err != nil { 95 t.Fatal(err) 96 } 97 98 value, err := getCgroupParamUint(helper.CgroupPath, "blkio.weight") 99 if err != nil { 100 t.Fatalf("Failed to parse blkio.weight - %s", err) 101 } 102 103 if value != weightAfter { 104 t.Fatal("Got the wrong value, set blkio.weight failed.") 105 } 106 } 107 108 func TestBlkioSetWeightDevice(t *testing.T) { 109 helper := NewCgroupTestUtil("blkio", t) 110 defer helper.cleanup() 111 112 const ( 113 weightDeviceBefore = "8:0 400" 114 ) 115 116 wd := configs.NewWeightDevice(8, 0, 500, 0) 117 weightDeviceAfter := wd.WeightString() 118 119 helper.writeFileContents(map[string]string{ 120 "blkio.weight_device": weightDeviceBefore, 121 }) 122 123 helper.CgroupData.config.Resources.BlkioWeightDevice = []*configs.WeightDevice{wd} 124 blkio := &BlkioGroup{} 125 if err := blkio.Set(helper.CgroupPath, helper.CgroupData.config); err != nil { 126 t.Fatal(err) 127 } 128 129 value, err := getCgroupParamString(helper.CgroupPath, "blkio.weight_device") 130 if err != nil { 131 t.Fatalf("Failed to parse blkio.weight_device - %s", err) 132 } 133 134 if value != weightDeviceAfter { 135 t.Fatal("Got the wrong value, set blkio.weight_device failed.") 136 } 137 } 138 139 // regression #274 140 func TestBlkioSetMultipleWeightDevice(t *testing.T) { 141 helper := NewCgroupTestUtil("blkio", t) 142 defer helper.cleanup() 143 144 const ( 145 weightDeviceBefore = "8:0 400" 146 ) 147 148 wd1 := configs.NewWeightDevice(8, 0, 500, 0) 149 wd2 := configs.NewWeightDevice(8, 16, 500, 0) 150 // we cannot actually set and check both because normal ioutil.WriteFile 151 // when writing to cgroup file will overwrite the whole file content instead 152 // of updating it as the kernel is doing. Just check the second device 153 // is present will suffice for the test to ensure multiple writes are done. 154 weightDeviceAfter := wd2.WeightString() 155 156 helper.writeFileContents(map[string]string{ 157 "blkio.weight_device": weightDeviceBefore, 158 }) 159 160 helper.CgroupData.config.Resources.BlkioWeightDevice = []*configs.WeightDevice{wd1, wd2} 161 blkio := &BlkioGroup{} 162 if err := blkio.Set(helper.CgroupPath, helper.CgroupData.config); err != nil { 163 t.Fatal(err) 164 } 165 166 value, err := getCgroupParamString(helper.CgroupPath, "blkio.weight_device") 167 if err != nil { 168 t.Fatalf("Failed to parse blkio.weight_device - %s", err) 169 } 170 171 if value != weightDeviceAfter { 172 t.Fatal("Got the wrong value, set blkio.weight_device failed.") 173 } 174 } 175 176 func TestBlkioStats(t *testing.T) { 177 helper := NewCgroupTestUtil("blkio", t) 178 defer helper.cleanup() 179 helper.writeFileContents(map[string]string{ 180 "blkio.io_service_bytes_recursive": serviceBytesRecursiveContents, 181 "blkio.io_serviced_recursive": servicedRecursiveContents, 182 "blkio.io_queued_recursive": queuedRecursiveContents, 183 "blkio.io_service_time_recursive": serviceTimeRecursiveContents, 184 "blkio.io_wait_time_recursive": waitTimeRecursiveContents, 185 "blkio.io_merged_recursive": mergedRecursiveContents, 186 "blkio.time_recursive": timeRecursiveContents, 187 "blkio.sectors_recursive": sectorsRecursiveContents, 188 }) 189 190 blkio := &BlkioGroup{} 191 actualStats := *cgroups.NewStats() 192 err := blkio.GetStats(helper.CgroupPath, &actualStats) 193 if err != nil { 194 t.Fatal(err) 195 } 196 197 // Verify expected stats. 198 expectedStats := cgroups.BlkioStats{} 199 appendBlkioStatEntry(&expectedStats.SectorsRecursive, 8, 0, 1024, "") 200 201 appendBlkioStatEntry(&expectedStats.IoServiceBytesRecursive, 8, 0, 100, "Read") 202 appendBlkioStatEntry(&expectedStats.IoServiceBytesRecursive, 8, 0, 200, "Write") 203 appendBlkioStatEntry(&expectedStats.IoServiceBytesRecursive, 8, 0, 300, "Sync") 204 appendBlkioStatEntry(&expectedStats.IoServiceBytesRecursive, 8, 0, 500, "Async") 205 appendBlkioStatEntry(&expectedStats.IoServiceBytesRecursive, 8, 0, 500, "Total") 206 207 appendBlkioStatEntry(&expectedStats.IoServicedRecursive, 8, 0, 10, "Read") 208 appendBlkioStatEntry(&expectedStats.IoServicedRecursive, 8, 0, 40, "Write") 209 appendBlkioStatEntry(&expectedStats.IoServicedRecursive, 8, 0, 20, "Sync") 210 appendBlkioStatEntry(&expectedStats.IoServicedRecursive, 8, 0, 30, "Async") 211 appendBlkioStatEntry(&expectedStats.IoServicedRecursive, 8, 0, 50, "Total") 212 213 appendBlkioStatEntry(&expectedStats.IoQueuedRecursive, 8, 0, 1, "Read") 214 appendBlkioStatEntry(&expectedStats.IoQueuedRecursive, 8, 0, 4, "Write") 215 appendBlkioStatEntry(&expectedStats.IoQueuedRecursive, 8, 0, 2, "Sync") 216 appendBlkioStatEntry(&expectedStats.IoQueuedRecursive, 8, 0, 3, "Async") 217 appendBlkioStatEntry(&expectedStats.IoQueuedRecursive, 8, 0, 5, "Total") 218 219 appendBlkioStatEntry(&expectedStats.IoServiceTimeRecursive, 8, 0, 173959, "Read") 220 appendBlkioStatEntry(&expectedStats.IoServiceTimeRecursive, 8, 0, 0, "Write") 221 appendBlkioStatEntry(&expectedStats.IoServiceTimeRecursive, 8, 0, 0, "Sync") 222 appendBlkioStatEntry(&expectedStats.IoServiceTimeRecursive, 8, 0, 173959, "Async") 223 appendBlkioStatEntry(&expectedStats.IoServiceTimeRecursive, 8, 0, 17395, "Total") 224 225 appendBlkioStatEntry(&expectedStats.IoWaitTimeRecursive, 8, 0, 15571, "Read") 226 appendBlkioStatEntry(&expectedStats.IoWaitTimeRecursive, 8, 0, 0, "Write") 227 appendBlkioStatEntry(&expectedStats.IoWaitTimeRecursive, 8, 0, 0, "Sync") 228 appendBlkioStatEntry(&expectedStats.IoWaitTimeRecursive, 8, 0, 15571, "Async") 229 appendBlkioStatEntry(&expectedStats.IoWaitTimeRecursive, 8, 0, 15571, "Total") 230 231 appendBlkioStatEntry(&expectedStats.IoMergedRecursive, 8, 0, 5, "Read") 232 appendBlkioStatEntry(&expectedStats.IoMergedRecursive, 8, 0, 10, "Write") 233 appendBlkioStatEntry(&expectedStats.IoMergedRecursive, 8, 0, 0, "Sync") 234 appendBlkioStatEntry(&expectedStats.IoMergedRecursive, 8, 0, 0, "Async") 235 appendBlkioStatEntry(&expectedStats.IoMergedRecursive, 8, 0, 15, "Total") 236 237 appendBlkioStatEntry(&expectedStats.IoTimeRecursive, 8, 0, 8, "") 238 239 expectBlkioStatsEquals(t, expectedStats, actualStats.BlkioStats) 240 } 241 242 func TestBlkioStatsNoSectorsFile(t *testing.T) { 243 helper := NewCgroupTestUtil("blkio", t) 244 defer helper.cleanup() 245 helper.writeFileContents(map[string]string{ 246 "blkio.io_service_bytes_recursive": serviceBytesRecursiveContents, 247 "blkio.io_serviced_recursive": servicedRecursiveContents, 248 "blkio.io_queued_recursive": queuedRecursiveContents, 249 "blkio.io_service_time_recursive": serviceTimeRecursiveContents, 250 "blkio.io_wait_time_recursive": waitTimeRecursiveContents, 251 "blkio.io_merged_recursive": mergedRecursiveContents, 252 "blkio.time_recursive": timeRecursiveContents, 253 }) 254 255 blkio := &BlkioGroup{} 256 actualStats := *cgroups.NewStats() 257 err := blkio.GetStats(helper.CgroupPath, &actualStats) 258 if err != nil { 259 t.Fatalf("Failed unexpectedly: %s", err) 260 } 261 } 262 263 func TestBlkioStatsNoServiceBytesFile(t *testing.T) { 264 helper := NewCgroupTestUtil("blkio", t) 265 defer helper.cleanup() 266 helper.writeFileContents(map[string]string{ 267 "blkio.io_serviced_recursive": servicedRecursiveContents, 268 "blkio.io_queued_recursive": queuedRecursiveContents, 269 "blkio.sectors_recursive": sectorsRecursiveContents, 270 "blkio.io_service_time_recursive": serviceTimeRecursiveContents, 271 "blkio.io_wait_time_recursive": waitTimeRecursiveContents, 272 "blkio.io_merged_recursive": mergedRecursiveContents, 273 "blkio.time_recursive": timeRecursiveContents, 274 }) 275 276 blkio := &BlkioGroup{} 277 actualStats := *cgroups.NewStats() 278 err := blkio.GetStats(helper.CgroupPath, &actualStats) 279 if err != nil { 280 t.Fatalf("Failed unexpectedly: %s", err) 281 } 282 } 283 284 func TestBlkioStatsNoServicedFile(t *testing.T) { 285 helper := NewCgroupTestUtil("blkio", t) 286 defer helper.cleanup() 287 helper.writeFileContents(map[string]string{ 288 "blkio.io_service_bytes_recursive": serviceBytesRecursiveContents, 289 "blkio.io_queued_recursive": queuedRecursiveContents, 290 "blkio.sectors_recursive": sectorsRecursiveContents, 291 "blkio.io_service_time_recursive": serviceTimeRecursiveContents, 292 "blkio.io_wait_time_recursive": waitTimeRecursiveContents, 293 "blkio.io_merged_recursive": mergedRecursiveContents, 294 "blkio.time_recursive": timeRecursiveContents, 295 }) 296 297 blkio := &BlkioGroup{} 298 actualStats := *cgroups.NewStats() 299 err := blkio.GetStats(helper.CgroupPath, &actualStats) 300 if err != nil { 301 t.Fatalf("Failed unexpectedly: %s", err) 302 } 303 } 304 305 func TestBlkioStatsNoQueuedFile(t *testing.T) { 306 helper := NewCgroupTestUtil("blkio", t) 307 defer helper.cleanup() 308 helper.writeFileContents(map[string]string{ 309 "blkio.io_service_bytes_recursive": serviceBytesRecursiveContents, 310 "blkio.io_serviced_recursive": servicedRecursiveContents, 311 "blkio.sectors_recursive": sectorsRecursiveContents, 312 "blkio.io_service_time_recursive": serviceTimeRecursiveContents, 313 "blkio.io_wait_time_recursive": waitTimeRecursiveContents, 314 "blkio.io_merged_recursive": mergedRecursiveContents, 315 "blkio.time_recursive": timeRecursiveContents, 316 }) 317 318 blkio := &BlkioGroup{} 319 actualStats := *cgroups.NewStats() 320 err := blkio.GetStats(helper.CgroupPath, &actualStats) 321 if err != nil { 322 t.Fatalf("Failed unexpectedly: %s", err) 323 } 324 } 325 326 func TestBlkioStatsNoServiceTimeFile(t *testing.T) { 327 if testing.Short() { 328 t.Skip("skipping test in short mode.") 329 } 330 helper := NewCgroupTestUtil("blkio", t) 331 defer helper.cleanup() 332 helper.writeFileContents(map[string]string{ 333 "blkio.io_service_bytes_recursive": serviceBytesRecursiveContents, 334 "blkio.io_serviced_recursive": servicedRecursiveContents, 335 "blkio.io_queued_recursive": queuedRecursiveContents, 336 "blkio.io_wait_time_recursive": waitTimeRecursiveContents, 337 "blkio.io_merged_recursive": mergedRecursiveContents, 338 "blkio.time_recursive": timeRecursiveContents, 339 "blkio.sectors_recursive": sectorsRecursiveContents, 340 }) 341 342 blkio := &BlkioGroup{} 343 actualStats := *cgroups.NewStats() 344 err := blkio.GetStats(helper.CgroupPath, &actualStats) 345 if err != nil { 346 t.Fatalf("Failed unexpectedly: %s", err) 347 } 348 } 349 350 func TestBlkioStatsNoWaitTimeFile(t *testing.T) { 351 if testing.Short() { 352 t.Skip("skipping test in short mode.") 353 } 354 helper := NewCgroupTestUtil("blkio", t) 355 defer helper.cleanup() 356 helper.writeFileContents(map[string]string{ 357 "blkio.io_service_bytes_recursive": serviceBytesRecursiveContents, 358 "blkio.io_serviced_recursive": servicedRecursiveContents, 359 "blkio.io_queued_recursive": queuedRecursiveContents, 360 "blkio.io_service_time_recursive": serviceTimeRecursiveContents, 361 "blkio.io_merged_recursive": mergedRecursiveContents, 362 "blkio.time_recursive": timeRecursiveContents, 363 "blkio.sectors_recursive": sectorsRecursiveContents, 364 }) 365 366 blkio := &BlkioGroup{} 367 actualStats := *cgroups.NewStats() 368 err := blkio.GetStats(helper.CgroupPath, &actualStats) 369 if err != nil { 370 t.Fatalf("Failed unexpectedly: %s", err) 371 } 372 } 373 374 func TestBlkioStatsNoMergedFile(t *testing.T) { 375 if testing.Short() { 376 t.Skip("skipping test in short mode.") 377 } 378 helper := NewCgroupTestUtil("blkio", t) 379 defer helper.cleanup() 380 helper.writeFileContents(map[string]string{ 381 "blkio.io_service_bytes_recursive": serviceBytesRecursiveContents, 382 "blkio.io_serviced_recursive": servicedRecursiveContents, 383 "blkio.io_queued_recursive": queuedRecursiveContents, 384 "blkio.io_service_time_recursive": serviceTimeRecursiveContents, 385 "blkio.io_wait_time_recursive": waitTimeRecursiveContents, 386 "blkio.time_recursive": timeRecursiveContents, 387 "blkio.sectors_recursive": sectorsRecursiveContents, 388 }) 389 390 blkio := &BlkioGroup{} 391 actualStats := *cgroups.NewStats() 392 err := blkio.GetStats(helper.CgroupPath, &actualStats) 393 if err != nil { 394 t.Fatalf("Failed unexpectedly: %s", err) 395 } 396 } 397 398 func TestBlkioStatsNoTimeFile(t *testing.T) { 399 if testing.Short() { 400 t.Skip("skipping test in short mode.") 401 } 402 helper := NewCgroupTestUtil("blkio", t) 403 defer helper.cleanup() 404 helper.writeFileContents(map[string]string{ 405 "blkio.io_service_bytes_recursive": serviceBytesRecursiveContents, 406 "blkio.io_serviced_recursive": servicedRecursiveContents, 407 "blkio.io_queued_recursive": queuedRecursiveContents, 408 "blkio.io_service_time_recursive": serviceTimeRecursiveContents, 409 "blkio.io_wait_time_recursive": waitTimeRecursiveContents, 410 "blkio.io_merged_recursive": mergedRecursiveContents, 411 "blkio.sectors_recursive": sectorsRecursiveContents, 412 }) 413 414 blkio := &BlkioGroup{} 415 actualStats := *cgroups.NewStats() 416 err := blkio.GetStats(helper.CgroupPath, &actualStats) 417 if err != nil { 418 t.Fatalf("Failed unexpectedly: %s", err) 419 } 420 } 421 422 func TestBlkioStatsUnexpectedNumberOfFields(t *testing.T) { 423 helper := NewCgroupTestUtil("blkio", t) 424 defer helper.cleanup() 425 helper.writeFileContents(map[string]string{ 426 "blkio.io_service_bytes_recursive": "8:0 Read 100 100", 427 "blkio.io_serviced_recursive": servicedRecursiveContents, 428 "blkio.io_queued_recursive": queuedRecursiveContents, 429 "blkio.sectors_recursive": sectorsRecursiveContents, 430 "blkio.io_service_time_recursive": serviceTimeRecursiveContents, 431 "blkio.io_wait_time_recursive": waitTimeRecursiveContents, 432 "blkio.io_merged_recursive": mergedRecursiveContents, 433 "blkio.time_recursive": timeRecursiveContents, 434 }) 435 436 blkio := &BlkioGroup{} 437 actualStats := *cgroups.NewStats() 438 err := blkio.GetStats(helper.CgroupPath, &actualStats) 439 if err == nil { 440 t.Fatal("Expected to fail, but did not") 441 } 442 } 443 444 func TestBlkioStatsUnexpectedFieldType(t *testing.T) { 445 helper := NewCgroupTestUtil("blkio", t) 446 defer helper.cleanup() 447 helper.writeFileContents(map[string]string{ 448 "blkio.io_service_bytes_recursive": "8:0 Read Write", 449 "blkio.io_serviced_recursive": servicedRecursiveContents, 450 "blkio.io_queued_recursive": queuedRecursiveContents, 451 "blkio.sectors_recursive": sectorsRecursiveContents, 452 "blkio.io_service_time_recursive": serviceTimeRecursiveContents, 453 "blkio.io_wait_time_recursive": waitTimeRecursiveContents, 454 "blkio.io_merged_recursive": mergedRecursiveContents, 455 "blkio.time_recursive": timeRecursiveContents, 456 }) 457 458 blkio := &BlkioGroup{} 459 actualStats := *cgroups.NewStats() 460 err := blkio.GetStats(helper.CgroupPath, &actualStats) 461 if err == nil { 462 t.Fatal("Expected to fail, but did not") 463 } 464 } 465 466 func TestNonCFQBlkioStats(t *testing.T) { 467 helper := NewCgroupTestUtil("blkio", t) 468 defer helper.cleanup() 469 helper.writeFileContents(map[string]string{ 470 "blkio.io_service_bytes_recursive": "", 471 "blkio.io_serviced_recursive": "", 472 "blkio.io_queued_recursive": "", 473 "blkio.sectors_recursive": "", 474 "blkio.io_service_time_recursive": "", 475 "blkio.io_wait_time_recursive": "", 476 "blkio.io_merged_recursive": "", 477 "blkio.time_recursive": "", 478 "blkio.throttle.io_service_bytes": throttleServiceBytes, 479 "blkio.throttle.io_serviced": throttleServiced, 480 }) 481 482 blkio := &BlkioGroup{} 483 actualStats := *cgroups.NewStats() 484 err := blkio.GetStats(helper.CgroupPath, &actualStats) 485 if err != nil { 486 t.Fatal(err) 487 } 488 489 // Verify expected stats. 490 expectedStats := cgroups.BlkioStats{} 491 492 appendBlkioStatEntry(&expectedStats.IoServiceBytesRecursive, 8, 0, 11030528, "Read") 493 appendBlkioStatEntry(&expectedStats.IoServiceBytesRecursive, 8, 0, 23, "Write") 494 appendBlkioStatEntry(&expectedStats.IoServiceBytesRecursive, 8, 0, 42, "Sync") 495 appendBlkioStatEntry(&expectedStats.IoServiceBytesRecursive, 8, 0, 11030528, "Async") 496 appendBlkioStatEntry(&expectedStats.IoServiceBytesRecursive, 8, 0, 11030528, "Total") 497 appendBlkioStatEntry(&expectedStats.IoServiceBytesRecursive, 252, 0, 11030528, "Read") 498 appendBlkioStatEntry(&expectedStats.IoServiceBytesRecursive, 252, 0, 23, "Write") 499 appendBlkioStatEntry(&expectedStats.IoServiceBytesRecursive, 252, 0, 42, "Sync") 500 appendBlkioStatEntry(&expectedStats.IoServiceBytesRecursive, 252, 0, 11030528, "Async") 501 appendBlkioStatEntry(&expectedStats.IoServiceBytesRecursive, 252, 0, 11030528, "Total") 502 503 appendBlkioStatEntry(&expectedStats.IoServicedRecursive, 8, 0, 164, "Read") 504 appendBlkioStatEntry(&expectedStats.IoServicedRecursive, 8, 0, 23, "Write") 505 appendBlkioStatEntry(&expectedStats.IoServicedRecursive, 8, 0, 42, "Sync") 506 appendBlkioStatEntry(&expectedStats.IoServicedRecursive, 8, 0, 164, "Async") 507 appendBlkioStatEntry(&expectedStats.IoServicedRecursive, 8, 0, 164, "Total") 508 appendBlkioStatEntry(&expectedStats.IoServicedRecursive, 252, 0, 164, "Read") 509 appendBlkioStatEntry(&expectedStats.IoServicedRecursive, 252, 0, 23, "Write") 510 appendBlkioStatEntry(&expectedStats.IoServicedRecursive, 252, 0, 42, "Sync") 511 appendBlkioStatEntry(&expectedStats.IoServicedRecursive, 252, 0, 164, "Async") 512 appendBlkioStatEntry(&expectedStats.IoServicedRecursive, 252, 0, 164, "Total") 513 514 expectBlkioStatsEquals(t, expectedStats, actualStats.BlkioStats) 515 } 516 517 func TestBlkioSetThrottleReadBpsDevice(t *testing.T) { 518 helper := NewCgroupTestUtil("blkio", t) 519 defer helper.cleanup() 520 521 const ( 522 throttleBefore = `8:0 1024` 523 ) 524 525 td := configs.NewThrottleDevice(8, 0, 2048) 526 throttleAfter := td.String() 527 528 helper.writeFileContents(map[string]string{ 529 "blkio.throttle.read_bps_device": throttleBefore, 530 }) 531 532 helper.CgroupData.config.Resources.BlkioThrottleReadBpsDevice = []*configs.ThrottleDevice{td} 533 blkio := &BlkioGroup{} 534 if err := blkio.Set(helper.CgroupPath, helper.CgroupData.config); err != nil { 535 t.Fatal(err) 536 } 537 538 value, err := getCgroupParamString(helper.CgroupPath, "blkio.throttle.read_bps_device") 539 if err != nil { 540 t.Fatalf("Failed to parse blkio.throttle.read_bps_device - %s", err) 541 } 542 543 if value != throttleAfter { 544 t.Fatal("Got the wrong value, set blkio.throttle.read_bps_device failed.") 545 } 546 } 547 func TestBlkioSetThrottleWriteBpsDevice(t *testing.T) { 548 helper := NewCgroupTestUtil("blkio", t) 549 defer helper.cleanup() 550 551 const ( 552 throttleBefore = `8:0 1024` 553 ) 554 555 td := configs.NewThrottleDevice(8, 0, 2048) 556 throttleAfter := td.String() 557 558 helper.writeFileContents(map[string]string{ 559 "blkio.throttle.write_bps_device": throttleBefore, 560 }) 561 562 helper.CgroupData.config.Resources.BlkioThrottleWriteBpsDevice = []*configs.ThrottleDevice{td} 563 blkio := &BlkioGroup{} 564 if err := blkio.Set(helper.CgroupPath, helper.CgroupData.config); err != nil { 565 t.Fatal(err) 566 } 567 568 value, err := getCgroupParamString(helper.CgroupPath, "blkio.throttle.write_bps_device") 569 if err != nil { 570 t.Fatalf("Failed to parse blkio.throttle.write_bps_device - %s", err) 571 } 572 573 if value != throttleAfter { 574 t.Fatal("Got the wrong value, set blkio.throttle.write_bps_device failed.") 575 } 576 } 577 func TestBlkioSetThrottleReadIOpsDevice(t *testing.T) { 578 helper := NewCgroupTestUtil("blkio", t) 579 defer helper.cleanup() 580 581 const ( 582 throttleBefore = `8:0 1024` 583 ) 584 585 td := configs.NewThrottleDevice(8, 0, 2048) 586 throttleAfter := td.String() 587 588 helper.writeFileContents(map[string]string{ 589 "blkio.throttle.read_iops_device": throttleBefore, 590 }) 591 592 helper.CgroupData.config.Resources.BlkioThrottleReadIOPSDevice = []*configs.ThrottleDevice{td} 593 blkio := &BlkioGroup{} 594 if err := blkio.Set(helper.CgroupPath, helper.CgroupData.config); err != nil { 595 t.Fatal(err) 596 } 597 598 value, err := getCgroupParamString(helper.CgroupPath, "blkio.throttle.read_iops_device") 599 if err != nil { 600 t.Fatalf("Failed to parse blkio.throttle.read_iops_device - %s", err) 601 } 602 603 if value != throttleAfter { 604 t.Fatal("Got the wrong value, set blkio.throttle.read_iops_device failed.") 605 } 606 } 607 func TestBlkioSetThrottleWriteIOpsDevice(t *testing.T) { 608 helper := NewCgroupTestUtil("blkio", t) 609 defer helper.cleanup() 610 611 const ( 612 throttleBefore = `8:0 1024` 613 ) 614 615 td := configs.NewThrottleDevice(8, 0, 2048) 616 throttleAfter := td.String() 617 618 helper.writeFileContents(map[string]string{ 619 "blkio.throttle.write_iops_device": throttleBefore, 620 }) 621 622 helper.CgroupData.config.Resources.BlkioThrottleWriteIOPSDevice = []*configs.ThrottleDevice{td} 623 blkio := &BlkioGroup{} 624 if err := blkio.Set(helper.CgroupPath, helper.CgroupData.config); err != nil { 625 t.Fatal(err) 626 } 627 628 value, err := getCgroupParamString(helper.CgroupPath, "blkio.throttle.write_iops_device") 629 if err != nil { 630 t.Fatalf("Failed to parse blkio.throttle.write_iops_device - %s", err) 631 } 632 633 if value != throttleAfter { 634 t.Fatal("Got the wrong value, set blkio.throttle.write_iops_device failed.") 635 } 636 }