Commit 2a4ca46b authored by Andrii Nakryiko's avatar Andrii Nakryiko Committed by Daniel Borkmann

selftests/bpf: Use both syntaxes for field-based CO-RE helpers

Excercise both supported forms of bpf_core_field_exists() and
bpf_core_field_size() helpers: variable-based field reference and
type/field name-based one.
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20220509004148.1801791-5-andrii@kernel.org
parent 73d0280f
...@@ -45,35 +45,34 @@ int test_core_existence(void *ctx) ...@@ -45,35 +45,34 @@ int test_core_existence(void *ctx)
struct core_reloc_existence_output *out = (void *)&data.out; struct core_reloc_existence_output *out = (void *)&data.out;
out->a_exists = bpf_core_field_exists(in->a); out->a_exists = bpf_core_field_exists(in->a);
if (bpf_core_field_exists(in->a)) if (bpf_core_field_exists(struct core_reloc_existence, a))
out->a_value = BPF_CORE_READ(in, a); out->a_value = BPF_CORE_READ(in, a);
else else
out->a_value = 0xff000001u; out->a_value = 0xff000001u;
out->b_exists = bpf_core_field_exists(in->b); out->b_exists = bpf_core_field_exists(in->b);
if (bpf_core_field_exists(in->b)) if (bpf_core_field_exists(struct core_reloc_existence, b))
out->b_value = BPF_CORE_READ(in, b); out->b_value = BPF_CORE_READ(in, b);
else else
out->b_value = 0xff000002u; out->b_value = 0xff000002u;
out->c_exists = bpf_core_field_exists(in->c); out->c_exists = bpf_core_field_exists(in->c);
if (bpf_core_field_exists(in->c)) if (bpf_core_field_exists(struct core_reloc_existence, c))
out->c_value = BPF_CORE_READ(in, c); out->c_value = BPF_CORE_READ(in, c);
else else
out->c_value = 0xff000003u; out->c_value = 0xff000003u;
out->arr_exists = bpf_core_field_exists(in->arr); out->arr_exists = bpf_core_field_exists(in->arr);
if (bpf_core_field_exists(in->arr)) if (bpf_core_field_exists(struct core_reloc_existence, arr))
out->arr_value = BPF_CORE_READ(in, arr[0]); out->arr_value = BPF_CORE_READ(in, arr[0]);
else else
out->arr_value = 0xff000004u; out->arr_value = 0xff000004u;
out->s_exists = bpf_core_field_exists(in->s); out->s_exists = bpf_core_field_exists(in->s);
if (bpf_core_field_exists(in->s)) if (bpf_core_field_exists(struct core_reloc_existence, s))
out->s_value = BPF_CORE_READ(in, s.x); out->s_value = BPF_CORE_READ(in, s.x);
else else
out->s_value = 0xff000005u; out->s_value = 0xff000005u;
return 0; return 0;
} }
...@@ -44,10 +44,10 @@ int test_core_size(void *ctx) ...@@ -44,10 +44,10 @@ int test_core_size(void *ctx)
out->struct_sz = bpf_core_field_size(in->struct_field); out->struct_sz = bpf_core_field_size(in->struct_field);
out->union_sz = bpf_core_field_size(in->union_field); out->union_sz = bpf_core_field_size(in->union_field);
out->arr_sz = bpf_core_field_size(in->arr_field); out->arr_sz = bpf_core_field_size(in->arr_field);
out->arr_elem_sz = bpf_core_field_size(in->arr_field[0]); out->arr_elem_sz = bpf_core_field_size(struct core_reloc_size, arr_field[0]);
out->ptr_sz = bpf_core_field_size(in->ptr_field); out->ptr_sz = bpf_core_field_size(struct core_reloc_size, ptr_field);
out->enum_sz = bpf_core_field_size(in->enum_field); out->enum_sz = bpf_core_field_size(struct core_reloc_size, enum_field);
out->float_sz = bpf_core_field_size(in->float_field); out->float_sz = bpf_core_field_size(struct core_reloc_size, float_field);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment