提交 565731ac 编写于 作者: J Johan Almbladh 提交者: Daniel Borkmann

bpf, tests: Add BPF_MOV tests for zero and sign extension

Tests for ALU32 and ALU64 MOV with different sizes of the immediate
value. Depending on the immediate field width of the native CPU
instructions, a JIT may generate code differently depending on the
immediate value. Test that zero or sign extension is performed as
expected. Mainly for JIT testing.
Signed-off-by: NJohan Almbladh <johan.almbladh@anyfinetworks.com>
Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
Acked-by: NYonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20210809091829.810076-3-johan.almbladh@anyfinetworks.com
上级 b55dfa85
......@@ -2360,6 +2360,48 @@ static struct bpf_test tests[] = {
{ },
{ { 0, 0x1 } },
},
{
"ALU_MOV_K: small negative",
.u.insns_int = {
BPF_ALU32_IMM(BPF_MOV, R0, -123),
BPF_EXIT_INSN(),
},
INTERNAL,
{ },
{ { 0, -123 } }
},
{
"ALU_MOV_K: small negative zero extension",
.u.insns_int = {
BPF_ALU32_IMM(BPF_MOV, R0, -123),
BPF_ALU64_IMM(BPF_RSH, R0, 32),
BPF_EXIT_INSN(),
},
INTERNAL,
{ },
{ { 0, 0 } }
},
{
"ALU_MOV_K: large negative",
.u.insns_int = {
BPF_ALU32_IMM(BPF_MOV, R0, -123456789),
BPF_EXIT_INSN(),
},
INTERNAL,
{ },
{ { 0, -123456789 } }
},
{
"ALU_MOV_K: large negative zero extension",
.u.insns_int = {
BPF_ALU32_IMM(BPF_MOV, R0, -123456789),
BPF_ALU64_IMM(BPF_RSH, R0, 32),
BPF_EXIT_INSN(),
},
INTERNAL,
{ },
{ { 0, 0 } }
},
{
"ALU64_MOV_K: dst = 2",
.u.insns_int = {
......@@ -2412,6 +2454,48 @@ static struct bpf_test tests[] = {
{ },
{ { 0, 0x1 } },
},
{
"ALU64_MOV_K: small negative",
.u.insns_int = {
BPF_ALU64_IMM(BPF_MOV, R0, -123),
BPF_EXIT_INSN(),
},
INTERNAL,
{ },
{ { 0, -123 } }
},
{
"ALU64_MOV_K: small negative sign extension",
.u.insns_int = {
BPF_ALU64_IMM(BPF_MOV, R0, -123),
BPF_ALU64_IMM(BPF_RSH, R0, 32),
BPF_EXIT_INSN(),
},
INTERNAL,
{ },
{ { 0, 0xffffffff } }
},
{
"ALU64_MOV_K: large negative",
.u.insns_int = {
BPF_ALU64_IMM(BPF_MOV, R0, -123456789),
BPF_EXIT_INSN(),
},
INTERNAL,
{ },
{ { 0, -123456789 } }
},
{
"ALU64_MOV_K: large negative sign extension",
.u.insns_int = {
BPF_ALU64_IMM(BPF_MOV, R0, -123456789),
BPF_ALU64_IMM(BPF_RSH, R0, 32),
BPF_EXIT_INSN(),
},
INTERNAL,
{ },
{ { 0, 0xffffffff } }
},
/* BPF_ALU | BPF_ADD | BPF_X */
{
"ALU_ADD_X: 1 + 2 = 3",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册