selftests/bpf: Use both syntaxes for field-based CO-RE helpers
authorAndrii Nakryiko <andrii@kernel.org>
Mon, 9 May 2022 00:41:43 +0000 (17:41 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Mon, 9 May 2022 15:15:32 +0000 (17:15 +0200)
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: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20220509004148.1801791-5-andrii@kernel.org
tools/testing/selftests/bpf/progs/test_core_reloc_existence.c
tools/testing/selftests/bpf/progs/test_core_reloc_size.c

index 7e45e2b..5b8a750 100644 (file)
@@ -45,35 +45,34 @@ int test_core_existence(void *ctx)
        struct core_reloc_existence_output *out = (void *)&data.out;
 
        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);
        else
                out->a_value = 0xff000001u;
 
        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);
        else
                out->b_value = 0xff000002u;
 
        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);
        else
                out->c_value = 0xff000003u;
 
        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]);
        else
                out->arr_value = 0xff000004u;
 
        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);
        else
                out->s_value = 0xff000005u;
 
        return 0;
 }
-
index 7b2d576..6766add 100644 (file)
@@ -44,10 +44,10 @@ int test_core_size(void *ctx)
        out->struct_sz = bpf_core_field_size(in->struct_field);
        out->union_sz = bpf_core_field_size(in->union_field);
        out->arr_sz = bpf_core_field_size(in->arr_field);
-       out->arr_elem_sz = bpf_core_field_size(in->arr_field[0]);
-       out->ptr_sz = bpf_core_field_size(in->ptr_field);
-       out->enum_sz = bpf_core_field_size(in->enum_field);
-       out->float_sz = bpf_core_field_size(in->float_field);
+       out->arr_elem_sz = bpf_core_field_size(struct core_reloc_size, arr_field[0]);
+       out->ptr_sz = bpf_core_field_size(struct core_reloc_size, ptr_field);
+       out->enum_sz = bpf_core_field_size(struct core_reloc_size, enum_field);
+       out->float_sz = bpf_core_field_size(struct core_reloc_size, float_field);
 
        return 0;
 }