Skip to content

Commit 5d7e8d4

Browse files
committed
selftests/bpf: Move stacktrace_map_raw_tp test to stacktrace_map object
Signed-off-by: Jiri Olsa <[email protected]>
1 parent 5a1fcce commit 5d7e8d4

File tree

3 files changed

+38
-72
lines changed

3 files changed

+38
-72
lines changed

tools/testing/selftests/bpf/prog_tests/stacktrace_map.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <test_progs.h>
33
#include "stacktrace_map.skel.h"
44

5-
void test_stacktrace_map(void)
5+
static void test_stacktrace_map_tp(bool raw_tp)
66
{
77
struct stacktrace_map *skel;
88
int control_map_fd, stackid_hmap_fd, stackmap_fd, stack_amap_fd;
@@ -19,8 +19,13 @@ void test_stacktrace_map(void)
1919
stackmap_fd = bpf_map__fd(skel->maps.stackmap);
2020
stack_amap_fd = bpf_map__fd(skel->maps.stack_amap);
2121

22-
err = stacktrace_map__attach(skel);
23-
if (!ASSERT_OK(err, "skel_attach"))
22+
if (raw_tp) {
23+
skel->links.tp = bpf_program__attach_raw_tracepoint(skel->progs.raw_tp, "sched_switch");
24+
} else {
25+
skel->links.tp = bpf_program__attach_tracepoint(skel->progs.tp, "sched", "sched_switch");
26+
}
27+
28+
if (!ASSERT_OK_PTR(skel->links.tp, "attach"))
2429
goto out;
2530
/* give some time for bpf program run */
2631
sleep(1);
@@ -60,3 +65,11 @@ void test_stacktrace_map(void)
6065
out:
6166
stacktrace_map__destroy(skel);
6267
}
68+
69+
void test_stacktrace_map(void)
70+
{
71+
if (test__start_subtest("tp"))
72+
test_stacktrace_map_tp(false);
73+
if (test__start_subtest("raw_tp"))
74+
test_stacktrace_map_tp(true);
75+
}

tools/testing/selftests/bpf/prog_tests/stacktrace_map_raw_tp.c

Lines changed: 0 additions & 64 deletions
This file was deleted.

tools/testing/selftests/bpf/progs/stacktrace_map.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,27 +51,44 @@ struct sched_switch_args {
5151
};
5252

5353
__u32 stack_id;
54-
SEC("tracepoint/sched/sched_switch")
55-
int oncpu(struct sched_switch_args *ctx)
54+
static inline void test_stackmap(void *ctx, int skip)
5655
{
5756
__u32 max_len = PERF_MAX_STACK_DEPTH * sizeof(__u64);
5857
__u32 key = 0, val = 0, *value_p;
5958
void *stack_p;
6059

6160
value_p = bpf_map_lookup_elem(&control_map, &key);
6261
if (value_p && *value_p)
63-
return 0; /* skip if non-zero *value_p */
62+
return; /* skip if non-zero *value_p */
6463

6564
/* The size of stackmap and stackid_hmap should be the same */
66-
key = bpf_get_stackid(ctx, &stackmap, 0);
65+
key = bpf_get_stackid(ctx, &stackmap, (u64) skip);
6766
if ((int)key >= 0) {
6867
stack_id = key;
6968
bpf_map_update_elem(&stackid_hmap, &key, &val, 0);
7069
stack_p = bpf_map_lookup_elem(&stack_amap, &key);
7170
if (stack_p)
72-
bpf_get_stack(ctx, stack_p, max_len, 0);
71+
bpf_get_stack(ctx, stack_p, max_len, (u64) skip);
7372
}
73+
}
74+
75+
SEC("tracepoint/sched/sched_switch")
76+
int tp(struct sched_switch_args *ctx)
77+
{
78+
test_stackmap(ctx, 0);
79+
return 0;
80+
}
7481

82+
#if defined(__TARGET_ARCH_x86)
83+
#define TRACING_SKIP 1
84+
#else
85+
#define TRACING_SKIP 2
86+
#endif
87+
88+
SEC("raw_tp/sched/sched_switch")
89+
int raw_tp(struct sched_switch_args *ctx)
90+
{
91+
test_stackmap(ctx, TRACING_SKIP);
7592
return 0;
7693
}
7794

0 commit comments

Comments
 (0)