// SPDX-License-Identifier: GPL-2.0 /* Copyright (c) 2022 Facebook */ #include #include "dynptr_fail.skel.h" #include "dynptr_success.skel.h" static const char * const success_tests[] = { "test_read_write", "test_data_slice", "test_ringbuf", }; static void verify_success(const char *prog_name) { struct dynptr_success *skel; struct bpf_program *prog; struct bpf_link *link; skel = dynptr_success__open(); if (!ASSERT_OK_PTR(skel, "dynptr_success__open")) return; skel->bss->pid = getpid(); dynptr_success__load(skel); if (!ASSERT_OK_PTR(skel, "dynptr_success__load")) goto cleanup; prog = bpf_object__find_program_by_name(skel->obj, prog_name); if (!ASSERT_OK_PTR(prog, "bpf_object__find_program_by_name")) goto cleanup; link = bpf_program__attach(prog); if (!ASSERT_OK_PTR(link, "bpf_program__attach")) goto cleanup; usleep(1); ASSERT_EQ(skel->bss->err, 0, "err"); bpf_link__destroy(link); cleanup: dynptr_success__destroy(skel); } void test_dynptr(void) { int i; for (i = 0; i < ARRAY_SIZE(success_tests); i++) { if (!test__start_subtest(success_tests[i])) continue; verify_success(success_tests[i]); } RUN_TESTS(dynptr_fail); }