Skip to content

Commit 7c09b4c

Browse files
author
Ma Shimiao
committed
add relative cgroupath test
Signed-off-by: Ma Shimiao <mashimiao.fnst@cn.fujitsu.com>
1 parent 1aebc09 commit 7c09b4c

6 files changed

Lines changed: 339 additions & 0 deletions
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/opencontainers/runtime-tools/cgroups"
7+
"github.com/opencontainers/runtime-tools/validation/util"
8+
)
9+
10+
func main() {
11+
var weight uint16 = 500
12+
var leafWeight uint16 = 300
13+
var major, minor int64 = 8, 0
14+
var rate uint64 = 102400
15+
g := util.GetDefaultGenerator()
16+
g.SetLinuxCgroupsPath(cgroups.RelCgroupPath)
17+
g.SetLinuxResourcesBlockIOWeight(weight)
18+
g.SetLinuxResourcesBlockIOLeafWeight(leafWeight)
19+
g.AddLinuxResourcesBlockIOWeightDevice(major, minor, weight)
20+
g.AddLinuxResourcesBlockIOLeafWeightDevice(major, minor, leafWeight)
21+
g.AddLinuxResourcesBlockIOThrottleReadBpsDevice(major, minor, rate)
22+
g.AddLinuxResourcesBlockIOThrottleWriteBpsDevice(major, minor, rate)
23+
g.AddLinuxResourcesBlockIOThrottleReadIOPSDevice(major, minor, rate)
24+
g.AddLinuxResourcesBlockIOThrottleWriteIOPSDevice(major, minor, rate)
25+
err := util.RuntimeOutsideValidate(g, cgroups.RelCgroupPath, func(pid int, path string) error {
26+
cg, err := cgroups.FindCgroup()
27+
if err != nil {
28+
return err
29+
}
30+
lbd, err := cg.GetBlockIOData(pid, path)
31+
if err != nil {
32+
return err
33+
}
34+
if *lbd.Weight != weight {
35+
return fmt.Errorf("blkio weight is not set correctly, expect: %d, actual: %d", weight, lbd.Weight)
36+
}
37+
if *lbd.LeafWeight != leafWeight {
38+
return fmt.Errorf("blkio leafWeight is not set correctly, expect: %d, actual: %d", weight, lbd.LeafWeight)
39+
}
40+
41+
found := false
42+
for _, wd := range lbd.WeightDevice {
43+
if wd.Major == major && wd.Minor == minor {
44+
found = true
45+
if *wd.Weight != weight {
46+
return fmt.Errorf("blkio weight for %d:%d is not set correctly, expect: %d, actual: %d", major, minor, weight, wd.Weight)
47+
}
48+
if *wd.LeafWeight != leafWeight {
49+
return fmt.Errorf("blkio leafWeight for %d:%d is not set correctly, expect: %d, actual: %d", major, minor, leafWeight, wd.LeafWeight)
50+
}
51+
}
52+
}
53+
if !found {
54+
return fmt.Errorf("blkio weightDevice for %d:%d is not set", major, minor)
55+
}
56+
57+
found = false
58+
for _, trbd := range lbd.ThrottleReadBpsDevice {
59+
if trbd.Major == major && trbd.Minor == minor {
60+
found = true
61+
if trbd.Rate != rate {
62+
return fmt.Errorf("blkio read bps for %d:%d is not set correctly, expect: %d, actual: %d", major, minor, rate, trbd.Rate)
63+
}
64+
}
65+
}
66+
if !found {
67+
return fmt.Errorf("blkio read bps for %d:%d is not set", major, minor)
68+
}
69+
70+
found = false
71+
for _, twbd := range lbd.ThrottleWriteBpsDevice {
72+
if twbd.Major == major && twbd.Minor == minor {
73+
found = true
74+
if twbd.Rate != rate {
75+
return fmt.Errorf("blkio write bps for %d:%d is not set correctly, expect: %d, actual: %d", major, minor, rate, twbd.Rate)
76+
}
77+
}
78+
}
79+
if !found {
80+
return fmt.Errorf("blkio write bps for %d:%d is not set", major, minor)
81+
}
82+
83+
found = false
84+
for _, trid := range lbd.ThrottleReadIOPSDevice {
85+
if trid.Major == major && trid.Minor == minor {
86+
found = true
87+
if trid.Rate != rate {
88+
return fmt.Errorf("blkio read iops for %d:%d is not set correctly, expect: %d, actual: %d", major, minor, rate, trid.Rate)
89+
}
90+
}
91+
}
92+
if !found {
93+
return fmt.Errorf("blkio read iops for %d:%d is not set", major, minor)
94+
}
95+
96+
found = false
97+
for _, twid := range lbd.ThrottleWriteIOPSDevice {
98+
if twid.Major == major && twid.Minor == minor {
99+
found = true
100+
if twid.Rate != rate {
101+
return fmt.Errorf("blkio write iops for %d:%d is not set correctly, expect: %d, actual: %d", major, minor, rate, twid.Rate)
102+
}
103+
}
104+
}
105+
if !found {
106+
return fmt.Errorf("blkio write iops for %d:%d is not set", major, minor)
107+
}
108+
109+
return nil
110+
})
111+
112+
if err != nil {
113+
util.Fatal(err)
114+
}
115+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/opencontainers/runtime-tools/cgroups"
7+
"github.com/opencontainers/runtime-tools/validation/util"
8+
)
9+
10+
func main() {
11+
var shares uint64 = 1024
12+
var period uint64 = 100000
13+
var quota int64 = 50000
14+
var cpus, mems string = "0-1", "0"
15+
g := util.GetDefaultGenerator()
16+
g.SetLinuxCgroupsPath(cgroups.RelCgroupPath)
17+
g.SetLinuxResourcesCPUShares(shares)
18+
g.SetLinuxResourcesCPUQuota(quota)
19+
g.SetLinuxResourcesCPUPeriod(period)
20+
g.SetLinuxResourcesCPUCpus(cpus)
21+
g.SetLinuxResourcesCPUMems(mems)
22+
err := util.RuntimeOutsideValidate(g, cgroups.RelCgroupPath, func(pid int, path string) error {
23+
cg, err := cgroups.FindCgroup()
24+
if err != nil {
25+
return err
26+
}
27+
lcd, err := cg.GetCPUData(pid, path)
28+
if err != nil {
29+
return err
30+
}
31+
if *lcd.Shares != shares {
32+
return fmt.Errorf("cpus shares limit is not set correctly, expect: %d, actual: %d", shares, lcd.Shares)
33+
}
34+
if *lcd.Quota != quota {
35+
return fmt.Errorf("cpus quota is not set correctly, expect: %d, actual: %d", quota, lcd.Quota)
36+
}
37+
if *lcd.Period != period {
38+
return fmt.Errorf("cpus period is not set correctly, expect: %d, actual: %d", period, lcd.Period)
39+
}
40+
if lcd.Cpus != cpus {
41+
return fmt.Errorf("cpus cpus is not set correctly, expect: %s, actual: %s", cpus, lcd.Cpus)
42+
}
43+
if lcd.Mems != mems {
44+
return fmt.Errorf("cpus mems is not set correctly, expect: %s, actual: %s", mems, lcd.Mems)
45+
}
46+
return nil
47+
})
48+
49+
if err != nil {
50+
util.Fatal(err)
51+
}
52+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/opencontainers/runtime-tools/cgroups"
7+
"github.com/opencontainers/runtime-tools/validation/util"
8+
)
9+
10+
func main() {
11+
page := "1GB"
12+
var limit uint64 = 56892210544640
13+
g := util.GetDefaultGenerator()
14+
g.SetLinuxCgroupsPath(cgroups.RelCgroupPath)
15+
g.AddLinuxResourcesHugepageLimit(page, limit)
16+
err := util.RuntimeOutsideValidate(g, cgroups.RelCgroupPath, func(pid int, path string) error {
17+
cg, err := cgroups.FindCgroup()
18+
if err != nil {
19+
return err
20+
}
21+
lhd, err := cg.GetHugepageLimitData(pid, path)
22+
if err != nil {
23+
return err
24+
}
25+
for _, lhl := range lhd {
26+
if lhl.Pagesize == page && lhl.Limit != limit {
27+
return fmt.Errorf("hugepage %s limit is not set correctly, expect: %d, actual: %d", page, limit, lhl.Limit)
28+
}
29+
}
30+
return nil
31+
})
32+
if err != nil {
33+
util.Fatal(err)
34+
}
35+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/opencontainers/runtime-tools/cgroups"
7+
"github.com/opencontainers/runtime-tools/validation/util"
8+
)
9+
10+
func main() {
11+
var limit int64 = 50593792
12+
var swappiness uint64 = 50
13+
g := util.GetDefaultGenerator()
14+
g.SetLinuxCgroupsPath(cgroups.RelCgroupPath)
15+
g.SetLinuxResourcesMemoryLimit(limit)
16+
g.SetLinuxResourcesMemoryReservation(limit)
17+
g.SetLinuxResourcesMemorySwap(limit)
18+
g.SetLinuxResourcesMemoryKernel(limit)
19+
g.SetLinuxResourcesMemoryKernelTCP(limit)
20+
g.SetLinuxResourcesMemorySwappiness(swappiness)
21+
g.SetLinuxResourcesMemoryDisableOOMKiller(true)
22+
err := util.RuntimeOutsideValidate(g, cgroups.RelCgroupPath, func(pid int, path string) error {
23+
cg, err := cgroups.FindCgroup()
24+
if err != nil {
25+
return err
26+
}
27+
lm, err := cg.GetMemoryData(pid, path)
28+
if err != nil {
29+
return err
30+
}
31+
if limit != *lm.Limit {
32+
return fmt.Errorf("memory limit is not set correctly, expect: %d, actual: %d", limit, *lm.Limit)
33+
}
34+
if limit != *lm.Reservation {
35+
return fmt.Errorf("memory reservation is not set correctly, expect: %d, actual: %d", limit, *lm.Reservation)
36+
}
37+
if limit != *lm.Swap {
38+
return fmt.Errorf("memory swap is not set correctly, expect: %d, actual: %d", limit, *lm.Reservation)
39+
}
40+
if limit != *lm.Kernel {
41+
return fmt.Errorf("memory kernel is not set correctly, expect: %d, actual: %d", limit, *lm.Kernel)
42+
}
43+
if limit != *lm.KernelTCP {
44+
return fmt.Errorf("memory kernelTCP is not set correctly, expect: %d, actual: %d", limit, *lm.Kernel)
45+
}
46+
if swappiness != *lm.Swappiness {
47+
return fmt.Errorf("memory swappiness is not set correctly, expect: %d, actual: %d", swappiness, *lm.Swappiness)
48+
}
49+
if true != *lm.DisableOOMKiller {
50+
return fmt.Errorf("memory oom is not set correctly, expect: %t, actual: %t", true, *lm.DisableOOMKiller)
51+
}
52+
return nil
53+
})
54+
if err != nil {
55+
util.Fatal(err)
56+
}
57+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/opencontainers/runtime-tools/cgroups"
7+
"github.com/opencontainers/runtime-tools/validation/util"
8+
)
9+
10+
func main() {
11+
var id, prio uint32 = 255, 10
12+
ifName := "lo"
13+
g := util.GetDefaultGenerator()
14+
g.SetLinuxCgroupsPath(cgroups.RelCgroupPath)
15+
g.SetLinuxResourcesNetworkClassID(id)
16+
err := util.RuntimeOutsideValidate(g, cgroups.RelCgroupPath, func(pid int, path string) error {
17+
cg, err := cgroups.FindCgroup()
18+
if err != nil {
19+
return err
20+
}
21+
lnd, err := cg.GetNetworkData(pid, path)
22+
if err != nil {
23+
return err
24+
}
25+
if *lnd.ClassID != id {
26+
return fmt.Errorf("network ID is not set correctly, expect: %d, actual: %d", id, lnd.ClassID)
27+
}
28+
found := false
29+
for _, lip := range lnd.Priorities {
30+
if lip.Name == ifName {
31+
found = true
32+
if lip.Priority != prio {
33+
return fmt.Errorf("network priority for %s is not set correctly, expect: %d, actual: %d", ifName, prio, lip.Priority)
34+
}
35+
}
36+
}
37+
if !found {
38+
return fmt.Errorf("network priority for %s is not set correctly", ifName)
39+
}
40+
41+
return nil
42+
})
43+
44+
if err != nil {
45+
util.Fatal(err)
46+
}
47+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/opencontainers/runtime-tools/cgroups"
7+
"github.com/opencontainers/runtime-tools/validation/util"
8+
)
9+
10+
func main() {
11+
var limit int64 = 1000
12+
g := util.GetDefaultGenerator()
13+
g.SetLinuxCgroupsPath(cgroups.RelCgroupPath)
14+
g.SetLinuxResourcesPidsLimit(limit)
15+
err := util.RuntimeOutsideValidate(g, cgroups.RelCgroupPath, func(pid int, path string) error {
16+
cg, err := cgroups.FindCgroup()
17+
if err != nil {
18+
return err
19+
}
20+
lpd, err := cg.GetPidsData(pid, path)
21+
if err != nil {
22+
return err
23+
}
24+
if lpd.Limit != limit {
25+
return fmt.Errorf("pids limit is not set correctly, expect: %d, actual: %d", limit, lpd.Limit)
26+
}
27+
return nil
28+
})
29+
30+
if err != nil {
31+
util.Fatal(err)
32+
}
33+
}

0 commit comments

Comments
 (0)