linux/tools/testing/selftests/bpf/prog_tests/stack_var_off.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0
   2#include <test_progs.h>
   3#include "test_stack_var_off.skel.h"
   4
   5/* Test read and writes to the stack performed with offsets that are not
   6 * statically known.
   7 */
   8void test_stack_var_off(void)
   9{
  10        int duration = 0;
  11        struct test_stack_var_off *skel;
  12
  13        skel = test_stack_var_off__open_and_load();
  14        if (CHECK(!skel, "skel_open", "failed to open skeleton\n"))
  15                return;
  16
  17        /* Give pid to bpf prog so it doesn't trigger for anyone else. */
  18        skel->bss->test_pid = getpid();
  19        /* Initialize the probe's input. */
  20        skel->bss->input[0] = 2;
  21        skel->bss->input[1] = 42;  /* This will be returned in probe_res. */
  22
  23        if (!ASSERT_OK(test_stack_var_off__attach(skel), "skel_attach"))
  24                goto cleanup;
  25
  26        /* Trigger probe. */
  27        usleep(1);
  28
  29        if (CHECK(skel->bss->probe_res != 42, "check_probe_res",
  30                  "wrong probe res: %d\n", skel->bss->probe_res))
  31                goto cleanup;
  32
  33cleanup:
  34        test_stack_var_off__destroy(skel);
  35}
  36