Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests Add BPF_XOR tests.
details: https://anonhg.NetBSD.org/src/rev/c9f44addbb3f
branches: trunk
changeset: 333862:c9f44addbb3f
user: alnsn <alnsn%NetBSD.org@localhost>
date: Wed Nov 19 22:56:35 2014 +0000
description:
Add BPF_XOR tests.
diffstat:
tests/lib/libbpfjit/t_bpfjit.c | 67 ++++++++++++++++++++++++++++++++++++++++-
tests/net/bpfjit/t_bpfjit.c | 57 ++++++++++++++++++++++++++++++++++-
2 files changed, 120 insertions(+), 4 deletions(-)
diffs (208 lines):
diff -r 4ec0bc0e8a7f -r c9f44addbb3f tests/lib/libbpfjit/t_bpfjit.c
--- a/tests/lib/libbpfjit/t_bpfjit.c Wed Nov 19 19:38:40 2014 +0000
+++ b/tests/lib/libbpfjit/t_bpfjit.c Wed Nov 19 22:56:35 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_bpfjit.c,v 1.6 2014/07/08 21:07:52 alnsn Exp $ */
+/* $NetBSD: t_bpfjit.c,v 1.7 2014/11/19 22:56:35 alnsn Exp $ */
/*-
* Copyright (c) 2011-2012, 2014 Alexander Nasonov.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_bpfjit.c,v 1.6 2014/07/08 21:07:52 alnsn Exp $");
+__RCSID("$NetBSD: t_bpfjit.c,v 1.7 2014/11/19 22:56:35 alnsn Exp $");
#include <atf-c.h>
#include <stdint.h>
@@ -459,6 +459,36 @@
bpfjit_free_code(code);
}
+ATF_TC(libbpfjit_alu_xor_k);
+ATF_TC_HEAD(libbpfjit_alu_xor_k, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test JIT compilation of BPF_ALU+BPF_XOR+BPF_K");
+}
+
+ATF_TC_BODY(libbpfjit_alu_xor_k, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_LD+BPF_IMM, 0xdead0f0f),
+ BPF_STMT(BPF_ALU+BPF_XOR+BPF_K, 0x0000b1e0),
+ BPF_STMT(BPF_RET+BPF_A, 0)
+ };
+
+ bpfjit_func_t code;
+ uint8_t pkt[1]; /* 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) == 0xdeadbeef);
+
+ bpfjit_free_code(code);
+}
+
ATF_TC(libbpfjit_alu_lsh_k);
ATF_TC_HEAD(libbpfjit_alu_lsh_k, tc)
{
@@ -1045,6 +1075,37 @@
bpfjit_free_code(code);
}
+ATF_TC(libbpfjit_alu_xor_x);
+ATF_TC_HEAD(libbpfjit_alu_xor_x, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test JIT compilation of BPF_ALU+BPF_XOR+BPF_X");
+}
+
+ATF_TC_BODY(libbpfjit_alu_xor_x, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_LD+BPF_IMM, 0xdead0f0f),
+ BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 0x0000b1e0),
+ BPF_STMT(BPF_ALU+BPF_XOR+BPF_X, 0),
+ BPF_STMT(BPF_RET+BPF_A, 0)
+ };
+
+ bpfjit_func_t code;
+ uint8_t pkt[1]; /* 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) == 0xdeadbeef);
+
+ bpfjit_free_code(code);
+}
+
ATF_TC(libbpfjit_alu_lsh_x);
ATF_TC_HEAD(libbpfjit_alu_lsh_x, tc)
{
@@ -3896,6 +3957,7 @@
ATF_TP_ADD_TC(tp, libbpfjit_alu_div80000000_k);
ATF_TP_ADD_TC(tp, libbpfjit_alu_and_k);
ATF_TP_ADD_TC(tp, libbpfjit_alu_or_k);
+ ATF_TP_ADD_TC(tp, libbpfjit_alu_xor_k);
ATF_TP_ADD_TC(tp, libbpfjit_alu_lsh_k);
ATF_TP_ADD_TC(tp, libbpfjit_alu_lsh0_k);
ATF_TP_ADD_TC(tp, libbpfjit_alu_rsh_k);
@@ -3914,6 +3976,7 @@
ATF_TP_ADD_TC(tp, libbpfjit_alu_div80000000_x);
ATF_TP_ADD_TC(tp, libbpfjit_alu_and_x);
ATF_TP_ADD_TC(tp, libbpfjit_alu_or_x);
+ ATF_TP_ADD_TC(tp, libbpfjit_alu_xor_x);
ATF_TP_ADD_TC(tp, libbpfjit_alu_lsh_x);
ATF_TP_ADD_TC(tp, libbpfjit_alu_lsh0_x);
ATF_TP_ADD_TC(tp, libbpfjit_alu_rsh_x);
diff -r 4ec0bc0e8a7f -r c9f44addbb3f tests/net/bpfjit/t_bpfjit.c
--- a/tests/net/bpfjit/t_bpfjit.c Wed Nov 19 19:38:40 2014 +0000
+++ b/tests/net/bpfjit/t_bpfjit.c Wed Nov 19 22:56:35 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_bpfjit.c,v 1.2 2014/07/08 21:44:26 alnsn Exp $ */
+/* $NetBSD: t_bpfjit.c,v 1.3 2014/11/19 23:00:12 alnsn Exp $ */
/*-
* Copyright (c) 2011-2012, 2014 Alexander Nasonov.
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_bpfjit.c,v 1.2 2014/07/08 21:44:26 alnsn Exp $");
+__RCSID("$NetBSD: t_bpfjit.c,v 1.3 2014/11/19 23:00:12 alnsn Exp $");
#include <sys/param.h>
#include <sys/mbuf.h>
@@ -414,6 +414,31 @@
ATF_CHECK(exec_prog(insns, insn_count, pkt, 1) == 0xdeadbeef);
}
+ATF_TC(bpfjit_alu_xor_k);
+ATF_TC_HEAD(bpfjit_alu_xor_k, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test JIT compilation of BPF_ALU+BPF_XOR+BPF_K");
+}
+
+ATF_TC_BODY(bpfjit_alu_xor_k, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_LD+BPF_IMM, 0xdead0f0f),
+ BPF_STMT(BPF_ALU+BPF_XOR+BPF_K, 0x0000b1e0),
+ 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) == 0xdeadbeef);
+}
+
ATF_TC(bpfjit_alu_lsh_k);
ATF_TC_HEAD(bpfjit_alu_lsh_k, tc)
{
@@ -920,6 +945,32 @@
ATF_CHECK(exec_prog(insns, insn_count, pkt, 1) == 0xdeadbeef);
}
+ATF_TC(bpfjit_alu_xor_x);
+ATF_TC_HEAD(bpfjit_alu_xor_x, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test JIT compilation of BPF_ALU+BPF_XOR+BPF_X");
+}
+
+ATF_TC_BODY(bpfjit_alu_xor_x, tc)
+{
+ static struct bpf_insn insns[] = {
+ BPF_STMT(BPF_LD+BPF_IMM, 0xdead0f0f),
+ BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 0x0000b1e0),
+ BPF_STMT(BPF_ALU+BPF_XOR+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) == 0xdeadbeef);
+}
+
ATF_TC(bpfjit_alu_lsh_x);
ATF_TC_HEAD(bpfjit_alu_lsh_x, tc)
{
@@ -3900,6 +3951,7 @@
ATF_TP_ADD_TC(tp, bpfjit_alu_div80000000_k);
ATF_TP_ADD_TC(tp, bpfjit_alu_and_k);
ATF_TP_ADD_TC(tp, bpfjit_alu_or_k);
+ ATF_TP_ADD_TC(tp, bpfjit_alu_xor_k);
ATF_TP_ADD_TC(tp, bpfjit_alu_lsh_k);
ATF_TP_ADD_TC(tp, bpfjit_alu_lsh0_k);
ATF_TP_ADD_TC(tp, bpfjit_alu_rsh_k);
@@ -3918,6 +3970,7 @@
ATF_TP_ADD_TC(tp, bpfjit_alu_div80000000_x);
ATF_TP_ADD_TC(tp, bpfjit_alu_and_x);
ATF_TP_ADD_TC(tp, bpfjit_alu_or_x);
+ ATF_TP_ADD_TC(tp, bpfjit_alu_xor_x);
ATF_TP_ADD_TC(tp, bpfjit_alu_lsh_x);
ATF_TP_ADD_TC(tp, bpfjit_alu_lsh0_x);
ATF_TP_ADD_TC(tp, bpfjit_alu_rsh_x);
Home |
Main Index |
Thread Index |
Old Index