1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright (c) 2021 Facebook */ 3 #include <test_progs.h> 4 #include "syscall.skel.h" 5 6 struct args { 7 __u64 log_buf; 8 __u32 log_size; 9 int max_entries; 10 int map_fd; 11 int prog_fd; 12 int btf_fd; 13 }; 14 15 void test_syscall(void) 16 { 17 static char verifier_log[8192]; 18 struct args ctx = { 19 .max_entries = 1024, 20 .log_buf = (uintptr_t) verifier_log, 21 .log_size = sizeof(verifier_log), 22 }; 23 struct bpf_prog_test_run_attr tattr = { 24 .ctx_in = &ctx, 25 .ctx_size_in = sizeof(ctx), 26 }; 27 struct syscall *skel = NULL; 28 __u64 key = 12, value = 0; 29 int err; 30 31 skel = syscall__open_and_load(); 32 if (!ASSERT_OK_PTR(skel, "skel_load")) 33 goto cleanup; 34 35 tattr.prog_fd = bpf_program__fd(skel->progs.bpf_prog); 36 err = bpf_prog_test_run_xattr(&tattr); 37 ASSERT_EQ(err, 0, "err"); 38 ASSERT_EQ(tattr.retval, 1, "retval"); 39 ASSERT_GT(ctx.map_fd, 0, "ctx.map_fd"); 40 ASSERT_GT(ctx.prog_fd, 0, "ctx.prog_fd"); 41 ASSERT_OK(memcmp(verifier_log, "processed", sizeof("processed") - 1), 42 "verifier_log"); 43 44 err = bpf_map_lookup_elem(ctx.map_fd, &key, &value); 45 ASSERT_EQ(err, 0, "map_lookup"); 46 ASSERT_EQ(value, 34, "map lookup value"); 47 cleanup: 48 syscall__destroy(skel); 49 if (ctx.prog_fd > 0) 50 close(ctx.prog_fd); 51 if (ctx.map_fd > 0) 52 close(ctx.map_fd); 53 if (ctx.btf_fd > 0) 54 close(ctx.btf_fd); 55 } 56