Bundle libseccomp 2.3.1
[linux-seccomp.git] / libseccomp / tests / testgen
1 #!/bin/bash
2
3 #
4 # libseccomp test output 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 # Dependency verification
29 #
30 # Arguments:
31 # 1 Dependency to check for
32 #
33 function verify_deps() {
34 [[ -z "$1" ]] && return
35 if ! which "$1" >& /dev/null; then
36 echo "error: install \"$1\" and include it in your \$PATH"
37 exit 1
38 fi
39 }
40
41 #
42 # Print out script usage details
43 #
44 function usage() {
45 cat << EOF
46 usage: regression [-h] [-d] [-l LABEL]
47
48 libseccomp test output generator script
49 optional arguments:
50 -h show this help message and exit
51 -b generate BPF output
52 -d generate disassembled BPF output
53 -p generate PFC output
54 -v perform valgrind checks
55 -l [LABEL] specifies label for the test output
56 EOF
57 }
58
59 #
60 # Print the test result
61 #
62 # Arguments:
63 # 1 string containing generated test number
64 # 2 string containing the test result
65 #
66 function print_result() {
67 printf "Test %s result: %s\n" "$1" "$2"
68 }
69
70 #
71 # Run the tests
72 #
73 # Arguments:
74 # 1 string containing output label
75 #
76 function run_tests() {
77 local batch_name
78 local label
79 local rc
80
81 if [[ -n $1 ]]; then
82 label=".$1"
83 else
84 label=""
85 fi
86
87 for file in *-sim-*.tests; do
88 # extract the batch name from the file name
89 batch_name=$(basename $file .tests)
90
91 if [[ -x "$batch_name" ]]; then
92 if [[ $opt_pfc -eq 1 ]]; then
93 ./$batch_name > ${batch_name}${label}.pfc
94 rc=$?
95 stats_all=$(($stats_all + 1))
96 if [[ $rc -eq 0 ]]; then
97 print_result "$batch_name [pfc]" "SUCCESS"
98 else
99 stats_failure=$(($stats_failure + 1))
100 print_result "$batch_name [pfc]" "FAILURE"
101 fi
102 fi
103
104 if [[ $opt_bpf -eq 1 ]]; then
105 ./$batch_name -b > ${batch_name}${label}.bpf
106 rc=$?
107 stats_all=$(($stats_all + 1))
108 if [[ $rc -eq 0 ]]; then
109 print_result "$batch_name [bpf]" "SUCCESS"
110 else
111 stats_failure=$(($stats_failure + 1))
112 print_result "$batch_name [bpf]" "FAILURE"
113 fi
114 fi
115
116 if [[ $opt_disasm -eq 1 ]]; then
117 ./$batch_name -b | \
118 ../tools/scmp_bpf_disasm > ${batch_name}${label}.bpfd
119 rc=$?
120 stats_all=$(($stats_all + 1))
121 if [[ $rc -eq 0 ]]; then
122 print_result "$batch_name [bpfd]" "SUCCESS"
123 else
124 stats_failure=$(($stats_failure + 1))
125 print_result "$batch_name [bpfd]" "FAILURE"
126 fi
127 fi
128
129 if [[ $opt_valgrind -eq 1 ]]; then
130 valgrind --tool=memcheck \
131 --quiet --error-exitcode=1 \
132 --leak-check=full \
133 --read-var-info=yes \
134 --track-origins=yes \
135 --suppressions=valgrind_test.supp \
136 -- ./$batch_name -b > /dev/null
137 rc=$?
138 stats_all=$(($stats_all + 1))
139 if [[ $rc -eq 0 ]]; then
140 print_result "$batch_name [valgrind]" "SUCCESS"
141 else
142 stats_failure=$(($stats_failure + 1))
143 print_result "$batch_name [valgrind]" "FAILURE"
144 fi
145 fi
146 else
147 stats_failure=$(($stats_failure + 1))
148 print_result "$batch_name" "FAILURE"
149 fi
150 done
151
152 return
153 }
154
155 ####
156 # main
157
158 opt_label=
159 opt_bpf=0
160 opt_disasm=0
161 opt_pfc=0
162 opt_valgrind=0
163
164 while getopts "bphdl:v" opt; do
165 case $opt in
166 b)
167 opt_bpf=1
168 ;;
169 d)
170 opt_disasm=1
171 ;;
172 l)
173 opt_label="$OPTARG"
174 ;;
175 p)
176 opt_pfc=1
177 ;;
178 v)
179 opt_valgrind=1
180 ;;
181 h|*)
182 usage
183 exit 1
184 ;;
185 esac
186 done
187
188 # verify valgrind
189 [[ $opt_valgrind -eq 1 ]] && verify_deps valgrind
190
191 stats_all=0
192 stats_failure=0
193
194 # display the test output and run the requested tests
195 echo "=============== $(date) ==============="
196 echo "Collecting Test Output (\"testgen $*\")"
197 run_tests "$opt_label"
198 echo "Test Summary"
199 echo " tests run: $stats_all"
200 echo " tests failed: $stats_failure"
201 echo "============================================================"
202
203 # cleanup and exit
204 rc=0
205 [[ $stats_failure -gt 0 ]] && rc=$(($rc + 2))
206
207 exit $rc
This page took 0.027101 seconds and 4 git commands to generate.