-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issues: #4195 #4265 (comment) Signed-off-by: lifubang <[email protected]>
- Loading branch information
Showing
2 changed files
with
95 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#!/usr/bin/env bats | ||
|
||
load helpers | ||
|
||
function setup() { | ||
# Do not change the Cur value to be equal to the Max value | ||
# Because in some environments, the soft and hard nofile limit have the same value. | ||
[ $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) | ||
soft="$hard" | ||
update_config ".process.rlimits = [{\"type\": \"RLIMIT_NOFILE\", \"hard\": ${hard}, \"soft\": ${soft}}]" | ||
update_config '.process.args = ["/bin/sh", "-c", "ulimit -n"]' | ||
|
||
runc run test_ulimit | ||
[ "$status" -eq 0 ] | ||
[[ "${output}" == "${soft}" ]] | ||
} | ||
|
||
@test "runc run with RLIMIT_NOFILE(Bigger than system's hard value)" { | ||
requires root | ||
# https://github.com/opencontainers/runc/pull/4265#discussion_r1588599809 | ||
hard=$(ulimit -n -H) | ||
soft=$((hard + 1)) | ||
update_config ".process.rlimits = [{\"type\": \"RLIMIT_NOFILE\", \"hard\": ${soft}, \"soft\": ${soft}}]" | ||
update_config '.process.args = ["/bin/sh", "-c", "ulimit -n"]' | ||
|
||
runc run test_ulimit | ||
[ "$status" -eq 0 ] | ||
[[ "${output}" == "${soft}" ]] | ||
} | ||
|
||
@test "runc run with RLIMIT_NOFILE(Smaller than system's hard value)" { | ||
hard=$(ulimit -n -H) | ||
soft=$((hard - 1)) | ||
update_config ".process.rlimits = [{\"type\": \"RLIMIT_NOFILE\", \"hard\": ${soft}, \"soft\": ${soft}}]" | ||
update_config '.process.args = ["/bin/sh", "-c", "ulimit -n"]' | ||
|
||
runc run test_ulimit | ||
[ "$status" -eq 0 ] | ||
[[ "${output}" == "${soft}" ]] | ||
} | ||
|
||
@test "runc exec with RLIMIT_NOFILE(The same as system's hard value)" { | ||
hard=$(ulimit -n -H) | ||
soft="$hard" | ||
update_config ".process.rlimits = [{\"type\": \"RLIMIT_NOFILE\", \"hard\": ${hard}, \"soft\": ${soft}}]" | ||
|
||
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}" == "${soft}" ]] | ||
} | ||
|
||
@test "runc exec with RLIMIT_NOFILE(Bigger than system's hard value)" { | ||
requires root | ||
hard=$(ulimit -n -H) | ||
soft=$((hard + 1)) | ||
update_config ".process.rlimits = [{\"type\": \"RLIMIT_NOFILE\", \"hard\": ${soft}, \"soft\": ${soft}}]" | ||
|
||
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}" == "${soft}" ]] | ||
} | ||
|
||
@test "runc exec with RLIMIT_NOFILE(Smaller than system's hard value)" { | ||
hard=$(ulimit -n -H) | ||
soft=$((hard - 1)) | ||
update_config ".process.rlimits = [{\"type\": \"RLIMIT_NOFILE\", \"hard\": ${soft}, \"soft\": ${soft}}]" | ||
|
||
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}" == "${soft}" ]] | ||
} |