File: stack_var_off.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 (35 lines) | stat: -rw-r--r-- 925 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
// SPDX-License-Identifier: GPL-2.0
#include <test_progs.h>
#include "test_stack_var_off.skel.h"

/* Test read and writes to the stack performed with offsets that are not
 * statically known.
 */
void test_stack_var_off(void)
{
	int duration = 0;
	struct test_stack_var_off *skel;

	skel = test_stack_var_off__open_and_load();
	if (CHECK(!skel, "skel_open", "failed to open skeleton\n"))
		return;

	/* Give pid to bpf prog so it doesn't trigger for anyone else. */
	skel->bss->test_pid = getpid();
	/* Initialize the probe's input. */
	skel->bss->input[0] = 2;
	skel->bss->input[1] = 42;  /* This will be returned in probe_res. */

	if (!ASSERT_OK(test_stack_var_off__attach(skel), "skel_attach"))
		goto cleanup;

	/* Trigger probe. */
	usleep(1);

	if (CHECK(skel->bss->probe_res != 42, "check_probe_res",
		  "wrong probe res: %d\n", skel->bss->probe_res))
		goto cleanup;

cleanup:
	test_stack_var_off__destroy(skel);
}