File: core_retro.c

package info (click to toggle)
linux 6.12.38-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,675,544 kB
  • sloc: ansic: 25,916,840; asm: 269,589; sh: 136,393; python: 65,219; makefile: 55,714; perl: 37,750; xml: 19,284; cpp: 5,894; yacc: 4,927; lex: 2,939; awk: 1,594; sed: 28; ruby: 25
file content (38 lines) | stat: -rw-r--r-- 913 bytes parent folder | download | duplicates (17)
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
// SPDX-License-Identifier: GPL-2.0
// Copyright (c) 2020 Facebook
#define _GNU_SOURCE
#include <test_progs.h>
#include "test_core_retro.skel.h"

void test_core_retro(void)
{
	int err, zero = 0, res, my_pid = getpid();
	struct test_core_retro *skel;

	/* load program */
	skel = test_core_retro__open_and_load();
	if (!ASSERT_OK_PTR(skel, "skel_load"))
		goto out_close;

	err = bpf_map__update_elem(skel->maps.exp_tgid_map, &zero, sizeof(zero),
				   &my_pid, sizeof(my_pid), 0);
	if (!ASSERT_OK(err, "map_update"))
		goto out_close;

	/* attach probe */
	err = test_core_retro__attach(skel);
	if (!ASSERT_OK(err, "attach_kprobe"))
		goto out_close;

	/* trigger */
	usleep(1);

	err = bpf_map__lookup_elem(skel->maps.results, &zero, sizeof(zero), &res, sizeof(res), 0);
	if (!ASSERT_OK(err, "map_lookup"))
		goto out_close;

	ASSERT_EQ(res, my_pid, "pid_check");

out_close:
	test_core_retro__destroy(skel);
}