github.com/dmaizel/tests@v0.0.0-20210728163746-cae6a2d9cee8/integration/docker/ulimit_test.go (about)

     1  // Copyright (c) 2018 Intel Corporation
     2  //
     3  // SPDX-License-Identifier: Apache-2.0
     4  
     5  package docker
     6  
     7  import (
     8  	"fmt"
     9  	"runtime"
    10  	"strings"
    11  
    12  	. "github.com/onsi/ginkgo"
    13  	. "github.com/onsi/ginkgo/extensions/table"
    14  	. "github.com/onsi/gomega"
    15  )
    16  
    17  func withUlimit(ulimit string, soft, hard int, option string) TableEntry {
    18  	return Entry(fmt.Sprintf("With ulimit %s=%d:%d",
    19  		ulimit, soft, hard), ulimit, soft, hard, option)
    20  }
    21  
    22  var _ = Describe("ulimits", func() {
    23  	var (
    24  		args     []string
    25  		id       string
    26  		stdout   string
    27  		exitCode int
    28  	)
    29  
    30  	BeforeEach(func() {
    31  		id = randomDockerName()
    32  	})
    33  
    34  	AfterEach(func() {
    35  		Expect(ExistDockerContainer(id)).NotTo(BeTrue())
    36  	})
    37  
    38  	DescribeTable("check ulimits",
    39  		func(ulimit string, soft, hard int, option string) {
    40  			// ARM doesn't support data rlimit, Issue https://github.com/kata-containers/tests/issues/990
    41  			if ulimit == "data" && runtime.GOARCH == "arm64" {
    42  				Skip("Issue: https://github.com/kata-containers/tests/issues/990")
    43  			}
    44  
    45  			ulimitStr := fmt.Sprintf("%s=%d:%d", ulimit, soft, hard)
    46  
    47  			switch ulimit {
    48  			// these ulimits are in 1024-byte increments
    49  			case "fsize", "data", "stack", "core", "rss", "memlock":
    50  				ulimitStr = fmt.Sprintf("%s=%d:%d", ulimit, soft*1024, hard*1024)
    51  			}
    52  
    53  			args = []string{"--name", id, "--rm", "--ulimit", ulimitStr, CentosImage,
    54  				"bash", "-c", fmt.Sprintf("echo $(ulimit %s -S):$(ulimit %s -H)", option, option)}
    55  			stdout, _, exitCode = dockerRun(args...)
    56  			Expect(exitCode).To(Equal(0))
    57  			Expect(strings.Trim(stdout, "\n\t ")).To(Equal(fmt.Sprintf("%d:%d", soft, hard)))
    58  		},
    59  		withUlimit("cpu", 1, 2, "-t"),
    60  		withUlimit("fsize", 66, 82, "-f"),
    61  		withUlimit("data", 1024000, 2048000, "-d"),
    62  		withUlimit("stack", 45, 78, "-s"),
    63  		withUlimit("core", 48, 95, "-c"),
    64  		withUlimit("rss", 56, 83, "-m"),
    65  		withUlimit("nproc", 3, 5, "-u"),
    66  		withUlimit("nofile", 1024, 1024, "-n"),
    67  		withUlimit("memlock", 68, 77, "-l"),
    68  		withUlimit("locks", 1024, 2048, "-x"),
    69  		withUlimit("sigpending", 1024, 2048, "-i"),
    70  		withUlimit("msgqueue", 1024, 2048, "-q"),
    71  		withUlimit("nice", 50, 70, "-e"),
    72  		withUlimit("rtprio", 100, 120, "-r"),
    73  	)
    74  })