tools/llvm: Do not build with symbols
[minix3.git] / tests / lib / libbpfjit / t_bpfjit.c
blob5faa017bb4d7e0c86f92e81cdfb64c2f5ec7060a
1 /* $NetBSD: t_bpfjit.c,v 1.2 2013/11/15 00:12:45 rmind Exp $ */
3 /*-
4 * Copyright (c) 2011-2012 Alexander Nasonov.
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
28 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __RCSID("$NetBSD: t_bpfjit.c,v 1.2 2013/11/15 00:12:45 rmind Exp $");
35 #include <atf-c.h>
36 #include <stdint.h>
37 #include <string.h>
39 #define __BPF_PRIVATE
40 #include <net/bpf.h>
41 #include <net/bpfjit.h>
43 static uint8_t deadbeef_at_5[16] = {
44 0, 0xf1, 2, 0xf3, 4, 0xde, 0xad, 0xbe, 0xef, 0xff
47 static bpf_ctx_t bc_zeroed;
48 static bpf_ctx_t *bc = &bc_zeroed;
50 ATF_TC(bpfjit_empty);
51 ATF_TC_HEAD(bpfjit_empty, tc)
53 atf_tc_set_md_var(tc, "descr",
54 "Test that JIT compilation for an empty bpf program fails");
57 ATF_TC_BODY(bpfjit_empty, tc)
59 struct bpf_insn dummy;
61 ATF_CHECK(bpfjit_generate_code(bc, &dummy, 0) == NULL);
64 ATF_TC(bpfjit_alu_add_k);
65 ATF_TC_HEAD(bpfjit_alu_add_k, tc)
67 atf_tc_set_md_var(tc, "descr",
68 "Test JIT compilation of BPF_ALU+BPF_ADD+BPF_K");
71 ATF_TC_BODY(bpfjit_alu_add_k, tc)
73 static struct bpf_insn insns[] = {
74 BPF_STMT(BPF_LD+BPF_IMM, 3),
75 BPF_STMT(BPF_ALU+BPF_ADD+BPF_K, 2),
76 BPF_STMT(BPF_RET+BPF_A, 0)
79 bpfjit_func_t code;
80 uint8_t pkt[1]; /* the program doesn't read any data */
82 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
84 ATF_CHECK(bpf_validate(insns, insn_count));
86 code = bpfjit_generate_code(bc, insns, insn_count);
87 ATF_REQUIRE(code != NULL);
89 ATF_CHECK(code(pkt, 1, 1) == 5);
91 bpfjit_free_code(code);
94 ATF_TC(bpfjit_alu_sub_k);
95 ATF_TC_HEAD(bpfjit_alu_sub_k, tc)
97 atf_tc_set_md_var(tc, "descr",
98 "Test JIT compilation of BPF_ALU+BPF_SUB+BPF_K");
101 ATF_TC_BODY(bpfjit_alu_sub_k, tc)
103 static struct bpf_insn insns[] = {
104 BPF_STMT(BPF_LD+BPF_IMM, 1),
105 BPF_STMT(BPF_ALU+BPF_SUB+BPF_K, 2),
106 BPF_STMT(BPF_RET+BPF_A, 0)
109 bpfjit_func_t code;
110 uint8_t pkt[1]; /* the program doesn't read any data */
112 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
114 ATF_CHECK(bpf_validate(insns, insn_count));
116 code = bpfjit_generate_code(bc, insns, insn_count);
117 ATF_REQUIRE(code != NULL);
119 ATF_CHECK(code(pkt, 1, 1) == UINT32_MAX);
121 bpfjit_free_code(code);
124 ATF_TC(bpfjit_alu_mul_k);
125 ATF_TC_HEAD(bpfjit_alu_mul_k, tc)
127 atf_tc_set_md_var(tc, "descr",
128 "Test JIT compilation of BPF_ALU+BPF_MUL+BPF_K");
131 ATF_TC_BODY(bpfjit_alu_mul_k, tc)
133 static struct bpf_insn insns[] = {
134 BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(0xffffffff)),
135 BPF_STMT(BPF_ALU+BPF_MUL+BPF_K, 3),
136 BPF_STMT(BPF_RET+BPF_A, 0)
139 bpfjit_func_t code;
140 uint8_t pkt[1]; /* the program doesn't read any data */
142 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
144 ATF_CHECK(bpf_validate(insns, insn_count));
146 code = bpfjit_generate_code(bc, insns, insn_count);
147 ATF_REQUIRE(code != NULL);
149 ATF_CHECK(code(pkt, 1, 1) == UINT32_C(0xfffffffd));
151 bpfjit_free_code(code);
154 ATF_TC(bpfjit_alu_div0_k);
155 ATF_TC_HEAD(bpfjit_alu_div0_k, tc)
157 atf_tc_set_md_var(tc, "descr",
158 "Test JIT compilation of BPF_ALU+BPF_DIV+BPF_K with k=0");
161 ATF_TC_BODY(bpfjit_alu_div0_k, tc)
163 static struct bpf_insn insns[] = {
164 BPF_STMT(BPF_ALU+BPF_DIV+BPF_K, 0),
165 BPF_STMT(BPF_RET+BPF_A, 0)
168 bpfjit_func_t code;
169 uint8_t pkt[1]; /* the program doesn't read any data */
171 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
173 //ATF_CHECK(bpf_validate(insns, insn_count));
175 code = bpfjit_generate_code(bc, insns, insn_count);
176 ATF_REQUIRE(code != NULL);
178 ATF_CHECK(code(pkt, 1, 1) == 0);
180 bpfjit_free_code(code);
183 ATF_TC(bpfjit_alu_div1_k);
184 ATF_TC_HEAD(bpfjit_alu_div1_k, tc)
186 atf_tc_set_md_var(tc, "descr",
187 "Test JIT compilation of BPF_ALU+BPF_DIV+BPF_K with k=1");
190 ATF_TC_BODY(bpfjit_alu_div1_k, tc)
192 static struct bpf_insn insns[] = {
193 BPF_STMT(BPF_LD+BPF_IMM, 7),
194 BPF_STMT(BPF_ALU+BPF_DIV+BPF_K, 1),
195 BPF_STMT(BPF_RET+BPF_A, 0)
198 bpfjit_func_t code;
199 uint8_t pkt[1]; /* the program doesn't read any data */
201 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
203 ATF_CHECK(bpf_validate(insns, insn_count));
205 code = bpfjit_generate_code(bc, insns, insn_count);
206 ATF_REQUIRE(code != NULL);
208 ATF_CHECK(code(pkt, 1, 1) == 7);
210 bpfjit_free_code(code);
213 ATF_TC(bpfjit_alu_div2_k);
214 ATF_TC_HEAD(bpfjit_alu_div2_k, tc)
216 atf_tc_set_md_var(tc, "descr",
217 "Test JIT compilation of BPF_ALU+BPF_DIV+BPF_K with k=2");
220 ATF_TC_BODY(bpfjit_alu_div2_k, tc)
222 static struct bpf_insn insns[] = {
223 BPF_STMT(BPF_LD+BPF_IMM, 7),
224 BPF_STMT(BPF_ALU+BPF_DIV+BPF_K, 2),
225 BPF_STMT(BPF_RET+BPF_A, 0)
228 bpfjit_func_t code;
229 uint8_t pkt[1]; /* the program doesn't read any data */
231 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
233 ATF_CHECK(bpf_validate(insns, insn_count));
235 code = bpfjit_generate_code(bc, insns, insn_count);
236 ATF_REQUIRE(code != NULL);
238 ATF_CHECK(code(pkt, 1, 1) == 3);
240 bpfjit_free_code(code);
243 ATF_TC(bpfjit_alu_div4_k);
244 ATF_TC_HEAD(bpfjit_alu_div4_k, tc)
246 atf_tc_set_md_var(tc, "descr",
247 "Test JIT compilation of BPF_ALU+BPF_DIV+BPF_K with k=4");
250 ATF_TC_BODY(bpfjit_alu_div4_k, tc)
252 static struct bpf_insn insns[] = {
253 BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(0xffffffff)),
254 BPF_STMT(BPF_ALU+BPF_DIV+BPF_K, 4),
255 BPF_STMT(BPF_RET+BPF_A, 0)
258 bpfjit_func_t code;
259 uint8_t pkt[1]; /* the program doesn't read any data */
261 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
263 ATF_CHECK(bpf_validate(insns, insn_count));
265 code = bpfjit_generate_code(bc, insns, insn_count);
266 ATF_REQUIRE(code != NULL);
268 ATF_CHECK(code(pkt, 1, 1) == UINT32_C(0x3fffffff));
270 bpfjit_free_code(code);
273 ATF_TC(bpfjit_alu_div10_k);
274 ATF_TC_HEAD(bpfjit_alu_div10_k, tc)
276 atf_tc_set_md_var(tc, "descr",
277 "Test JIT compilation of BPF_ALU+BPF_DIV+BPF_K with k=10");
280 ATF_TC_BODY(bpfjit_alu_div10_k, tc)
282 static struct bpf_insn insns[] = {
283 BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(4294843849)),
284 BPF_STMT(BPF_ALU+BPF_DIV+BPF_K, 10),
285 BPF_STMT(BPF_RET+BPF_A, 0)
288 bpfjit_func_t code;
289 uint8_t pkt[1]; /* the program doesn't read any data */
291 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
293 ATF_CHECK(bpf_validate(insns, insn_count));
295 code = bpfjit_generate_code(bc, insns, insn_count);
296 ATF_REQUIRE(code != NULL);
298 ATF_CHECK(code(pkt, 1, 1) == UINT32_C(429484384));
300 bpfjit_free_code(code);
303 ATF_TC(bpfjit_alu_div10000_k);
304 ATF_TC_HEAD(bpfjit_alu_div10000_k, tc)
306 atf_tc_set_md_var(tc, "descr",
307 "Test JIT compilation of BPF_ALU+BPF_DIV+BPF_K with k=10000");
310 ATF_TC_BODY(bpfjit_alu_div10000_k, tc)
312 static struct bpf_insn insns[] = {
313 BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(4294843849)),
314 BPF_STMT(BPF_ALU+BPF_DIV+BPF_K, 10000),
315 BPF_STMT(BPF_RET+BPF_A, 0)
318 bpfjit_func_t code;
319 uint8_t pkt[1]; /* the program doesn't read any data */
321 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
323 ATF_CHECK(bpf_validate(insns, insn_count));
325 code = bpfjit_generate_code(bc, insns, insn_count);
326 ATF_REQUIRE(code != NULL);
328 ATF_CHECK(code(pkt, 1, 1) == UINT32_C(429484));
330 bpfjit_free_code(code);
333 ATF_TC(bpfjit_alu_div7609801_k);
334 ATF_TC_HEAD(bpfjit_alu_div7609801_k, tc)
336 atf_tc_set_md_var(tc, "descr",
337 "Test JIT compilation of BPF_ALU+BPF_DIV+BPF_K with k=7609801");
340 ATF_TC_BODY(bpfjit_alu_div7609801_k, tc)
342 static struct bpf_insn insns[] = {
343 BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(4294967295)),
344 BPF_STMT(BPF_ALU+BPF_DIV+BPF_K, UINT32_C(7609801)),
345 BPF_STMT(BPF_RET+BPF_A, 0)
348 bpfjit_func_t code;
349 uint8_t pkt[1]; /* the program doesn't read any data */
351 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
353 ATF_CHECK(bpf_validate(insns, insn_count));
355 code = bpfjit_generate_code(bc, insns, insn_count);
356 ATF_REQUIRE(code != NULL);
358 ATF_CHECK(code(pkt, 1, 1) == 564);
360 bpfjit_free_code(code);
363 ATF_TC(bpfjit_alu_div80000000_k);
364 ATF_TC_HEAD(bpfjit_alu_div80000000_k, tc)
366 atf_tc_set_md_var(tc, "descr",
367 "Test JIT compilation of BPF_ALU+BPF_DIV+BPF_K with k=0x80000000");
370 ATF_TC_BODY(bpfjit_alu_div80000000_k, tc)
372 static struct bpf_insn insns[] = {
373 BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(0xffffffde)),
374 BPF_STMT(BPF_ALU+BPF_DIV+BPF_K, UINT32_C(0x80000000)),
375 BPF_STMT(BPF_RET+BPF_A, 0)
378 bpfjit_func_t code;
379 uint8_t pkt[1]; /* the program doesn't read any data */
381 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
383 ATF_CHECK(bpf_validate(insns, insn_count));
385 code = bpfjit_generate_code(bc, insns, insn_count);
386 ATF_REQUIRE(code != NULL);
388 ATF_CHECK(code(pkt, 1, 1) == 1);
390 bpfjit_free_code(code);
393 ATF_TC(bpfjit_alu_and_k);
394 ATF_TC_HEAD(bpfjit_alu_and_k, tc)
396 atf_tc_set_md_var(tc, "descr",
397 "Test JIT compilation of BPF_ALU+BPF_AND+BPF_K");
400 ATF_TC_BODY(bpfjit_alu_and_k, tc)
402 static struct bpf_insn insns[] = {
403 BPF_STMT(BPF_LD+BPF_IMM, 0xdead),
404 BPF_STMT(BPF_ALU+BPF_AND+BPF_K, 0xbeef),
405 BPF_STMT(BPF_RET+BPF_A, 0)
408 bpfjit_func_t code;
409 uint8_t pkt[1]; /* the program doesn't read any data */
411 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
413 ATF_CHECK(bpf_validate(insns, insn_count));
415 code = bpfjit_generate_code(bc, insns, insn_count);
416 ATF_REQUIRE(code != NULL);
418 ATF_CHECK(code(pkt, 1, 1) == (0xdead&0xbeef));
420 bpfjit_free_code(code);
423 ATF_TC(bpfjit_alu_or_k);
424 ATF_TC_HEAD(bpfjit_alu_or_k, tc)
426 atf_tc_set_md_var(tc, "descr",
427 "Test JIT compilation of BPF_ALU+BPF_OR+BPF_K");
430 ATF_TC_BODY(bpfjit_alu_or_k, tc)
432 static struct bpf_insn insns[] = {
433 BPF_STMT(BPF_LD+BPF_IMM, 0xdead0000),
434 BPF_STMT(BPF_ALU+BPF_OR+BPF_K, 0x0000beef),
435 BPF_STMT(BPF_RET+BPF_A, 0)
438 bpfjit_func_t code;
439 uint8_t pkt[1]; /* the program doesn't read any data */
441 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
443 ATF_CHECK(bpf_validate(insns, insn_count));
445 code = bpfjit_generate_code(bc, insns, insn_count);
446 ATF_REQUIRE(code != NULL);
448 ATF_CHECK(code(pkt, 1, 1) == 0xdeadbeef);
450 bpfjit_free_code(code);
453 ATF_TC(bpfjit_alu_lsh_k);
454 ATF_TC_HEAD(bpfjit_alu_lsh_k, tc)
456 atf_tc_set_md_var(tc, "descr",
457 "Test JIT compilation of BPF_ALU+BPF_LSH+BPF_K");
460 ATF_TC_BODY(bpfjit_alu_lsh_k, tc)
462 static struct bpf_insn insns[] = {
463 BPF_STMT(BPF_LD+BPF_IMM, 0xdeadbeef),
464 BPF_STMT(BPF_ALU+BPF_LSH+BPF_K, 16),
465 BPF_STMT(BPF_RET+BPF_A, 0)
468 bpfjit_func_t code;
469 uint8_t pkt[1]; /* the program doesn't read any data */
471 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
473 ATF_CHECK(bpf_validate(insns, insn_count));
475 code = bpfjit_generate_code(bc, insns, insn_count);
476 ATF_REQUIRE(code != NULL);
478 ATF_CHECK(code(pkt, 1, 1) == 0xbeef0000);
480 bpfjit_free_code(code);
483 ATF_TC(bpfjit_alu_lsh0_k);
484 ATF_TC_HEAD(bpfjit_alu_lsh0_k, tc)
486 atf_tc_set_md_var(tc, "descr",
487 "Test JIT compilation of BPF_ALU+BPF_LSH+BPF_K with k=0");
490 ATF_TC_BODY(bpfjit_alu_lsh0_k, tc)
492 static struct bpf_insn insns[] = {
493 BPF_STMT(BPF_LD+BPF_IMM, 0xdeadbeef),
494 BPF_STMT(BPF_ALU+BPF_LSH+BPF_K, 0),
495 BPF_STMT(BPF_RET+BPF_A, 0)
498 bpfjit_func_t code;
499 uint8_t pkt[1]; /* the program doesn't read any data */
501 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
503 ATF_CHECK(bpf_validate(insns, insn_count));
505 code = bpfjit_generate_code(bc, insns, insn_count);
506 ATF_REQUIRE(code != NULL);
508 ATF_CHECK(code(pkt, 1, 1) == 0xdeadbeef);
510 bpfjit_free_code(code);
513 ATF_TC(bpfjit_alu_rsh_k);
514 ATF_TC_HEAD(bpfjit_alu_rsh_k, tc)
516 atf_tc_set_md_var(tc, "descr",
517 "Test JIT compilation of BPF_ALU+BPF_RSH+BPF_K");
520 ATF_TC_BODY(bpfjit_alu_rsh_k, tc)
522 static struct bpf_insn insns[] = {
523 BPF_STMT(BPF_LD+BPF_IMM, 0xdeadbeef),
524 BPF_STMT(BPF_ALU+BPF_RSH+BPF_K, 16),
525 BPF_STMT(BPF_RET+BPF_A, 0)
528 bpfjit_func_t code;
529 uint8_t pkt[1]; /* the program doesn't read any data */
531 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
533 ATF_CHECK(bpf_validate(insns, insn_count));
535 code = bpfjit_generate_code(bc, insns, insn_count);
536 ATF_REQUIRE(code != NULL);
538 ATF_CHECK(code(pkt, 1, 1) == 0x0000dead);
540 bpfjit_free_code(code);
543 ATF_TC(bpfjit_alu_rsh0_k);
544 ATF_TC_HEAD(bpfjit_alu_rsh0_k, tc)
546 atf_tc_set_md_var(tc, "descr",
547 "Test JIT compilation of BPF_ALU+BPF_RSH+BPF_K with k=0");
550 ATF_TC_BODY(bpfjit_alu_rsh0_k, tc)
552 static struct bpf_insn insns[] = {
553 BPF_STMT(BPF_LD+BPF_IMM, 0xdeadbeef),
554 BPF_STMT(BPF_ALU+BPF_RSH+BPF_K, 0),
555 BPF_STMT(BPF_RET+BPF_A, 0)
558 bpfjit_func_t code;
559 uint8_t pkt[1]; /* the program doesn't read any data */
561 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
563 ATF_CHECK(bpf_validate(insns, insn_count));
565 code = bpfjit_generate_code(bc, insns, insn_count);
566 ATF_REQUIRE(code != NULL);
568 ATF_CHECK(code(pkt, 1, 1) == 0xdeadbeef);
570 bpfjit_free_code(code);
573 ATF_TC(bpfjit_alu_modulo_k);
574 ATF_TC_HEAD(bpfjit_alu_modulo_k, tc)
576 atf_tc_set_md_var(tc, "descr",
577 "Test JIT compilation of modulo logic of BPF_ALU+BPF_K operations");
580 ATF_TC_BODY(bpfjit_alu_modulo_k, tc)
582 static struct bpf_insn insns[] = {
583 BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(0x7fffff77)),
585 /* (7FFFFF77 * 0FFFFF77) = 07FFFFB2,F0004951 */
586 BPF_STMT(BPF_ALU+BPF_MUL+BPF_K, UINT32_C(0x0fffff77)),
588 /* 07FFFFB2,F0004951 << 1 = 0FFFFF65,E00092A2 */
589 BPF_STMT(BPF_ALU+BPF_LSH+BPF_K, 1),
591 /* 0FFFFF65,E00092A2 + DDDDDDDD = 0FFFFF66,BDDE707F */
592 BPF_STMT(BPF_ALU+BPF_ADD+BPF_K, UINT32_C(0xdddddddd)),
594 /* 0FFFFF66,BDDE707F - FFFFFFFF = 0FFFFF65,BDDE7080 */
595 BPF_STMT(BPF_ALU+BPF_SUB+BPF_K, UINT32_C(0xffffffff)),
597 /* 0FFFFF65,BDDE7080 | 0000030C = 0FFFFF65,BDDE738C */
598 BPF_STMT(BPF_ALU+BPF_OR+BPF_K, UINT32_C(0x0000030c)),
600 /* -0FFFFF65,BDDE738C mod(2^64) = F000009A,42218C74 */
601 BPF_STMT(BPF_ALU+BPF_NEG, 0),
603 /* F000009A,42218C74 & FFFFFF0F = F000009A,42218C04 */
604 BPF_STMT(BPF_ALU+BPF_AND+BPF_K, UINT32_C(0xffffff0f)),
606 /* F000009A,42218C74 >> 3 = 1E000013,48443180 */
607 /* 00000000,42218C74 >> 3 = 00000000,08443180 */
608 BPF_STMT(BPF_ALU+BPF_RSH+BPF_K, 3),
610 /* 00000000,08443180 * 7FFFFF77 = 042218BB,93818280 */
611 BPF_STMT(BPF_ALU+BPF_MUL+BPF_K, UINT32_C(0x7fffff77)),
613 /* 042218BB,93818280 / DEAD = 000004C0,71CBBBC3 */
614 /* 00000000,93818280 / DEAD = 00000000,0000A994 */
615 BPF_STMT(BPF_ALU+BPF_DIV+BPF_K, UINT32_C(0xdead)),
617 BPF_STMT(BPF_RET+BPF_A, 0)
620 bpfjit_func_t code;
621 uint8_t pkt[1]; /* the program doesn't read any data */
623 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
625 ATF_CHECK(bpf_validate(insns, insn_count));
627 code = bpfjit_generate_code(bc, insns, insn_count);
628 ATF_REQUIRE(code != NULL);
630 ATF_CHECK(code(pkt, 1, 1) != UINT32_C(0x71cbbbc3));
631 ATF_CHECK(code(pkt, 1, 1) == UINT32_C(0x0000a994));
634 bpfjit_free_code(code);
637 ATF_TC(bpfjit_alu_add_x);
638 ATF_TC_HEAD(bpfjit_alu_add_x, tc)
640 atf_tc_set_md_var(tc, "descr",
641 "Test JIT compilation of BPF_ALU+BPF_ADD+BPF_X");
644 ATF_TC_BODY(bpfjit_alu_add_x, tc)
646 static struct bpf_insn insns[] = {
647 BPF_STMT(BPF_LD+BPF_IMM, 3),
648 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 2),
649 BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0),
650 BPF_STMT(BPF_RET+BPF_A, 0)
653 bpfjit_func_t code;
654 uint8_t pkt[1]; /* the program doesn't read any data */
656 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
658 ATF_CHECK(bpf_validate(insns, insn_count));
660 code = bpfjit_generate_code(bc, insns, insn_count);
661 ATF_REQUIRE(code != NULL);
663 ATF_CHECK(code(pkt, 1, 1) == 5);
665 bpfjit_free_code(code);
668 ATF_TC(bpfjit_alu_sub_x);
669 ATF_TC_HEAD(bpfjit_alu_sub_x, tc)
671 atf_tc_set_md_var(tc, "descr",
672 "Test JIT compilation of BPF_ALU+BPF_SUB+BPF_X");
675 ATF_TC_BODY(bpfjit_alu_sub_x, tc)
677 static struct bpf_insn insns[] = {
678 BPF_STMT(BPF_LD+BPF_IMM, 1),
679 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 2),
680 BPF_STMT(BPF_ALU+BPF_SUB+BPF_X, 0),
681 BPF_STMT(BPF_RET+BPF_A, 0)
684 bpfjit_func_t code;
685 uint8_t pkt[1]; /* the program doesn't read any data */
687 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
689 ATF_CHECK(bpf_validate(insns, insn_count));
691 code = bpfjit_generate_code(bc, insns, insn_count);
692 ATF_REQUIRE(code != NULL);
694 ATF_CHECK(code(pkt, 1, 1) == UINT32_MAX);
696 bpfjit_free_code(code);
699 ATF_TC(bpfjit_alu_mul_x);
700 ATF_TC_HEAD(bpfjit_alu_mul_x, tc)
702 atf_tc_set_md_var(tc, "descr",
703 "Test JIT compilation of BPF_ALU+BPF_MUL+BPF_X");
706 ATF_TC_BODY(bpfjit_alu_mul_x, tc)
708 static struct bpf_insn insns[] = {
709 BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(0xffffffff)),
710 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 3),
711 BPF_STMT(BPF_ALU+BPF_MUL+BPF_X, 0),
712 BPF_STMT(BPF_RET+BPF_A, 0)
715 bpfjit_func_t code;
716 uint8_t pkt[1]; /* the program doesn't read any data */
718 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
720 ATF_CHECK(bpf_validate(insns, insn_count));
722 code = bpfjit_generate_code(bc, insns, insn_count);
723 ATF_REQUIRE(code != NULL);
725 ATF_CHECK(code(pkt, 1, 1) == UINT32_C(0xfffffffd));
727 bpfjit_free_code(code);
730 ATF_TC(bpfjit_alu_div0_x);
731 ATF_TC_HEAD(bpfjit_alu_div0_x, tc)
733 atf_tc_set_md_var(tc, "descr",
734 "Test JIT compilation of BPF_ALU+BPF_DIV+BPF_X with X=0");
737 ATF_TC_BODY(bpfjit_alu_div0_x, tc)
739 static struct bpf_insn insns[] = {
740 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 0),
741 BPF_STMT(BPF_ALU+BPF_DIV+BPF_X, 0),
742 BPF_STMT(BPF_RET+BPF_A, 0)
745 bpfjit_func_t code;
746 uint8_t pkt[1]; /* the program doesn't read any data */
748 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
750 ATF_CHECK(bpf_validate(insns, insn_count));
752 code = bpfjit_generate_code(bc, insns, insn_count);
753 ATF_REQUIRE(code != NULL);
755 ATF_CHECK(code(pkt, 1, 1) == 0);
757 bpfjit_free_code(code);
760 ATF_TC(bpfjit_alu_div1_x);
761 ATF_TC_HEAD(bpfjit_alu_div1_x, tc)
763 atf_tc_set_md_var(tc, "descr",
764 "Test JIT compilation of BPF_ALU+BPF_DIV+BPF_X with X=1");
767 ATF_TC_BODY(bpfjit_alu_div1_x, tc)
769 static struct bpf_insn insns[] = {
770 BPF_STMT(BPF_LD+BPF_IMM, 7),
771 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 1),
772 BPF_STMT(BPF_ALU+BPF_DIV+BPF_X, 0),
773 BPF_STMT(BPF_RET+BPF_A, 0)
776 bpfjit_func_t code;
777 uint8_t pkt[1]; /* the program doesn't read any data */
779 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
781 ATF_CHECK(bpf_validate(insns, insn_count));
783 code = bpfjit_generate_code(bc, insns, insn_count);
784 ATF_REQUIRE(code != NULL);
786 ATF_CHECK(code(pkt, 1, 1) == 7);
788 bpfjit_free_code(code);
791 ATF_TC(bpfjit_alu_div2_x);
792 ATF_TC_HEAD(bpfjit_alu_div2_x, tc)
794 atf_tc_set_md_var(tc, "descr",
795 "Test JIT compilation of BPF_ALU+BPF_DIV+BPF_X with X=2");
798 ATF_TC_BODY(bpfjit_alu_div2_x, tc)
800 static struct bpf_insn insns[] = {
801 BPF_STMT(BPF_LD+BPF_IMM, 7),
802 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 2),
803 BPF_STMT(BPF_ALU+BPF_DIV+BPF_X, 0),
804 BPF_STMT(BPF_RET+BPF_A, 0)
807 bpfjit_func_t code;
808 uint8_t pkt[1]; /* the program doesn't read any data */
810 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
812 ATF_CHECK(bpf_validate(insns, insn_count));
814 code = bpfjit_generate_code(bc, insns, insn_count);
815 ATF_REQUIRE(code != NULL);
817 ATF_CHECK(code(pkt, 1, 1) == 3);
819 bpfjit_free_code(code);
822 ATF_TC(bpfjit_alu_div4_x);
823 ATF_TC_HEAD(bpfjit_alu_div4_x, tc)
825 atf_tc_set_md_var(tc, "descr",
826 "Test JIT compilation of BPF_ALU+BPF_DIV+BPF_X with X=4");
829 ATF_TC_BODY(bpfjit_alu_div4_x, tc)
831 static struct bpf_insn insns[] = {
832 BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(0xffffffff)),
833 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 4),
834 BPF_STMT(BPF_ALU+BPF_DIV+BPF_X, 0),
835 BPF_STMT(BPF_RET+BPF_A, 0)
838 bpfjit_func_t code;
839 uint8_t pkt[1]; /* the program doesn't read any data */
841 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
843 ATF_CHECK(bpf_validate(insns, insn_count));
845 code = bpfjit_generate_code(bc, insns, insn_count);
846 ATF_REQUIRE(code != NULL);
848 ATF_CHECK(code(pkt, 1, 1) == UINT32_C(0x3fffffff));
850 bpfjit_free_code(code);
853 ATF_TC(bpfjit_alu_div10_x);
854 ATF_TC_HEAD(bpfjit_alu_div10_x, tc)
856 atf_tc_set_md_var(tc, "descr",
857 "Test JIT compilation of BPF_ALU+BPF_DIV+BPF_X with X=10");
860 ATF_TC_BODY(bpfjit_alu_div10_x, tc)
862 static struct bpf_insn insns[] = {
863 BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(4294843849)),
864 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 10),
865 BPF_STMT(BPF_ALU+BPF_DIV+BPF_X, 0),
866 BPF_STMT(BPF_RET+BPF_A, 0)
869 bpfjit_func_t code;
870 uint8_t pkt[1]; /* the program doesn't read any data */
872 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
874 ATF_CHECK(bpf_validate(insns, insn_count));
876 code = bpfjit_generate_code(bc, insns, insn_count);
877 ATF_REQUIRE(code != NULL);
879 ATF_CHECK(code(pkt, 1, 1) == UINT32_C(429484384));
881 bpfjit_free_code(code);
884 ATF_TC(bpfjit_alu_div10000_x);
885 ATF_TC_HEAD(bpfjit_alu_div10000_x, tc)
887 atf_tc_set_md_var(tc, "descr",
888 "Test JIT compilation of BPF_ALU+BPF_DIV+BPF_X with X=10000");
891 ATF_TC_BODY(bpfjit_alu_div10000_x, tc)
893 static struct bpf_insn insns[] = {
894 BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(4294843849)),
895 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 10000),
896 BPF_STMT(BPF_ALU+BPF_DIV+BPF_X, 0),
897 BPF_STMT(BPF_RET+BPF_A, 0)
900 bpfjit_func_t code;
901 uint8_t pkt[1]; /* the program doesn't read any data */
903 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
905 ATF_CHECK(bpf_validate(insns, insn_count));
907 code = bpfjit_generate_code(bc, insns, insn_count);
908 ATF_REQUIRE(code != NULL);
910 ATF_CHECK(code(pkt, 1, 1) == UINT32_C(429484));
912 bpfjit_free_code(code);
915 ATF_TC(bpfjit_alu_div7609801_x);
916 ATF_TC_HEAD(bpfjit_alu_div7609801_x, tc)
918 atf_tc_set_md_var(tc, "descr",
919 "Test JIT compilation of BPF_ALU+BPF_DIV+BPF_X with X=7609801");
922 ATF_TC_BODY(bpfjit_alu_div7609801_x, tc)
924 static struct bpf_insn insns[] = {
925 BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(4294967295)),
926 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, UINT32_C(7609801)),
927 BPF_STMT(BPF_ALU+BPF_DIV+BPF_X, 0),
928 BPF_STMT(BPF_RET+BPF_A, 0)
931 bpfjit_func_t code;
932 uint8_t pkt[1]; /* the program doesn't read any data */
934 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
936 ATF_CHECK(bpf_validate(insns, insn_count));
938 code = bpfjit_generate_code(bc, insns, insn_count);
939 ATF_REQUIRE(code != NULL);
941 ATF_CHECK(code(pkt, 1, 1) == 564);
943 bpfjit_free_code(code);
946 ATF_TC(bpfjit_alu_div80000000_x);
947 ATF_TC_HEAD(bpfjit_alu_div80000000_x, tc)
949 atf_tc_set_md_var(tc, "descr",
950 "Test JIT compilation of BPF_ALU+BPF_DIV+BPF_X with X=0x80000000");
953 ATF_TC_BODY(bpfjit_alu_div80000000_x, tc)
955 static struct bpf_insn insns[] = {
956 BPF_STMT(BPF_LD+BPF_IMM, UINT32_MAX - 33),
957 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, UINT32_C(0x80000000)),
958 BPF_STMT(BPF_ALU+BPF_DIV+BPF_X, 0),
959 BPF_STMT(BPF_RET+BPF_A, 0)
962 bpfjit_func_t code;
963 uint8_t pkt[1]; /* the program doesn't read any data */
965 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
967 ATF_CHECK(bpf_validate(insns, insn_count));
969 code = bpfjit_generate_code(bc, insns, insn_count);
970 ATF_REQUIRE(code != NULL);
972 ATF_CHECK(code(pkt, 1, 1) == 1);
974 bpfjit_free_code(code);
977 ATF_TC(bpfjit_alu_and_x);
978 ATF_TC_HEAD(bpfjit_alu_and_x, tc)
980 atf_tc_set_md_var(tc, "descr",
981 "Test JIT compilation of BPF_ALU+BPF_AND+BPF_X");
984 ATF_TC_BODY(bpfjit_alu_and_x, tc)
986 static struct bpf_insn insns[] = {
987 BPF_STMT(BPF_LD+BPF_IMM, 0xdead),
988 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 0xbeef),
989 BPF_STMT(BPF_ALU+BPF_AND+BPF_X, 0),
990 BPF_STMT(BPF_RET+BPF_A, 0)
993 bpfjit_func_t code;
994 uint8_t pkt[1]; /* the program doesn't read any data */
996 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
998 ATF_CHECK(bpf_validate(insns, insn_count));
1000 code = bpfjit_generate_code(bc, insns, insn_count);
1001 ATF_REQUIRE(code != NULL);
1003 ATF_CHECK(code(pkt, 1, 1) == (0xdead&0xbeef));
1005 bpfjit_free_code(code);
1008 ATF_TC(bpfjit_alu_or_x);
1009 ATF_TC_HEAD(bpfjit_alu_or_x, tc)
1011 atf_tc_set_md_var(tc, "descr",
1012 "Test JIT compilation of BPF_ALU+BPF_OR+BPF_X");
1015 ATF_TC_BODY(bpfjit_alu_or_x, tc)
1017 static struct bpf_insn insns[] = {
1018 BPF_STMT(BPF_LD+BPF_IMM, 0xdead0000),
1019 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 0x0000beef),
1020 BPF_STMT(BPF_ALU+BPF_OR+BPF_X, 0),
1021 BPF_STMT(BPF_RET+BPF_A, 0)
1024 bpfjit_func_t code;
1025 uint8_t pkt[1]; /* the program doesn't read any data */
1027 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
1029 ATF_CHECK(bpf_validate(insns, insn_count));
1031 code = bpfjit_generate_code(bc, insns, insn_count);
1032 ATF_REQUIRE(code != NULL);
1034 ATF_CHECK(code(pkt, 1, 1) == 0xdeadbeef);
1036 bpfjit_free_code(code);
1039 ATF_TC(bpfjit_alu_lsh_x);
1040 ATF_TC_HEAD(bpfjit_alu_lsh_x, tc)
1042 atf_tc_set_md_var(tc, "descr",
1043 "Test JIT compilation of BPF_ALU+BPF_LSH+BPF_X");
1046 ATF_TC_BODY(bpfjit_alu_lsh_x, tc)
1048 static struct bpf_insn insns[] = {
1049 BPF_STMT(BPF_LD+BPF_IMM, 0xdeadbeef),
1050 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 16),
1051 BPF_STMT(BPF_ALU+BPF_LSH+BPF_X, 0),
1052 BPF_STMT(BPF_RET+BPF_A, 0)
1055 bpfjit_func_t code;
1056 uint8_t pkt[1]; /* the program doesn't read any data */
1058 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
1060 ATF_CHECK(bpf_validate(insns, insn_count));
1062 code = bpfjit_generate_code(bc, insns, insn_count);
1063 ATF_REQUIRE(code != NULL);
1065 ATF_CHECK(code(pkt, 1, 1) == 0xbeef0000);
1067 bpfjit_free_code(code);
1070 ATF_TC(bpfjit_alu_lsh0_x);
1071 ATF_TC_HEAD(bpfjit_alu_lsh0_x, tc)
1073 atf_tc_set_md_var(tc, "descr",
1074 "Test JIT compilation of BPF_ALU+BPF_LSH+BPF_X with k=0");
1077 ATF_TC_BODY(bpfjit_alu_lsh0_x, tc)
1079 static struct bpf_insn insns[] = {
1080 BPF_STMT(BPF_LD+BPF_IMM, 0xdeadbeef),
1081 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 0),
1082 BPF_STMT(BPF_ALU+BPF_LSH+BPF_X, 0),
1083 BPF_STMT(BPF_RET+BPF_A, 0)
1086 bpfjit_func_t code;
1087 uint8_t pkt[1]; /* the program doesn't read any data */
1089 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
1091 ATF_CHECK(bpf_validate(insns, insn_count));
1093 code = bpfjit_generate_code(bc, insns, insn_count);
1094 ATF_REQUIRE(code != NULL);
1096 ATF_CHECK(code(pkt, 1, 1) == 0xdeadbeef);
1098 bpfjit_free_code(code);
1101 ATF_TC(bpfjit_alu_rsh_x);
1102 ATF_TC_HEAD(bpfjit_alu_rsh_x, tc)
1104 atf_tc_set_md_var(tc, "descr",
1105 "Test JIT compilation of BPF_ALU+BPF_RSH+BPF_X");
1108 ATF_TC_BODY(bpfjit_alu_rsh_x, tc)
1110 static struct bpf_insn insns[] = {
1111 BPF_STMT(BPF_LD+BPF_IMM, 0xdeadbeef),
1112 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 16),
1113 BPF_STMT(BPF_ALU+BPF_RSH+BPF_X, 0),
1114 BPF_STMT(BPF_RET+BPF_A, 0)
1117 bpfjit_func_t code;
1118 uint8_t pkt[1]; /* the program doesn't read any data */
1120 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
1122 ATF_CHECK(bpf_validate(insns, insn_count));
1124 code = bpfjit_generate_code(bc, insns, insn_count);
1125 ATF_REQUIRE(code != NULL);
1127 ATF_CHECK(code(pkt, 1, 1) == 0x0000dead);
1129 bpfjit_free_code(code);
1132 ATF_TC(bpfjit_alu_rsh0_x);
1133 ATF_TC_HEAD(bpfjit_alu_rsh0_x, tc)
1135 atf_tc_set_md_var(tc, "descr",
1136 "Test JIT compilation of BPF_ALU+BPF_RSH+BPF_X with k=0");
1139 ATF_TC_BODY(bpfjit_alu_rsh0_x, tc)
1141 static struct bpf_insn insns[] = {
1142 BPF_STMT(BPF_LD+BPF_IMM, 0xdeadbeef),
1143 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 0),
1144 BPF_STMT(BPF_ALU+BPF_RSH+BPF_X, 0),
1145 BPF_STMT(BPF_RET+BPF_A, 0)
1148 bpfjit_func_t code;
1149 uint8_t pkt[1]; /* the program doesn't read any data */
1151 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
1153 ATF_CHECK(bpf_validate(insns, insn_count));
1155 code = bpfjit_generate_code(bc, insns, insn_count);
1156 ATF_REQUIRE(code != NULL);
1158 ATF_CHECK(code(pkt, 1, 1) == 0xdeadbeef);
1160 bpfjit_free_code(code);
1163 ATF_TC(bpfjit_alu_modulo_x);
1164 ATF_TC_HEAD(bpfjit_alu_modulo_x, tc)
1166 atf_tc_set_md_var(tc, "descr",
1167 "Test JIT compilation of modulo logic of BPF_ALU+BPF_X operations");
1170 ATF_TC_BODY(bpfjit_alu_modulo_x, tc)
1172 static struct bpf_insn insns[] = {
1173 BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(0x7fffff77)),
1175 /* (7FFFFF77 * 0FFFFF77) = 07FFFFB2,F0004951 */
1176 BPF_STMT(BPF_LDX+BPF_W+BPF_K, UINT32_C(0x0fffff77)),
1177 BPF_STMT(BPF_ALU+BPF_MUL+BPF_X, 0),
1179 /* 07FFFFB2,F0004951 << 1 = 0FFFFF65,E00092A2 */
1180 BPF_STMT(BPF_LDX+BPF_W+BPF_K, 1),
1181 BPF_STMT(BPF_ALU+BPF_LSH+BPF_X, 0),
1183 /* 0FFFFF65,E00092A2 + DDDDDDDD = 0FFFFF66,BDDE707F */
1184 BPF_STMT(BPF_LDX+BPF_W+BPF_K, UINT32_C(0xdddddddd)),
1185 BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0),
1187 /* 0FFFFF66,BDDE707F - FFFFFFFF = 0FFFFF65,BDDE7080 */
1188 BPF_STMT(BPF_LDX+BPF_W+BPF_K, UINT32_C(0xffffffff)),
1189 BPF_STMT(BPF_ALU+BPF_SUB+BPF_X, 0),
1191 /* 0FFFFF65,BDDE7080 | 0000030C = 0FFFFF65,BDDE738C */
1192 BPF_STMT(BPF_LDX+BPF_W+BPF_K, UINT32_C(0x0000030c)),
1193 BPF_STMT(BPF_ALU+BPF_OR+BPF_X, 0),
1195 /* -0FFFFF65,BDDE738C mod(2^64) = F000009A,42218C74 */
1196 BPF_STMT(BPF_ALU+BPF_NEG, 0),
1198 /* F000009A,42218C74 & FFFFFF0F = F000009A,42218C04 */
1199 BPF_STMT(BPF_LDX+BPF_W+BPF_K, UINT32_C(0xffffff0f)),
1200 BPF_STMT(BPF_ALU+BPF_AND+BPF_X, 0),
1202 /* F000009A,42218C74 >> 3 = 1E000013,48443180 */
1203 /* 00000000,42218C74 >> 3 = 00000000,08443180 */
1204 BPF_STMT(BPF_LDX+BPF_W+BPF_K, 3),
1205 BPF_STMT(BPF_ALU+BPF_RSH+BPF_X, 0),
1207 /* 00000000,08443180 * 7FFFFF77 = 042218BB,93818280 */
1208 BPF_STMT(BPF_LDX+BPF_W+BPF_K, UINT32_C(0x7fffff77)),
1209 BPF_STMT(BPF_ALU+BPF_MUL+BPF_X, 0),
1211 /* 042218BB,93818280 / DEAD = 000004C0,71CBBBC3 */
1212 /* 00000000,93818280 / DEAD = 00000000,0000A994 */
1213 BPF_STMT(BPF_LDX+BPF_W+BPF_K, UINT32_C(0xdead)),
1214 BPF_STMT(BPF_ALU+BPF_DIV+BPF_X, 0),
1216 BPF_STMT(BPF_RET+BPF_A, 0)
1219 bpfjit_func_t code;
1220 uint8_t pkt[1]; /* the program doesn't read any data */
1222 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
1224 ATF_CHECK(bpf_validate(insns, insn_count));
1226 code = bpfjit_generate_code(bc, insns, insn_count);
1227 ATF_REQUIRE(code != NULL);
1229 ATF_CHECK(code(pkt, 1, 1) != UINT32_C(0x71cbbbc3));
1230 ATF_CHECK(code(pkt, 1, 1) == UINT32_C(0x0000a994));
1233 bpfjit_free_code(code);
1236 ATF_TC(bpfjit_alu_neg);
1237 ATF_TC_HEAD(bpfjit_alu_neg, tc)
1239 atf_tc_set_md_var(tc, "descr",
1240 "Test JIT compilation of BPF_ALU+BPF_NEG");
1243 ATF_TC_BODY(bpfjit_alu_neg, tc)
1245 static struct bpf_insn insns[] = {
1246 BPF_STMT(BPF_LD+BPF_IMM, 777),
1247 BPF_STMT(BPF_ALU+BPF_NEG, 0),
1248 BPF_STMT(BPF_RET+BPF_A, 0)
1251 bpfjit_func_t code;
1252 uint8_t pkt[1]; /* the program doesn't read any data */
1254 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
1256 ATF_CHECK(bpf_validate(insns, insn_count));
1258 code = bpfjit_generate_code(bc, insns, insn_count);
1259 ATF_REQUIRE(code != NULL);
1261 ATF_CHECK(code(pkt, 1, 1) == 0u-777u);
1263 bpfjit_free_code(code);
1266 ATF_TC(bpfjit_jmp_ja);
1267 ATF_TC_HEAD(bpfjit_jmp_ja, tc)
1269 atf_tc_set_md_var(tc, "descr",
1270 "Test JIT compilation of BPF_JMP+BPF_JA");
1273 ATF_TC_BODY(bpfjit_jmp_ja, tc)
1275 static struct bpf_insn insns[] = {
1276 BPF_STMT(BPF_JMP+BPF_JA, 1),
1277 BPF_STMT(BPF_RET+BPF_K, 0),
1278 BPF_STMT(BPF_RET+BPF_K, UINT32_MAX),
1279 BPF_STMT(BPF_RET+BPF_K, 1),
1280 BPF_STMT(BPF_RET+BPF_K, 2),
1281 BPF_STMT(BPF_RET+BPF_K, 3),
1284 bpfjit_func_t code;
1285 uint8_t pkt[1]; /* the program doesn't read any data */
1287 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
1289 ATF_CHECK(bpf_validate(insns, insn_count));
1291 code = bpfjit_generate_code(bc, insns, insn_count);
1292 ATF_REQUIRE(code != NULL);
1294 ATF_CHECK(code(pkt, 1, 1) == UINT32_MAX);
1296 bpfjit_free_code(code);
1299 ATF_TC(bpfjit_jmp_jgt_k);
1300 ATF_TC_HEAD(bpfjit_jmp_jgt_k, tc)
1302 atf_tc_set_md_var(tc, "descr",
1303 "Test JIT compilation of BPF_JMP+BPF_JGT+BPF_K");
1306 ATF_TC_BODY(bpfjit_jmp_jgt_k, tc)
1308 static struct bpf_insn insns[] = {
1309 BPF_STMT(BPF_LD+BPF_W+BPF_LEN, 0),
1310 BPF_JUMP(BPF_JMP+BPF_JGT+BPF_K, 7, 0, 1),
1311 BPF_STMT(BPF_RET+BPF_K, 0),
1312 BPF_JUMP(BPF_JMP+BPF_JGT+BPF_K, 2, 2, 0),
1313 BPF_JUMP(BPF_JMP+BPF_JGT+BPF_K, 9, 0, 0),
1314 BPF_STMT(BPF_RET+BPF_K, 1),
1315 BPF_JUMP(BPF_JMP+BPF_JGT+BPF_K, 4, 1, 1),
1316 BPF_STMT(BPF_RET+BPF_K, 2),
1317 BPF_JUMP(BPF_JMP+BPF_JGT+BPF_K, 6, 2, 3),
1318 BPF_STMT(BPF_RET+BPF_K, 3),
1319 BPF_STMT(BPF_RET+BPF_K, 4),
1320 BPF_STMT(BPF_RET+BPF_K, 5),
1321 BPF_JUMP(BPF_JMP+BPF_JGT+BPF_K, 5, 3, 1),
1322 BPF_STMT(BPF_RET+BPF_K, 6),
1323 BPF_JUMP(BPF_JMP+BPF_JGT+BPF_K, 0, 0, 0),
1324 BPF_STMT(BPF_RET+BPF_K, 7),
1325 BPF_STMT(BPF_RET+BPF_K, 8)
1328 bpfjit_func_t code;
1329 uint8_t pkt[8]; /* the program doesn't read any data */
1331 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
1333 ATF_CHECK(bpf_validate(insns, insn_count));
1335 code = bpfjit_generate_code(bc, insns, insn_count);
1336 ATF_REQUIRE(code != NULL);
1338 ATF_CHECK(code(pkt, 1, 1) == 1);
1339 ATF_CHECK(code(pkt, 2, 2) == 1);
1340 ATF_CHECK(code(pkt, 3, 3) == 7);
1341 ATF_CHECK(code(pkt, 4, 4) == 7);
1342 ATF_CHECK(code(pkt, 5, 5) == 7);
1343 ATF_CHECK(code(pkt, 6, 6) == 8);
1344 ATF_CHECK(code(pkt, 7, 7) == 5);
1345 ATF_CHECK(code(pkt, 8, 8) == 0);
1347 bpfjit_free_code(code);
1350 ATF_TC(bpfjit_jmp_jge_k);
1351 ATF_TC_HEAD(bpfjit_jmp_jge_k, tc)
1353 atf_tc_set_md_var(tc, "descr",
1354 "Test JIT compilation of BPF_JMP+BPF_JGE+BPF_K");
1357 ATF_TC_BODY(bpfjit_jmp_jge_k, tc)
1359 static struct bpf_insn insns[] = {
1360 BPF_STMT(BPF_LD+BPF_W+BPF_LEN, 0),
1361 BPF_JUMP(BPF_JMP+BPF_JGE+BPF_K, 8, 0, 1),
1362 BPF_STMT(BPF_RET+BPF_K, 0),
1363 BPF_JUMP(BPF_JMP+BPF_JGE+BPF_K, 3, 2, 0),
1364 BPF_JUMP(BPF_JMP+BPF_JGE+BPF_K, 9, 0, 0),
1365 BPF_STMT(BPF_RET+BPF_K, 1),
1366 BPF_JUMP(BPF_JMP+BPF_JGE+BPF_K, 5, 1, 1),
1367 BPF_STMT(BPF_RET+BPF_K, 2),
1368 BPF_JUMP(BPF_JMP+BPF_JGE+BPF_K, 7, 2, 3),
1369 BPF_STMT(BPF_RET+BPF_K, 3),
1370 BPF_STMT(BPF_RET+BPF_K, 4),
1371 BPF_STMT(BPF_RET+BPF_K, 5),
1372 BPF_JUMP(BPF_JMP+BPF_JGE+BPF_K, 6, 3, 1),
1373 BPF_STMT(BPF_RET+BPF_K, 6),
1374 BPF_JUMP(BPF_JMP+BPF_JGE+BPF_K, 1, 0, 0),
1375 BPF_STMT(BPF_RET+BPF_K, 7),
1376 BPF_STMT(BPF_RET+BPF_K, 8)
1379 bpfjit_func_t code;
1380 uint8_t pkt[8]; /* the program doesn't read any data */
1382 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
1384 ATF_CHECK(bpf_validate(insns, insn_count));
1386 code = bpfjit_generate_code(bc, insns, insn_count);
1387 ATF_REQUIRE(code != NULL);
1389 ATF_CHECK(code(pkt, 1, 1) == 1);
1390 ATF_CHECK(code(pkt, 2, 2) == 1);
1391 ATF_CHECK(code(pkt, 3, 3) == 7);
1392 ATF_CHECK(code(pkt, 4, 4) == 7);
1393 ATF_CHECK(code(pkt, 5, 5) == 7);
1394 ATF_CHECK(code(pkt, 6, 6) == 8);
1395 ATF_CHECK(code(pkt, 7, 7) == 5);
1396 ATF_CHECK(code(pkt, 8, 8) == 0);
1398 bpfjit_free_code(code);
1401 ATF_TC(bpfjit_jmp_jeq_k);
1402 ATF_TC_HEAD(bpfjit_jmp_jeq_k, tc)
1404 atf_tc_set_md_var(tc, "descr",
1405 "Test JIT compilation of BPF_JMP+BPF_JEQ+BPF_K");
1408 ATF_TC_BODY(bpfjit_jmp_jeq_k, tc)
1410 static struct bpf_insn insns[] = {
1411 BPF_STMT(BPF_LD+BPF_W+BPF_LEN, 0),
1412 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 8, 0, 1),
1413 BPF_STMT(BPF_RET+BPF_K, 0),
1414 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 3, 1, 0),
1415 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 9, 1, 1),
1416 BPF_STMT(BPF_RET+BPF_K, 1),
1417 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 5, 1, 1),
1418 BPF_STMT(BPF_RET+BPF_K, 2),
1419 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 7, 2, 3),
1420 BPF_STMT(BPF_RET+BPF_K, 3),
1421 BPF_STMT(BPF_RET+BPF_K, 4),
1422 BPF_STMT(BPF_RET+BPF_K, 5),
1423 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 6, 3, 1),
1424 BPF_STMT(BPF_RET+BPF_K, 6),
1425 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 1, 0, 0),
1426 BPF_STMT(BPF_RET+BPF_K, 7),
1427 BPF_STMT(BPF_RET+BPF_K, 8)
1430 bpfjit_func_t code;
1431 uint8_t pkt[8]; /* the program doesn't read any data */
1433 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
1435 ATF_CHECK(bpf_validate(insns, insn_count));
1437 code = bpfjit_generate_code(bc, insns, insn_count);
1438 ATF_REQUIRE(code != NULL);
1440 ATF_CHECK(code(pkt, 1, 1) == 7);
1441 ATF_CHECK(code(pkt, 2, 2) == 7);
1442 ATF_CHECK(code(pkt, 3, 3) == 1);
1443 ATF_CHECK(code(pkt, 4, 4) == 7);
1444 ATF_CHECK(code(pkt, 5, 5) == 7);
1445 ATF_CHECK(code(pkt, 6, 6) == 8);
1446 ATF_CHECK(code(pkt, 7, 7) == 5);
1447 ATF_CHECK(code(pkt, 8, 8) == 0);
1449 bpfjit_free_code(code);
1452 ATF_TC(bpfjit_jmp_jset_k);
1453 ATF_TC_HEAD(bpfjit_jmp_jset_k, tc)
1455 atf_tc_set_md_var(tc, "descr",
1456 "Test JIT compilation of BPF_JMP+BPF_JSET+BPF_K");
1459 ATF_TC_BODY(bpfjit_jmp_jset_k, tc)
1461 static struct bpf_insn insns[] = {
1462 BPF_STMT(BPF_LD+BPF_W+BPF_LEN, 0),
1463 BPF_JUMP(BPF_JMP+BPF_JSET+BPF_K, 8, 0, 1),
1464 BPF_STMT(BPF_RET+BPF_K, 0),
1465 BPF_JUMP(BPF_JMP+BPF_JSET+BPF_K, 4, 2, 0),
1466 BPF_JUMP(BPF_JMP+BPF_JSET+BPF_K, 3, 0, 0),
1467 BPF_STMT(BPF_RET+BPF_K, 1),
1468 BPF_JUMP(BPF_JMP+BPF_JSET+BPF_K, 2, 1, 1),
1469 BPF_STMT(BPF_RET+BPF_K, 2),
1470 BPF_JUMP(BPF_JMP+BPF_JSET+BPF_K, 1, 2, 3),
1471 BPF_STMT(BPF_RET+BPF_K, 3),
1472 BPF_STMT(BPF_RET+BPF_K, 4),
1473 BPF_STMT(BPF_RET+BPF_K, 5),
1474 BPF_JUMP(BPF_JMP+BPF_JSET+BPF_K, 2, 3, 1),
1475 BPF_STMT(BPF_RET+BPF_K, 6),
1476 BPF_JUMP(BPF_JMP+BPF_JSET+BPF_K, 7, 0, 0),
1477 BPF_STMT(BPF_RET+BPF_K, 7),
1478 BPF_STMT(BPF_RET+BPF_K, 8)
1481 bpfjit_func_t code;
1482 uint8_t pkt[8]; /* the program doesn't read any data */
1484 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
1486 ATF_CHECK(bpf_validate(insns, insn_count));
1488 code = bpfjit_generate_code(bc, insns, insn_count);
1489 ATF_REQUIRE(code != NULL);
1491 ATF_CHECK(code(pkt, 1, 1) == 1);
1492 ATF_CHECK(code(pkt, 2, 2) == 1);
1493 ATF_CHECK(code(pkt, 3, 3) == 1);
1494 ATF_CHECK(code(pkt, 4, 4) == 7);
1495 ATF_CHECK(code(pkt, 5, 5) == 5);
1496 ATF_CHECK(code(pkt, 6, 6) == 8);
1497 ATF_CHECK(code(pkt, 7, 7) == 5);
1498 ATF_CHECK(code(pkt, 8, 8) == 0);
1500 bpfjit_free_code(code);
1503 ATF_TC(bpfjit_jmp_modulo_k);
1504 ATF_TC_HEAD(bpfjit_jmp_modulo_k, tc)
1506 atf_tc_set_md_var(tc, "descr",
1507 "Test JIT compilation of modulo logic of BPF_JMP+BPF_K operations");
1510 ATF_TC_BODY(bpfjit_jmp_modulo_k, tc)
1512 static struct bpf_insn insns[] = {
1513 BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(0x7fffff77)),
1514 BPF_STMT(BPF_ALU+BPF_LSH+BPF_K, 4),
1515 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, UINT32_C(0xfffff770), 1, 0),
1516 BPF_STMT(BPF_RET+BPF_K, 0),
1517 BPF_JUMP(BPF_JMP+BPF_JGT+BPF_K, UINT32_C(0xfffff770), 0, 1),
1518 BPF_STMT(BPF_RET+BPF_K, 1),
1519 BPF_JUMP(BPF_JMP+BPF_JGE+BPF_K, UINT32_C(0xfffff771), 0, 1),
1520 BPF_STMT(BPF_RET+BPF_K, 2),
1521 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, UINT32_C(0xfffff770), 0, 3),
1522 BPF_JUMP(BPF_JMP+BPF_JGT+BPF_K, UINT32_C(0xfffff770), 2, 0),
1523 BPF_JUMP(BPF_JMP+BPF_JGE+BPF_K, UINT32_C(0xfffff771), 1, 0),
1524 BPF_STMT(BPF_JMP+BPF_JA, 1),
1525 BPF_STMT(BPF_RET+BPF_K, 3),
1527 /* FFFFF770+FFFFF770 = 00000001,FFFFEEE0 */
1528 BPF_STMT(BPF_ALU+BPF_ADD+BPF_K, UINT32_C(0xfffff770)),
1530 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, UINT32_C(0xffffeee0), 1, 0),
1531 BPF_STMT(BPF_RET+BPF_K, 4),
1532 BPF_JUMP(BPF_JMP+BPF_JGT+BPF_K, UINT32_C(0xffffeee0), 0, 1),
1533 BPF_STMT(BPF_RET+BPF_K, 5),
1534 BPF_JUMP(BPF_JMP+BPF_JGE+BPF_K, UINT32_C(0xffffeee1), 0, 1),
1535 BPF_STMT(BPF_RET+BPF_K, 6),
1536 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, UINT32_C(0xffffeee0), 0, 3),
1537 BPF_JUMP(BPF_JMP+BPF_JGT+BPF_K, UINT32_C(0xffffeee0), 2, 0),
1538 BPF_JUMP(BPF_JMP+BPF_JGE+BPF_K, UINT32_C(0xffffeee1), 1, 0),
1539 BPF_STMT(BPF_RET+BPF_K, UINT32_MAX),
1540 BPF_STMT(BPF_RET+BPF_K, 7)
1543 bpfjit_func_t code;
1544 uint8_t pkt[1]; /* the program doesn't read any data */
1546 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
1548 ATF_CHECK(bpf_validate(insns, insn_count));
1550 code = bpfjit_generate_code(bc, insns, insn_count);
1551 ATF_REQUIRE(code != NULL);
1553 ATF_CHECK(code(pkt, 1, 1) == UINT32_MAX);
1555 bpfjit_free_code(code);
1558 ATF_TC(bpfjit_jmp_jgt_x);
1559 ATF_TC_HEAD(bpfjit_jmp_jgt_x, tc)
1561 atf_tc_set_md_var(tc, "descr",
1562 "Test JIT compilation of BPF_JMP+BPF_JGT+BPF_X");
1565 ATF_TC_BODY(bpfjit_jmp_jgt_x, tc)
1567 static struct bpf_insn insns[] = {
1568 BPF_STMT(BPF_LD+BPF_W+BPF_LEN, 0),
1569 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 7),
1570 BPF_JUMP(BPF_JMP+BPF_JGT+BPF_X, 0, 0, 1),
1571 BPF_STMT(BPF_RET+BPF_K, 0),
1572 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 2),
1573 BPF_JUMP(BPF_JMP+BPF_JGT+BPF_X, 0, 3, 0),
1574 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 9),
1575 BPF_JUMP(BPF_JMP+BPF_JGT+BPF_X, 0, 0, 0),
1576 BPF_STMT(BPF_RET+BPF_K, 1),
1577 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 4),
1578 BPF_JUMP(BPF_JMP+BPF_JGT+BPF_X, 0, 1, 1),
1579 BPF_STMT(BPF_RET+BPF_K, 2),
1580 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 6),
1581 BPF_JUMP(BPF_JMP+BPF_JGT+BPF_X, 0, 2, 3),
1582 BPF_STMT(BPF_RET+BPF_K, 3),
1583 BPF_STMT(BPF_RET+BPF_K, 4),
1584 BPF_STMT(BPF_RET+BPF_K, 5),
1585 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 5),
1586 BPF_JUMP(BPF_JMP+BPF_JGT+BPF_X, 0, 4, 1),
1587 BPF_STMT(BPF_RET+BPF_K, 6),
1588 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 0),
1589 BPF_JUMP(BPF_JMP+BPF_JGT+BPF_X, 0, 0, 0),
1590 BPF_STMT(BPF_RET+BPF_K, 7),
1591 BPF_STMT(BPF_RET+BPF_K, 8)
1594 bpfjit_func_t code;
1595 uint8_t pkt[8]; /* the program doesn't read any data */
1597 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
1599 ATF_CHECK(bpf_validate(insns, insn_count));
1601 code = bpfjit_generate_code(bc, insns, insn_count);
1602 ATF_REQUIRE(code != NULL);
1604 ATF_CHECK(code(pkt, 1, 1) == 1);
1605 ATF_CHECK(code(pkt, 2, 2) == 1);
1606 ATF_CHECK(code(pkt, 3, 3) == 7);
1607 ATF_CHECK(code(pkt, 4, 4) == 7);
1608 ATF_CHECK(code(pkt, 5, 5) == 7);
1609 ATF_CHECK(code(pkt, 6, 6) == 8);
1610 ATF_CHECK(code(pkt, 7, 7) == 5);
1611 ATF_CHECK(code(pkt, 8, 8) == 0);
1613 bpfjit_free_code(code);
1616 ATF_TC(bpfjit_jmp_jge_x);
1617 ATF_TC_HEAD(bpfjit_jmp_jge_x, tc)
1619 atf_tc_set_md_var(tc, "descr",
1620 "Test JIT compilation of BPF_JMP+BPF_JGE+BPF_X");
1623 ATF_TC_BODY(bpfjit_jmp_jge_x, tc)
1625 static struct bpf_insn insns[] = {
1626 BPF_STMT(BPF_LD+BPF_W+BPF_LEN, 0),
1627 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 8),
1628 BPF_JUMP(BPF_JMP+BPF_JGE+BPF_X, 0, 0, 1),
1629 BPF_STMT(BPF_RET+BPF_K, 0),
1630 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 3),
1631 BPF_JUMP(BPF_JMP+BPF_JGE+BPF_X, 0, 3, 0),
1632 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 9),
1633 BPF_JUMP(BPF_JMP+BPF_JGE+BPF_X, 0, 0, 0),
1634 BPF_STMT(BPF_RET+BPF_K, 1),
1635 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 5),
1636 BPF_JUMP(BPF_JMP+BPF_JGE+BPF_X, 0, 1, 1),
1637 BPF_STMT(BPF_RET+BPF_K, 2),
1638 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 7),
1639 BPF_JUMP(BPF_JMP+BPF_JGE+BPF_X, 0, 2, 3),
1640 BPF_STMT(BPF_RET+BPF_K, 3),
1641 BPF_STMT(BPF_RET+BPF_K, 4),
1642 BPF_STMT(BPF_RET+BPF_K, 5),
1643 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 6),
1644 BPF_JUMP(BPF_JMP+BPF_JGE+BPF_X, 0, 4, 1),
1645 BPF_STMT(BPF_RET+BPF_K, 6),
1646 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 1),
1647 BPF_JUMP(BPF_JMP+BPF_JGE+BPF_X, 0, 0, 0),
1648 BPF_STMT(BPF_RET+BPF_K, 7),
1649 BPF_STMT(BPF_RET+BPF_K, 8)
1652 bpfjit_func_t code;
1653 uint8_t pkt[8]; /* the program doesn't read any data */
1655 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
1657 ATF_CHECK(bpf_validate(insns, insn_count));
1659 code = bpfjit_generate_code(bc, insns, insn_count);
1660 ATF_REQUIRE(code != NULL);
1662 ATF_CHECK(code(pkt, 1, 1) == 1);
1663 ATF_CHECK(code(pkt, 2, 2) == 1);
1664 ATF_CHECK(code(pkt, 3, 3) == 7);
1665 ATF_CHECK(code(pkt, 4, 4) == 7);
1666 ATF_CHECK(code(pkt, 5, 5) == 7);
1667 ATF_CHECK(code(pkt, 6, 6) == 8);
1668 ATF_CHECK(code(pkt, 7, 7) == 5);
1669 ATF_CHECK(code(pkt, 8, 8) == 0);
1671 bpfjit_free_code(code);
1674 ATF_TC(bpfjit_jmp_jeq_x);
1675 ATF_TC_HEAD(bpfjit_jmp_jeq_x, tc)
1677 atf_tc_set_md_var(tc, "descr",
1678 "Test JIT compilation of BPF_JMP+BPF_JEQ+BPF_X");
1681 ATF_TC_BODY(bpfjit_jmp_jeq_x, tc)
1683 static struct bpf_insn insns[] = {
1684 BPF_STMT(BPF_LD+BPF_W+BPF_LEN, 0),
1685 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 8),
1686 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 0, 1),
1687 BPF_STMT(BPF_RET+BPF_K, 0),
1688 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 3),
1689 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 2, 0),
1690 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 9),
1691 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 1, 1),
1692 BPF_STMT(BPF_RET+BPF_K, 1),
1693 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 5),
1694 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 1, 1),
1695 BPF_STMT(BPF_RET+BPF_K, 2),
1696 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 7),
1697 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 2, 3),
1698 BPF_STMT(BPF_RET+BPF_K, 3),
1699 BPF_STMT(BPF_RET+BPF_K, 4),
1700 BPF_STMT(BPF_RET+BPF_K, 5),
1701 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 6),
1702 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 3, 1),
1703 BPF_STMT(BPF_RET+BPF_K, 6),
1704 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 1, 0, 0),
1705 BPF_STMT(BPF_RET+BPF_K, 7),
1706 BPF_STMT(BPF_RET+BPF_K, 8)
1709 bpfjit_func_t code;
1710 uint8_t pkt[8]; /* the program doesn't read any data */
1712 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
1714 ATF_CHECK(bpf_validate(insns, insn_count));
1716 code = bpfjit_generate_code(bc, insns, insn_count);
1717 ATF_REQUIRE(code != NULL);
1719 ATF_CHECK(code(pkt, 1, 1) == 7);
1720 ATF_CHECK(code(pkt, 2, 2) == 7);
1721 ATF_CHECK(code(pkt, 3, 3) == 1);
1722 ATF_CHECK(code(pkt, 4, 4) == 7);
1723 ATF_CHECK(code(pkt, 5, 5) == 7);
1724 ATF_CHECK(code(pkt, 6, 6) == 8);
1725 ATF_CHECK(code(pkt, 7, 7) == 5);
1726 ATF_CHECK(code(pkt, 8, 8) == 0);
1728 bpfjit_free_code(code);
1731 ATF_TC(bpfjit_jmp_jset_x);
1732 ATF_TC_HEAD(bpfjit_jmp_jset_x, tc)
1734 atf_tc_set_md_var(tc, "descr",
1735 "Test JIT compilation of BPF_JMP+BPF_JSET+BPF_X");
1738 ATF_TC_BODY(bpfjit_jmp_jset_x, tc)
1740 static struct bpf_insn insns[] = {
1741 BPF_STMT(BPF_LD+BPF_W+BPF_LEN, 0),
1742 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 8),
1743 BPF_JUMP(BPF_JMP+BPF_JSET+BPF_X, 0, 0, 1),
1744 BPF_STMT(BPF_RET+BPF_K, 0),
1745 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 4),
1746 BPF_JUMP(BPF_JMP+BPF_JSET+BPF_X, 0, 2, 0),
1747 BPF_JUMP(BPF_JMP+BPF_JSET+BPF_X, 3, 0, 0),
1748 BPF_STMT(BPF_RET+BPF_K, 1),
1749 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 2),
1750 BPF_JUMP(BPF_JMP+BPF_JSET+BPF_X, 0, 1, 1),
1751 BPF_STMT(BPF_RET+BPF_K, 2),
1752 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 1),
1753 BPF_JUMP(BPF_JMP+BPF_JSET+BPF_X, 0, 2, 3),
1754 BPF_STMT(BPF_RET+BPF_K, 3),
1755 BPF_STMT(BPF_RET+BPF_K, 4),
1756 BPF_STMT(BPF_RET+BPF_K, 5),
1757 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 2),
1758 BPF_JUMP(BPF_JMP+BPF_JSET+BPF_X, 0, 4, 1),
1759 BPF_STMT(BPF_RET+BPF_K, 6),
1760 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 7),
1761 BPF_JUMP(BPF_JMP+BPF_JSET+BPF_X, 0, 0, 0),
1762 BPF_STMT(BPF_RET+BPF_K, 7),
1763 BPF_STMT(BPF_RET+BPF_K, 8)
1766 bpfjit_func_t code;
1767 uint8_t pkt[8]; /* the program doesn't read any data */
1769 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
1771 ATF_CHECK(bpf_validate(insns, insn_count));
1773 code = bpfjit_generate_code(bc, insns, insn_count);
1774 ATF_REQUIRE(code != NULL);
1776 ATF_CHECK(code(pkt, 1, 1) == 1);
1777 ATF_CHECK(code(pkt, 2, 2) == 1);
1778 ATF_CHECK(code(pkt, 3, 3) == 1);
1779 ATF_CHECK(code(pkt, 4, 4) == 7);
1780 ATF_CHECK(code(pkt, 5, 5) == 5);
1781 ATF_CHECK(code(pkt, 6, 6) == 8);
1782 ATF_CHECK(code(pkt, 7, 7) == 5);
1783 ATF_CHECK(code(pkt, 8, 8) == 0);
1785 bpfjit_free_code(code);
1788 ATF_TC(bpfjit_jmp_modulo_x);
1789 ATF_TC_HEAD(bpfjit_jmp_modulo_x, tc)
1791 atf_tc_set_md_var(tc, "descr",
1792 "Test JIT compilation of modulo logic of BPF_JMP+BPF_X operations");
1795 ATF_TC_BODY(bpfjit_jmp_modulo_x, tc)
1797 static struct bpf_insn insns[] = {
1798 BPF_STMT(BPF_LD+BPF_IMM, UINT32_C(0x7fffff77)),
1799 /* FFFFF770 << 4 = FFFFF770 */
1800 BPF_STMT(BPF_ALU+BPF_LSH+BPF_K, 4),
1802 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, UINT32_C(0xfffff770)),
1803 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 1, 0),
1804 BPF_STMT(BPF_RET+BPF_K, 0),
1805 BPF_JUMP(BPF_JMP+BPF_JGT+BPF_X, 0, 0, 1),
1806 BPF_STMT(BPF_RET+BPF_K, 1),
1807 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, UINT32_C(0xfffff771)),
1808 BPF_JUMP(BPF_JMP+BPF_JGE+BPF_X, 0, 0, 1),
1809 BPF_STMT(BPF_RET+BPF_K, 2),
1810 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, UINT32_C(0xfffff770)),
1811 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 0, 4),
1812 BPF_JUMP(BPF_JMP+BPF_JGT+BPF_X, 0, 3, 0),
1813 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, UINT32_C(0xfffff771)),
1814 BPF_JUMP(BPF_JMP+BPF_JGE+BPF_X, 0, 1, 0),
1815 BPF_STMT(BPF_JMP+BPF_JA, 1),
1816 BPF_STMT(BPF_RET+BPF_K, 3),
1818 /* FFFFF770+FFFFF770 = 00000001,FFFFEEE0 */
1819 BPF_STMT(BPF_ALU+BPF_ADD+BPF_K, UINT32_C(0xfffff770)),
1821 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, UINT32_C(0xffffeee0)),
1822 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 1, 0),
1823 BPF_STMT(BPF_RET+BPF_K, 4),
1824 BPF_JUMP(BPF_JMP+BPF_JGT+BPF_X, 0, 0, 1),
1825 BPF_STMT(BPF_RET+BPF_K, 5),
1826 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, UINT32_C(0xffffeee1)),
1827 BPF_JUMP(BPF_JMP+BPF_JGE+BPF_X, 0, 0, 1),
1828 BPF_STMT(BPF_RET+BPF_K, 6),
1829 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, UINT32_C(0xffffeee0)),
1830 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 0, 4),
1831 BPF_JUMP(BPF_JMP+BPF_JGT+BPF_X, 0, 3, 0),
1832 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, UINT32_C(0xffffeee1)),
1833 BPF_JUMP(BPF_JMP+BPF_JGE+BPF_X, 0, 1, 0),
1834 BPF_STMT(BPF_RET+BPF_K, UINT32_MAX),
1835 BPF_STMT(BPF_RET+BPF_K, 7)
1838 bpfjit_func_t code;
1839 uint8_t pkt[1]; /* the program doesn't read any data */
1841 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
1843 ATF_CHECK(bpf_validate(insns, insn_count));
1845 code = bpfjit_generate_code(bc, insns, insn_count);
1846 ATF_REQUIRE(code != NULL);
1848 ATF_CHECK(code(pkt, 1, 1) == UINT32_MAX);
1850 bpfjit_free_code(code);
1853 ATF_TC(bpfjit_ld_abs);
1854 ATF_TC_HEAD(bpfjit_ld_abs, tc)
1856 atf_tc_set_md_var(tc, "descr",
1857 "Test JIT compilation of BPF_LD+BPF_ABS");
1860 ATF_TC_BODY(bpfjit_ld_abs, tc)
1862 static struct bpf_insn insns[3][2] = {
1864 BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 5),
1865 BPF_STMT(BPF_RET+BPF_A, 0)
1868 BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 5),
1869 BPF_STMT(BPF_RET+BPF_A, 0)
1872 BPF_STMT(BPF_LD+BPF_W+BPF_ABS, 5),
1873 BPF_STMT(BPF_RET+BPF_A, 0)
1877 static size_t lengths[3] = { 1, 2, 4 };
1878 static unsigned int expected[3] = { 0xde, 0xdead, 0xdeadbeef };
1880 size_t i, l;
1881 uint8_t *pkt = deadbeef_at_5;
1882 size_t pktsize = sizeof(deadbeef_at_5);
1884 size_t insn_count = sizeof(insns[0]) / sizeof(insns[0][0]);
1886 for (i = 0; i < 3; i++) {
1887 bpfjit_func_t code;
1889 ATF_CHECK(bpf_validate(insns[i], insn_count));
1891 code = bpfjit_generate_code(bc, insns[i], insn_count);
1892 ATF_REQUIRE(code != NULL);
1894 for (l = 0; l < 5 + lengths[i]; l++) {
1895 ATF_CHECK(code(pkt, l, l) == 0);
1896 ATF_CHECK(code(pkt, pktsize, l) == 0);
1899 l = 5 + lengths[i];
1900 ATF_CHECK(code(pkt, l, l) == expected[i]);
1901 ATF_CHECK(code(pkt, pktsize, l) == expected[i]);
1903 l = pktsize;
1904 ATF_CHECK(code(pkt, l, l) == expected[i]);
1906 bpfjit_free_code(code);
1910 ATF_TC(bpfjit_ld_abs_k_overflow);
1911 ATF_TC_HEAD(bpfjit_ld_abs_k_overflow, tc)
1913 atf_tc_set_md_var(tc, "descr",
1914 "Test JIT compilation of BPF_LD+BPF_ABS with overflow in k+4");
1917 ATF_TC_BODY(bpfjit_ld_abs_k_overflow, tc)
1919 static struct bpf_insn insns[12][3] = {
1921 BPF_STMT(BPF_LD+BPF_H+BPF_ABS, UINT32_MAX),
1922 BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 7),
1923 BPF_STMT(BPF_RET+BPF_K, 1)
1926 BPF_STMT(BPF_LD+BPF_H+BPF_ABS, UINT32_MAX - 1),
1927 BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 7),
1928 BPF_STMT(BPF_RET+BPF_K, 1)
1931 BPF_STMT(BPF_LD+BPF_W+BPF_ABS, UINT32_MAX),
1932 BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 7),
1933 BPF_STMT(BPF_RET+BPF_K, 1)
1936 BPF_STMT(BPF_LD+BPF_W+BPF_ABS, UINT32_MAX - 1),
1937 BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 7),
1938 BPF_STMT(BPF_RET+BPF_K, 1)
1941 BPF_STMT(BPF_LD+BPF_W+BPF_ABS, UINT32_MAX - 2),
1942 BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 7),
1943 BPF_STMT(BPF_RET+BPF_K, 1)
1946 BPF_STMT(BPF_LD+BPF_W+BPF_ABS, UINT32_MAX - 3),
1947 BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 7),
1948 BPF_STMT(BPF_RET+BPF_K, 1)
1951 BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 7),
1952 BPF_STMT(BPF_LD+BPF_H+BPF_ABS, UINT32_MAX),
1953 BPF_STMT(BPF_RET+BPF_K, 1)
1956 BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 7),
1957 BPF_STMT(BPF_LD+BPF_H+BPF_ABS, UINT32_MAX - 1),
1958 BPF_STMT(BPF_RET+BPF_K, 1)
1961 BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 7),
1962 BPF_STMT(BPF_LD+BPF_W+BPF_ABS, UINT32_MAX),
1963 BPF_STMT(BPF_RET+BPF_K, 1)
1966 BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 7),
1967 BPF_STMT(BPF_LD+BPF_W+BPF_ABS, UINT32_MAX - 1),
1968 BPF_STMT(BPF_RET+BPF_K, 1)
1971 BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 7),
1972 BPF_STMT(BPF_LD+BPF_W+BPF_ABS, UINT32_MAX - 2),
1973 BPF_STMT(BPF_RET+BPF_K, 1)
1976 BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 7),
1977 BPF_STMT(BPF_LD+BPF_W+BPF_ABS, UINT32_MAX - 3),
1978 BPF_STMT(BPF_RET+BPF_K, 1)
1982 int i;
1983 uint8_t pkt[8] = { 0 };
1985 size_t insn_count = sizeof(insns[0]) / sizeof(insns[0][0]);
1987 for (i = 0; i < 3; i++) {
1988 bpfjit_func_t code;
1990 ATF_CHECK(bpf_validate(insns[i], insn_count));
1992 code = bpfjit_generate_code(bc, insns[i], insn_count);
1993 ATF_REQUIRE(code != NULL);
1995 ATF_CHECK(code(pkt, 8, 8) == 0);
1997 bpfjit_free_code(code);
2001 ATF_TC(bpfjit_ld_ind);
2002 ATF_TC_HEAD(bpfjit_ld_ind, tc)
2004 atf_tc_set_md_var(tc, "descr",
2005 "Test JIT compilation of BPF_LD+BPF_IND");
2008 ATF_TC_BODY(bpfjit_ld_ind, tc)
2010 static struct bpf_insn insns[6][3] = {
2012 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 3),
2013 BPF_STMT(BPF_LD+BPF_B+BPF_IND, 2),
2014 BPF_STMT(BPF_RET+BPF_A, 0)
2017 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 3),
2018 BPF_STMT(BPF_LD+BPF_H+BPF_IND, 2),
2019 BPF_STMT(BPF_RET+BPF_A, 0)
2022 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 3),
2023 BPF_STMT(BPF_LD+BPF_W+BPF_IND, 2),
2024 BPF_STMT(BPF_RET+BPF_A, 0)
2027 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 5),
2028 BPF_STMT(BPF_LD+BPF_B+BPF_IND, 0),
2029 BPF_STMT(BPF_RET+BPF_A, 0)
2032 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 5),
2033 BPF_STMT(BPF_LD+BPF_H+BPF_IND, 0),
2034 BPF_STMT(BPF_RET+BPF_A, 0)
2037 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 5),
2038 BPF_STMT(BPF_LD+BPF_W+BPF_IND, 0),
2039 BPF_STMT(BPF_RET+BPF_A, 0)
2043 static size_t lengths[6] = { 1, 2, 4, 1, 2, 4 };
2045 static unsigned int expected[6] = {
2046 0xde, 0xdead, 0xdeadbeef,
2047 0xde, 0xdead, 0xdeadbeef
2050 size_t i, l;
2051 uint8_t *pkt = deadbeef_at_5;
2052 size_t pktsize = sizeof(deadbeef_at_5);
2054 size_t insn_count = sizeof(insns[0]) / sizeof(insns[0][0]);
2056 for (i = 0; i < 3; i++) {
2057 bpfjit_func_t code;
2059 ATF_CHECK(bpf_validate(insns[i], insn_count));
2061 code = bpfjit_generate_code(bc, insns[i], insn_count);
2062 ATF_REQUIRE(code != NULL);
2064 for (l = 0; l < 5 + lengths[i]; l++) {
2065 ATF_CHECK(code(pkt, l, l) == 0);
2066 ATF_CHECK(code(pkt, pktsize, l) == 0);
2069 l = 5 + lengths[i];
2070 ATF_CHECK(code(pkt, l, l) == expected[i]);
2071 ATF_CHECK(code(pkt, pktsize, l) == expected[i]);
2073 l = pktsize;
2074 ATF_CHECK(code(pkt, l, l) == expected[i]);
2076 bpfjit_free_code(code);
2080 ATF_TC(bpfjit_ld_ind_k_overflow);
2081 ATF_TC_HEAD(bpfjit_ld_ind_k_overflow, tc)
2083 atf_tc_set_md_var(tc, "descr",
2084 "Test JIT compilation of BPF_LD+BPF_IND with overflow in k+4");
2087 ATF_TC_BODY(bpfjit_ld_ind_k_overflow, tc)
2089 static struct bpf_insn insns[12][3] = {
2091 BPF_STMT(BPF_LD+BPF_H+BPF_IND, UINT32_MAX),
2092 BPF_STMT(BPF_LD+BPF_H+BPF_IND, 7),
2093 BPF_STMT(BPF_RET+BPF_K, 1)
2096 BPF_STMT(BPF_LD+BPF_H+BPF_IND, UINT32_MAX - 1),
2097 BPF_STMT(BPF_LD+BPF_H+BPF_IND, 7),
2098 BPF_STMT(BPF_RET+BPF_K, 1)
2101 BPF_STMT(BPF_LD+BPF_W+BPF_IND, UINT32_MAX),
2102 BPF_STMT(BPF_LD+BPF_H+BPF_IND, 7),
2103 BPF_STMT(BPF_RET+BPF_K, 1)
2106 BPF_STMT(BPF_LD+BPF_W+BPF_IND, UINT32_MAX - 1),
2107 BPF_STMT(BPF_LD+BPF_H+BPF_IND, 7),
2108 BPF_STMT(BPF_RET+BPF_K, 1)
2111 BPF_STMT(BPF_LD+BPF_W+BPF_IND, UINT32_MAX - 2),
2112 BPF_STMT(BPF_LD+BPF_H+BPF_IND, 7),
2113 BPF_STMT(BPF_RET+BPF_K, 1)
2116 BPF_STMT(BPF_LD+BPF_W+BPF_IND, UINT32_MAX - 3),
2117 BPF_STMT(BPF_LD+BPF_H+BPF_IND, 7),
2118 BPF_STMT(BPF_RET+BPF_K, 1)
2121 BPF_STMT(BPF_LD+BPF_H+BPF_IND, 7),
2122 BPF_STMT(BPF_LD+BPF_H+BPF_IND, UINT32_MAX),
2123 BPF_STMT(BPF_RET+BPF_K, 1)
2126 BPF_STMT(BPF_LD+BPF_H+BPF_IND, 7),
2127 BPF_STMT(BPF_LD+BPF_H+BPF_IND, UINT32_MAX - 1),
2128 BPF_STMT(BPF_RET+BPF_K, 1)
2131 BPF_STMT(BPF_LD+BPF_H+BPF_IND, 7),
2132 BPF_STMT(BPF_LD+BPF_W+BPF_IND, UINT32_MAX),
2133 BPF_STMT(BPF_RET+BPF_K, 1)
2136 BPF_STMT(BPF_LD+BPF_H+BPF_IND, 7),
2137 BPF_STMT(BPF_LD+BPF_W+BPF_IND, UINT32_MAX - 1),
2138 BPF_STMT(BPF_RET+BPF_K, 1)
2141 BPF_STMT(BPF_LD+BPF_H+BPF_IND, 7),
2142 BPF_STMT(BPF_LD+BPF_W+BPF_IND, UINT32_MAX - 2),
2143 BPF_STMT(BPF_RET+BPF_K, 1)
2146 BPF_STMT(BPF_LD+BPF_H+BPF_IND, 7),
2147 BPF_STMT(BPF_LD+BPF_W+BPF_IND, UINT32_MAX - 3),
2148 BPF_STMT(BPF_RET+BPF_K, 1)
2152 int i;
2153 uint8_t pkt[8] = { 0 };
2155 size_t insn_count = sizeof(insns[0]) / sizeof(insns[0][0]);
2157 for (i = 0; i < 3; i++) {
2158 bpfjit_func_t code;
2160 ATF_CHECK(bpf_validate(insns[i], insn_count));
2162 code = bpfjit_generate_code(bc, insns[i], insn_count);
2163 ATF_REQUIRE(code != NULL);
2165 ATF_CHECK(code(pkt, 8, 8) == 0);
2167 bpfjit_free_code(code);
2171 ATF_TC(bpfjit_ld_ind_x_overflow1);
2172 ATF_TC_HEAD(bpfjit_ld_ind_x_overflow1, tc)
2174 atf_tc_set_md_var(tc, "descr",
2175 "Test JIT compilation of BPF_LD+BPF_IND with overflow in X+4");
2178 ATF_TC_BODY(bpfjit_ld_ind_x_overflow1, tc)
2180 static struct bpf_insn insns[] = {
2181 BPF_STMT(BPF_LD+BPF_LEN, 0),
2182 BPF_STMT(BPF_ALU+BPF_ADD+BPF_K, UINT32_C(0xffffffff)),
2183 BPF_STMT(BPF_MISC+BPF_TAX, 0),
2184 BPF_STMT(BPF_LD+BPF_B+BPF_IND, 0),
2185 BPF_STMT(BPF_RET+BPF_A, 0)
2188 size_t i;
2189 bpfjit_func_t code;
2190 uint8_t pkt[8] = { 10, 20, 30, 40, 50, 60, 70, 80 };
2192 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
2194 ATF_CHECK(bpf_validate(insns, insn_count));
2196 code = bpfjit_generate_code(bc, insns, insn_count);
2197 ATF_REQUIRE(code != NULL);
2199 for (i = 1; i <= sizeof(pkt); i++) {
2200 ATF_CHECK(bpf_filter(insns, pkt, i, i) == 10 * i);
2201 ATF_CHECK(code(pkt, i, i) == 10 * i);
2204 bpfjit_free_code(code);
2207 ATF_TC(bpfjit_ld_ind_x_overflow2);
2208 ATF_TC_HEAD(bpfjit_ld_ind_x_overflow2, tc)
2210 atf_tc_set_md_var(tc, "descr",
2211 "Test JIT compilation of BPF_LD+BPF_IND with overflow in X+4");
2214 ATF_TC_BODY(bpfjit_ld_ind_x_overflow2, tc)
2216 static struct bpf_insn insns[] = {
2217 BPF_STMT(BPF_LD+BPF_LEN, 0),
2218 BPF_STMT(BPF_ALU+BPF_ADD+BPF_K, UINT32_C(0xffffffff)),
2219 BPF_STMT(BPF_ST, 3),
2220 BPF_STMT(BPF_LDX+BPF_W+BPF_MEM, 3),
2221 BPF_STMT(BPF_LD+BPF_B+BPF_IND, 0),
2222 BPF_STMT(BPF_RET+BPF_A, 0)
2225 size_t i;
2226 bpfjit_func_t code;
2227 uint8_t pkt[8] = { 10, 20, 30, 40, 50, 60, 70, 80 };
2229 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
2231 ATF_CHECK(bpf_validate(insns, insn_count));
2233 code = bpfjit_generate_code(bc, insns, insn_count);
2234 ATF_REQUIRE(code != NULL);
2236 for (i = 1; i <= sizeof(pkt); i++) {
2237 ATF_CHECK(bpf_filter(insns, pkt, i, i) == 10 * i);
2238 ATF_CHECK(code(pkt, i, i) == 10 * i);
2241 bpfjit_free_code(code);
2244 ATF_TC(bpfjit_ld_len);
2245 ATF_TC_HEAD(bpfjit_ld_len, tc)
2247 atf_tc_set_md_var(tc, "descr",
2248 "Test JIT compilation of BPF_LD+BPF_W+BPF_LEN");
2251 ATF_TC_BODY(bpfjit_ld_len, tc)
2253 static struct bpf_insn insns[] = {
2254 BPF_STMT(BPF_LD+BPF_W+BPF_LEN, 0),
2255 BPF_STMT(BPF_RET+BPF_A, 0)
2258 size_t i;
2259 bpfjit_func_t code;
2260 uint8_t pkt[32]; /* the program doesn't read any data */
2262 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
2264 ATF_CHECK(bpf_validate(insns, insn_count));
2266 code = bpfjit_generate_code(bc, insns, insn_count);
2267 ATF_REQUIRE(code != NULL);
2269 for (i = 0; i < sizeof(pkt); i++)
2270 ATF_CHECK(code(pkt, i, 1) == i);
2272 bpfjit_free_code(code);
2275 ATF_TC(bpfjit_ld_imm);
2276 ATF_TC_HEAD(bpfjit_ld_imm, tc)
2278 atf_tc_set_md_var(tc, "descr",
2279 "Test JIT compilation of BPF_LD+BPF_IMM");
2282 ATF_TC_BODY(bpfjit_ld_imm, tc)
2284 static struct bpf_insn insns[] = {
2285 BPF_STMT(BPF_LD+BPF_IMM, UINT32_MAX),
2286 BPF_STMT(BPF_RET+BPF_A, 0)
2289 bpfjit_func_t code;
2290 uint8_t pkt[1]; /* the program doesn't read any data */
2292 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
2294 ATF_CHECK(bpf_validate(insns, insn_count));
2296 code = bpfjit_generate_code(bc, insns, insn_count);
2297 ATF_REQUIRE(code != NULL);
2299 ATF_CHECK(code(pkt, 1, 1) == UINT32_MAX);
2301 bpfjit_free_code(code);
2304 ATF_TC(bpfjit_ldx_imm1);
2305 ATF_TC_HEAD(bpfjit_ldx_imm1, tc)
2307 atf_tc_set_md_var(tc, "descr",
2308 "Test JIT compilation of BPF_LDX+BPF_IMM");
2311 ATF_TC_BODY(bpfjit_ldx_imm1, tc)
2313 static struct bpf_insn insns[] = {
2314 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, UINT32_MAX - 5),
2315 BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0),
2316 BPF_STMT(BPF_RET+BPF_A, 0)
2319 bpfjit_func_t code;
2320 uint8_t pkt[1]; /* the program doesn't read any data */
2322 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
2324 ATF_CHECK(bpf_validate(insns, insn_count));
2326 code = bpfjit_generate_code(bc, insns, insn_count);
2327 ATF_REQUIRE(code != NULL);
2329 ATF_CHECK(code(pkt, 1, 1) == UINT32_MAX - 5);
2331 bpfjit_free_code(code);
2334 ATF_TC(bpfjit_ldx_imm2);
2335 ATF_TC_HEAD(bpfjit_ldx_imm2, tc)
2337 atf_tc_set_md_var(tc, "descr",
2338 "Test JIT compilation of BPF_LDX+BPF_IMM");
2341 ATF_TC_BODY(bpfjit_ldx_imm2, tc)
2343 static struct bpf_insn insns[] = {
2344 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 5),
2345 BPF_STMT(BPF_LD+BPF_IMM, 5),
2346 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 1, 0),
2347 BPF_STMT(BPF_RET+BPF_K, 7),
2348 BPF_STMT(BPF_RET+BPF_K, UINT32_MAX)
2351 bpfjit_func_t code;
2352 uint8_t pkt[1]; /* the program doesn't read any data */
2354 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
2356 ATF_CHECK(bpf_validate(insns, insn_count));
2358 code = bpfjit_generate_code(bc, insns, insn_count);
2359 ATF_REQUIRE(code != NULL);
2361 ATF_CHECK(code(pkt, 1, 1) == UINT32_MAX);
2363 bpfjit_free_code(code);
2366 ATF_TC(bpfjit_ldx_len1);
2367 ATF_TC_HEAD(bpfjit_ldx_len1, tc)
2369 atf_tc_set_md_var(tc, "descr",
2370 "Test JIT compilation of BPF_LDX+BPF_LEN");
2373 ATF_TC_BODY(bpfjit_ldx_len1, tc)
2375 static struct bpf_insn insns[] = {
2376 BPF_STMT(BPF_LDX+BPF_W+BPF_LEN, 0),
2377 BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0),
2378 BPF_STMT(BPF_RET+BPF_A, 0)
2381 size_t i;
2382 bpfjit_func_t code;
2383 uint8_t pkt[5]; /* the program doesn't read any data */
2385 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
2387 ATF_CHECK(bpf_validate(insns, insn_count));
2389 code = bpfjit_generate_code(bc, insns, insn_count);
2390 ATF_REQUIRE(code != NULL);
2392 for (i = 1; i < sizeof(pkt); i++) {
2393 ATF_CHECK(code(pkt, i, 1) == i);
2394 ATF_CHECK(code(pkt, i + 1, i) == i + 1);
2397 bpfjit_free_code(code);
2400 ATF_TC(bpfjit_ldx_len2);
2401 ATF_TC_HEAD(bpfjit_ldx_len2, tc)
2403 atf_tc_set_md_var(tc, "descr",
2404 "Test JIT compilation of BPF_LDX+BPF_LEN");
2407 ATF_TC_BODY(bpfjit_ldx_len2, tc)
2409 static struct bpf_insn insns[] = {
2410 BPF_STMT(BPF_LDX+BPF_W+BPF_LEN, 0),
2411 BPF_STMT(BPF_LD+BPF_IMM, 5),
2412 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_X, 0, 1, 0),
2413 BPF_STMT(BPF_RET+BPF_K, 7),
2414 BPF_STMT(BPF_RET+BPF_K, UINT32_MAX)
2417 bpfjit_func_t code;
2418 uint8_t pkt[5]; /* the program doesn't read any data */
2420 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
2422 ATF_CHECK(bpf_validate(insns, insn_count));
2424 code = bpfjit_generate_code(bc, insns, insn_count);
2425 ATF_REQUIRE(code != NULL);
2427 ATF_CHECK(code(pkt, 5, 1) == UINT32_MAX);
2428 ATF_CHECK(code(pkt, 6, 5) == 7);
2430 bpfjit_free_code(code);
2433 ATF_TC(bpfjit_ldx_msh);
2434 ATF_TC_HEAD(bpfjit_ldx_msh, tc)
2436 atf_tc_set_md_var(tc, "descr",
2437 "Test JIT compilation of BPF_LDX+BPF_MSH");
2440 ATF_TC_BODY(bpfjit_ldx_msh, tc)
2442 static struct bpf_insn insns[] = {
2443 BPF_STMT(BPF_LDX+BPF_B+BPF_MSH, 1),
2444 BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0),
2445 BPF_STMT(BPF_RET+BPF_A, 0)
2448 bpfjit_func_t code;
2449 uint8_t pkt[2] = { 0, 0x7a };
2451 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
2453 ATF_CHECK(bpf_validate(insns, insn_count));
2455 code = bpfjit_generate_code(bc, insns, insn_count);
2456 ATF_REQUIRE(code != NULL);
2458 ATF_CHECK(code(pkt, 2, 2) == 40);
2460 bpfjit_free_code(code);
2463 ATF_TC(bpfjit_misc_tax);
2464 ATF_TC_HEAD(bpfjit_misc_tax, tc)
2466 atf_tc_set_md_var(tc, "descr",
2467 "Test JIT compilation of BPF_MISC+BPF_TAX");
2470 ATF_TC_BODY(bpfjit_misc_tax, tc)
2472 static struct bpf_insn insns[] = {
2473 BPF_STMT(BPF_LD+BPF_IMM, 3),
2474 BPF_STMT(BPF_MISC+BPF_TAX, 0),
2475 BPF_STMT(BPF_LD+BPF_B+BPF_IND, 2),
2476 BPF_STMT(BPF_RET+BPF_A, 0)
2479 bpfjit_func_t code;
2480 uint8_t pkt[] = { 0, 11, 22, 33, 44, 55 };
2482 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
2484 ATF_CHECK(bpf_validate(insns, insn_count));
2486 code = bpfjit_generate_code(bc, insns, insn_count);
2487 ATF_REQUIRE(code != NULL);
2489 ATF_CHECK(code(pkt, sizeof(pkt), sizeof(pkt)) == 55);
2491 bpfjit_free_code(code);
2494 ATF_TC(bpfjit_misc_txa);
2495 ATF_TC_HEAD(bpfjit_misc_txa, tc)
2497 atf_tc_set_md_var(tc, "descr",
2498 "Test JIT compilation of BPF_MISC+BPF_TXA");
2501 ATF_TC_BODY(bpfjit_misc_txa, tc)
2503 static struct bpf_insn insns[] = {
2504 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 391),
2505 BPF_STMT(BPF_MISC+BPF_TXA, 0),
2506 BPF_STMT(BPF_RET+BPF_A, 0)
2509 bpfjit_func_t code;
2510 uint8_t pkt[1]; /* the program doesn't read any data */
2512 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
2514 ATF_CHECK(bpf_validate(insns, insn_count));
2516 code = bpfjit_generate_code(bc, insns, insn_count);
2517 ATF_REQUIRE(code != NULL);
2519 ATF_CHECK(code(pkt, 1, 1) == 391);
2521 bpfjit_free_code(code);
2524 ATF_TC(bpfjit_st1);
2525 ATF_TC_HEAD(bpfjit_st1, tc)
2527 atf_tc_set_md_var(tc, "descr",
2528 "Test JIT compilation of BPF_ST");
2531 ATF_TC_BODY(bpfjit_st1, tc)
2533 static struct bpf_insn insns[] = {
2534 BPF_STMT(BPF_LD+BPF_W+BPF_LEN, 0),
2535 BPF_STMT(BPF_ST, 0),
2536 BPF_STMT(BPF_LD+BPF_MEM, 0),
2537 BPF_STMT(BPF_RET+BPF_A, 0)
2540 size_t i;
2541 bpfjit_func_t code;
2542 uint8_t pkt[16]; /* the program doesn't read any data */
2544 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
2546 ATF_CHECK(bpf_validate(insns, insn_count));
2548 code = bpfjit_generate_code(bc, insns, insn_count);
2549 ATF_REQUIRE(code != NULL);
2551 for (i = 1; i <= sizeof(pkt); i++)
2552 ATF_CHECK(code(pkt, i, sizeof(pkt)) == i);
2554 bpfjit_free_code(code);
2557 ATF_TC(bpfjit_st2);
2558 ATF_TC_HEAD(bpfjit_st2, tc)
2560 atf_tc_set_md_var(tc, "descr",
2561 "Test JIT compilation of BPF_ST");
2564 ATF_TC_BODY(bpfjit_st2, tc)
2566 static struct bpf_insn insns[] = {
2567 BPF_STMT(BPF_LD+BPF_W+BPF_LEN, 0),
2568 BPF_STMT(BPF_ST, BPF_MEMWORDS-1),
2569 BPF_STMT(BPF_LD+BPF_MEM, 0),
2570 BPF_STMT(BPF_RET+BPF_A, 0)
2573 bpfjit_func_t code;
2574 uint8_t pkt[1]; /* the program doesn't read any data */
2576 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
2578 ATF_CHECK(bpf_validate(insns, insn_count));
2580 code = bpfjit_generate_code(bc, insns, insn_count);
2581 ATF_REQUIRE(code != NULL);
2583 ATF_CHECK(code(pkt, 1, 1) == 0);
2585 bpfjit_free_code(code);
2588 ATF_TC(bpfjit_st3);
2589 ATF_TC_HEAD(bpfjit_st3, tc)
2591 atf_tc_set_md_var(tc, "descr",
2592 "Test JIT compilation of BPF_ST");
2595 ATF_TC_BODY(bpfjit_st3, tc)
2597 static struct bpf_insn insns[] = {
2598 BPF_STMT(BPF_LD+BPF_W+BPF_LEN, 0),
2599 BPF_STMT(BPF_ST, 0),
2600 BPF_STMT(BPF_ALU+BPF_ADD+BPF_K, 100),
2601 BPF_STMT(BPF_ST, BPF_MEMWORDS-1),
2602 BPF_STMT(BPF_ALU+BPF_ADD+BPF_K, 200),
2603 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 301, 2, 0),
2604 BPF_STMT(BPF_LD+BPF_MEM, BPF_MEMWORDS-1),
2605 BPF_STMT(BPF_RET+BPF_A, 0),
2606 BPF_STMT(BPF_LD+BPF_MEM, 0),
2607 BPF_STMT(BPF_RET+BPF_A, 0)
2610 bpfjit_func_t code;
2611 uint8_t pkt[2]; /* the program doesn't read any data */
2613 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
2615 ATF_REQUIRE(BPF_MEMWORDS > 1);
2617 ATF_CHECK(bpf_validate(insns, insn_count));
2619 code = bpfjit_generate_code(bc, insns, insn_count);
2620 ATF_REQUIRE(code != NULL);
2622 ATF_CHECK(code(pkt, 1, 1) == 1);
2623 ATF_CHECK(code(pkt, 2, 2) == 102);
2625 bpfjit_free_code(code);
2628 ATF_TC(bpfjit_st4);
2629 ATF_TC_HEAD(bpfjit_st4, tc)
2631 atf_tc_set_md_var(tc, "descr",
2632 "Test JIT compilation of BPF_ST");
2635 ATF_TC_BODY(bpfjit_st4, tc)
2637 static struct bpf_insn insns[] = {
2638 BPF_STMT(BPF_LD+BPF_W+BPF_LEN, 0),
2639 BPF_STMT(BPF_ST, 5),
2640 BPF_STMT(BPF_ALU+BPF_ADD+BPF_K, 100),
2641 BPF_STMT(BPF_ST, BPF_MEMWORDS-1),
2642 BPF_STMT(BPF_ALU+BPF_ADD+BPF_K, 200),
2643 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 301, 2, 0),
2644 BPF_STMT(BPF_LD+BPF_MEM, BPF_MEMWORDS-1),
2645 BPF_STMT(BPF_RET+BPF_A, 0),
2646 BPF_STMT(BPF_LD+BPF_MEM, 5),
2647 BPF_STMT(BPF_RET+BPF_A, 0)
2650 bpfjit_func_t code;
2651 uint8_t pkt[2]; /* the program doesn't read any data */
2653 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
2655 ATF_REQUIRE(BPF_MEMWORDS > 6);
2657 ATF_CHECK(bpf_validate(insns, insn_count));
2659 code = bpfjit_generate_code(bc, insns, insn_count);
2660 ATF_REQUIRE(code != NULL);
2662 ATF_CHECK(code(pkt, 1, 1) == 1);
2663 ATF_CHECK(code(pkt, 2, 2) == 102);
2665 bpfjit_free_code(code);
2668 ATF_TC(bpfjit_st5);
2669 ATF_TC_HEAD(bpfjit_st5, tc)
2671 atf_tc_set_md_var(tc, "descr",
2672 "Test JIT compilation of BPF_ST");
2675 ATF_TC_BODY(bpfjit_st5, tc)
2677 struct bpf_insn insns[5*BPF_MEMWORDS+2];
2678 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
2680 size_t k;
2681 bpfjit_func_t code;
2682 uint8_t pkt[BPF_MEMWORDS]; /* the program doesn't read any data */
2684 memset(insns, 0, sizeof(insns));
2686 /* for each k do M[k] = k */
2687 for (k = 0; k < BPF_MEMWORDS; k++) {
2688 insns[2*k].code = BPF_LD+BPF_IMM;
2689 insns[2*k].k = 3*k;
2690 insns[2*k+1].code = BPF_ST;
2691 insns[2*k+1].k = k;
2694 /* load wirelen into A */
2695 insns[2*BPF_MEMWORDS].code = BPF_LD+BPF_W+BPF_LEN;
2697 /* for each k, if (A == k + 1) return M[k] */
2698 for (k = 0; k < BPF_MEMWORDS; k++) {
2699 insns[2*BPF_MEMWORDS+3*k+1].code = BPF_JMP+BPF_JEQ+BPF_K;
2700 insns[2*BPF_MEMWORDS+3*k+1].k = k+1;
2701 insns[2*BPF_MEMWORDS+3*k+1].jt = 0;
2702 insns[2*BPF_MEMWORDS+3*k+1].jf = 2;
2703 insns[2*BPF_MEMWORDS+3*k+2].code = BPF_LD+BPF_MEM;
2704 insns[2*BPF_MEMWORDS+3*k+2].k = k;
2705 insns[2*BPF_MEMWORDS+3*k+3].code = BPF_RET+BPF_A;
2706 insns[2*BPF_MEMWORDS+3*k+3].k = 0;
2709 insns[5*BPF_MEMWORDS+1].code = BPF_RET+BPF_K;
2710 insns[5*BPF_MEMWORDS+1].k = UINT32_MAX;
2712 ATF_CHECK(bpf_validate(insns, insn_count));
2714 code = bpfjit_generate_code(bc, insns, insn_count);
2715 ATF_REQUIRE(code != NULL);
2717 for (k = 1; k <= sizeof(pkt); k++)
2718 ATF_CHECK(code(pkt, k, k) == 3*(k-1));
2720 bpfjit_free_code(code);
2723 ATF_TC(bpfjit_stx1);
2724 ATF_TC_HEAD(bpfjit_stx1, tc)
2726 atf_tc_set_md_var(tc, "descr",
2727 "Test JIT compilation of BPF_STX");
2730 ATF_TC_BODY(bpfjit_stx1, tc)
2732 static struct bpf_insn insns[] = {
2733 BPF_STMT(BPF_LDX+BPF_W+BPF_LEN, 0),
2734 BPF_STMT(BPF_STX, 0),
2735 BPF_STMT(BPF_LDX+BPF_W+BPF_MEM, 0),
2736 BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0),
2737 BPF_STMT(BPF_RET+BPF_A, 0)
2740 size_t i;
2741 bpfjit_func_t code;
2742 uint8_t pkt[16]; /* the program doesn't read any data */
2744 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
2746 ATF_CHECK(bpf_validate(insns, insn_count));
2748 code = bpfjit_generate_code(bc, insns, insn_count);
2749 ATF_REQUIRE(code != NULL);
2751 for (i = 1; i <= sizeof(pkt); i++)
2752 ATF_CHECK(code(pkt, i, sizeof(pkt)) == i);
2754 bpfjit_free_code(code);
2757 ATF_TC(bpfjit_stx2);
2758 ATF_TC_HEAD(bpfjit_stx2, tc)
2760 atf_tc_set_md_var(tc, "descr",
2761 "Test JIT compilation of BPF_STX");
2764 ATF_TC_BODY(bpfjit_stx2, tc)
2766 static struct bpf_insn insns[] = {
2767 BPF_STMT(BPF_LDX+BPF_W+BPF_LEN, 0),
2768 BPF_STMT(BPF_STX, BPF_MEMWORDS-1),
2769 BPF_STMT(BPF_LDX+BPF_W+BPF_MEM, 0),
2770 BPF_STMT(BPF_MISC+BPF_TXA, 0),
2771 BPF_STMT(BPF_RET+BPF_A, 0)
2774 bpfjit_func_t code;
2775 uint8_t pkt[1]; /* the program doesn't read any data */
2777 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
2779 ATF_CHECK(bpf_validate(insns, insn_count));
2781 code = bpfjit_generate_code(bc, insns, insn_count);
2782 ATF_REQUIRE(code != NULL);
2784 ATF_CHECK(code(pkt, 1, 1) == 0);
2786 bpfjit_free_code(code);
2789 ATF_TC(bpfjit_stx3);
2790 ATF_TC_HEAD(bpfjit_stx3, tc)
2792 atf_tc_set_md_var(tc, "descr",
2793 "Test JIT compilation of BPF_STX");
2796 ATF_TC_BODY(bpfjit_stx3, tc)
2798 static struct bpf_insn insns[] = {
2799 BPF_STMT(BPF_LDX+BPF_W+BPF_LEN, 0),
2800 BPF_STMT(BPF_STX, 5),
2801 BPF_STMT(BPF_STX, 2),
2802 BPF_STMT(BPF_STX, 3),
2803 BPF_STMT(BPF_LDX+BPF_W+BPF_MEM, 1),
2804 BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0),
2805 BPF_STMT(BPF_LDX+BPF_W+BPF_MEM, 2),
2806 BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0),
2807 BPF_STMT(BPF_LDX+BPF_W+BPF_MEM, 3),
2808 BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0),
2809 BPF_STMT(BPF_LDX+BPF_W+BPF_MEM, 5),
2810 BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0),
2811 BPF_STMT(BPF_LDX+BPF_W+BPF_MEM, 6),
2812 BPF_STMT(BPF_ALU+BPF_ADD+BPF_X, 0),
2813 BPF_STMT(BPF_RET+BPF_A, 0)
2816 size_t i;
2817 bpfjit_func_t code;
2818 uint8_t pkt[16]; /* the program doesn't read any data */
2820 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
2822 ATF_CHECK(bpf_validate(insns, insn_count));
2824 code = bpfjit_generate_code(bc, insns, insn_count);
2825 ATF_REQUIRE(code != NULL);
2827 for (i = 1; i <= sizeof(pkt); i++)
2828 ATF_CHECK(code(pkt, i, sizeof(pkt)) == 3 * i);
2830 bpfjit_free_code(code);
2833 ATF_TC(bpfjit_stx4);
2834 ATF_TC_HEAD(bpfjit_stx4, tc)
2836 atf_tc_set_md_var(tc, "descr",
2837 "Test JIT compilation of BPF_STX");
2840 ATF_TC_BODY(bpfjit_stx4, tc)
2842 struct bpf_insn insns[5*BPF_MEMWORDS+2];
2843 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
2845 size_t k;
2846 bpfjit_func_t code;
2847 uint8_t pkt[BPF_MEMWORDS]; /* the program doesn't read any data */
2849 memset(insns, 0, sizeof(insns));
2851 /* for each k do M[k] = k */
2852 for (k = 0; k < BPF_MEMWORDS; k++) {
2853 insns[2*k].code = BPF_LDX+BPF_W+BPF_IMM;
2854 insns[2*k].k = 3*k;
2855 insns[2*k+1].code = BPF_STX;
2856 insns[2*k+1].k = k;
2859 /* load wirelen into A */
2860 insns[2*BPF_MEMWORDS].code = BPF_LD+BPF_W+BPF_LEN;
2862 /* for each k, if (A == k + 1) return M[k] */
2863 for (k = 0; k < BPF_MEMWORDS; k++) {
2864 insns[2*BPF_MEMWORDS+3*k+1].code = BPF_JMP+BPF_JEQ+BPF_K;
2865 insns[2*BPF_MEMWORDS+3*k+1].k = k+1;
2866 insns[2*BPF_MEMWORDS+3*k+1].jt = 0;
2867 insns[2*BPF_MEMWORDS+3*k+1].jf = 2;
2868 insns[2*BPF_MEMWORDS+3*k+2].code = BPF_LD+BPF_MEM;
2869 insns[2*BPF_MEMWORDS+3*k+2].k = k;
2870 insns[2*BPF_MEMWORDS+3*k+3].code = BPF_RET+BPF_A;
2871 insns[2*BPF_MEMWORDS+3*k+3].k = 0;
2874 insns[5*BPF_MEMWORDS+1].code = BPF_RET+BPF_K;
2875 insns[5*BPF_MEMWORDS+1].k = UINT32_MAX;
2877 ATF_CHECK(bpf_validate(insns, insn_count));
2879 code = bpfjit_generate_code(bc, insns, insn_count);
2880 ATF_REQUIRE(code != NULL);
2882 for (k = 1; k <= sizeof(pkt); k++)
2883 ATF_CHECK(code(pkt, k, k) == 3*(k-1));
2885 bpfjit_free_code(code);
2888 ATF_TC(bpfjit_opt_ld_abs_1);
2889 ATF_TC_HEAD(bpfjit_opt_ld_abs_1, tc)
2891 atf_tc_set_md_var(tc, "descr",
2892 "Test JIT compilation with length optimization "
2893 "applied to BPF_LD+BPF_ABS");
2896 ATF_TC_BODY(bpfjit_opt_ld_abs_1, tc)
2898 static struct bpf_insn insns[] = {
2899 BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 12),
2900 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x800, 0, 8),
2901 BPF_STMT(BPF_LD+BPF_W+BPF_ABS, 26),
2902 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x8003700f, 0, 2),
2903 BPF_STMT(BPF_LD+BPF_W+BPF_ABS, 30),
2904 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x80037023, 3, 4),
2905 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x80037023, 0, 3),
2906 BPF_STMT(BPF_LD+BPF_W+BPF_ABS, 30),
2907 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x8003700f, 0, 1),
2908 BPF_STMT(BPF_RET+BPF_K, UINT32_MAX),
2909 BPF_STMT(BPF_RET+BPF_K, 0),
2912 size_t i, j;
2913 bpfjit_func_t code;
2914 uint8_t pkt[2][34] = {
2916 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0x08, 0x00,
2917 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
2918 0x80, 0x03, 0x70, 0x0f,
2919 0x80, 0x03, 0x70, 0x23
2922 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0x08, 0x00,
2923 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
2924 0x80, 0x03, 0x70, 0x23,
2925 0x80, 0x03, 0x70, 0x0f
2929 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
2931 ATF_CHECK(bpf_validate(insns, insn_count));
2933 code = bpfjit_generate_code(bc, insns, insn_count);
2934 ATF_REQUIRE(code != NULL);
2936 for (i = 0; i < 2; i++) {
2937 for (j = 1; j < sizeof(pkt[i]); j++)
2938 ATF_CHECK(code(pkt[i], j, j) == 0);
2939 ATF_CHECK(code(pkt[i], j, j) == UINT32_MAX);
2942 bpfjit_free_code(code);
2945 ATF_TC(bpfjit_opt_ld_abs_2);
2946 ATF_TC_HEAD(bpfjit_opt_ld_abs_2, tc)
2948 atf_tc_set_md_var(tc, "descr",
2949 "Test JIT compilation with length optimization "
2950 "applied to BPF_LD+BPF_ABS");
2953 ATF_TC_BODY(bpfjit_opt_ld_abs_2, tc)
2955 static struct bpf_insn insns[] = {
2956 BPF_STMT(BPF_LD+BPF_W+BPF_ABS, 26),
2957 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x8003700f, 0, 2),
2958 BPF_STMT(BPF_LD+BPF_W+BPF_ABS, 30),
2959 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x80037023, 3, 6),
2960 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x80037023, 0, 5),
2961 BPF_STMT(BPF_LD+BPF_W+BPF_ABS, 30),
2962 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x8003700f, 0, 3),
2963 BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 12),
2964 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x800, 0, 1),
2965 BPF_STMT(BPF_RET+BPF_K, UINT32_MAX),
2966 BPF_STMT(BPF_RET+BPF_K, 0),
2969 size_t i, j;
2970 bpfjit_func_t code;
2971 uint8_t pkt[2][34] = {
2973 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0x08, 0x00,
2974 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
2975 0x80, 0x03, 0x70, 0x0f,
2976 0x80, 0x03, 0x70, 0x23
2979 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0x08, 0x00,
2980 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
2981 0x80, 0x03, 0x70, 0x23,
2982 0x80, 0x03, 0x70, 0x0f
2986 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
2988 ATF_CHECK(bpf_validate(insns, insn_count));
2990 code = bpfjit_generate_code(bc, insns, insn_count);
2991 ATF_REQUIRE(code != NULL);
2993 for (i = 0; i < 2; i++) {
2994 for (j = 1; j < sizeof(pkt[i]); j++)
2995 ATF_CHECK(code(pkt[i], j, j) == 0);
2996 ATF_CHECK(code(pkt[i], j, j) == UINT32_MAX);
2999 bpfjit_free_code(code);
3002 ATF_TC(bpfjit_opt_ld_abs_3);
3003 ATF_TC_HEAD(bpfjit_opt_ld_abs_3, tc)
3005 atf_tc_set_md_var(tc, "descr",
3006 "Test JIT compilation with length optimization "
3007 "applied to BPF_LD+BPF_ABS");
3010 ATF_TC_BODY(bpfjit_opt_ld_abs_3, tc)
3012 static struct bpf_insn insns[] = {
3013 BPF_STMT(BPF_LD+BPF_W+BPF_ABS, 30),
3014 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x80037023, 0, 2),
3015 BPF_STMT(BPF_LD+BPF_W+BPF_ABS, 26),
3016 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x8003700f, 3, 6),
3017 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x8003700f, 0, 5),
3018 BPF_STMT(BPF_LD+BPF_W+BPF_ABS, 26),
3019 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x80037023, 0, 3),
3020 BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 12),
3021 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x800, 0, 1),
3022 BPF_STMT(BPF_RET+BPF_K, UINT32_MAX),
3023 BPF_STMT(BPF_RET+BPF_K, 0),
3026 size_t i, j;
3027 bpfjit_func_t code;
3028 uint8_t pkt[2][34] = {
3030 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0x08, 0x00,
3031 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
3032 0x80, 0x03, 0x70, 0x0f,
3033 0x80, 0x03, 0x70, 0x23
3036 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0x08, 0x00,
3037 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
3038 0x80, 0x03, 0x70, 0x23,
3039 0x80, 0x03, 0x70, 0x0f
3043 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
3045 ATF_CHECK(bpf_validate(insns, insn_count));
3047 code = bpfjit_generate_code(bc, insns, insn_count);
3048 ATF_REQUIRE(code != NULL);
3050 for (i = 0; i < 2; i++) {
3051 for (j = 1; j < sizeof(pkt[i]); j++)
3052 ATF_CHECK(code(pkt[i], j, j) == 0);
3053 ATF_CHECK(code(pkt[i], j, j) == UINT32_MAX);
3056 bpfjit_free_code(code);
3059 ATF_TC(bpfjit_opt_ld_ind_1);
3060 ATF_TC_HEAD(bpfjit_opt_ld_ind_1, tc)
3062 atf_tc_set_md_var(tc, "descr",
3063 "Test JIT compilation with length optimization "
3064 "applied to BPF_LD+BPF_IND");
3067 ATF_TC_BODY(bpfjit_opt_ld_ind_1, tc)
3069 static struct bpf_insn insns[] = {
3070 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 12),
3071 BPF_STMT(BPF_LD+BPF_H+BPF_IND, 0),
3072 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x800, 0, 8),
3073 BPF_STMT(BPF_LD+BPF_W+BPF_IND, 14),
3074 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x8003700f, 0, 2),
3075 BPF_STMT(BPF_LD+BPF_W+BPF_IND, 18),
3076 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x80037023, 3, 4),
3077 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x80037023, 0, 3),
3078 BPF_STMT(BPF_LD+BPF_W+BPF_IND, 18),
3079 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x8003700f, 0, 1),
3080 BPF_STMT(BPF_RET+BPF_K, UINT32_MAX),
3081 BPF_STMT(BPF_RET+BPF_K, 0),
3084 size_t i, j;
3085 bpfjit_func_t code;
3086 uint8_t pkt[2][34] = {
3088 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0x08, 0x00,
3089 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
3090 0x80, 0x03, 0x70, 0x0f,
3091 0x80, 0x03, 0x70, 0x23
3094 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0x08, 0x00,
3095 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
3096 0x80, 0x03, 0x70, 0x23,
3097 0x80, 0x03, 0x70, 0x0f
3101 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
3103 ATF_CHECK(bpf_validate(insns, insn_count));
3105 code = bpfjit_generate_code(bc, insns, insn_count);
3106 ATF_REQUIRE(code != NULL);
3108 for (i = 0; i < 2; i++) {
3109 for (j = 1; j < sizeof(pkt[i]); j++)
3110 ATF_CHECK(code(pkt[i], j, j) == 0);
3111 ATF_CHECK(code(pkt[i], j, j) == UINT32_MAX);
3114 bpfjit_free_code(code);
3117 ATF_TC(bpfjit_opt_ld_ind_2);
3118 ATF_TC_HEAD(bpfjit_opt_ld_ind_2, tc)
3120 atf_tc_set_md_var(tc, "descr",
3121 "Test JIT compilation with length optimization "
3122 "applied to BPF_LD+BPF_IND");
3125 ATF_TC_BODY(bpfjit_opt_ld_ind_2, tc)
3127 static struct bpf_insn insns[] = {
3128 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 0),
3129 BPF_STMT(BPF_LD+BPF_W+BPF_IND, 26),
3130 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x8003700f, 0, 2),
3131 BPF_STMT(BPF_LD+BPF_W+BPF_IND, 30),
3132 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x80037023, 3, 6),
3133 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x80037023, 0, 5),
3134 BPF_STMT(BPF_LD+BPF_W+BPF_IND, 30),
3135 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x8003700f, 0, 3),
3136 BPF_STMT(BPF_LD+BPF_H+BPF_IND, 12),
3137 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x800, 0, 1),
3138 BPF_STMT(BPF_RET+BPF_K, UINT32_MAX),
3139 BPF_STMT(BPF_RET+BPF_K, 0),
3142 size_t i, j;
3143 bpfjit_func_t code;
3144 uint8_t pkt[2][34] = {
3146 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0x08, 0x00,
3147 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
3148 0x80, 0x03, 0x70, 0x0f,
3149 0x80, 0x03, 0x70, 0x23
3152 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0x08, 0x00,
3153 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
3154 0x80, 0x03, 0x70, 0x23,
3155 0x80, 0x03, 0x70, 0x0f
3159 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
3161 ATF_CHECK(bpf_validate(insns, insn_count));
3163 code = bpfjit_generate_code(bc, insns, insn_count);
3164 ATF_REQUIRE(code != NULL);
3166 for (i = 0; i < 2; i++) {
3167 for (j = 1; j < sizeof(pkt[i]); j++)
3168 ATF_CHECK(code(pkt[i], j, j) == 0);
3169 ATF_CHECK(code(pkt[i], j, j) == UINT32_MAX);
3172 bpfjit_free_code(code);
3175 ATF_TC(bpfjit_opt_ld_ind_3);
3176 ATF_TC_HEAD(bpfjit_opt_ld_ind_3, tc)
3178 atf_tc_set_md_var(tc, "descr",
3179 "Test JIT compilation with length optimization "
3180 "applied to BPF_LD+BPF_IND");
3183 ATF_TC_BODY(bpfjit_opt_ld_ind_3, tc)
3185 static struct bpf_insn insns[] = {
3186 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 15),
3187 BPF_STMT(BPF_LD+BPF_W+BPF_IND, 15),
3188 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x80037023, 0, 2),
3189 BPF_STMT(BPF_LD+BPF_W+BPF_IND, 11),
3190 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x8003700f, 3, 7),
3191 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x8003700f, 0, 6),
3192 BPF_STMT(BPF_LD+BPF_W+BPF_IND, 11),
3193 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x80037023, 0, 4),
3194 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 0),
3195 BPF_STMT(BPF_LD+BPF_H+BPF_IND, 12),
3196 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x800, 0, 1),
3197 BPF_STMT(BPF_RET+BPF_K, UINT32_MAX),
3198 BPF_STMT(BPF_RET+BPF_K, 0),
3201 size_t i, j;
3202 bpfjit_func_t code;
3203 uint8_t pkt[2][34] = {
3205 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0x08, 0x00,
3206 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
3207 0x80, 0x03, 0x70, 0x0f,
3208 0x80, 0x03, 0x70, 0x23
3211 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0x08, 0x00,
3212 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
3213 0x80, 0x03, 0x70, 0x23,
3214 0x80, 0x03, 0x70, 0x0f
3218 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
3220 ATF_CHECK(bpf_validate(insns, insn_count));
3222 code = bpfjit_generate_code(bc, insns, insn_count);
3223 ATF_REQUIRE(code != NULL);
3225 for (i = 0; i < 2; i++) {
3226 for (j = 1; j < sizeof(pkt[i]); j++)
3227 ATF_CHECK(code(pkt[i], j, j) == 0);
3228 ATF_CHECK(code(pkt[i], j, j) == UINT32_MAX);
3231 bpfjit_free_code(code);
3234 ATF_TC(bpfjit_opt_ld_ind_4);
3235 ATF_TC_HEAD(bpfjit_opt_ld_ind_4, tc)
3237 atf_tc_set_md_var(tc, "descr",
3238 "Test JIT compilation with length optimization "
3239 "applied to BPF_LD+BPF_IND");
3242 ATF_TC_BODY(bpfjit_opt_ld_ind_4, tc)
3244 static struct bpf_insn insns[] = {
3245 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 11),
3246 BPF_STMT(BPF_LD+BPF_W+BPF_IND, 19),
3247 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x80037023, 0, 2),
3248 BPF_STMT(BPF_LD+BPF_W+BPF_IND, 15),
3249 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x8003700f, 3, 7),
3250 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x8003700f, 0, 6),
3251 BPF_STMT(BPF_LD+BPF_W+BPF_IND, 15),
3252 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x80037023, 0, 4),
3253 BPF_STMT(BPF_LDX+BPF_W+BPF_IMM, 0),
3254 BPF_STMT(BPF_LD+BPF_H+BPF_IND, 12),
3255 BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x800, 0, 1),
3256 BPF_STMT(BPF_RET+BPF_K, UINT32_MAX),
3257 BPF_STMT(BPF_RET+BPF_K, 0),
3260 size_t i, j;
3261 bpfjit_func_t code;
3262 uint8_t pkt[2][34] = {
3264 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0x08, 0x00,
3265 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
3266 0x80, 0x03, 0x70, 0x0f,
3267 0x80, 0x03, 0x70, 0x23
3270 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0x08, 0x00,
3271 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
3272 0x80, 0x03, 0x70, 0x23,
3273 0x80, 0x03, 0x70, 0x0f
3277 size_t insn_count = sizeof(insns) / sizeof(insns[0]);
3279 ATF_CHECK(bpf_validate(insns, insn_count));
3281 code = bpfjit_generate_code(bc, insns, insn_count);
3282 ATF_REQUIRE(code != NULL);
3284 for (i = 0; i < 2; i++) {
3285 for (j = 1; j < sizeof(pkt[i]); j++)
3286 ATF_CHECK(code(pkt[i], j, j) == 0);
3287 ATF_CHECK(code(pkt[i], j, j) == UINT32_MAX);
3290 bpfjit_free_code(code);
3293 ATF_TP_ADD_TCS(tp)
3296 ATF_TP_ADD_TC(tp, bpfjit_empty);
3297 ATF_TP_ADD_TC(tp, bpfjit_alu_add_k);
3298 ATF_TP_ADD_TC(tp, bpfjit_alu_sub_k);
3299 ATF_TP_ADD_TC(tp, bpfjit_alu_mul_k);
3300 ATF_TP_ADD_TC(tp, bpfjit_alu_div0_k);
3301 ATF_TP_ADD_TC(tp, bpfjit_alu_div1_k);
3302 ATF_TP_ADD_TC(tp, bpfjit_alu_div2_k);
3303 ATF_TP_ADD_TC(tp, bpfjit_alu_div4_k);
3304 ATF_TP_ADD_TC(tp, bpfjit_alu_div10_k);
3305 ATF_TP_ADD_TC(tp, bpfjit_alu_div10000_k);
3306 ATF_TP_ADD_TC(tp, bpfjit_alu_div7609801_k);
3307 ATF_TP_ADD_TC(tp, bpfjit_alu_div80000000_k);
3308 ATF_TP_ADD_TC(tp, bpfjit_alu_and_k);
3309 ATF_TP_ADD_TC(tp, bpfjit_alu_or_k);
3310 ATF_TP_ADD_TC(tp, bpfjit_alu_lsh_k);
3311 ATF_TP_ADD_TC(tp, bpfjit_alu_lsh0_k);
3312 ATF_TP_ADD_TC(tp, bpfjit_alu_rsh_k);
3313 ATF_TP_ADD_TC(tp, bpfjit_alu_rsh0_k);
3314 ATF_TP_ADD_TC(tp, bpfjit_alu_modulo_k);
3315 ATF_TP_ADD_TC(tp, bpfjit_alu_add_x);
3316 ATF_TP_ADD_TC(tp, bpfjit_alu_sub_x);
3317 ATF_TP_ADD_TC(tp, bpfjit_alu_mul_x);
3318 ATF_TP_ADD_TC(tp, bpfjit_alu_div0_x);
3319 ATF_TP_ADD_TC(tp, bpfjit_alu_div1_x);
3320 ATF_TP_ADD_TC(tp, bpfjit_alu_div2_x);
3321 ATF_TP_ADD_TC(tp, bpfjit_alu_div4_x);
3322 ATF_TP_ADD_TC(tp, bpfjit_alu_div10_x);
3323 ATF_TP_ADD_TC(tp, bpfjit_alu_div10000_x);
3324 ATF_TP_ADD_TC(tp, bpfjit_alu_div7609801_x);
3325 ATF_TP_ADD_TC(tp, bpfjit_alu_div80000000_x);
3326 ATF_TP_ADD_TC(tp, bpfjit_alu_and_x);
3327 ATF_TP_ADD_TC(tp, bpfjit_alu_or_x);
3328 ATF_TP_ADD_TC(tp, bpfjit_alu_lsh_x);
3329 ATF_TP_ADD_TC(tp, bpfjit_alu_lsh0_x);
3330 ATF_TP_ADD_TC(tp, bpfjit_alu_rsh_x);
3331 ATF_TP_ADD_TC(tp, bpfjit_alu_rsh0_x);
3332 ATF_TP_ADD_TC(tp, bpfjit_alu_modulo_x);
3333 ATF_TP_ADD_TC(tp, bpfjit_alu_neg);
3334 ATF_TP_ADD_TC(tp, bpfjit_jmp_ja);
3335 ATF_TP_ADD_TC(tp, bpfjit_jmp_jgt_k);
3336 ATF_TP_ADD_TC(tp, bpfjit_jmp_jge_k);
3337 ATF_TP_ADD_TC(tp, bpfjit_jmp_jeq_k);
3338 ATF_TP_ADD_TC(tp, bpfjit_jmp_jset_k);
3339 ATF_TP_ADD_TC(tp, bpfjit_jmp_modulo_k);
3340 ATF_TP_ADD_TC(tp, bpfjit_jmp_jgt_x);
3341 ATF_TP_ADD_TC(tp, bpfjit_jmp_jge_x);
3342 ATF_TP_ADD_TC(tp, bpfjit_jmp_jeq_x);
3343 ATF_TP_ADD_TC(tp, bpfjit_jmp_jset_x);
3344 ATF_TP_ADD_TC(tp, bpfjit_jmp_modulo_x);
3345 ATF_TP_ADD_TC(tp, bpfjit_ld_abs);
3346 ATF_TP_ADD_TC(tp, bpfjit_ld_abs_k_overflow);
3347 ATF_TP_ADD_TC(tp, bpfjit_ld_ind);
3348 ATF_TP_ADD_TC(tp, bpfjit_ld_ind_k_overflow);
3349 ATF_TP_ADD_TC(tp, bpfjit_ld_ind_x_overflow1);
3350 ATF_TP_ADD_TC(tp, bpfjit_ld_ind_x_overflow2);
3351 ATF_TP_ADD_TC(tp, bpfjit_ld_len);
3352 ATF_TP_ADD_TC(tp, bpfjit_ld_imm);
3353 ATF_TP_ADD_TC(tp, bpfjit_ldx_imm1);
3354 ATF_TP_ADD_TC(tp, bpfjit_ldx_imm2);
3355 ATF_TP_ADD_TC(tp, bpfjit_ldx_len1);
3356 ATF_TP_ADD_TC(tp, bpfjit_ldx_len2);
3357 ATF_TP_ADD_TC(tp, bpfjit_ldx_msh);
3358 ATF_TP_ADD_TC(tp, bpfjit_misc_tax);
3359 ATF_TP_ADD_TC(tp, bpfjit_misc_txa);
3360 ATF_TP_ADD_TC(tp, bpfjit_st1);
3361 ATF_TP_ADD_TC(tp, bpfjit_st2);
3362 ATF_TP_ADD_TC(tp, bpfjit_st3);
3363 ATF_TP_ADD_TC(tp, bpfjit_st4);
3364 ATF_TP_ADD_TC(tp, bpfjit_st5);
3365 ATF_TP_ADD_TC(tp, bpfjit_stx1);
3366 ATF_TP_ADD_TC(tp, bpfjit_stx2);
3367 ATF_TP_ADD_TC(tp, bpfjit_stx3);
3368 ATF_TP_ADD_TC(tp, bpfjit_stx4);
3369 ATF_TP_ADD_TC(tp, bpfjit_opt_ld_abs_1);
3370 ATF_TP_ADD_TC(tp, bpfjit_opt_ld_abs_2);
3371 ATF_TP_ADD_TC(tp, bpfjit_opt_ld_abs_3);
3372 ATF_TP_ADD_TC(tp, bpfjit_opt_ld_ind_1);
3373 ATF_TP_ADD_TC(tp, bpfjit_opt_ld_ind_2);
3374 ATF_TP_ADD_TC(tp, bpfjit_opt_ld_ind_3);
3375 ATF_TP_ADD_TC(tp, bpfjit_opt_ld_ind_4);
3376 /* XXX: bpfjit_opt_ldx_msh */
3378 return atf_no_error();