Add a test case for null filter.
This commit is contained in:
parent
a2b12e3b23
commit
218223bb17
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=182221
@ -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}
|
||||
|
@ -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)
|
||||
|
29
tools/regression/bpf/bpf_filter/tests/test0079.h
Normal file
29
tools/regression/bpf/bpf_filter/tests/test0079.h
Normal file
@ -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;
|
Loading…
Reference in New Issue
Block a user