summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/bpf/prog_tests/get_func_args_test.c
blob: 85c427119fe92329b3cb4256cb99a34795bf1521 (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
43
44
// SPDX-License-Identifier: GPL-2.0
#include <test_progs.h>
#include "get_func_args_test.skel.h"

void test_get_func_args_test(void)
{
	struct get_func_args_test *skel = NULL;
	__u32 duration = 0, retval;
	int err, prog_fd;

	skel = get_func_args_test__open_and_load();
	if (!ASSERT_OK_PTR(skel, "get_func_args_test__open_and_load"))
		return;

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

	/* This runs bpf_fentry_test* functions and triggers
	 * fentry/fexit programs.
	 */
	prog_fd = bpf_program__fd(skel->progs.test1);
	err = bpf_prog_test_run(prog_fd, 1, NULL, 0,
				NULL, NULL, &retval, &duration);
	ASSERT_OK(err, "test_run");
	ASSERT_EQ(retval, 0, "test_run");

	/* This runs bpf_modify_return_test function and triggers
	 * fmod_ret_test and fexit_test programs.
	 */
	prog_fd = bpf_program__fd(skel->progs.fmod_ret_test);
	err = bpf_prog_test_run(prog_fd, 1, NULL, 0,
				NULL, NULL, &retval, &duration);
	ASSERT_OK(err, "test_run");
	ASSERT_EQ(retval, 1234, "test_run");

	ASSERT_EQ(skel->bss->test1_result, 1, "test1_result");
	ASSERT_EQ(skel->bss->test2_result, 1, "test2_result");
	ASSERT_EQ(skel->bss->test3_result, 1, "test3_result");
	ASSERT_EQ(skel->bss->test4_result, 1, "test4_result");

cleanup:
	get_func_args_test__destroy(skel);
}