Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/net/bpfjit Add BPF_MOD tests. Plus one tiny change.
details: https://anonhg.NetBSD.org/src/rev/82cfbc371f6e
branches: trunk
changeset: 333872:82cfbc371f6e
user: alnsn <alnsn%NetBSD.org@localhost>
date: Thu Nov 20 11:36:13 2014 +0000
description:
Add BPF_MOD tests. Plus one tiny change.
diffstat:
tests/net/bpfjit/t_bpfjit.c | 428 +++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 425 insertions(+), 3 deletions(-)
diffs (truncated from 477 to 300 lines):
diff -r 796cbfeb7379 -r 82cfbc371f6e tests/net/bpfjit/t_bpfjit.c
--- a/tests/net/bpfjit/t_bpfjit.c Thu Nov 20 11:08:29 2014 +0000
+++ b/tests/net/bpfjit/t_bpfjit.c Thu Nov 20 11:36:13 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_bpfjit.c,v 1.3 2014/11/19 23:00:12 alnsn Exp $ */
+/* $NetBSD: t_bpfjit.c,v 1.4 2014/11/20 11:36:13 alnsn Exp $ */
/*-
* Copyright (c) 2011-2012, 2014 Alexander Nasonov.
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_bpfjit.c,v 1.3 2014/11/19 23:00:12 alnsn Exp $");
+__RCSID("$NetBSD: t_bpfjit.c,v 1.4 2014/11/20 11:36:13 alnsn Exp $");
#include <sys/param.h>
#include <sys/mbuf.h>
@@ -364,6 +364,205 @@
ATF_CHECK(exec_prog(insns, insn_count, pkt, 1) == 1);
}
+ATF_TC(bpfjit_alu_mod0_k);
+ATF_TC_HEAD(bpfjit_alu_mod0_k, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test JIT compilation of BPF_ALU+BPF_MOD+BPF_K with k=0");
+}
+
+ATF_TC_BODY(bpfjit_alu_mod0_k, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_ALU+BPF_MOD+BPF_K, 0),
+ BPF_STMT(BPF_RET+BPF_A, 0)
+ };
+
+ uint8_t pkt[1]; /* the program doesn't read any data */
+
+ size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+ RZ(rump_init());
+
+ //ATF_CHECK(prog_validate(insns, insn_count));
+ ATF_CHECK(exec_prog(insns, insn_count, pkt, 1) == 0);
+}
+
+ATF_TC(bpfjit_alu_mod1_k);
+ATF_TC_HEAD(bpfjit_alu_mod1_k, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test JIT compilation of BPF_ALU+BPF_MOD+BPF_K with k=1");
+}
+
+ATF_TC_BODY(bpfjit_alu_mod1_k, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_LD+BPF_IMM, 7),
+ BPF_STMT(BPF_ALU+BPF_MOD+BPF_K, 1),
+ BPF_STMT(BPF_RET+BPF_A, 0)
+ };
+
+ uint8_t pkt[1]; /* the program doesn't read any data */
+
+ size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+ RZ(rump_init());
+
+ ATF_CHECK(prog_validate(insns, insn_count));
+ ATF_CHECK(exec_prog(insns, insn_count, pkt, 1) == 0);
+}
+
+ATF_TC(bpfjit_alu_mod2_k);
+ATF_TC_HEAD(bpfjit_alu_mod2_k, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test JIT compilation of BPF_ALU+BPF_MOD+BPF_K with k=2");
+}
+
+ATF_TC_BODY(bpfjit_alu_mod2_k, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_LD+BPF_IMM, 7),
+ BPF_STMT(BPF_ALU+BPF_MOD+BPF_K, 2),
+ BPF_STMT(BPF_RET+BPF_A, 0)
+ };
+
+ uint8_t pkt[1]; /* the program doesn't read any data */
+
+ size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+ RZ(rump_init());
+
+ ATF_CHECK(prog_validate(insns, insn_count));
+ ATF_CHECK(exec_prog(insns, insn_count, pkt, 1) == 1);
+}
+
+ATF_TC(bpfjit_alu_mod4_k);
+ATF_TC_HEAD(bpfjit_alu_mod4_k, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test JIT compilation of BPF_ALU+BPF_MOD+BPF_K with k=4");
+}
+
+ATF_TC_BODY(bpfjit_alu_mod4_k, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(0xffffffff)),
+ BPF_STMT(BPF_ALU+BPF_MOD+BPF_K, 4),
+ BPF_STMT(BPF_RET+BPF_A, 0)
+ };
+
+ uint8_t pkt[1]; /* the program doesn't read any data */
+
+ size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+ RZ(rump_init());
+
+ ATF_CHECK(prog_validate(insns, insn_count));
+ ATF_CHECK(exec_prog(insns, insn_count, pkt, 1) == 3);
+}
+
+ATF_TC(bpfjit_alu_mod10_k);
+ATF_TC_HEAD(bpfjit_alu_mod10_k, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test JIT compilation of BPF_ALU+BPF_MOD+BPF_K with k=10");
+}
+
+ATF_TC_BODY(bpfjit_alu_mod10_k, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(4294843849)),
+ BPF_STMT(BPF_ALU+BPF_MOD+BPF_K, 10),
+ BPF_STMT(BPF_RET+BPF_A, 0)
+ };
+
+ uint8_t pkt[1]; /* the program doesn't read any data */
+
+ size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+ RZ(rump_init());
+
+ ATF_CHECK(prog_validate(insns, insn_count));
+ ATF_CHECK(exec_prog(insns, insn_count, pkt, 1) == 9);
+}
+
+ATF_TC(bpfjit_alu_mod10000_k);
+ATF_TC_HEAD(bpfjit_alu_mod10000_k, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test JIT compilation of BPF_ALU+BPF_MOD+BPF_K with k=10000");
+}
+
+ATF_TC_BODY(bpfjit_alu_mod10000_k, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(4294843849)),
+ BPF_STMT(BPF_ALU+BPF_MOD+BPF_K, 10000),
+ BPF_STMT(BPF_RET+BPF_A, 0)
+ };
+
+ uint8_t pkt[1]; /* the program doesn't read any data */
+
+ size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+ RZ(rump_init());
+
+ ATF_CHECK(prog_validate(insns, insn_count));
+ ATF_CHECK(exec_prog(insns, insn_count, pkt, 1) == 3849);
+}
+
+ATF_TC(bpfjit_alu_mod7609801_k);
+ATF_TC_HEAD(bpfjit_alu_mod7609801_k, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test JIT compilation of BPF_ALU+BPF_MOD+BPF_K with k=7609801");
+}
+
+ATF_TC_BODY(bpfjit_alu_mod7609801_k, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(4294967295)),
+ BPF_STMT(BPF_ALU+BPF_MOD+BPF_K, UINT32_C(7609801)),
+ BPF_STMT(BPF_RET+BPF_A, 0)
+ };
+
+ uint8_t pkt[1]; /* the program doesn't read any data */
+
+ size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+ RZ(rump_init());
+
+ ATF_CHECK(prog_validate(insns, insn_count));
+ ATF_CHECK(exec_prog(insns, insn_count, pkt, 1) == 3039531);
+}
+
+ATF_TC(bpfjit_alu_mod80000000_k);
+ATF_TC_HEAD(bpfjit_alu_mod80000000_k, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test JIT compilation of BPF_ALU+BPF_MOD+BPF_K with k=0x80000000");
+}
+
+ATF_TC_BODY(bpfjit_alu_mod80000000_k, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(0xffffffde)),
+ BPF_STMT(BPF_ALU+BPF_MOD+BPF_K, UINT32_C(0x80000000)),
+ BPF_STMT(BPF_RET+BPF_A, 0)
+ };
+
+ uint8_t pkt[1]; /* the program doesn't read any data */
+
+ size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+ RZ(rump_init());
+
+ ATF_CHECK(prog_validate(insns, insn_count));
+ ATF_CHECK(exec_prog(insns, insn_count, pkt, 1) == UINT32_C(0x7fffffde));
+}
+
ATF_TC(bpfjit_alu_and_k);
ATF_TC_HEAD(bpfjit_alu_and_k, tc)
{
@@ -877,7 +1076,7 @@
ATF_TC_BODY(bpfjit_alu_div80000000_x, tc)
{
static struct bpf_insn insns[] = {
- BPF_STMT(BPF_LD+BPF_IMM, UINT32_MAX - 33),
+ BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(0xffffffde)),
BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, UINT32_C(0x80000000)),
BPF_STMT(BPF_ALU+BPF_DIV+BPF_X, 0),
BPF_STMT(BPF_RET+BPF_A, 0)
@@ -893,6 +1092,213 @@
ATF_CHECK(exec_prog(insns, insn_count, pkt, 1) == 1);
}
+ATF_TC(bpfjit_alu_mod0_x);
+ATF_TC_HEAD(bpfjit_alu_mod0_x, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test JIT compilation of BPF_ALU+BPF_MOD+BPF_X with X=0");
+}
+
+ATF_TC_BODY(bpfjit_alu_mod0_x, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 0),
+ BPF_STMT(BPF_ALU+BPF_MOD+BPF_X, 0),
+ BPF_STMT(BPF_RET+BPF_A, 0)
+ };
+
+ uint8_t pkt[1]; /* the program doesn't read any data */
+
+ size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+ RZ(rump_init());
+
+ ATF_CHECK(prog_validate(insns, insn_count));
+ ATF_CHECK(exec_prog(insns, insn_count, pkt, 1) == 0);
+}
+
+ATF_TC(bpfjit_alu_mod1_x);
+ATF_TC_HEAD(bpfjit_alu_mod1_x, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test JIT compilation of BPF_ALU+BPF_MOD+BPF_X with X=1");
+}
+
+ATF_TC_BODY(bpfjit_alu_mod1_x, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_LD+BPF_IMM, 7),
+ BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 1),
+ BPF_STMT(BPF_ALU+BPF_MOD+BPF_X, 0),
+ BPF_STMT(BPF_RET+BPF_A, 0)
+ };
+
+ uint8_t pkt[1]; /* the program doesn't read any data */
+
+ size_t insn_count = sizeof(insns) / sizeof(insns[0]);
+
+ RZ(rump_init());
+
+ ATF_CHECK(prog_validate(insns, insn_count));
+ ATF_CHECK(exec_prog(insns, insn_count, pkt, 1) == 0);
+}
+
+ATF_TC(bpfjit_alu_mod2_x);
+ATF_TC_HEAD(bpfjit_alu_mod2_x, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test JIT compilation of BPF_ALU+BPF_MOD+BPF_X with X=2");
+}
+
+ATF_TC_BODY(bpfjit_alu_mod2_x, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_LD+BPF_IMM, 7),
+ BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 2),
Home |
Main Index |
Thread Index |
Old Index