Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/net Clone libbpfjit tests to check kernel implementati...
details: https://anonhg.NetBSD.org/src/rev/0daf7319c9b2
branches: trunk
changeset: 330440:0daf7319c9b2
user: alnsn <alnsn%NetBSD.org@localhost>
date: Tue Jul 08 21:44:26 2014 +0000
description:
Clone libbpfjit tests to check kernel implementation of bpfjit.
Old content of t_bpfjit.c will be moved to t_mbuf.c shortly.
Change packet buffers to unsigned char[] type.
diffstat:
tests/net/bpf/h_bpf.h | 40 +-
tests/net/bpf/t_mbuf.c | 46 +-
tests/net/bpfjit/t_bpfjit.c | 4281 ++++++++++++++++++++++++++++++++++++++----
3 files changed, 3854 insertions(+), 513 deletions(-)
diffs (truncated from 4736 to 300 lines):
diff -r d9fd2f6c59fe -r 0daf7319c9b2 tests/net/bpf/h_bpf.h
--- a/tests/net/bpf/h_bpf.h Tue Jul 08 21:13:01 2014 +0000
+++ b/tests/net/bpf/h_bpf.h Tue Jul 08 21:44:26 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: h_bpf.h,v 1.1 2014/07/07 19:34:32 alnsn Exp $ */
+/* $NetBSD: h_bpf.h,v 1.2 2014/07/08 21:44:26 alnsn Exp $ */
/*-
* Copyright (c) 2014 Alexander Nasonov.
@@ -57,18 +57,18 @@
*/
static inline const uint8_t *
init_mchain2(struct mbuf *mb1, struct mbuf *mb2,
- char pkt[], size_t pktsize, size_t split)
+ unsigned char pkt[], size_t pktsize, size_t split)
{
(void)memset(mb1, 0, sizeof(*mb1));
- mb1->m_data = pkt;
+ mb1->m_data = (char *)pkt;
mb1->m_next = (split < pktsize) ? mb2 : NULL;
mb1->m_len = (split < pktsize) ? split : pktsize;
if (split < pktsize) {
(void)memset(mb2, 0, sizeof(*mb2));
mb2->m_next = NULL;
- mb2->m_data = &pkt[split];
+ mb2->m_data = (char *)&pkt[split];
mb2->m_len = pktsize - split;
}
@@ -76,11 +76,39 @@
}
/*
+ * Compile and run a filter program.
+ */
+static inline unsigned int
+exec_prog(struct bpf_insn *insns, size_t insn_count,
+ unsigned char pkt[], size_t pktsize)
+{
+ bpfjit_func_t fn;
+ bpf_args_t args;
+ unsigned int res;
+
+ args.pkt = (const uint8_t *)pkt;
+ args.buflen = pktsize;
+ args.wirelen = pktsize;
+
+ rump_schedule();
+ fn = rumpns_bpfjit_generate_code(NULL, insns, insn_count);
+ rump_unschedule();
+
+ res = fn(NULL, &args);
+
+ rump_schedule();
+ rumpns_bpfjit_free_code(fn);
+ rump_unschedule();
+
+ return res;
+}
+
+/*
* Interpret a filter program with mbuf chain passed to bpf_filter_ext().
*/
static inline unsigned int
interp_prog_mchain2(struct bpf_insn *insns,
- char *pkt, size_t pktsize, size_t split)
+ unsigned char pkt[], size_t pktsize, size_t split)
{
uint32_t mem[BPF_MEMWORDS];
struct mbuf mb1, mb2;
@@ -104,7 +132,7 @@
*/
static inline unsigned int
exec_prog_mchain2(struct bpf_insn *insns, size_t insn_count,
- char *pkt, size_t pktsize, size_t split)
+ unsigned char pkt[], size_t pktsize, size_t split)
{
bpfjit_func_t fn;
struct mbuf mb1, mb2;
diff -r d9fd2f6c59fe -r 0daf7319c9b2 tests/net/bpf/t_mbuf.c
--- a/tests/net/bpf/t_mbuf.c Tue Jul 08 21:13:01 2014 +0000
+++ b/tests/net/bpf/t_mbuf.c Tue Jul 08 21:44:26 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mbuf.c,v 1.1 2014/07/07 19:40:28 alnsn Exp $ */
+/* $NetBSD: t_mbuf.c,v 1.2 2014/07/08 21:44:26 alnsn Exp $ */
/*-
* Copyright (c) 2014 Alexander Nasonov.
@@ -27,16 +27,14 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_mbuf.c,v 1.1 2014/07/07 19:40:28 alnsn Exp $");
+__RCSID("$NetBSD: t_mbuf.c,v 1.2 2014/07/08 21:44:26 alnsn Exp $");
#include <sys/param.h>
#include <sys/mbuf.h>
-#include <unistd.h>
#include <net/bpf.h>
#include <stdint.h>
-#include <stdio.h>
#include <string.h>
#include <rump/rump.h>
@@ -79,7 +77,7 @@
BPF_STMT(BPF_RET+BPF_A, 0), /* ret A */
};
- static char P[] = { 1, 2, 3, 4, 5 };
+ static unsigned char P[] = { 1, 2, 3, 4, 5 };
const unsigned int res = 120;
if (!prog_validate(insns, sizeof(insns) / sizeof(insns[0])))
@@ -109,7 +107,7 @@
BPF_STMT(BPF_RET+BPF_A, 0), /* ret A */
};
- static char P[] = { 1, 2, 3, 4, 5 };
+ static unsigned char P[] = { 1, 2, 3, 4, 5 };
const unsigned int res = 0x0a0e; /* 10 14 */
if (!prog_validate(insns, sizeof(insns) / sizeof(insns[0])))
@@ -131,7 +129,7 @@
BPF_STMT(BPF_RET+BPF_A, 0), /* ret A */
};
- static char P[] = { 1, 2, 3, 4, 5 };
+ static unsigned char P[] = { 1, 2, 3, 4, 5 };
const unsigned int res = 0x03050709;
if (!prog_validate(insns, sizeof(insns) / sizeof(insns[0])))
@@ -172,7 +170,7 @@
BPF_STMT(BPF_RET+BPF_A, 0), /* ret A */
};
- static char P[] = { 1, 2, 3, 4, 5 };
+ static unsigned char P[] = { 1, 2, 3, 4, 5 };
const unsigned int res = 15;
if (!prog_validate(insns, sizeof(insns) / sizeof(insns[0])))
@@ -201,7 +199,7 @@
BPF_STMT(BPF_RET+BPF_A, 0), /* ret A */
};
- static char P[] = { 1, 2, 3, 4, 5 };
+ static unsigned char P[] = { 1, 2, 3, 4, 5 };
const unsigned int res = 0x05080b0e;
if (!prog_validate(insns, sizeof(insns) / sizeof(insns[0])))
@@ -235,7 +233,7 @@
BPF_STMT(BPF_RET+BPF_A, 0), /* ret A */
};
- static char P[] = { 1, 2, 3, 4, 5 };
+ static unsigned char P[] = { 1, 2, 3, 4, 5 };
const unsigned int res = 0x0a0e; /* 10 14 */
if (!prog_validate(insns, sizeof(insns) / sizeof(insns[0])))
@@ -274,7 +272,7 @@
BPF_STMT(BPF_RET+BPF_A, 0), /* ret A */
};
- static char P[] = { 1, 2, 3, 4, 5 };
+ static unsigned char P[] = { 1, 2, 3, 4, 5 };
const unsigned int res = 120;
if (!prog_validate(insns, sizeof(insns) / sizeof(insns[0])))
@@ -292,7 +290,7 @@
BPF_STMT(BPF_RET+BPF_A, 0),
};
- static char P[] = { 1, 2, 3, 4, 5 };
+ static unsigned char P[] = { 1, 2, 3, 4, 5 };
if (!prog_validate(insns, sizeof(insns) / sizeof(insns[0])))
return false;
@@ -309,7 +307,7 @@
BPF_STMT(BPF_RET+BPF_A, 0),
};
- static char P[] = { 1, 2, 3, 4, 5 };
+ static unsigned char P[] = { 1, 2, 3, 4, 5 };
if (!prog_validate(insns, sizeof(insns) / sizeof(insns[0])))
return false;
@@ -326,7 +324,7 @@
BPF_STMT(BPF_RET+BPF_A, 0),
};
- static char P[] = { 1, 2, 3, 4, 5 };
+ static unsigned char P[] = { 1, 2, 3, 4, 5 };
if (!prog_validate(insns, sizeof(insns) / sizeof(insns[0])))
return false;
@@ -343,7 +341,7 @@
BPF_STMT(BPF_RET+BPF_A, 0),
};
- static char P[] = { 1, 2, 3, 4, 5 };
+ static unsigned char P[] = { 1, 2, 3, 4, 5 };
if (!prog_validate(insns, sizeof(insns) / sizeof(insns[0])))
return false;
@@ -361,7 +359,7 @@
BPF_STMT(BPF_RET+BPF_A, 0),
};
- static char P[] = { 1, 2, 3, 4, 5 };
+ static unsigned char P[] = { 1, 2, 3, 4, 5 };
if (!prog_validate(insns, sizeof(insns) / sizeof(insns[0])))
return false;
@@ -379,7 +377,7 @@
BPF_STMT(BPF_RET+BPF_A, 0),
};
- static char P[] = { 1, 2, 3, 4, 5 };
+ static unsigned char P[] = { 1, 2, 3, 4, 5 };
if (!prog_validate(insns, sizeof(insns) / sizeof(insns[0])))
return false;
@@ -396,7 +394,7 @@
BPF_STMT(BPF_RET+BPF_A, 0),
};
- static char P[] = { 1, 2, 3, 4, 5 };
+ static unsigned char P[] = { 1, 2, 3, 4, 5 };
if (!prog_validate(insns, sizeof(insns) / sizeof(insns[0])))
return false;
@@ -414,7 +412,7 @@
BPF_STMT(BPF_RET+BPF_A, 0),
};
- static char P[] = { 1, 2, 3, 4, 5 };
+ static unsigned char P[] = { 1, 2, 3, 4, 5 };
if (!prog_validate(insns, sizeof(insns) / sizeof(insns[0])))
return false;
@@ -432,7 +430,7 @@
BPF_STMT(BPF_RET+BPF_A, 0),
};
- static char P[] = { 1, 2, 3, 4, 5 };
+ static unsigned char P[] = { 1, 2, 3, 4, 5 };
if (!prog_validate(insns, sizeof(insns) / sizeof(insns[0])))
return false;
@@ -449,7 +447,7 @@
BPF_STMT(BPF_RET+BPF_A, 0),
};
- static char P[] = { 1, 2, 3, 4, 5 };
+ static unsigned char P[] = { 1, 2, 3, 4, 5 };
if (!prog_validate(insns, sizeof(insns) / sizeof(insns[0])))
return false;
@@ -467,7 +465,7 @@
BPF_STMT(BPF_RET+BPF_A, 0),
};
- static char P[] = { 1, 2, 3, 4, 5 };
+ static unsigned char P[] = { 1, 2, 3, 4, 5 };
if (!prog_validate(insns, sizeof(insns) / sizeof(insns[0])))
return false;
@@ -485,7 +483,7 @@
BPF_STMT(BPF_RET+BPF_A, 0),
};
- static char P[] = { 1, 2, 3, 4, 5 };
+ static unsigned char P[] = { 1, 2, 3, 4, 5 };
if (!prog_validate(insns, sizeof(insns) / sizeof(insns[0])))
return false;
@@ -503,7 +501,7 @@
BPF_STMT(BPF_RET+BPF_A, 0),
};
- static char P[] = { 1, 2, 3, 4, 5 };
+ static unsigned char P[] = { 1, 2, 3, 4, 5 };
if (!prog_validate(insns, sizeof(insns) / sizeof(insns[0])))
return false;
diff -r d9fd2f6c59fe -r 0daf7319c9b2 tests/net/bpfjit/t_bpfjit.c
--- a/tests/net/bpfjit/t_bpfjit.c Tue Jul 08 21:13:01 2014 +0000
+++ b/tests/net/bpfjit/t_bpfjit.c Tue Jul 08 21:44:26 2014 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: t_bpfjit.c,v 1.1 2014/06/30 21:30:51 alnsn Exp $ */
+/* $NetBSD: t_bpfjit.c,v 1.2 2014/07/08 21:44:26 alnsn Exp $ */
/*-
- * Copyright (c) 2014 Alexander Nasonov.
+ * Copyright (c) 2011-2012, 2014 Alexander Nasonov.
* All rights reserved.
*
Home |
Main Index |
Thread Index |
Old Index