Skip to content

Commit ef113d1

Browse files
author
Dongsu Park
committed
validation: add different test cases for blkio cgroup tests
Test if blkio cgroups tests work corectly, with different rate values. Also test it with empty weight values in the input json file. Signed-off-by: Dongsu Park <[email protected]>
1 parent cf9decf commit ef113d1

File tree

1 file changed

+43
-7
lines changed

1 file changed

+43
-7
lines changed

validation/linux_cgroups_blkio.go

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,72 @@
11
package main
22

33
import (
4+
"fmt"
5+
"runtime"
6+
47
"github.com/mndrix/tap-go"
58
"github.com/opencontainers/runtime-tools/cgroups"
69
"github.com/opencontainers/runtime-tools/validation/util"
710
)
811

9-
func main() {
12+
func testBlkioCgroups(rate uint64, isEmpty bool) error {
1013
var weight uint16 = 500
1114
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
1421

1522
t := tap.New()
1623
t.Header(0)
1724
defer t.AutoPlan()
1825

1926
g, err := util.GetDefaultGenerator()
2027
if err != nil {
21-
util.Fatal(err)
28+
return err
2229
}
30+
2331
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+
2638
g.AddLinuxResourcesBlockIOWeightDevice(major, minor, weight)
2739
g.AddLinuxResourcesBlockIOLeafWeightDevice(major, minor, leafWeight)
2840
g.AddLinuxResourcesBlockIOThrottleReadBpsDevice(major, minor, rate)
2941
g.AddLinuxResourcesBlockIOThrottleWriteBpsDevice(major, minor, rate)
3042
g.AddLinuxResourcesBlockIOThrottleReadIOPSDevice(major, minor, rate)
3143
g.AddLinuxResourcesBlockIOThrottleWriteIOPSDevice(major, minor, rate)
44+
3245
err = util.RuntimeOutsideValidate(g, t, util.ValidateLinuxResourcesBlockIO)
3346
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+
}
3571
}
3672
}

0 commit comments

Comments
 (0)