Skip to content

Commit

Permalink
selftests/bpf: test_progs: remove unused ret
Browse files Browse the repository at this point in the history
send_signal test returns static codes from the subtests which
nobody looks at, let's rely on the CHECK macros instead.

Signed-off-by: Stanislav Fomichev <sdf@google.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
  • Loading branch information
Stanislav Fomichev authored and Daniel Borkmann committed Aug 27, 2019
1 parent 62d69f2 commit 86ccc38
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions tools/testing/selftests/bpf/prog_tests/send_signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ static void sigusr1_handler(int signum)
sigusr1_received++;
}

static int test_send_signal_common(struct perf_event_attr *attr,
static void test_send_signal_common(struct perf_event_attr *attr,
int prog_type,
const char *test_name)
{
Expand All @@ -23,13 +23,13 @@ static int test_send_signal_common(struct perf_event_attr *attr,

if (CHECK(pipe(pipe_c2p), test_name,
"pipe pipe_c2p error: %s\n", strerror(errno)))
goto no_fork_done;
return;

if (CHECK(pipe(pipe_p2c), test_name,
"pipe pipe_p2c error: %s\n", strerror(errno))) {
close(pipe_c2p[0]);
close(pipe_c2p[1]);
goto no_fork_done;
return;
}

pid = fork();
Expand All @@ -38,7 +38,7 @@ static int test_send_signal_common(struct perf_event_attr *attr,
close(pipe_c2p[1]);
close(pipe_p2c[0]);
close(pipe_p2c[1]);
goto no_fork_done;
return;
}

if (pid == 0) {
Expand Down Expand Up @@ -125,7 +125,7 @@ static int test_send_signal_common(struct perf_event_attr *attr,
goto disable_pmu;
}

err = CHECK(buf[0] != '2', test_name, "incorrect result\n");
CHECK(buf[0] != '2', test_name, "incorrect result\n");

/* notify child safe to exit */
write(pipe_p2c[1], buf, 1);
Expand All @@ -138,11 +138,9 @@ static int test_send_signal_common(struct perf_event_attr *attr,
close(pipe_c2p[0]);
close(pipe_p2c[1]);
wait(NULL);
no_fork_done:
return err;
}

static int test_send_signal_tracepoint(void)
static void test_send_signal_tracepoint(void)
{
const char *id_path = "/sys/kernel/debug/tracing/events/syscalls/sys_enter_nanosleep/id";
struct perf_event_attr attr = {
Expand All @@ -159,33 +157,33 @@ static int test_send_signal_tracepoint(void)
if (CHECK(efd < 0, "tracepoint",
"open syscalls/sys_enter_nanosleep/id failure: %s\n",
strerror(errno)))
return -1;
return;

bytes = read(efd, buf, sizeof(buf));
close(efd);
if (CHECK(bytes <= 0 || bytes >= sizeof(buf), "tracepoint",
"read syscalls/sys_enter_nanosleep/id failure: %s\n",
strerror(errno)))
return -1;
return;

attr.config = strtol(buf, NULL, 0);

return test_send_signal_common(&attr, BPF_PROG_TYPE_TRACEPOINT, "tracepoint");
test_send_signal_common(&attr, BPF_PROG_TYPE_TRACEPOINT, "tracepoint");
}

static int test_send_signal_perf(void)
static void test_send_signal_perf(void)
{
struct perf_event_attr attr = {
.sample_period = 1,
.type = PERF_TYPE_SOFTWARE,
.config = PERF_COUNT_SW_CPU_CLOCK,
};

return test_send_signal_common(&attr, BPF_PROG_TYPE_PERF_EVENT,
"perf_sw_event");
test_send_signal_common(&attr, BPF_PROG_TYPE_PERF_EVENT,
"perf_sw_event");
}

static int test_send_signal_nmi(void)
static void test_send_signal_nmi(void)
{
struct perf_event_attr attr = {
.sample_freq = 50,
Expand All @@ -205,25 +203,23 @@ static int test_send_signal_nmi(void)
printf("%s:SKIP:no PERF_COUNT_HW_CPU_CYCLES\n",
__func__);
test__skip();
return 0;
return;
}
/* Let the test fail with a more informative message */
} else {
close(pmu_fd);
}

return test_send_signal_common(&attr, BPF_PROG_TYPE_PERF_EVENT,
"perf_hw_event");
test_send_signal_common(&attr, BPF_PROG_TYPE_PERF_EVENT,
"perf_hw_event");
}

void test_send_signal(void)
{
int ret = 0;

if (test__start_subtest("send_signal_tracepoint"))
ret |= test_send_signal_tracepoint();
test_send_signal_tracepoint();
if (test__start_subtest("send_signal_perf"))
ret |= test_send_signal_perf();
test_send_signal_perf();
if (test__start_subtest("send_signal_nmi"))
ret |= test_send_signal_nmi();
test_send_signal_nmi();
}

0 comments on commit 86ccc38

Please sign in to comment.