File: stacktrace_map_skip.c

package info (click to toggle)
linux 6.1.8-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,488,076 kB
  • sloc: ansic: 23,401,844; asm: 266,744; sh: 108,976; makefile: 49,705; python: 36,927; perl: 36,810; cpp: 6,044; yacc: 4,904; lex: 2,722; awk: 1,440; ruby: 25; sed: 5
file content (63 lines) | stat: -rw-r--r-- 1,694 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// SPDX-License-Identifier: GPL-2.0
#include <test_progs.h>
#include "stacktrace_map_skip.skel.h"

#define TEST_STACK_DEPTH  2

void test_stacktrace_map_skip(void)
{
	struct stacktrace_map_skip *skel;
	int stackid_hmap_fd, stackmap_fd, stack_amap_fd;
	int err, stack_trace_len;

	skel = stacktrace_map_skip__open_and_load();
	if (!ASSERT_OK_PTR(skel, "skel_open_and_load"))
		return;

	/* find map fds */
	stackid_hmap_fd = bpf_map__fd(skel->maps.stackid_hmap);
	if (!ASSERT_GE(stackid_hmap_fd, 0, "stackid_hmap fd"))
		goto out;

	stackmap_fd = bpf_map__fd(skel->maps.stackmap);
	if (!ASSERT_GE(stackmap_fd, 0, "stackmap fd"))
		goto out;

	stack_amap_fd = bpf_map__fd(skel->maps.stack_amap);
	if (!ASSERT_GE(stack_amap_fd, 0, "stack_amap fd"))
		goto out;

	skel->bss->pid = getpid();

	err = stacktrace_map_skip__attach(skel);
	if (!ASSERT_OK(err, "skel_attach"))
		goto out;

	/* give some time for bpf program run */
	sleep(1);

	/* disable stack trace collection */
	skel->bss->control = 1;

	/* for every element in stackid_hmap, we can find a corresponding one
	 * in stackmap, and vise versa.
	 */
	err = compare_map_keys(stackid_hmap_fd, stackmap_fd);
	if (!ASSERT_OK(err, "compare_map_keys stackid_hmap vs. stackmap"))
		goto out;

	err = compare_map_keys(stackmap_fd, stackid_hmap_fd);
	if (!ASSERT_OK(err, "compare_map_keys stackmap vs. stackid_hmap"))
		goto out;

	stack_trace_len = TEST_STACK_DEPTH * sizeof(__u64);
	err = compare_stack_ips(stackmap_fd, stack_amap_fd, stack_trace_len);
	if (!ASSERT_OK(err, "compare_stack_ips stackmap vs. stack_amap"))
		goto out;

	if (!ASSERT_EQ(skel->bss->failed, 0, "skip_failed"))
		goto out;

out:
	stacktrace_map_skip__destroy(skel);
}