selftests/bpf: Add unit tests for new bswap insns
Add unit tests for bswap insns. Signed-off-by: Yonghong Song <yonghong.song@linux.dev> Link: https://lore.kernel.org/r/20230728011314.3720109-1-yonghong.song@linux.dev Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
f02ec3ff3f
commit
79dbabc175
@ -11,6 +11,7 @@
|
||||
#include "verifier_bounds_deduction_non_const.skel.h"
|
||||
#include "verifier_bounds_mix_sign_unsign.skel.h"
|
||||
#include "verifier_bpf_get_stack.skel.h"
|
||||
#include "verifier_bswap.skel.h"
|
||||
#include "verifier_btf_ctx_access.skel.h"
|
||||
#include "verifier_cfg.skel.h"
|
||||
#include "verifier_cgroup_inv_retcode.skel.h"
|
||||
@ -115,6 +116,7 @@ void test_verifier_bounds_deduction(void) { RUN(verifier_bounds_deduction);
|
||||
void test_verifier_bounds_deduction_non_const(void) { RUN(verifier_bounds_deduction_non_const); }
|
||||
void test_verifier_bounds_mix_sign_unsign(void) { RUN(verifier_bounds_mix_sign_unsign); }
|
||||
void test_verifier_bpf_get_stack(void) { RUN(verifier_bpf_get_stack); }
|
||||
void test_verifier_bswap(void) { RUN(verifier_bswap); }
|
||||
void test_verifier_btf_ctx_access(void) { RUN(verifier_btf_ctx_access); }
|
||||
void test_verifier_cfg(void) { RUN(verifier_cfg); }
|
||||
void test_verifier_cgroup_inv_retcode(void) { RUN(verifier_cgroup_inv_retcode); }
|
||||
|
59
tools/testing/selftests/bpf/progs/verifier_bswap.c
Normal file
59
tools/testing/selftests/bpf/progs/verifier_bswap.c
Normal file
@ -0,0 +1,59 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
#include <linux/bpf.h>
|
||||
#include <bpf/bpf_helpers.h>
|
||||
#include "bpf_misc.h"
|
||||
|
||||
#if defined(__TARGET_ARCH_x86) && __clang_major__ >= 18
|
||||
|
||||
SEC("socket")
|
||||
__description("BSWAP, 16")
|
||||
__success __success_unpriv __retval(0x23ff)
|
||||
__naked void bswap_16(void)
|
||||
{
|
||||
asm volatile (" \
|
||||
r0 = 0xff23; \
|
||||
r0 = bswap16 r0; \
|
||||
exit; \
|
||||
" ::: __clobber_all);
|
||||
}
|
||||
|
||||
SEC("socket")
|
||||
__description("BSWAP, 32")
|
||||
__success __success_unpriv __retval(0x23ff0000)
|
||||
__naked void bswap_32(void)
|
||||
{
|
||||
asm volatile (" \
|
||||
r0 = 0xff23; \
|
||||
r0 = bswap32 r0; \
|
||||
exit; \
|
||||
" ::: __clobber_all);
|
||||
}
|
||||
|
||||
SEC("socket")
|
||||
__description("BSWAP, 64")
|
||||
__success __success_unpriv __retval(0x34ff12ff)
|
||||
__naked void bswap_64(void)
|
||||
{
|
||||
asm volatile (" \
|
||||
r0 = %[u64_val] ll; \
|
||||
r0 = bswap64 r0; \
|
||||
exit; \
|
||||
" :
|
||||
: [u64_val]"i"(0xff12ff34ff56ff78ull)
|
||||
: __clobber_all);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
SEC("socket")
|
||||
__description("cpuv4 is not supported by compiler or jit, use a dummy test")
|
||||
__success
|
||||
int dummy_test(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
Loading…
x
Reference in New Issue
Block a user