Loading...
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright (c) 2019 Facebook */
3#include <test_progs.h>
4#include "fentry_test.lskel.h"
5
6static int fentry_test(struct fentry_test_lskel *fentry_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 = fentry_test_lskel__attach(fentry_skel);
14 if (!ASSERT_OK(err, "fentry_attach"))
15 return err;
16
17 /* Check that already linked program can't be attached again. */
18 link_fd = fentry_test_lskel__test1__attach(fentry_skel);
19 if (!ASSERT_LT(link_fd, 0, "fentry_attach_link"))
20 return -1;
21
22 prog_fd = fentry_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 *)fentry_skel->bss;
28 for (i = 0; i < sizeof(*fentry_skel->bss) / sizeof(__u64); i++) {
29 if (!ASSERT_EQ(result[i], 1, "fentry_result"))
30 return -1;
31 }
32
33 fentry_test_lskel__detach(fentry_skel);
34
35 /* zero results for re-attach test */
36 memset(fentry_skel->bss, 0, sizeof(*fentry_skel->bss));
37 return 0;
38}
39
40void test_fentry_test(void)
41{
42 struct fentry_test_lskel *fentry_skel = NULL;
43 int err;
44
45 fentry_skel = fentry_test_lskel__open_and_load();
46 if (!ASSERT_OK_PTR(fentry_skel, "fentry_skel_load"))
47 goto cleanup;
48
49 err = fentry_test(fentry_skel);
50 if (!ASSERT_OK(err, "fentry_first_attach"))
51 goto cleanup;
52
53 err = fentry_test(fentry_skel);
54 ASSERT_OK(err, "fentry_second_attach");
55
56cleanup:
57 fentry_test_lskel__destroy(fentry_skel);
58}
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright (c) 2019 Facebook */
3#include <test_progs.h>
4#include "fentry_test.skel.h"
5
6void test_fentry_test(void)
7{
8 struct fentry_test *fentry_skel = NULL;
9 int err, prog_fd, i;
10 __u32 duration = 0, retval;
11 __u64 *result;
12
13 fentry_skel = fentry_test__open_and_load();
14 if (CHECK(!fentry_skel, "fentry_skel_load", "fentry skeleton failed\n"))
15 goto cleanup;
16
17 err = fentry_test__attach(fentry_skel);
18 if (CHECK(err, "fentry_attach", "fentry attach failed: %d\n", err))
19 goto cleanup;
20
21 prog_fd = bpf_program__fd(fentry_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 *)fentry_skel->bss;
29 for (i = 0; i < 6; i++) {
30 if (CHECK(result[i] != 1, "result",
31 "fentry_test%d failed err %lld\n", i + 1, result[i]))
32 goto cleanup;
33 }
34
35cleanup:
36 fentry_test__destroy(fentry_skel);
37}