github.com/containers/podman/v2@v2.2.2-0.20210501105131-c1e07d070c4c/test/e2e/run_memory_test.go (about) 1 package integration 2 3 import ( 4 "os" 5 6 . "github.com/containers/podman/v2/test/utils" 7 . "github.com/onsi/ginkgo" 8 . "github.com/onsi/gomega" 9 ) 10 11 var _ = Describe("Podman run memory", func() { 12 var ( 13 tempdir string 14 err error 15 podmanTest *PodmanTestIntegration 16 ) 17 18 BeforeEach(func() { 19 SkipIfRootlessCgroupsV1("Setting Memory not supported on cgroupv1 for rootless users") 20 21 tempdir, err = CreateTempDirInTempDir() 22 if err != nil { 23 os.Exit(1) 24 } 25 podmanTest = PodmanTestCreate(tempdir) 26 podmanTest.Setup() 27 podmanTest.SeedImages() 28 }) 29 30 AfterEach(func() { 31 podmanTest.Cleanup() 32 f := CurrentGinkgoTestDescription() 33 processTestResult(f) 34 35 }) 36 37 It("podman run memory test", func() { 38 var session *PodmanSessionIntegration 39 40 if CGROUPSV2 { 41 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"}) 42 } else { 43 session = podmanTest.Podman([]string{"run", "--memory=40m", ALPINE, "cat", "/sys/fs/cgroup/memory/memory.limit_in_bytes"}) 44 } 45 session.WaitWithDefaultTimeout() 46 Expect(session.ExitCode()).To(Equal(0)) 47 Expect(session.OutputToString()).To(Equal("41943040")) 48 }) 49 50 It("podman run memory-reservation test", func() { 51 if podmanTest.Host.Distribution == "ubuntu" { 52 Skip("Unable to perform test on Ubuntu distributions due to memory management") 53 } 54 55 var session *PodmanSessionIntegration 56 57 if CGROUPSV2 { 58 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"}) 59 } else { 60 session = podmanTest.Podman([]string{"run", "--memory-reservation=40m", ALPINE, "cat", "/sys/fs/cgroup/memory/memory.soft_limit_in_bytes"}) 61 } 62 63 session.WaitWithDefaultTimeout() 64 Expect(session.ExitCode()).To(Equal(0)) 65 Expect(session.OutputToString()).To(Equal("41943040")) 66 }) 67 68 It("podman run memory-swappiness test", func() { 69 SkipIfCgroupV2("memory-swappiness not supported on cgroupV2") 70 session := podmanTest.Podman([]string{"run", "--memory-swappiness=15", ALPINE, "cat", "/sys/fs/cgroup/memory/memory.swappiness"}) 71 session.WaitWithDefaultTimeout() 72 Expect(session.ExitCode()).To(Equal(0)) 73 Expect(session.OutputToString()).To(Equal("15")) 74 }) 75 76 It("podman run kernel-memory test", func() { 77 if podmanTest.Host.Distribution == "ubuntu" { 78 Skip("Unable to perform test on Ubuntu distributions due to memory management") 79 } 80 81 var session *PodmanSessionIntegration 82 83 if CGROUPSV2 { 84 session = podmanTest.Podman([]string{"run", "--net=none", "--memory-reservation=40m", ALPINE, "sh", "-c", "cat /sys/fs/cgroup/$(sed -e 's|0::||' < /proc/self/cgroup)/memory.low"}) 85 } else { 86 session = podmanTest.Podman([]string{"run", "--memory-reservation=40m", ALPINE, "cat", "/sys/fs/cgroup/memory/memory.soft_limit_in_bytes"}) 87 } 88 89 session.WaitWithDefaultTimeout() 90 Expect(session.ExitCode()).To(Equal(0)) 91 Expect(session.OutputToString()).To(Equal("41943040")) 92 }) 93 })