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

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
Loading
Loading
Loading
Loading
+5 −6
Original line number Diff line number Diff line
@@ -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;
}
+4 −4
Original line number Diff line number Diff line
@@ -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;
}