Skip to content

Commit 2b27941

Browse files
yonghong-songborkmann
authored andcommitted
tools/bpf: adjust rlimit RLIMIT_MEMLOCK for test_verifier_log
The default rlimit RLIMIT_MEMLOCK is 64KB. In certain cases, e.g. in a test machine mimicking our production system, this test may fail due to unable to charge the required memory for prog load: # ./test_verifier_log Test log_level 0... ERROR: Program load returned: ret:-1/errno:1, expected ret:-1/errno:22 Changing the default rlimit RLIMIT_MEMLOCK to unlimited makes the test always pass. Signed-off-by: Yonghong Song <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
1 parent 23721a7 commit 2b27941

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

tools/testing/selftests/bpf/test_verifier_log.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include <stdio.h>
44
#include <string.h>
55
#include <unistd.h>
6+
#include <sys/time.h>
7+
#include <sys/resource.h>
68

79
#include <linux/bpf.h>
810
#include <linux/filter.h>
@@ -131,11 +133,16 @@ static void test_log_bad(char *log, size_t log_len, int log_level)
131133

132134
int main(int argc, char **argv)
133135
{
136+
struct rlimit limit = { RLIM_INFINITY, RLIM_INFINITY };
134137
char full_log[LOG_SIZE];
135138
char log[LOG_SIZE];
136139
size_t want_len;
137140
int i;
138141

142+
/* allow unlimited locked memory to have more consistent error code */
143+
if (setrlimit(RLIMIT_MEMLOCK, &limit) < 0)
144+
perror("Unable to lift memlock rlimit");
145+
139146
memset(log, 1, LOG_SIZE);
140147

141148
/* Test incorrect attr */

0 commit comments

Comments
 (0)