mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-10 21:53:57 +08:00
tests/int: build TestPids pipelines programmatically
TestPids used long hand-written /bin/true pipelines for the 4-, 32- and
64-command cases. This made the test easy to typo and hard to review, as
seen by the earlier "bin/true" entries.
Build the shell pipelines instead, preserving the existing test coverage
while making the command counts explicit.
Signed-off-by: Ricardo Branco <rbranco@suse.de>
(cherry picked from commit 3acb097f93)
Signed-off-by: Ricardo Branco <rbranco@suse.de>
This commit is contained in:
@@ -530,6 +530,10 @@ func TestPidsSystemd(t *testing.T) {
|
||||
|
||||
func mkPtr[T any](v T) *T { return &v }
|
||||
|
||||
func truePipeline(n int) string {
|
||||
return strings.Join(slices.Repeat([]string{"/bin/true"}, n), " | ")
|
||||
}
|
||||
|
||||
func testPids(t *testing.T, systemd bool) {
|
||||
if testing.Short() {
|
||||
return
|
||||
@@ -539,29 +543,17 @@ func testPids(t *testing.T, systemd bool) {
|
||||
config.Cgroups.Resources.PidsLimit = mkPtr[int64](-1)
|
||||
|
||||
// Running multiple processes, expecting it to succeed with no pids limit.
|
||||
runContainerOk(t, config, "/bin/sh", "-c", "/bin/true | /bin/true | /bin/true | /bin/true")
|
||||
runContainerOk(t, config, "/bin/sh", "-c", truePipeline(4))
|
||||
|
||||
// Enforce a permissive limit. This needs to be fairly hand-wavey due to the
|
||||
// issues with running Go binaries with pids restrictions (see below).
|
||||
config.Cgroups.Resources.PidsLimit = mkPtr[int64](64)
|
||||
runContainerOk(t, config, "/bin/sh", "-c", `
|
||||
/bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true |
|
||||
/bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true |
|
||||
/bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true |
|
||||
/bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true`)
|
||||
runContainerOk(t, config, "/bin/sh", "-c", truePipeline(32))
|
||||
|
||||
// Enforce a restrictive limit. 64 * /bin/true + 1 * shell should cause
|
||||
// this to fail reliably.
|
||||
config.Cgroups.Resources.PidsLimit = mkPtr[int64](64)
|
||||
out, _, err := runContainer(t, config, "/bin/sh", "-c", `
|
||||
/bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true |
|
||||
/bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true |
|
||||
/bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true |
|
||||
/bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true |
|
||||
/bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true |
|
||||
/bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true |
|
||||
/bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true |
|
||||
/bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true`)
|
||||
out, _, err := runContainer(t, config, "/bin/sh", "-c", truePipeline(64))
|
||||
if err != nil && !strings.Contains(out.String(), "sh: can't fork") {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user