Skip to content

Commit a78d0db

Browse files
author
Alexei Starovoitov
committed
selftests/bpf: add loop test 4
Add a test that returns a 'random' number between [0, 2^20) If state pruning is not working correctly for loop body the number of processed insns will be 2^20 * num_of_insns_in_loop_body and the program will be rejected. Signed-off-by: Alexei Starovoitov <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Acked-by: Yonghong Song <[email protected]>
1 parent 02bc2b6 commit a78d0db

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

tools/testing/selftests/bpf/prog_tests/bpf_verif_scale.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ void test_bpf_verif_scale(void)
7171

7272
{ "loop1.o", BPF_PROG_TYPE_RAW_TRACEPOINT },
7373
{ "loop2.o", BPF_PROG_TYPE_RAW_TRACEPOINT },
74+
{ "loop4.o", BPF_PROG_TYPE_SCHED_CLS },
7475

7576
/* partial unroll. 19k insn in a loop.
7677
* Total program size 20.8k insn.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
// Copyright (c) 2019 Facebook
3+
#include <linux/bpf.h>
4+
#include "bpf_helpers.h"
5+
6+
char _license[] SEC("license") = "GPL";
7+
8+
SEC("socket")
9+
int combinations(volatile struct __sk_buff* skb)
10+
{
11+
int ret = 0, i;
12+
13+
#pragma nounroll
14+
for (i = 0; i < 20; i++)
15+
if (skb->len)
16+
ret |= 1 << i;
17+
return ret;
18+
}

0 commit comments

Comments
 (0)