summaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/bpf/prog_tests/linked_funcs.c
blob: e9916f2817ecf6656c07a9c3d2ed50763263b1ad (plain)
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
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2021 Facebook */

#include <test_progs.h>
#include <sys/syscall.h>
#include "linked_funcs.skel.h"

void test_linked_funcs(void)
{
	int err;
	struct linked_funcs *skel;

	skel = linked_funcs__open();
	if (!ASSERT_OK_PTR(skel, "skel_open"))
		return;

	skel->rodata->my_tid = syscall(SYS_gettid);
	skel->bss->syscall_id = SYS_getpgid;

	err = linked_funcs__load(skel);
	if (!ASSERT_OK(err, "skel_load"))
		goto cleanup;

	err = linked_funcs__attach(skel);
	if (!ASSERT_OK(err, "skel_attach"))
		goto cleanup;

	/* trigger */
	syscall(SYS_getpgid);

	ASSERT_EQ(skel->bss->output_val1, 2000 + 2000, "output_val1");
	ASSERT_EQ(skel->bss->output_ctx1, SYS_getpgid, "output_ctx1");
	ASSERT_EQ(skel->bss->output_weak1, 42, "output_weak1");

	ASSERT_EQ(skel->bss->output_val2, 2 * 1000 + 2 * (2 * 1000), "output_val2");
	ASSERT_EQ(skel->bss->output_ctx2, SYS_getpgid, "output_ctx2");
	/* output_weak2 should never be updated */
	ASSERT_EQ(skel->bss->output_weak2, 0, "output_weak2");

cleanup:
	linked_funcs__destroy(skel);
}