Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include <test_progs.h>
0003 #include "test_stack_var_off.skel.h"
0004 
0005 /* Test read and writes to the stack performed with offsets that are not
0006  * statically known.
0007  */
0008 void test_stack_var_off(void)
0009 {
0010     int duration = 0;
0011     struct test_stack_var_off *skel;
0012 
0013     skel = test_stack_var_off__open_and_load();
0014     if (CHECK(!skel, "skel_open", "failed to open skeleton\n"))
0015         return;
0016 
0017     /* Give pid to bpf prog so it doesn't trigger for anyone else. */
0018     skel->bss->test_pid = getpid();
0019     /* Initialize the probe's input. */
0020     skel->bss->input[0] = 2;
0021     skel->bss->input[1] = 42;  /* This will be returned in probe_res. */
0022 
0023     if (!ASSERT_OK(test_stack_var_off__attach(skel), "skel_attach"))
0024         goto cleanup;
0025 
0026     /* Trigger probe. */
0027     usleep(1);
0028 
0029     if (CHECK(skel->bss->probe_res != 42, "check_probe_res",
0030           "wrong probe res: %d\n", skel->bss->probe_res))
0031         goto cleanup;
0032 
0033 cleanup:
0034     test_stack_var_off__destroy(skel);
0035 }