Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/lib/libbpfjit Add BPF_MOD tests. Plus one tiny change.
details: https://anonhg.NetBSD.org/src/rev/796cbfeb7379
branches: trunk
changeset: 333871:796cbfeb7379
user: alnsn <alnsn%NetBSD.org@localhost>
date: Thu Nov 20 11:08:29 2014 +0000
description:
Add BPF_MOD tests. Plus one tiny change.
diffstat:
tests/lib/libbpfjit/t_bpfjit.c | 508 ++++++++++++++++++++++++++++++++++++++++-
1 files changed, 505 insertions(+), 3 deletions(-)
diffs (truncated from 557 to 300 lines):
diff -r cc7aeeaba5e4 -r 796cbfeb7379 tests/lib/libbpfjit/t_bpfjit.c
--- a/tests/lib/libbpfjit/t_bpfjit.c Thu Nov 20 10:31:10 2014 +0000
+++ b/tests/lib/libbpfjit/t_bpfjit.c Thu Nov 20 11:08:29 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_bpfjit.c,v 1.7 2014/11/19 22:56:35 alnsn Exp $ */
+/* $NetBSD: t_bpfjit.c,v 1.8 2014/11/20 11:08:29 alnsn Exp $ */
/*-
* Copyright (c) 2011-2012, 2014 Alexander Nasonov.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_bpfjit.c,v 1.7 2014/11/19 22:56:35 alnsn Exp $");
+__RCSID("$NetBSD: t_bpfjit.c,v 1.8 2014/11/20 11:08:29 alnsn Exp $");
#include <atf-c.h>
#include <stdint.h>
@@ -399,6 +399,245 @@
bpfjit_free_code(code);
}
+ATF_TC(libbpfjit_alu_mod0_k);
+ATF_TC_HEAD(libbpfjit_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(libbpfjit_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)
+ };
+
+ 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) == 0);
+
+ bpfjit_free_code(code);
+}
+
+ATF_TC(libbpfjit_alu_mod1_k);
+ATF_TC_HEAD(libbpfjit_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(libbpfjit_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)
+ };
+
+ 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) == 0);
+
+ bpfjit_free_code(code);
+}
+
+ATF_TC(libbpfjit_alu_mod2_k);
+ATF_TC_HEAD(libbpfjit_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(libbpfjit_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)
+ };
+
+ 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) == 1);
+
+ bpfjit_free_code(code);
+}
+
+ATF_TC(libbpfjit_alu_mod4_k);
+ATF_TC_HEAD(libbpfjit_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(libbpfjit_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)
+ };
+
+ 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) == 3);
+
+ bpfjit_free_code(code);
+}
+
+ATF_TC(libbpfjit_alu_mod10_k);
+ATF_TC_HEAD(libbpfjit_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(libbpfjit_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)
+ };
+
+ 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) == 9);
+
+ bpfjit_free_code(code);
+}
+
+ATF_TC(libbpfjit_alu_mod10000_k);
+ATF_TC_HEAD(libbpfjit_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(libbpfjit_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)
+ };
+
+ 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) == 3849);
+
+ bpfjit_free_code(code);
+}
+
+ATF_TC(libbpfjit_alu_mod7609801_k);
+ATF_TC_HEAD(libbpfjit_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(libbpfjit_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)
+ };
+
+ 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) == UINT32_C(3039531));
+
+ bpfjit_free_code(code);
+}
+
+ATF_TC(libbpfjit_alu_mod80000000_k);
+ATF_TC_HEAD(libbpfjit_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(libbpfjit_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)
+ };
+
+ 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) == UINT32_C(0x7fffffde));
+
+ bpfjit_free_code(code);
+}
+
ATF_TC(libbpfjit_alu_and_k);
ATF_TC_HEAD(libbpfjit_alu_and_k, tc)
{
@@ -992,7 +1231,7 @@
ATF_TC_BODY(libbpfjit_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)
@@ -1013,6 +1252,253 @@
bpfjit_free_code(code);
}
+ATF_TC(libbpfjit_alu_mod0_x);
+ATF_TC_HEAD(libbpfjit_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(libbpfjit_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)
+ };
+
+ 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);
Home |
Main Index |
Thread Index |
Old Index