linux/tools/testing/selftests/bpf/prog_tests/task_pt_regs.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0
   2#define _GNU_SOURCE
   3#include <test_progs.h>
   4#include "test_task_pt_regs.skel.h"
   5
   6void test_task_pt_regs(void)
   7{
   8        struct test_task_pt_regs *skel;
   9        struct bpf_link *uprobe_link;
  10        size_t uprobe_offset;
  11        ssize_t base_addr;
  12        bool match;
  13
  14        base_addr = get_base_addr();
  15        if (!ASSERT_GT(base_addr, 0, "get_base_addr"))
  16                return;
  17        uprobe_offset = get_uprobe_offset(&get_base_addr, base_addr);
  18
  19        skel = test_task_pt_regs__open_and_load();
  20        if (!ASSERT_OK_PTR(skel, "skel_open"))
  21                return;
  22        if (!ASSERT_OK_PTR(skel->bss, "check_bss"))
  23                goto cleanup;
  24
  25        uprobe_link = bpf_program__attach_uprobe(skel->progs.handle_uprobe,
  26                                                 false /* retprobe */,
  27                                                 0 /* self pid */,
  28                                                 "/proc/self/exe",
  29                                                 uprobe_offset);
  30        if (!ASSERT_OK_PTR(uprobe_link, "attach_uprobe"))
  31                goto cleanup;
  32        skel->links.handle_uprobe = uprobe_link;
  33
  34        /* trigger & validate uprobe */
  35        get_base_addr();
  36
  37        if (!ASSERT_EQ(skel->bss->uprobe_res, 1, "check_uprobe_res"))
  38                goto cleanup;
  39
  40        match = !memcmp(&skel->bss->current_regs, &skel->bss->ctx_regs,
  41                        sizeof(skel->bss->current_regs));
  42        ASSERT_TRUE(match, "check_regs_match");
  43
  44cleanup:
  45        test_task_pt_regs__destroy(skel);
  46}
  47