github.com/opencontainers/runtime-tools@v0.9.0/validation/linux_cgroups_blkio/linux_cgroups_blkio.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "runtime" 6 7 "github.com/mndrix/tap-go" 8 "github.com/opencontainers/runtime-tools/cgroups" 9 "github.com/opencontainers/runtime-tools/validation/util" 10 ) 11 12 func testBlkioCgroups(rate uint64, isEmpty bool) error { 13 var weight uint16 = 500 14 var leafWeight uint16 = 300 15 16 // It's assumed that a device /dev/sda (8:0) exists on the test system. 17 // The minor number must be always 0, as it's only allowed to set blkio 18 // weights to a whole block device /dev/sda, not to partitions like sda1. 19 var major int64 = 8 20 var minor int64 21 22 t := tap.New() 23 t.Header(0) 24 defer t.AutoPlan() 25 26 g, err := util.GetDefaultGenerator() 27 if err != nil { 28 return err 29 } 30 31 g.SetLinuxCgroupsPath(cgroups.AbsCgroupPath) 32 33 if !isEmpty { 34 g.SetLinuxResourcesBlockIOWeight(weight) 35 g.SetLinuxResourcesBlockIOLeafWeight(leafWeight) 36 } 37 38 g.AddLinuxResourcesBlockIOWeightDevice(major, minor, weight) 39 g.AddLinuxResourcesBlockIOLeafWeightDevice(major, minor, leafWeight) 40 g.AddLinuxResourcesBlockIOThrottleReadBpsDevice(major, minor, rate) 41 g.AddLinuxResourcesBlockIOThrottleWriteBpsDevice(major, minor, rate) 42 g.AddLinuxResourcesBlockIOThrottleReadIOPSDevice(major, minor, rate) 43 g.AddLinuxResourcesBlockIOThrottleWriteIOPSDevice(major, minor, rate) 44 45 err = util.RuntimeOutsideValidate(g, t, util.ValidateLinuxResourcesBlockIO) 46 if err != nil { 47 return err 48 } 49 return nil 50 } 51 52 func main() { 53 if "linux" != runtime.GOOS { 54 util.Fatal(fmt.Errorf("linux-specific cgroup test")) 55 } 56 57 cases := []struct { 58 rate uint64 59 isEmpty bool 60 }{ 61 {102400, false}, 62 {204800, false}, 63 {102400, true}, 64 {204800, true}, 65 } 66 67 for _, c := range cases { 68 if err := testBlkioCgroups(c.rate, c.isEmpty); err != nil { 69 util.Fatal(err) 70 } 71 } 72 }