Improve send_signal BPF test stability
Substitute sleep with dummy CPU intensive computation. Finish aforemention computation as soon as signal was delivered to the test process. Make the BPF code to only execute when PID global variable is set Signed-off-by: Mykola Lysenko <mykolal@fb.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Acked-by: Yonghong Song <yhs@fb.com> Link: https://lore.kernel.org/bpf/20220308200449.1757478-3-mykolal@fb.com
This commit is contained in:
parent
d4b5405444
commit
1fd4986412
@ -4,11 +4,11 @@
|
||||
#include <sys/resource.h>
|
||||
#include "test_send_signal_kern.skel.h"
|
||||
|
||||
int sigusr1_received = 0;
|
||||
static int sigusr1_received;
|
||||
|
||||
static void sigusr1_handler(int signum)
|
||||
{
|
||||
sigusr1_received++;
|
||||
sigusr1_received = 1;
|
||||
}
|
||||
|
||||
static void test_send_signal_common(struct perf_event_attr *attr,
|
||||
@ -40,9 +40,10 @@ static void test_send_signal_common(struct perf_event_attr *attr,
|
||||
|
||||
if (pid == 0) {
|
||||
int old_prio;
|
||||
volatile int j = 0;
|
||||
|
||||
/* install signal handler and notify parent */
|
||||
signal(SIGUSR1, sigusr1_handler);
|
||||
ASSERT_NEQ(signal(SIGUSR1, sigusr1_handler), SIG_ERR, "signal");
|
||||
|
||||
close(pipe_c2p[0]); /* close read */
|
||||
close(pipe_p2c[1]); /* close write */
|
||||
@ -63,9 +64,11 @@ static void test_send_signal_common(struct perf_event_attr *attr,
|
||||
ASSERT_EQ(read(pipe_p2c[0], buf, 1), 1, "pipe_read");
|
||||
|
||||
/* wait a little for signal handler */
|
||||
sleep(1);
|
||||
for (int i = 0; i < 100000000 && !sigusr1_received; i++)
|
||||
j /= i + 1;
|
||||
|
||||
buf[0] = sigusr1_received ? '2' : '0';
|
||||
ASSERT_EQ(sigusr1_received, 1, "sigusr1_received");
|
||||
ASSERT_EQ(write(pipe_c2p[1], buf, 1), 1, "pipe_write");
|
||||
|
||||
/* wait for parent notification and exit */
|
||||
@ -93,7 +96,7 @@ static void test_send_signal_common(struct perf_event_attr *attr,
|
||||
goto destroy_skel;
|
||||
}
|
||||
} else {
|
||||
pmu_fd = syscall(__NR_perf_event_open, attr, pid, -1,
|
||||
pmu_fd = syscall(__NR_perf_event_open, attr, pid, -1 /* cpu */,
|
||||
-1 /* group id */, 0 /* flags */);
|
||||
if (!ASSERT_GE(pmu_fd, 0, "perf_event_open")) {
|
||||
err = -1;
|
||||
@ -110,9 +113,9 @@ static void test_send_signal_common(struct perf_event_attr *attr,
|
||||
ASSERT_EQ(read(pipe_c2p[0], buf, 1), 1, "pipe_read");
|
||||
|
||||
/* trigger the bpf send_signal */
|
||||
skel->bss->pid = pid;
|
||||
skel->bss->sig = SIGUSR1;
|
||||
skel->bss->signal_thread = signal_thread;
|
||||
skel->bss->sig = SIGUSR1;
|
||||
skel->bss->pid = pid;
|
||||
|
||||
/* notify child that bpf program can send_signal now */
|
||||
ASSERT_EQ(write(pipe_p2c[1], buf, 1), 1, "pipe_write");
|
||||
|
@ -10,7 +10,7 @@ static __always_inline int bpf_send_signal_test(void *ctx)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (status != 0 || sig == 0 || pid == 0)
|
||||
if (status != 0 || pid == 0)
|
||||
return 0;
|
||||
|
||||
if ((bpf_get_current_pid_tgid() >> 32) == pid) {
|
||||
|
Loading…
Reference in New Issue
Block a user