diff options
author | Alexei Starovoitov <ast@plumgrid.com> | 2014-10-28 18:11:42 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-10-30 15:44:37 -0400 |
commit | 342ded409608f84fe929216efe0ca2d45e2656be (patch) | |
tree | 5af9807e4493d1a8d5cb46f53a87ede0d9b0bfa8 /samples | |
parent | 9c3997601d51069ec08d7d06cf31a17884056cc2 (diff) |
samples: bpf: add a verifier test and summary line
- add a test specifically targeting verifier state pruning.
It checks state propagation between registers, storing that
state into stack and state pruning algorithm recognizing
equivalent stack and register states.
- add summary line to spot failures easier
Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'samples')
-rw-r--r-- | samples/bpf/test_verifier.c | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/samples/bpf/test_verifier.c b/samples/bpf/test_verifier.c index eb4bec0ad8af..63402742345e 100644 --- a/samples/bpf/test_verifier.c +++ b/samples/bpf/test_verifier.c | |||
@@ -602,6 +602,45 @@ static struct bpf_test tests[] = { | |||
602 | }, | 602 | }, |
603 | .result = ACCEPT, | 603 | .result = ACCEPT, |
604 | }, | 604 | }, |
605 | { | ||
606 | "jump test 5", | ||
607 | .insns = { | ||
608 | BPF_MOV64_REG(BPF_REG_2, BPF_REG_10), | ||
609 | BPF_MOV64_REG(BPF_REG_3, BPF_REG_2), | ||
610 | BPF_JMP_IMM(BPF_JGE, BPF_REG_1, 0, 2), | ||
611 | BPF_STX_MEM(BPF_DW, BPF_REG_2, BPF_REG_3, -8), | ||
612 | BPF_JMP_IMM(BPF_JA, 0, 0, 2), | ||
613 | BPF_STX_MEM(BPF_DW, BPF_REG_2, BPF_REG_2, -8), | ||
614 | BPF_JMP_IMM(BPF_JA, 0, 0, 0), | ||
615 | BPF_MOV64_IMM(BPF_REG_0, 0), | ||
616 | BPF_JMP_IMM(BPF_JGE, BPF_REG_1, 0, 2), | ||
617 | BPF_STX_MEM(BPF_DW, BPF_REG_2, BPF_REG_3, -8), | ||
618 | BPF_JMP_IMM(BPF_JA, 0, 0, 2), | ||
619 | BPF_STX_MEM(BPF_DW, BPF_REG_2, BPF_REG_2, -8), | ||
620 | BPF_JMP_IMM(BPF_JA, 0, 0, 0), | ||
621 | BPF_MOV64_IMM(BPF_REG_0, 0), | ||
622 | BPF_JMP_IMM(BPF_JGE, BPF_REG_1, 0, 2), | ||
623 | BPF_STX_MEM(BPF_DW, BPF_REG_2, BPF_REG_3, -8), | ||
624 | BPF_JMP_IMM(BPF_JA, 0, 0, 2), | ||
625 | BPF_STX_MEM(BPF_DW, BPF_REG_2, BPF_REG_2, -8), | ||
626 | BPF_JMP_IMM(BPF_JA, 0, 0, 0), | ||
627 | BPF_MOV64_IMM(BPF_REG_0, 0), | ||
628 | BPF_JMP_IMM(BPF_JGE, BPF_REG_1, 0, 2), | ||
629 | BPF_STX_MEM(BPF_DW, BPF_REG_2, BPF_REG_3, -8), | ||
630 | BPF_JMP_IMM(BPF_JA, 0, 0, 2), | ||
631 | BPF_STX_MEM(BPF_DW, BPF_REG_2, BPF_REG_2, -8), | ||
632 | BPF_JMP_IMM(BPF_JA, 0, 0, 0), | ||
633 | BPF_MOV64_IMM(BPF_REG_0, 0), | ||
634 | BPF_JMP_IMM(BPF_JGE, BPF_REG_1, 0, 2), | ||
635 | BPF_STX_MEM(BPF_DW, BPF_REG_2, BPF_REG_3, -8), | ||
636 | BPF_JMP_IMM(BPF_JA, 0, 0, 2), | ||
637 | BPF_STX_MEM(BPF_DW, BPF_REG_2, BPF_REG_2, -8), | ||
638 | BPF_JMP_IMM(BPF_JA, 0, 0, 0), | ||
639 | BPF_MOV64_IMM(BPF_REG_0, 0), | ||
640 | BPF_EXIT_INSN(), | ||
641 | }, | ||
642 | .result = ACCEPT, | ||
643 | }, | ||
605 | }; | 644 | }; |
606 | 645 | ||
607 | static int probe_filter_length(struct bpf_insn *fp) | 646 | static int probe_filter_length(struct bpf_insn *fp) |
@@ -630,7 +669,7 @@ static int create_map(void) | |||
630 | 669 | ||
631 | static int test(void) | 670 | static int test(void) |
632 | { | 671 | { |
633 | int prog_fd, i; | 672 | int prog_fd, i, pass_cnt = 0, err_cnt = 0; |
634 | 673 | ||
635 | for (i = 0; i < ARRAY_SIZE(tests); i++) { | 674 | for (i = 0; i < ARRAY_SIZE(tests); i++) { |
636 | struct bpf_insn *prog = tests[i].insns; | 675 | struct bpf_insn *prog = tests[i].insns; |
@@ -657,21 +696,25 @@ static int test(void) | |||
657 | printf("FAIL\nfailed to load prog '%s'\n", | 696 | printf("FAIL\nfailed to load prog '%s'\n", |
658 | strerror(errno)); | 697 | strerror(errno)); |
659 | printf("%s", bpf_log_buf); | 698 | printf("%s", bpf_log_buf); |
699 | err_cnt++; | ||
660 | goto fail; | 700 | goto fail; |
661 | } | 701 | } |
662 | } else { | 702 | } else { |
663 | if (prog_fd >= 0) { | 703 | if (prog_fd >= 0) { |
664 | printf("FAIL\nunexpected success to load\n"); | 704 | printf("FAIL\nunexpected success to load\n"); |
665 | printf("%s", bpf_log_buf); | 705 | printf("%s", bpf_log_buf); |
706 | err_cnt++; | ||
666 | goto fail; | 707 | goto fail; |
667 | } | 708 | } |
668 | if (strstr(bpf_log_buf, tests[i].errstr) == 0) { | 709 | if (strstr(bpf_log_buf, tests[i].errstr) == 0) { |
669 | printf("FAIL\nunexpected error message: %s", | 710 | printf("FAIL\nunexpected error message: %s", |
670 | bpf_log_buf); | 711 | bpf_log_buf); |
712 | err_cnt++; | ||
671 | goto fail; | 713 | goto fail; |
672 | } | 714 | } |
673 | } | 715 | } |
674 | 716 | ||
717 | pass_cnt++; | ||
675 | printf("OK\n"); | 718 | printf("OK\n"); |
676 | fail: | 719 | fail: |
677 | if (map_fd >= 0) | 720 | if (map_fd >= 0) |
@@ -679,6 +722,7 @@ fail: | |||
679 | close(prog_fd); | 722 | close(prog_fd); |
680 | 723 | ||
681 | } | 724 | } |
725 | printf("Summary: %d PASSED, %d FAILED\n", pass_cnt, err_cnt); | ||
682 | 726 | ||
683 | return 0; | 727 | return 0; |
684 | } | 728 | } |