fentry_test.c (1493B)
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}