aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/testing/selftests/bpf/test_progs.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c
index c52bd90fbb34..c59d2e015d16 100644
--- a/tools/testing/selftests/bpf/test_progs.c
+++ b/tools/testing/selftests/bpf/test_progs.c
@@ -12,6 +12,7 @@
12#include <stdlib.h> 12#include <stdlib.h>
13#include <stdarg.h> 13#include <stdarg.h>
14#include <time.h> 14#include <time.h>
15#include <signal.h>
15 16
16#include <linux/types.h> 17#include <linux/types.h>
17typedef __u16 __sum16; 18typedef __u16 __sum16;
@@ -28,6 +29,7 @@ typedef __u16 __sum16;
28#include <sys/ioctl.h> 29#include <sys/ioctl.h>
29#include <sys/wait.h> 30#include <sys/wait.h>
30#include <sys/types.h> 31#include <sys/types.h>
32#include <sys/time.h>
31#include <fcntl.h> 33#include <fcntl.h>
32#include <pthread.h> 34#include <pthread.h>
33#include <linux/bpf.h> 35#include <linux/bpf.h>
@@ -2108,6 +2110,46 @@ close_prog_noerr:
2108 bpf_object__close(obj); 2110 bpf_object__close(obj);
2109} 2111}
2110 2112
2113static void sigalrm_handler(int s) {}
2114static struct sigaction sigalrm_action = {
2115 .sa_handler = sigalrm_handler,
2116};
2117
2118static void test_signal_pending(enum bpf_prog_type prog_type)
2119{
2120 struct bpf_insn prog[4096];
2121 struct itimerval timeo = {
2122 .it_value.tv_usec = 100000, /* 100ms */
2123 };
2124 __u32 duration, retval;
2125 int prog_fd;
2126 int err;
2127 int i;
2128
2129 for (i = 0; i < ARRAY_SIZE(prog); i++)
2130 prog[i] = BPF_ALU64_IMM(BPF_MOV, BPF_REG_0, 0);
2131 prog[ARRAY_SIZE(prog) - 1] = BPF_EXIT_INSN();
2132
2133 prog_fd = bpf_load_program(prog_type, prog, ARRAY_SIZE(prog),
2134 "GPL", 0, NULL, 0);
2135 CHECK(prog_fd < 0, "test-run", "errno %d\n", errno);
2136
2137 err = sigaction(SIGALRM, &sigalrm_action, NULL);
2138 CHECK(err, "test-run-signal-sigaction", "errno %d\n", errno);
2139
2140 err = setitimer(ITIMER_REAL, &timeo, NULL);
2141 CHECK(err, "test-run-signal-timer", "errno %d\n", errno);
2142
2143 err = bpf_prog_test_run(prog_fd, 0xffffffff, &pkt_v4, sizeof(pkt_v4),
2144 NULL, NULL, &retval, &duration);
2145 CHECK(duration > 500000000, /* 500ms */
2146 "test-run-signal-duration",
2147 "duration %dns > 500ms\n",
2148 duration);
2149
2150 signal(SIGALRM, SIG_DFL);
2151}
2152
2111int main(void) 2153int main(void)
2112{ 2154{
2113 srand(time(NULL)); 2155 srand(time(NULL));
@@ -2138,6 +2180,8 @@ int main(void)
2138 test_flow_dissector(); 2180 test_flow_dissector();
2139 test_spinlock(); 2181 test_spinlock();
2140 test_map_lock(); 2182 test_map_lock();
2183 test_signal_pending(BPF_PROG_TYPE_SOCKET_FILTER);
2184 test_signal_pending(BPF_PROG_TYPE_FLOW_DISSECTOR);
2141 2185
2142 printf("Summary: %d PASSED, %d FAILED\n", pass_cnt, error_cnt); 2186 printf("Summary: %d PASSED, %d FAILED\n", pass_cnt, error_cnt);
2143 return error_cnt ? EXIT_FAILURE : EXIT_SUCCESS; 2187 return error_cnt ? EXIT_FAILURE : EXIT_SUCCESS;