Loading...
1// SPDX-License-Identifier: GPL-2.0
2#include <test_progs.h>
3#include <network_helpers.h>
4
5static void sigalrm_handler(int s) {}
6static struct sigaction sigalrm_action = {
7 .sa_handler = sigalrm_handler,
8};
9
10static void test_signal_pending_by_type(enum bpf_prog_type prog_type)
11{
12 struct bpf_insn prog[4096];
13 struct itimerval timeo = {
14 .it_value.tv_usec = 100000, /* 100ms */
15 };
16 int prog_fd;
17 int err;
18 int i;
19 LIBBPF_OPTS(bpf_test_run_opts, topts,
20 .data_in = &pkt_v4,
21 .data_size_in = sizeof(pkt_v4),
22 .repeat = 0xffffffff,
23 );
24
25 for (i = 0; i < ARRAY_SIZE(prog); i++)
26 prog[i] = BPF_ALU64_IMM(BPF_MOV, BPF_REG_0, 0);
27 prog[ARRAY_SIZE(prog) - 1] = BPF_EXIT_INSN();
28
29 prog_fd = bpf_test_load_program(prog_type, prog, ARRAY_SIZE(prog),
30 "GPL", 0, NULL, 0);
31 ASSERT_GE(prog_fd, 0, "test-run load");
32
33 err = sigaction(SIGALRM, &sigalrm_action, NULL);
34 ASSERT_OK(err, "test-run-signal-sigaction");
35
36 err = setitimer(ITIMER_REAL, &timeo, NULL);
37 ASSERT_OK(err, "test-run-signal-timer");
38
39 err = bpf_prog_test_run_opts(prog_fd, &topts);
40 ASSERT_LE(topts.duration, 500000000 /* 500ms */,
41 "test-run-signal-duration");
42
43 signal(SIGALRM, SIG_DFL);
44}
45
46void test_signal_pending(void)
47{
48 test_signal_pending_by_type(BPF_PROG_TYPE_SOCKET_FILTER);
49 test_signal_pending_by_type(BPF_PROG_TYPE_FLOW_DISSECTOR);
50}
1// SPDX-License-Identifier: GPL-2.0
2#include <test_progs.h>
3#include <network_helpers.h>
4
5static void sigalrm_handler(int s) {}
6static struct sigaction sigalrm_action = {
7 .sa_handler = sigalrm_handler,
8};
9
10static void test_signal_pending_by_type(enum bpf_prog_type prog_type)
11{
12 struct bpf_insn prog[4096];
13 struct itimerval timeo = {
14 .it_value.tv_usec = 100000, /* 100ms */
15 };
16 __u32 duration = 0, retval;
17 int prog_fd;
18 int err;
19 int i;
20
21 for (i = 0; i < ARRAY_SIZE(prog); i++)
22 prog[i] = BPF_ALU64_IMM(BPF_MOV, BPF_REG_0, 0);
23 prog[ARRAY_SIZE(prog) - 1] = BPF_EXIT_INSN();
24
25 prog_fd = bpf_load_program(prog_type, prog, ARRAY_SIZE(prog),
26 "GPL", 0, NULL, 0);
27 CHECK(prog_fd < 0, "test-run", "errno %d\n", errno);
28
29 err = sigaction(SIGALRM, &sigalrm_action, NULL);
30 CHECK(err, "test-run-signal-sigaction", "errno %d\n", errno);
31
32 err = setitimer(ITIMER_REAL, &timeo, NULL);
33 CHECK(err, "test-run-signal-timer", "errno %d\n", errno);
34
35 err = bpf_prog_test_run(prog_fd, 0xffffffff, &pkt_v4, sizeof(pkt_v4),
36 NULL, NULL, &retval, &duration);
37 CHECK(duration > 500000000, /* 500ms */
38 "test-run-signal-duration",
39 "duration %dns > 500ms\n",
40 duration);
41
42 signal(SIGALRM, SIG_DFL);
43}
44
45void test_signal_pending(enum bpf_prog_type prog_type)
46{
47 test_signal_pending_by_type(BPF_PROG_TYPE_SOCKET_FILTER);
48 test_signal_pending_by_type(BPF_PROG_TYPE_FLOW_DISSECTOR);
49}