core_retro.c (913B)
1// SPDX-License-Identifier: GPL-2.0 2// Copyright (c) 2020 Facebook 3#define _GNU_SOURCE 4#include <test_progs.h> 5#include "test_core_retro.skel.h" 6 7void test_core_retro(void) 8{ 9 int err, zero = 0, res, my_pid = getpid(); 10 struct test_core_retro *skel; 11 12 /* load program */ 13 skel = test_core_retro__open_and_load(); 14 if (!ASSERT_OK_PTR(skel, "skel_load")) 15 goto out_close; 16 17 err = bpf_map__update_elem(skel->maps.exp_tgid_map, &zero, sizeof(zero), 18 &my_pid, sizeof(my_pid), 0); 19 if (!ASSERT_OK(err, "map_update")) 20 goto out_close; 21 22 /* attach probe */ 23 err = test_core_retro__attach(skel); 24 if (!ASSERT_OK(err, "attach_kprobe")) 25 goto out_close; 26 27 /* trigger */ 28 usleep(1); 29 30 err = bpf_map__lookup_elem(skel->maps.results, &zero, sizeof(zero), &res, sizeof(res), 0); 31 if (!ASSERT_OK(err, "map_lookup")) 32 goto out_close; 33 34 ASSERT_EQ(res, my_pid, "pid_check"); 35 36out_close: 37 test_core_retro__destroy(skel); 38}