0001
0002 #include <test_progs.h>
0003 #include <network_helpers.h>
0004
0005 static void sigalrm_handler(int s) {}
0006 static struct sigaction sigalrm_action = {
0007 .sa_handler = sigalrm_handler,
0008 };
0009
0010 static void test_signal_pending_by_type(enum bpf_prog_type prog_type)
0011 {
0012 struct bpf_insn prog[4096];
0013 struct itimerval timeo = {
0014 .it_value.tv_usec = 100000,
0015 };
0016 int prog_fd;
0017 int err;
0018 int i;
0019 LIBBPF_OPTS(bpf_test_run_opts, topts,
0020 .data_in = &pkt_v4,
0021 .data_size_in = sizeof(pkt_v4),
0022 .repeat = 0xffffffff,
0023 );
0024
0025 for (i = 0; i < ARRAY_SIZE(prog); i++)
0026 prog[i] = BPF_ALU64_IMM(BPF_MOV, BPF_REG_0, 0);
0027 prog[ARRAY_SIZE(prog) - 1] = BPF_EXIT_INSN();
0028
0029 prog_fd = bpf_test_load_program(prog_type, prog, ARRAY_SIZE(prog),
0030 "GPL", 0, NULL, 0);
0031 ASSERT_GE(prog_fd, 0, "test-run load");
0032
0033 err = sigaction(SIGALRM, &sigalrm_action, NULL);
0034 ASSERT_OK(err, "test-run-signal-sigaction");
0035
0036 err = setitimer(ITIMER_REAL, &timeo, NULL);
0037 ASSERT_OK(err, "test-run-signal-timer");
0038
0039 err = bpf_prog_test_run_opts(prog_fd, &topts);
0040 ASSERT_LE(topts.duration, 500000000 ,
0041 "test-run-signal-duration");
0042
0043 signal(SIGALRM, SIG_DFL);
0044 }
0045
0046 void test_signal_pending(void)
0047 {
0048 test_signal_pending_by_type(BPF_PROG_TYPE_SOCKET_FILTER);
0049 test_signal_pending_by_type(BPF_PROG_TYPE_FLOW_DISSECTOR);
0050 }