Linux Audio

Check our new training course

Loading...
v6.2
 1// SPDX-License-Identifier: GPL-2.0
 2/* Copyright (c) 2019 Facebook */
 3#include <test_progs.h>
 4#include "fexit_test.lskel.h"
 5
 6static int fexit_test(struct fexit_test_lskel *fexit_skel)
 7{
 
 8	int err, prog_fd, i;
 9	int link_fd;
10	__u64 *result;
11	LIBBPF_OPTS(bpf_test_run_opts, topts);
12
13	err = fexit_test_lskel__attach(fexit_skel);
14	if (!ASSERT_OK(err, "fexit_attach"))
15		return err;
16
17	/* Check that already linked program can't be attached again. */
18	link_fd = fexit_test_lskel__test1__attach(fexit_skel);
19	if (!ASSERT_LT(link_fd, 0, "fexit_attach_link"))
20		return -1;
21
22	prog_fd = fexit_skel->progs.test1.prog_fd;
23	err = bpf_prog_test_run_opts(prog_fd, &topts);
24	ASSERT_OK(err, "test_run");
25	ASSERT_EQ(topts.retval, 0, "test_run");
26
27	result = (__u64 *)fexit_skel->bss;
28	for (i = 0; i < sizeof(*fexit_skel->bss) / sizeof(__u64); i++) {
29		if (!ASSERT_EQ(result[i], 1, "fexit_result"))
30			return -1;
31	}
32
33	fexit_test_lskel__detach(fexit_skel);
34
35	/* zero results for re-attach test */
36	memset(fexit_skel->bss, 0, sizeof(*fexit_skel->bss));
37	return 0;
38}
39
40void test_fexit_test(void)
41{
42	struct fexit_test_lskel *fexit_skel = NULL;
43	int err;
44
45	fexit_skel = fexit_test_lskel__open_and_load();
46	if (!ASSERT_OK_PTR(fexit_skel, "fexit_skel_load"))
47		goto cleanup;
48
49	err = fexit_test(fexit_skel);
50	if (!ASSERT_OK(err, "fexit_first_attach"))
51		goto cleanup;
52
53	err = fexit_test(fexit_skel);
54	ASSERT_OK(err, "fexit_second_attach");
 
 
 
 
 
 
 
 
 
 
 
55
56cleanup:
57	fexit_test_lskel__destroy(fexit_skel);
58}
v5.9
 1// SPDX-License-Identifier: GPL-2.0
 2/* Copyright (c) 2019 Facebook */
 3#include <test_progs.h>
 4#include "fexit_test.skel.h"
 5
 6void test_fexit_test(void)
 7{
 8	struct fexit_test *fexit_skel = NULL;
 9	int err, prog_fd, i;
10	__u32 duration = 0, retval;
11	__u64 *result;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
13	fexit_skel = fexit_test__open_and_load();
14	if (CHECK(!fexit_skel, "fexit_skel_load", "fexit skeleton failed\n"))
 
 
 
 
 
15		goto cleanup;
16
17	err = fexit_test__attach(fexit_skel);
18	if (CHECK(err, "fexit_attach", "fexit attach failed: %d\n", err))
19		goto cleanup;
20
21	prog_fd = bpf_program__fd(fexit_skel->progs.test1);
22	err = bpf_prog_test_run(prog_fd, 1, NULL, 0,
23				NULL, NULL, &retval, &duration);
24	CHECK(err || retval, "test_run",
25	      "err %d errno %d retval %d duration %d\n",
26	      err, errno, retval, duration);
27
28	result = (__u64 *)fexit_skel->bss;
29	for (i = 0; i < 6; i++) {
30		if (CHECK(result[i] != 1, "result",
31			  "fexit_test%d failed err %lld\n", i + 1, result[i]))
32			goto cleanup;
33	}
34
35cleanup:
36	fexit_test__destroy(fexit_skel);
37}