Skip to content

Commit

Permalink
Add btests for fd limit-capping behavior at Zeek startup.
Browse files Browse the repository at this point in the history
  • Loading branch information
ckreibich committed Nov 21, 2024
1 parent 5a2b686 commit ce5bb43
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 0 deletions.
3 changes: 3 additions & 0 deletions testing/btest/Baseline/core.fd-limits-2/output
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
100
100
4 changes: 4 additions & 0 deletions testing/btest/Baseline/core.fd-limits-3/output
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
warning in <...>/init-bare.zeek, line 1: reduced open file descriptor limits (soft/hard 1500000/2000000 -> 1048576/1048576)
1048576
1048576
3 changes: 3 additions & 0 deletions testing/btest/Baseline/core.fd-limits-4/output
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
1500000
2000000
3 changes: 3 additions & 0 deletions testing/btest/Baseline/core.fd-limits-5/output
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
1500000
2000000
3 changes: 3 additions & 0 deletions testing/btest/Baseline/core.fd-limits/output
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
100
150
77 changes: 77 additions & 0 deletions testing/btest/core/fd-limits.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Check the file descriptor limit behavior Zeek applies at startup.
# Zeek's built-in default limit is 1024 * 1024 = 1048576 open fds.

# @TEST-REQUIRES: ulimit -n -S >limit.soft
# @TEST-REQUIRES: ulimit -n -H >limit.hard
# @TEST-EXEC: unset ZEEK_NOFILE_MAX; LIM_SOFT=$(cat limit.soft) LIM_HARD=$(cat limit.hard) bash %INPUT
# @TEST-EXEC: if [ ! -f skip ]; then TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff output; fi

# @TEST-START-FILE limits.zeek
event zeek_init()
{
# Report resulting limits to stderr:
system("ulimit -n -S");
system("ulimit -n -H");
}
# @TEST-END-FILE

# @TEST-START-FILE limits.sh
setcaps() {
local soft=$1
local hard=$2

ulimit -S -n $soft || {
echo "Skipping $TEST_NAME, could not set soft fd limit $soft."
touch skip
exit 0
}
ulimit -H -n $hard || {
echo "Skipping $TEST_NAME, could not set hard fd limit $hard."
touch skip
exit 0
}
}
# @TEST-END-FILE

# Apply low limits and no ZEEK_NOFILE_MAX variable.
# The limits should stay unchanged with no warning message.

. ./limits.sh
setcaps 100 150
zeek -b limits.zeek 2>output

# @TEST-START-NEXT
# Establish a low limit via ZEEK_NOFILE_MAX.
# Zeek should apply these values, without a warning message.

# Verify that one can actually set these values, then revert to defaults.
setcaps 100 100
setcaps $LIM_SOFT $LIM_HARD

export ZEEK_NOFILE_MAX=100
zeek -b limits.zeek 2>output

# @TEST-START-NEXT
# With high limits and no ZEEK_NOFILE_MAX Zeek should cap and produce a
# warning message.

. ./limits.sh
setcaps 1500000 2000000
zeek -b limits.zeek 2>output

# @TEST-START-NEXT
# With high limits and the capping mechanism disabled, the values should remain intact.

. ./limits.sh
setcaps 1500000 2000000
export ZEEK_NOFILE_MAX=
zeek -b limits.zeek 2>output

# @TEST-START-NEXT
# With high limits and the capping mechanism disabled, the values should remain intact.

. ./limits.sh
setcaps 1500000 2000000
export ZEEK_NOFILE_MAX=0
zeek -b limits.zeek 2>output

0 comments on commit ce5bb43

Please sign in to comment.