[PATCH bpf-next v6 2/3] selftests/bpf: Copy insn_is_pseudo_func() into testing_helpers

Tiezhu Yang posted 3 patches 1 year, 11 months ago
There is a newer version of this series
[PATCH bpf-next v6 2/3] selftests/bpf: Copy insn_is_pseudo_func() into testing_helpers
Posted by Tiezhu Yang 1 year, 11 months ago
insn_is_pseudo_func() will be used in test_verifier, the original idea is
to move it from libbpf.c to libbpf_internal.h and then include the header
to reuse this function, this just adds more internal code of libbpf used
by selftests. While we have allowed it in some cases to avoid duplication
of more complex logic, it is not justified in this case.

Since insn_is_pseudo_func() and its helper is_ldimm64_insn() are trivial
enough, just copy into testing_helpers.

Suggested-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 tools/testing/selftests/bpf/testing_helpers.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/tools/testing/selftests/bpf/testing_helpers.h b/tools/testing/selftests/bpf/testing_helpers.h
index d14de81727e6..cd77dce1b1da 100644
--- a/tools/testing/selftests/bpf/testing_helpers.h
+++ b/tools/testing/selftests/bpf/testing_helpers.h
@@ -54,4 +54,14 @@ int get_xlated_program(int fd_prog, struct bpf_insn **buf, __u32 *cnt);
 int testing_prog_flags(void);
 bool is_jit_enabled(void);
 
+static inline bool is_ldimm64_insn(struct bpf_insn *insn)
+{
+	return insn->code == (BPF_LD | BPF_IMM | BPF_DW);
+}
+
+static inline bool insn_is_pseudo_func(struct bpf_insn *insn)
+{
+	return is_ldimm64_insn(insn) && insn->src_reg == BPF_PSEUDO_FUNC;
+}
+
 #endif /* __TESTING_HELPERS_H */
-- 
2.42.0
Re: [PATCH bpf-next v6 2/3] selftests/bpf: Copy insn_is_pseudo_func() into testing_helpers
Posted by Song Liu 1 year, 11 months ago
On Sun, Jan 21, 2024 at 11:57 PM Tiezhu Yang <yangtiezhu@loongson.cn> wrote:
>
> insn_is_pseudo_func() will be used in test_verifier, the original idea is
> to move it from libbpf.c to libbpf_internal.h and then include the header
> to reuse this function, this just adds more internal code of libbpf used
> by selftests. While we have allowed it in some cases to avoid duplication
> of more complex logic, it is not justified in this case.
>
> Since insn_is_pseudo_func() and its helper is_ldimm64_insn() are trivial
> enough, just copy into testing_helpers.
>
> Suggested-by: Andrii Nakryiko <andrii@kernel.org>
> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>

Acked-by: Song Liu <song@kernel.org>