1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
// SPDX-License-Identifier: GPL-2.0
#include <test_progs.h>
#include "struct_ops_private_stack.skel.h"
#include "struct_ops_private_stack_fail.skel.h"
#include "struct_ops_private_stack_recur.skel.h"
static void test_private_stack(void)
{
struct struct_ops_private_stack *skel;
struct bpf_link *link;
int err;
skel = struct_ops_private_stack__open();
if (!ASSERT_OK_PTR(skel, "struct_ops_private_stack__open"))
return;
if (skel->data->skip) {
test__skip();
goto cleanup;
}
err = struct_ops_private_stack__load(skel);
if (!ASSERT_OK(err, "struct_ops_private_stack__load"))
goto cleanup;
link = bpf_map__attach_struct_ops(skel->maps.testmod_1);
if (!ASSERT_OK_PTR(link, "attach_struct_ops"))
goto cleanup;
ASSERT_OK(trigger_module_test_read(256), "trigger_read");
ASSERT_EQ(skel->bss->val_i, 3, "val_i");
ASSERT_EQ(skel->bss->val_j, 8, "val_j");
bpf_link__destroy(link);
cleanup:
struct_ops_private_stack__destroy(skel);
}
static void test_private_stack_fail(void)
{
struct struct_ops_private_stack_fail *skel;
int err;
skel = struct_ops_private_stack_fail__open();
if (!ASSERT_OK_PTR(skel, "struct_ops_private_stack_fail__open"))
return;
if (skel->data->skip) {
test__skip();
goto cleanup;
}
err = struct_ops_private_stack_fail__load(skel);
if (!ASSERT_ERR(err, "struct_ops_private_stack_fail__load"))
goto cleanup;
return;
cleanup:
struct_ops_private_stack_fail__destroy(skel);
}
static void test_private_stack_recur(void)
{
struct struct_ops_private_stack_recur *skel;
struct bpf_link *link;
int err;
skel = struct_ops_private_stack_recur__open();
if (!ASSERT_OK_PTR(skel, "struct_ops_private_stack_recur__open"))
return;
if (skel->data->skip) {
test__skip();
goto cleanup;
}
err = struct_ops_private_stack_recur__load(skel);
if (!ASSERT_OK(err, "struct_ops_private_stack_recur__load"))
goto cleanup;
link = bpf_map__attach_struct_ops(skel->maps.testmod_1);
if (!ASSERT_OK_PTR(link, "attach_struct_ops"))
goto cleanup;
ASSERT_OK(trigger_module_test_read(256), "trigger_read");
ASSERT_EQ(skel->bss->val_j, 3, "val_j");
bpf_link__destroy(link);
cleanup:
struct_ops_private_stack_recur__destroy(skel);
}
void test_struct_ops_private_stack(void)
{
if (test__start_subtest("private_stack"))
test_private_stack();
if (test__start_subtest("private_stack_fail"))
test_private_stack_fail();
if (test__start_subtest("private_stack_recur"))
test_private_stack_recur();
}
|