github.com/containers/podman/v4@v4.9.4/test/e2e/run_memory_test.go (about) 1 package integration 2 3 import ( 4 "fmt" 5 6 . "github.com/containers/podman/v4/test/utils" 7 . "github.com/onsi/ginkgo/v2" 8 . "github.com/onsi/gomega" 9 ) 10 11 var _ = Describe("Podman run memory", func() { 12 13 BeforeEach(func() { 14 SkipIfRootlessCgroupsV1("Setting Memory not supported on cgroupv1 for rootless users") 15 }) 16 17 It("podman run memory test", func() { 18 var session *PodmanSessionIntegration 19 20 if CGROUPSV2 { 21 session = podmanTest.Podman([]string{"run", "--memory=40m", "--net=none", ALPINE, "sh", "-c", "cat /sys/fs/cgroup/$(sed -e 's|0::||' < /proc/self/cgroup)/memory.max"}) 22 } else { 23 session = podmanTest.Podman([]string{"run", "--memory=40m", ALPINE, "cat", "/sys/fs/cgroup/memory/memory.limit_in_bytes"}) 24 } 25 session.WaitWithDefaultTimeout() 26 Expect(session).Should(ExitCleanly()) 27 Expect(session.OutputToString()).To(Equal("41943040")) 28 }) 29 30 It("podman run memory-reservation test", func() { 31 var session *PodmanSessionIntegration 32 33 if CGROUPSV2 { 34 session = podmanTest.Podman([]string{"run", "--memory-reservation=40m", "--net=none", ALPINE, "sh", "-c", "cat /sys/fs/cgroup/$(sed -e 's|0::||' < /proc/self/cgroup)/memory.low"}) 35 } else { 36 session = podmanTest.Podman([]string{"run", "--memory-reservation=40m", ALPINE, "cat", "/sys/fs/cgroup/memory/memory.soft_limit_in_bytes"}) 37 } 38 39 session.WaitWithDefaultTimeout() 40 Expect(session).Should(ExitCleanly()) 41 Expect(session.OutputToString()).To(Equal("41943040")) 42 }) 43 44 It("podman run memory-swap test", func() { 45 var ( 46 session *PodmanSessionIntegration 47 expect string 48 ) 49 50 if CGROUPSV2 { 51 session = podmanTest.Podman([]string{"run", "--memory=20m", "--memory-swap=30M", "--net=none", ALPINE, "sh", "-c", "cat /sys/fs/cgroup/$(sed -e 's|0::||' < /proc/self/cgroup)/memory.swap.max"}) 52 expect = "10485760" 53 } else { 54 session = podmanTest.Podman([]string{"run", "--memory=20m", "--memory-swap=30M", ALPINE, "cat", "/sys/fs/cgroup/memory/memory.memsw.limit_in_bytes"}) 55 expect = "31457280" 56 } 57 session.WaitWithDefaultTimeout() 58 Expect(session).Should(ExitCleanly()) 59 Expect(session.OutputToString()).To(Equal(expect)) 60 }) 61 62 for _, limit := range []string{"0", "15", "100"} { 63 limit := limit // Keep this value in a proper scope 64 testName := fmt.Sprintf("podman run memory-swappiness test(%s)", limit) 65 It(testName, func() { 66 SkipIfCgroupV2("memory-swappiness not supported on cgroupV2") 67 session := podmanTest.Podman([]string{"run", fmt.Sprintf("--memory-swappiness=%s", limit), ALPINE, "cat", "/sys/fs/cgroup/memory/memory.swappiness"}) 68 session.WaitWithDefaultTimeout() 69 Expect(session).Should(ExitCleanly()) 70 Expect(session.OutputToString()).To(Equal(limit)) 71 }) 72 } 73 })