Linux Audio

Check our new training course

Loading...
Note: File does not exist in v4.10.11.
 1// SPDX-License-Identifier: GPL-2.0
 2/* Copyright (c) 2022 Facebook */
 3
 4#include <test_progs.h>
 5#include "dynptr_fail.skel.h"
 6#include "dynptr_success.skel.h"
 7
 8static struct {
 9	const char *prog_name;
10	const char *expected_err_msg;
11} dynptr_tests[] = {
12	/* success cases */
13	{"test_read_write", NULL},
14	{"test_data_slice", NULL},
15	{"test_ringbuf", NULL},
16};
17
18static void verify_success(const char *prog_name)
19{
20	struct dynptr_success *skel;
21	struct bpf_program *prog;
22	struct bpf_link *link;
23
24	skel = dynptr_success__open();
25	if (!ASSERT_OK_PTR(skel, "dynptr_success__open"))
26		return;
27
28	skel->bss->pid = getpid();
29
30	dynptr_success__load(skel);
31	if (!ASSERT_OK_PTR(skel, "dynptr_success__load"))
32		goto cleanup;
33
34	prog = bpf_object__find_program_by_name(skel->obj, prog_name);
35	if (!ASSERT_OK_PTR(prog, "bpf_object__find_program_by_name"))
36		goto cleanup;
37
38	link = bpf_program__attach(prog);
39	if (!ASSERT_OK_PTR(link, "bpf_program__attach"))
40		goto cleanup;
41
42	usleep(1);
43
44	ASSERT_EQ(skel->bss->err, 0, "err");
45
46	bpf_link__destroy(link);
47
48cleanup:
49	dynptr_success__destroy(skel);
50}
51
52void test_dynptr(void)
53{
54	int i;
55
56	for (i = 0; i < ARRAY_SIZE(dynptr_tests); i++) {
57		if (!test__start_subtest(dynptr_tests[i].prog_name))
58			continue;
59
60		verify_success(dynptr_tests[i].prog_name);
61	}
62
63	RUN_TESTS(dynptr_fail);
64}