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>
This commit is contained in:
Ricardo Branco
2026-05-24 11:12:23 +02:00
parent d0aeb9e3e2
commit 3acb097f93

View File

@@ -535,6 +535,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
@@ -544,29 +548,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)
}