github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/test/e2e/run_cpu_test.go (about) 1 package integration 2 3 import ( 4 "io/ioutil" 5 "os" 6 7 . "github.com/hanks177/podman/v4/test/utils" 8 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/gomega" 10 . "github.com/onsi/gomega/gexec" 11 ) 12 13 var _ = Describe("Podman run cpu", func() { 14 var ( 15 tempdir string 16 err error 17 podmanTest *PodmanTestIntegration 18 ) 19 20 BeforeEach(func() { 21 SkipIfRootlessCgroupsV1("Setting CPU not supported on cgroupv1 for rootless users") 22 23 tempdir, err = CreateTempDirInTempDir() 24 if err != nil { 25 os.Exit(1) 26 } 27 28 if CGROUPSV2 { 29 if err := ioutil.WriteFile("/sys/fs/cgroup/cgroup.subtree_control", []byte("+cpuset"), 0644); err != nil { 30 Skip("cpuset controller not available on the current kernel") 31 } 32 } 33 34 podmanTest = PodmanTestCreate(tempdir) 35 podmanTest.Setup() 36 }) 37 38 AfterEach(func() { 39 podmanTest.Cleanup() 40 f := CurrentGinkgoTestDescription() 41 processTestResult(f) 42 43 }) 44 45 It("podman run cpu-period", func() { 46 var result *PodmanSessionIntegration 47 if CGROUPSV2 { 48 result = podmanTest.Podman([]string{"run", "--rm", "--cpu-period=5000", ALPINE, "sh", "-c", "cat /sys/fs/cgroup/$(sed -e 's|0::||' < /proc/self/cgroup)/cpu.max"}) 49 } else { 50 result = podmanTest.Podman([]string{"run", "--rm", "--cpu-period=5000", ALPINE, "cat", "/sys/fs/cgroup/cpu/cpu.cfs_period_us"}) 51 } 52 result.WaitWithDefaultTimeout() 53 Expect(result).Should(Exit(0)) 54 Expect(result.OutputToString()).To(ContainSubstring("5000")) 55 }) 56 57 It("podman run cpu-quota", func() { 58 var result *PodmanSessionIntegration 59 60 if CGROUPSV2 { 61 result = podmanTest.Podman([]string{"run", "--rm", "--cpu-quota=5000", ALPINE, "sh", "-c", "cat /sys/fs/cgroup/$(sed -e 's|0::||' < /proc/self/cgroup)/cpu.max"}) 62 } else { 63 result = podmanTest.Podman([]string{"run", "--rm", "--cpu-quota=5000", ALPINE, "cat", "/sys/fs/cgroup/cpu/cpu.cfs_quota_us"}) 64 } 65 result.WaitWithDefaultTimeout() 66 Expect(result).Should(Exit(0)) 67 Expect(result.OutputToString()).To(ContainSubstring("5000")) 68 }) 69 70 It("podman run cpus", func() { 71 if CGROUPSV2 { 72 result := podmanTest.Podman([]string{"run", "--rm", "--cpu-quota=5000", ALPINE, "sh", "-c", "cat /sys/fs/cgroup/$(sed -e 's|0::||' < /proc/self/cgroup)/cpu.max"}) 73 result.WaitWithDefaultTimeout() 74 Expect(result).Should(Exit(0)) 75 Expect(result.OutputToString()).To(Equal("5000 100000")) 76 } else { 77 result := podmanTest.Podman([]string{"run", "--rm", "--cpus=0.5", ALPINE, "cat", "/sys/fs/cgroup/cpu/cpu.cfs_period_us"}) 78 result.WaitWithDefaultTimeout() 79 Expect(result).Should(Exit(0)) 80 Expect(result.OutputToString()).To(Equal("100000")) 81 82 result = podmanTest.Podman([]string{"run", "--rm", "--cpus=0.5", ALPINE, "cat", "/sys/fs/cgroup/cpu/cpu.cfs_quota_us"}) 83 result.WaitWithDefaultTimeout() 84 Expect(result).Should(Exit(0)) 85 Expect(result.OutputToString()).To(Equal("50000")) 86 } 87 }) 88 89 It("podman run cpu-shares", func() { 90 if CGROUPSV2 { 91 // [2-262144] is mapped to [1-10000] 92 result := podmanTest.Podman([]string{"run", "--rm", "--cpu-shares=262144", ALPINE, "sh", "-c", "cat /sys/fs/cgroup/$(sed -e 's|0::||' < /proc/self/cgroup)/cpu.weight"}) 93 result.WaitWithDefaultTimeout() 94 Expect(result).Should(Exit(0)) 95 Expect(result.OutputToString()).To(Equal("10000")) 96 } else { 97 result := podmanTest.Podman([]string{"run", "--rm", "--cpu-shares=2", ALPINE, "cat", "/sys/fs/cgroup/cpu/cpu.shares"}) 98 result.WaitWithDefaultTimeout() 99 Expect(result).Should(Exit(0)) 100 Expect(result.OutputToString()).To(Equal("2")) 101 } 102 }) 103 104 It("podman run cpuset-cpus", func() { 105 var result *PodmanSessionIntegration 106 107 if CGROUPSV2 { 108 result = podmanTest.Podman([]string{"run", "--rm", "--cpuset-cpus=0", ALPINE, "sh", "-c", "cat /sys/fs/cgroup/$(sed -e 's|0::||' < /proc/self/cgroup)/cpuset.cpus.effective"}) 109 } else { 110 result = podmanTest.Podman([]string{"run", "--rm", "--cpuset-cpus=0", ALPINE, "cat", "/sys/fs/cgroup/cpuset/cpuset.cpus"}) 111 } 112 result.WaitWithDefaultTimeout() 113 Expect(result).Should(Exit(0)) 114 Expect(result.OutputToString()).To(Equal("0")) 115 }) 116 117 It("podman run cpuset-mems", func() { 118 var result *PodmanSessionIntegration 119 120 if CGROUPSV2 { 121 result = podmanTest.Podman([]string{"run", "--rm", "--cpuset-mems=0", ALPINE, "sh", "-c", "cat /sys/fs/cgroup/$(sed -e 's|0::||' < /proc/self/cgroup)/cpuset.mems.effective"}) 122 } else { 123 result = podmanTest.Podman([]string{"run", "--rm", "--cpuset-mems=0", ALPINE, "cat", "/sys/fs/cgroup/cpuset/cpuset.mems"}) 124 } 125 result.WaitWithDefaultTimeout() 126 Expect(result).Should(Exit(0)) 127 Expect(result.OutputToString()).To(Equal("0")) 128 }) 129 130 It("podman run cpus and cpu-period", func() { 131 result := podmanTest.Podman([]string{"run", "--rm", "--cpu-period=5000", "--cpus=0.5", ALPINE, "ls"}) 132 result.WaitWithDefaultTimeout() 133 Expect(result).To(ExitWithError()) 134 }) 135 136 It("podman run cpus and cpu-quota", func() { 137 result := podmanTest.Podman([]string{"run", "--rm", "--cpu-quota=5000", "--cpus=0.5", ALPINE, "ls"}) 138 result.WaitWithDefaultTimeout() 139 Expect(result).To(ExitWithError()) 140 }) 141 })