summaryrefslogtreecommitdiffstats
path: root/tools/regression
diff options
context:
space:
mode:
authorjkim <jkim@FreeBSD.org>2008-08-26 21:54:47 +0000
committerjkim <jkim@FreeBSD.org>2008-08-26 21:54:47 +0000
commit2efee2eeaa24c19e319f7acce4815bc119fc4cbc (patch)
treeb784f9b2902961d41efe626443a8e745a395a8f6 /tools/regression
parente41f677c9fc357d041e7ea3fa4529dbc69aa1cef (diff)
downloadFreeBSD-src-2efee2eeaa24c19e319f7acce4815bc119fc4cbc.zip
FreeBSD-src-2efee2eeaa24c19e319f7acce4815bc119fc4cbc.tar.gz
Add a test case for null filter.
Diffstat (limited to 'tools/regression')
-rw-r--r--tools/regression/bpf/bpf_filter/Makefile8
-rw-r--r--tools/regression/bpf/bpf_filter/bpf_test.c9
-rw-r--r--tools/regression/bpf/bpf_filter/tests/test0079.h29
3 files changed, 35 insertions, 11 deletions
diff --git a/tools/regression/bpf/bpf_filter/Makefile b/tools/regression/bpf/bpf_filter/Makefile
index 6b4c1bc..cadf844 100644
--- a/tools/regression/bpf/bpf_filter/Makefile
+++ b/tools/regression/bpf/bpf_filter/Makefile
@@ -19,7 +19,7 @@ TEST_CASES?= test0001 test0002 test0003 test0004 \
test0065 test0066 test0067 test0068 \
test0069 test0070 test0071 test0072 \
test0073 test0074 test0075 test0076 \
- test0077 test0078
+ test0077 test0078 test0079
SYSDIR?= ${.CURDIR}/../../../../sys
@@ -37,7 +37,8 @@ CFLAGS+= -DLOG_LEVEL="${LOG_LEVEL}"
CFLAGS+= -DBPF_VALIDATE=${BPF_VALIDATE}
.endif
-.if (${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "i386") && defined(BPF_JIT)
+.if defined(BPF_JIT) && \
+ (${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "i386")
SRCS+= ${SYSDIR}/net/bpf_jitter.c \
${SYSDIR}/${MACHINE_ARCH}/${MACHINE_ARCH}/bpf_jit_machdep.c
CFLAGS+= -DBPF_JIT_COMPILER
@@ -49,7 +50,8 @@ WARNS?= 2
.for TEST in ${TEST_CASES}
${TEST}: ${.CURDIR}/tests/${TEST}.h ${SRCS}
- @${CC} ${CFLAGS} -DBPF_TEST_H=\"${TEST}.h\" -o ${.CURDIR}/${TEST} ${SRCS}
+ @${CC} ${CFLAGS} -DBPF_TEST_H=\"${TEST}.h\" \
+ -o ${.CURDIR}/${TEST} ${SRCS}
.endfor
all: ${TEST_CASES}
diff --git a/tools/regression/bpf/bpf_filter/bpf_test.c b/tools/regression/bpf/bpf_filter/bpf_test.c
index 94e7d7d..40b5af5 100644
--- a/tools/regression/bpf/bpf_filter/bpf_test.c
+++ b/tools/regression/bpf/bpf_filter/bpf_test.c
@@ -52,10 +52,7 @@ __FBSDID("$FreeBSD$");
static void sig_handler(int);
-#if defined(BPF_JIT_COMPILER) || defined(BPF_VALIDATE)
static int nins = sizeof(pc) / sizeof(pc[0]);
-#endif
-
static int verbose = LOG_LEVEL;
#ifdef BPF_JIT_COMPILER
@@ -68,10 +65,6 @@ bpf_compile_and_filter(void)
bpf_jit_filter *filter;
u_int i, ret;
- /* Do not use BPF JIT compiler for an empty program */
- if (nins == 0)
- return (0);
-
/* Compile the BPF filter program and generate native code. */
if ((filter = bpf_jitter(pc, nins)) == NULL) {
if (verbose > 1)
@@ -263,7 +256,7 @@ main(void)
ret = bpf_compile_and_filter();
#else
for (i = 0; i < BPF_NRUNS; i++)
- ret = bpf_filter(pc, pkt, wirelen, buflen);
+ ret = bpf_filter(nins != 0 ? pc : NULL, pkt, wirelen, buflen);
#endif
if (ret != expect) {
if (verbose > 1)
diff --git a/tools/regression/bpf/bpf_filter/tests/test0079.h b/tools/regression/bpf/bpf_filter/tests/test0079.h
new file mode 100644
index 0000000..78169e0
--- /dev/null
+++ b/tools/regression/bpf/bpf_filter/tests/test0079.h
@@ -0,0 +1,29 @@
+/*-
+ * Test 0079: An empty filter program.
+ *
+ * $FreeBSD$
+ */
+
+/* BPF program */
+struct bpf_insn pc[] = {
+};
+
+/* Packet */
+u_char pkt[] = {
+ 0x00,
+};
+
+/* Packet length seen on wire */
+u_int wirelen = sizeof(pkt);
+
+/* Packet length passed on buffer */
+u_int buflen = sizeof(pkt);
+
+/* Invalid instruction */
+int invalid = 0;
+
+/* Expected return value */
+u_int expect = (u_int)-1;
+
+/* Expeced signal */
+int expect_signal = 0;
OpenPOWER on IntegriCloud