Skip to content

Commit

Permalink
add ulimits.bats
Browse files Browse the repository at this point in the history
issues:
#4195
#4265 (comment)

Signed-off-by: lifubang <[email protected]>
  • Loading branch information
lifubang committed May 3, 2024
1 parent 7a017af commit ee30e0d
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ task:
systemctl restart sshd
host_info_script: |
uname -a
ulimit -a
ulimit -aH
# -----
/usr/local/go/bin/go version
# -----
Expand Down
85 changes: 85 additions & 0 deletions tests/integration/rlimits.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env bats

load helpers

function setup() {
[ $EUID -eq 0 ] && prlimit --nofile=1024:65536 -p $$
setup_busybox
}

function teardown() {
teardown_bundle
}

@test "runc run with RLIMIT_NOFILE(The same as system's hard value)" {
# https://github.com/opencontainers/runc/pull/4265#discussion_r1588599809
hard=$(ulimit -n -H)
update_config ".process.rlimits = [{\"type\": \"RLIMIT_NOFILE\", \"hard\": ${hard}, \"soft\": ${hard}}]"
update_config '.process.args = ["/bin/sh", "-c", "ulimit -n"]'

runc run test_ulimit
[ "$status" -eq 0 ]
[[ "${output}" == "${hard}" ]]
}

@test "runc run with RLIMIT_NOFILE(Bigger than system's hard value)" {
# https://github.com/opencontainers/runc/pull/4265#discussion_r1588599809
hard=$(ulimit -n -H)
val=$(($hard+1))
update_config ".process.rlimits = [{\"type\": \"RLIMIT_NOFILE\", \"hard\": ${val}, \"soft\": ${val}}]"
update_config '.process.args = ["/bin/sh", "-c", "ulimit -n"]'

runc run test_ulimit
[ "$status" -eq 0 ]
[[ "${output}" == "${val}" ]]
}

@test "runc run with RLIMIT_NOFILE(Smaller than system's hard value)" {
hard=$(ulimit -n -H)
val=$(($hard-1))
update_config ".process.rlimits = [{\"type\": \"RLIMIT_NOFILE\", \"hard\": ${val}, \"soft\": ${val}}]"
update_config '.process.args = ["/bin/sh", "-c", "ulimit -n"]'

runc run test_ulimit
[ "$status" -eq 0 ]
[[ "${output}" == "${val}" ]]
}

@test "runc exec with RLIMIT_NOFILE(The same as system's hard value)" {
hard=$(ulimit -n -H)
update_config ".process.rlimits = [{\"type\": \"RLIMIT_NOFILE\", \"hard\": ${hard}, \"soft\": ${hard}}]"

runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ]

runc exec test_busybox /bin/sh -c "ulimit -n"
[ "$status" -eq 0 ]
[[ "${output}" == "${hard}" ]]
}

@test "runc exec with RLIMIT_NOFILE(Bigger than system's hard value)" {
hard=$(ulimit -n -H)
val=$(($hard+1))
update_config ".process.rlimits = [{\"type\": \"RLIMIT_NOFILE\", \"hard\": ${val}, \"soft\": ${val}}]"

runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ]

runc exec test_busybox /bin/sh -c "ulimit -n"
[ "$status" -eq 0 ]
[[ "${output}" == "${val}" ]]
}

@test "runc exec with RLIMIT_NOFILE(Smaller than system's hard value)" {
hard=$(ulimit -n -H)
val=$(($hard-1))
update_config ".process.rlimits = [{\"type\": \"RLIMIT_NOFILE\", \"hard\": ${val}, \"soft\": ${val}}]"

runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ]

# issue: https://github.com/opencontainers/runc/issues/4195
runc exec test_busybox /bin/sh -c "ulimit -n"
[ "$status" -eq 0 ]
[[ "${output}" == "${val}" ]]
}

0 comments on commit ee30e0d

Please sign in to comment.