Skip to content

Commit

Permalink
selftests/bpf: Copy insn_is_pseudo_func() into testing_helpers
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Tiezhu Yang <[email protected]>
  • Loading branch information
Tiezhu Yang authored and intel-lab-lkp committed Jan 22, 2024
1 parent 51bc7c7 commit 627170b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tools/testing/selftests/bpf/testing_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

0 comments on commit 627170b

Please sign in to comment.