Skip to content

Commit b712995

Browse files
author
Ma Shimiao
committed
add cgroup cpus test for runtime
Signed-off-by: Ma Shimiao <mashimiao.fnst@cn.fujitsu.com>
1 parent f1e02ff commit b712995

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

validation/linux_cgroups_cpus.go

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("/test")
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, func(path string) error {
23+
cg, err := cgroups.FindCgroup()
24+
if err != nil {
25+
return err
26+
}
27+
lcd, err := cg.GetCPUData(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+
}

0 commit comments

Comments
 (0)