|
| 1 | +#!/usr/bin/env bats |
| 2 | + |
| 3 | +load helpers |
| 4 | + |
| 5 | +function setup() { |
| 6 | + # Do not change the Cur value to be equal to the Max value |
| 7 | + # Because in some environments, the soft and hard nofile limit have the same value. |
| 8 | + [ $EUID -eq 0 ] && prlimit --nofile=1024:65536 -p $$ |
| 9 | + setup_busybox |
| 10 | +} |
| 11 | + |
| 12 | +function teardown() { |
| 13 | + teardown_bundle |
| 14 | +} |
| 15 | + |
| 16 | +@test "runc run with RLIMIT_NOFILE(The same as system's hard value)" { |
| 17 | + # https://github.com/opencontainers/runc/pull/4265#discussion_r1588599809 |
| 18 | + hard=$(ulimit -n -H) |
| 19 | + soft="$hard" |
| 20 | + update_config ".process.rlimits = [{\"type\": \"RLIMIT_NOFILE\", \"hard\": ${hard}, \"soft\": ${soft}}]" |
| 21 | + update_config '.process.args = ["/bin/sh", "-c", "ulimit -n"]' |
| 22 | + |
| 23 | + runc run test_ulimit |
| 24 | + [ "$status" -eq 0 ] |
| 25 | + [[ "${output}" == "${soft}" ]] |
| 26 | +} |
| 27 | + |
| 28 | +@test "runc run with RLIMIT_NOFILE(Bigger than system's hard value)" { |
| 29 | + requires root |
| 30 | + # https://github.com/opencontainers/runc/pull/4265#discussion_r1588599809 |
| 31 | + hard=$(ulimit -n -H) |
| 32 | + soft=$((hard + 1)) |
| 33 | + update_config ".process.rlimits = [{\"type\": \"RLIMIT_NOFILE\", \"hard\": ${soft}, \"soft\": ${soft}}]" |
| 34 | + update_config '.process.args = ["/bin/sh", "-c", "ulimit -n"]' |
| 35 | + |
| 36 | + runc run test_ulimit |
| 37 | + [ "$status" -eq 0 ] |
| 38 | + [[ "${output}" == "${soft}" ]] |
| 39 | +} |
| 40 | + |
| 41 | +@test "runc run with RLIMIT_NOFILE(Smaller than system's hard value)" { |
| 42 | + hard=$(ulimit -n -H) |
| 43 | + soft=$((hard - 1)) |
| 44 | + update_config ".process.rlimits = [{\"type\": \"RLIMIT_NOFILE\", \"hard\": ${soft}, \"soft\": ${soft}}]" |
| 45 | + update_config '.process.args = ["/bin/sh", "-c", "ulimit -n"]' |
| 46 | + |
| 47 | + runc run test_ulimit |
| 48 | + [ "$status" -eq 0 ] |
| 49 | + [[ "${output}" == "${soft}" ]] |
| 50 | +} |
| 51 | + |
| 52 | +@test "runc exec with RLIMIT_NOFILE(The same as system's hard value)" { |
| 53 | + hard=$(ulimit -n -H) |
| 54 | + soft="$hard" |
| 55 | + update_config ".process.rlimits = [{\"type\": \"RLIMIT_NOFILE\", \"hard\": ${hard}, \"soft\": ${soft}}]" |
| 56 | + |
| 57 | + runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox |
| 58 | + [ "$status" -eq 0 ] |
| 59 | + |
| 60 | + runc exec test_busybox /bin/sh -c "ulimit -n" |
| 61 | + [ "$status" -eq 0 ] |
| 62 | + [[ "${output}" == "${soft}" ]] |
| 63 | +} |
| 64 | + |
| 65 | +@test "runc exec with RLIMIT_NOFILE(Bigger than system's hard value)" { |
| 66 | + requires root |
| 67 | + hard=$(ulimit -n -H) |
| 68 | + soft=$((hard + 1)) |
| 69 | + update_config ".process.rlimits = [{\"type\": \"RLIMIT_NOFILE\", \"hard\": ${soft}, \"soft\": ${soft}}]" |
| 70 | + |
| 71 | + runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox |
| 72 | + [ "$status" -eq 0 ] |
| 73 | + |
| 74 | + runc exec test_busybox /bin/sh -c "ulimit -n" |
| 75 | + [ "$status" -eq 0 ] |
| 76 | + [[ "${output}" == "${soft}" ]] |
| 77 | +} |
| 78 | + |
| 79 | +@test "runc exec with RLIMIT_NOFILE(Smaller than system's hard value)" { |
| 80 | + hard=$(ulimit -n -H) |
| 81 | + soft=$((hard - 1)) |
| 82 | + update_config ".process.rlimits = [{\"type\": \"RLIMIT_NOFILE\", \"hard\": ${soft}, \"soft\": ${soft}}]" |
| 83 | + |
| 84 | + runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox |
| 85 | + [ "$status" -eq 0 ] |
| 86 | + |
| 87 | + # issue: https://github.com/opencontainers/runc/issues/4195 |
| 88 | + runc exec test_busybox /bin/sh -c "ulimit -n" |
| 89 | + [ "$status" -eq 0 ] |
| 90 | + [[ "${output}" == "${soft}" ]] |
| 91 | +} |
0 commit comments