Improve libbpfjit_jmp_jeq_x test.
This commit is contained in:
parent
73969c29cc
commit
3228cf99a8
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: t_bpfjit.c,v 1.11 2015/02/11 23:33:16 alnsn Exp $ */
|
||||
/* $NetBSD: t_bpfjit.c,v 1.12 2015/02/14 20:29:36 alnsn Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2011-2012, 2014 Alexander Nasonov.
|
||||
@ -30,7 +30,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: t_bpfjit.c,v 1.11 2015/02/11 23:33:16 alnsn Exp $");
|
||||
__RCSID("$NetBSD: t_bpfjit.c,v 1.12 2015/02/14 20:29:36 alnsn Exp $");
|
||||
|
||||
#include <atf-c.h>
|
||||
#include <stdint.h>
|
||||
@ -2354,26 +2354,26 @@ ATF_TC_BODY(libbpfjit_jmp_jeq_x, tc)
|
||||
BPF_STMT(BPF_LD+BPF_W+BPF_LEN, 0),
|
||||
BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 8),
|
||||
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 0, 1),
|
||||
BPF_STMT(BPF_RET+BPF_K, 0),
|
||||
BPF_STMT(BPF_RET+BPF_K, 1),
|
||||
BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 3),
|
||||
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 2, 0),
|
||||
BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 9),
|
||||
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 1, 1),
|
||||
BPF_STMT(BPF_RET+BPF_K, 1),
|
||||
BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 5),
|
||||
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 1, 1),
|
||||
BPF_STMT(BPF_RET+BPF_K, 2),
|
||||
BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 5),
|
||||
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 0, 1),
|
||||
BPF_STMT(BPF_RET+BPF_K, 3),
|
||||
BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 7),
|
||||
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 2, 3),
|
||||
BPF_STMT(BPF_RET+BPF_K, 3),
|
||||
BPF_STMT(BPF_RET+BPF_K, 4),
|
||||
BPF_STMT(BPF_RET+BPF_K, 5),
|
||||
BPF_STMT(BPF_RET+BPF_K, 6),
|
||||
BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 6),
|
||||
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 3, 1),
|
||||
BPF_STMT(BPF_RET+BPF_K, 6),
|
||||
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 1, 0, 0),
|
||||
BPF_STMT(BPF_RET+BPF_K, 7),
|
||||
BPF_STMT(BPF_RET+BPF_K, 8)
|
||||
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 1, 0),
|
||||
BPF_STMT(BPF_RET+BPF_K, 8),
|
||||
BPF_STMT(BPF_RET+BPF_K, 9)
|
||||
};
|
||||
|
||||
bpfjit_func_t code;
|
||||
@ -2386,14 +2386,14 @@ ATF_TC_BODY(libbpfjit_jmp_jeq_x, tc)
|
||||
code = bpfjit_generate_code(NULL, insns, insn_count);
|
||||
ATF_REQUIRE(code != NULL);
|
||||
|
||||
ATF_CHECK(jitcall(code, pkt, 1, 1) == 7);
|
||||
ATF_CHECK(jitcall(code, pkt, 2, 2) == 7);
|
||||
ATF_CHECK(jitcall(code, pkt, 3, 3) == 1);
|
||||
ATF_CHECK(jitcall(code, pkt, 4, 4) == 7);
|
||||
ATF_CHECK(jitcall(code, pkt, 5, 5) == 7);
|
||||
ATF_CHECK(jitcall(code, pkt, 6, 6) == 8);
|
||||
ATF_CHECK(jitcall(code, pkt, 7, 7) == 5);
|
||||
ATF_CHECK(jitcall(code, pkt, 8, 8) == 0);
|
||||
ATF_CHECK(jitcall(code, pkt, 1, 1) == 8);
|
||||
ATF_CHECK(jitcall(code, pkt, 2, 2) == 8);
|
||||
ATF_CHECK(jitcall(code, pkt, 3, 3) == 2);
|
||||
ATF_CHECK(jitcall(code, pkt, 4, 4) == 8);
|
||||
ATF_CHECK(jitcall(code, pkt, 5, 5) == 3);
|
||||
ATF_CHECK(jitcall(code, pkt, 6, 6) == 9);
|
||||
ATF_CHECK(jitcall(code, pkt, 7, 7) == 6);
|
||||
ATF_CHECK(jitcall(code, pkt, 8, 8) == 1);
|
||||
|
||||
bpfjit_free_code(code);
|
||||
}
|
||||
@ -2455,6 +2455,37 @@ ATF_TC_BODY(libbpfjit_jmp_jset_x, tc)
|
||||
bpfjit_free_code(code);
|
||||
}
|
||||
|
||||
ATF_TC(libbpfjit_jmp_x_uninitialised);
|
||||
ATF_TC_HEAD(libbpfjit_jmp_x_uninitialised, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Test JIT compilation "
|
||||
"of BPF_JMP+BPF_EQ+BPF_X with uninitialised X");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(libbpfjit_jmp_x_uninitialised, tc)
|
||||
{
|
||||
static struct bpf_insn insns[] = {
|
||||
BPF_STMT(BPF_LD+BPF_W+BPF_LEN, 0), /* A > 0 */
|
||||
BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 0, 1),
|
||||
BPF_STMT(BPF_RET+BPF_K, 11),
|
||||
BPF_STMT(BPF_RET+BPF_K, 10)
|
||||
};
|
||||
|
||||
bpfjit_func_t code;
|
||||
uint8_t pkt[8]; /* the program doesn't read any data */
|
||||
|
||||
size_t insn_count = sizeof(insns) / sizeof(insns[0]);
|
||||
|
||||
ATF_CHECK(bpf_validate(insns, insn_count));
|
||||
|
||||
code = bpfjit_generate_code(NULL, insns, insn_count);
|
||||
ATF_REQUIRE(code != NULL);
|
||||
|
||||
ATF_CHECK(jitcall(code, pkt, 1, 1) == 10);
|
||||
|
||||
bpfjit_free_code(code);
|
||||
}
|
||||
|
||||
ATF_TC(libbpfjit_jmp_modulo_x);
|
||||
ATF_TC_HEAD(libbpfjit_jmp_modulo_x, tc)
|
||||
{
|
||||
@ -4613,6 +4644,7 @@ ATF_TP_ADD_TCS(tp)
|
||||
ATF_TP_ADD_TC(tp, libbpfjit_jmp_jge_x);
|
||||
ATF_TP_ADD_TC(tp, libbpfjit_jmp_jeq_x);
|
||||
ATF_TP_ADD_TC(tp, libbpfjit_jmp_jset_x);
|
||||
ATF_TP_ADD_TC(tp, libbpfjit_jmp_x_uninitialised);
|
||||
ATF_TP_ADD_TC(tp, libbpfjit_jmp_modulo_x);
|
||||
ATF_TP_ADD_TC(tp, libbpfjit_ld_abs);
|
||||
ATF_TP_ADD_TC(tp, libbpfjit_ld_abs_k_overflow);
|
||||
|
Loading…
Reference in New Issue
Block a user