| 1 | #!/bin/bash |
| 2 | |
| 3 | # |
| 4 | # libseccomp test diff generator |
| 5 | # |
| 6 | # Copyright (c) 2013 Red Hat <pmoore@redhat.com> |
| 7 | # Author: Paul Moore <paul@paul-moore.com> |
| 8 | # |
| 9 | |
| 10 | # |
| 11 | # This library is free software; you can redistribute it and/or modify it |
| 12 | # under the terms of version 2.1 of the GNU Lesser General Public License as |
| 13 | # published by the Free Software Foundation. |
| 14 | # |
| 15 | # This library is distributed in the hope that it will be useful, but WITHOUT |
| 16 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 17 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License |
| 18 | # for more details. |
| 19 | # |
| 20 | # You should have received a copy of the GNU Lesser General Public License |
| 21 | # along with this library; if not, see <http://www.gnu.org/licenses>. |
| 22 | # |
| 23 | |
| 24 | #### |
| 25 | # functions |
| 26 | |
| 27 | # |
| 28 | # Print out script usage details |
| 29 | # |
| 30 | function usage() { |
| 31 | cat << EOF |
| 32 | usage: regression [-h] LABEL_1 LABEL_2 |
| 33 | |
| 34 | libseccomp test diff generator script |
| 35 | optional arguments: |
| 36 | -h show this help message and exit |
| 37 | EOF |
| 38 | } |
| 39 | |
| 40 | # |
| 41 | # Print the test header |
| 42 | # |
| 43 | # Arguments: |
| 44 | # 1 string containing generated test number |
| 45 | # |
| 46 | function print_test() { |
| 47 | printf "Test %s comparison:\n" "$1" |
| 48 | } |
| 49 | |
| 50 | # |
| 51 | # Compare the tests |
| 52 | # |
| 53 | # Arguments: |
| 54 | # 1 string containing first test label |
| 55 | # 2 string containing second test label |
| 56 | # |
| 57 | function diff_tests() { |
| 58 | local batch_name |
| 59 | local label_a |
| 60 | local label_b |
| 61 | local file_a |
| 62 | local file_b |
| 63 | |
| 64 | if [[ -n $1 ]]; then |
| 65 | label_a=".$1" |
| 66 | else |
| 67 | label_a="" |
| 68 | fi |
| 69 | |
| 70 | if [[ -n $2 ]]; then |
| 71 | label_b=".$2" |
| 72 | else |
| 73 | label_b="" |
| 74 | fi |
| 75 | |
| 76 | for file in *-sim-*.tests; do |
| 77 | # extract the batch name from the file name |
| 78 | batch_name=$(basename $file .tests) |
| 79 | |
| 80 | print_test "$batch_name" |
| 81 | |
| 82 | file_a="${batch_name}${label_a}" |
| 83 | file_b="${batch_name}${label_b}" |
| 84 | |
| 85 | if [[ -r "$file_a.pfc" && -r "$file_b.pfc" ]]; then |
| 86 | diff -pu "$file_a.pfc" "$file_b.pfc" |
| 87 | fi |
| 88 | |
| 89 | if [[ -r "$file_a.bpf" && -r "$file_b.bpf" ]]; then |
| 90 | diff -pu "$file_a.bpf" "$file_b.bpf" |
| 91 | fi |
| 92 | |
| 93 | if [[ -r "$file_a.bpfd" && -r "$file_b.bpfd" ]]; then |
| 94 | diff -pu "$file_a.bpfd" "$file_b.bpfd" |
| 95 | fi |
| 96 | done |
| 97 | |
| 98 | return |
| 99 | } |
| 100 | |
| 101 | #### |
| 102 | # main |
| 103 | |
| 104 | opt_label= |
| 105 | opt_disasm=0 |
| 106 | |
| 107 | while getopts "h" opt; do |
| 108 | case $opt in |
| 109 | h|*) |
| 110 | usage |
| 111 | exit 1 |
| 112 | ;; |
| 113 | esac |
| 114 | done |
| 115 | |
| 116 | stats_all=0 |
| 117 | stats_failure=0 |
| 118 | |
| 119 | # display the test output and run the requested tests |
| 120 | echo "=============== $(date) ===============" |
| 121 | echo "Comparing Test Output (\"testdiff $*\")" |
| 122 | diff_tests "$1" "$2" |
| 123 | echo "============================================================" |
| 124 | |
| 125 | # exit |
| 126 | exit 0 |