|
1 | 1 | package main |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "fmt" |
| 5 | + "runtime" |
| 6 | + |
4 | 7 | "github.com/mndrix/tap-go" |
5 | 8 | "github.com/opencontainers/runtime-tools/cgroups" |
6 | 9 | "github.com/opencontainers/runtime-tools/validation/util" |
7 | 10 | ) |
8 | 11 |
|
9 | | -func main() { |
| 12 | +func testBlkioCgroups(rate uint64, isEmpty bool) error { |
10 | 13 | var weight uint16 = 500 |
11 | 14 | var leafWeight uint16 = 300 |
12 | | - var major, minor int64 = 8, 0 |
13 | | - var rate uint64 = 102400 |
| 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 |
14 | 21 |
|
15 | 22 | t := tap.New() |
16 | 23 | t.Header(0) |
17 | 24 | defer t.AutoPlan() |
18 | 25 |
|
19 | 26 | g, err := util.GetDefaultGenerator() |
20 | 27 | if err != nil { |
21 | | - util.Fatal(err) |
| 28 | + return err |
22 | 29 | } |
| 30 | + |
23 | 31 | g.SetLinuxCgroupsPath(cgroups.AbsCgroupPath) |
24 | | - g.SetLinuxResourcesBlockIOWeight(weight) |
25 | | - g.SetLinuxResourcesBlockIOLeafWeight(leafWeight) |
| 32 | + |
| 33 | + if !isEmpty { |
| 34 | + g.SetLinuxResourcesBlockIOWeight(weight) |
| 35 | + g.SetLinuxResourcesBlockIOLeafWeight(leafWeight) |
| 36 | + } |
| 37 | + |
26 | 38 | g.AddLinuxResourcesBlockIOWeightDevice(major, minor, weight) |
27 | 39 | g.AddLinuxResourcesBlockIOLeafWeightDevice(major, minor, leafWeight) |
28 | 40 | g.AddLinuxResourcesBlockIOThrottleReadBpsDevice(major, minor, rate) |
29 | 41 | g.AddLinuxResourcesBlockIOThrottleWriteBpsDevice(major, minor, rate) |
30 | 42 | g.AddLinuxResourcesBlockIOThrottleReadIOPSDevice(major, minor, rate) |
31 | 43 | g.AddLinuxResourcesBlockIOThrottleWriteIOPSDevice(major, minor, rate) |
| 44 | + |
32 | 45 | err = util.RuntimeOutsideValidate(g, t, util.ValidateLinuxResourcesBlockIO) |
33 | 46 | if err != nil { |
34 | | - util.Fatal(err) |
| 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 | + } |
35 | 71 | } |
36 | 72 | } |
0 commit comments