9 # A full copy of the text of the CDDL should have accompanied this
10 # source. A copy of the CDDL is also available via the Internet at
11 # http://www.illumos.org/license/CDDL.
12 #
13
14 #
15 # Copyright (c) 2019, Joyent, Inc.
16 #
17
18 #
19 # Run all of the various CTF tests
20 #
21
22 unalias -a
23 #set -o xtrace
24
25 if [[ -z "$TMPDIR" ]]; then
26 TMPDIR="/tmp"
27 fi
28
29 ctf_arg0=$(basename $0)
30 ctf_root=$(cd $(dirname $0) && echo $PWD)
31 ctf_tests=
32 ctf_compiler="gcc"
33 ctf_convert="ctfconvert"
34 ctf_merge="ctfmerge"
35 ctf_debugflags="-gdwarf-2 "
36 ctf_mach32="-m32"
37 ctf_mach64="-m64"
38 ctf_32cflags="$ctf_mach32 $ctf_debugflags"
39 ctf_64cflags="$ctf_mach64 $ctf_debugflags"
40 ctf_temp="$TMPDIR/ctftest.$$.o"
41 ctf_makefile="Makefile.ctftest"
42 ctf_nerrs=0
43
44 usage()
45 {
46 typeset msg="$*"
47 [[ -z "$msg" ]] || echo "$msg" >&2
48 cat <<USAGE >&2
49 Usage: $ctf_arg0 [-c compiler] [-g flags] [-m ctfmerge] [-t ctfconvert]
50
51 Runs the CTF test suite
52
53 -c compiler Use the specified compiler, defaults to 'gcc'
54 on path.
55 -g flags Use flags to generate debug info. Defaults to
56 "-gdwarf-2".
57 -m ctfmerge Use the specified ctfmerge, defaults to
58 'ctfmerge' on path.
59 -t ctfconvert Use the specified ctfconvert, defaults to
60 'ctfconvert' on path.
61 USAGE
62 exit 2
63 }
64
65
66 test_fail()
67 {
68 typeset msg="$*"
69 [[ -z "$msg" ]] && msg="failed"
70 echo "TEST FAILED: $msg" >&2
71 ((ctf_nerrs++))
72 }
73
74 fatal()
75 {
76 typeset msg="$*"
77 [[ -z "$msg" ]] && msg="failed"
78 echo "$ctf_arg0: $msg" >&2
79 rm -f "$ctf_tmp32" "$ctf_temp64"
80 exit 1
81 }
82
83 check_env()
84 {
85 if which "$1" 2>/dev/null >/dev/null; then
86 return
87 fi
88
89 [[ -f "$1" ]] || fatal "failed to find tool $1"
90 }
91
92 announce()
93 {
94 cat << EOF
95 Beginning CTF tests with the following settings:
96 COMPILER: $(which $ctf_compiler)
97 CTFCONVERT: $(which $ctf_convert)
98 CTFMERGE: $(which $ctf_merge)
99 32-bit CFLAGS: $ctf_32cflags
100 64-bit CFLAGS: $ctf_64cflags
101
102 EOF
103 }
104
105 run_one()
106 {
107 typeset source=$1 checker=$2 flags=$3
108
109 if ! "$ctf_compiler" $flags -o "$ctf_temp" -c "$source"; then
110 test_fail "failed to compile $source with flags: $flags"
111 return
112 fi
113
114 if ! "$ctf_convert" "$ctf_temp"; then
115 test_fail "failed to convert CTF in $source"
116 return
117 fi
118
119 if ! "$checker" "$ctf_temp"; then
120 test_fail "check for $source, $checker, failed"
121 return
122 fi
123
124 echo "TEST PASSED: $source $flags"
125 }
126
127 #
128 # Perform a more complex build. The Makefile present will drive the
129 # building of the artifacts and the running of the tests based on the
130 # variables that we pass to it.
131 #
132 run_dir()
133 {
134 typeset dir outdir check32 check64 flags32 flags64
135
136 dir=$1
137 outdir="$TMPDIR/ctftest.$$-$(basename $d)"
138 check32=$2
139 flags32=$3
140 check64=$4
141 flags64=$5
142
143 if ! mkdir $outdir; then
144 fatal "failed to make temporary directory '$outdir'"
145 fi
146
147 if ! make -C $dir -f Makefile.ctftest \
148 BUILDDIR="$outdir" \
149 CC="$ctf_compiler" \
150 CFLAGS32="$ctf_mach32" \
151 CFLAGS64="$ctf_mach64" \
152 DEBUGFLAGS="$ctf_debugflags" \
153 CTFCONVERT="$ctf_convert" \
154 CTFMERGE="$ctf_merge" \
155 build 1>/dev/null; then
156 rm -rf $outdir
157 test_fail "failed to build $dir"
158 return
159 fi
160
161 if ! make -C $dir -f Makefile.ctftest \
162 BUILDDIR="$outdir" \
163 CHECK32="$check32" \
164 CHECK64="$check64" \
165 run-test 1>/dev/null; then
166 rm -rf $outdir
167 test_fail "failed to run tests for $dir"
168 return
169 fi
193 else
194 test_fail "missing checker for $t"
195 fi
196 done
197
198 for d in $(find "$ctf_root" -maxdepth 1 -type d -name 'test-*'); do
199 [[ ! -f "$d/$ctf_makefile" ]] && continue
200 base=$(basename "$d")
201 check=$(echo "$base" | sed s/test-/check-/)
202 if [[ -f "$ctf_root/$check" ]]; then
203 run_dir $d "$ctf_root/$check" "$ctf_32cflags" \
204 "$ctf_root/$check" "$ctf_64cflags"
205 elif [[ -f "$ctf_root/$check-32" && \
206 -f "$ctf_root/$check-64" ]]; then
207 run_dir $d "$ctf_root/$check-32" "$ctf_32cflags" \
208 "$ctf_root/$check-64" "$ctf_64cflags"
209 else
210 test_fail "missing checker for $t"
211 fi
212 done
213 }
214
215 while getopts ":c:g:m:t:" c $@; do
216 case "$c" in
217 c)
218 ctf_compiler=$OPTARG
219 ;;
220 g)
221 ctf_debugflags=$OPTARG
222 ;;
223 m)
224 ctf_merge=$OPTARG
225 ;;
226 t)
227 ctf_convert=$OPTARG
228 ;;
229 :)
230 usage "option requires an argument -- $OPTARG"
231 ;;
232 *)
233 usage "invalid option -- $OPTARG"
234 ;;
235 esac
236 done
237
238 ctf_32cflags="$ctf_mach32 $ctf_debugflags"
239 ctf_64cflags="$ctf_mach64 $ctf_debugflags"
240
241 check_env "$ctf_compiler"
242 check_env "$ctf_convert"
243 check_env "$ctf_merge"
244 announce
245
246 run_tests
247
248 if [[ $ctf_nerrs -ne 0 ]]; then
249 if [[ $ctf_nerrs -eq 1 ]]; then
250 printf "\n%s: %u test failed\n" "$ctf_arg0" "$ctf_nerrs"
251 else
252 printf "\n%s: %u tests failed\n" "$ctf_arg0" "$ctf_nerrs"
253 fi
254 else
255 printf "\n%s: All tests passed successfully\n" "$ctf_arg0"
256 exit 0
257 fi
|
9 # A full copy of the text of the CDDL should have accompanied this
10 # source. A copy of the CDDL is also available via the Internet at
11 # http://www.illumos.org/license/CDDL.
12 #
13
14 #
15 # Copyright (c) 2019, Joyent, Inc.
16 #
17
18 #
19 # Run all of the various CTF tests
20 #
21
22 unalias -a
23 #set -o xtrace
24
25 if [[ -z "$TMPDIR" ]]; then
26 TMPDIR="/tmp"
27 fi
28
29
30 ctf_arg0=$(basename $0)
31 ctf_root=$(cd $(dirname $0) && echo $PWD)
32 ctf_tests=
33 ctf_cc="gcc"
34 ctf_cxx="g++"
35 ctf_as="as"
36 ctf_convert="ctfconvert"
37 ctf_merge="ctfmerge"
38 ctf_debugflags="-gdwarf-2 "
39 ctf_mach32="-m32"
40 ctf_mach64="-m64"
41 ctf_temp="$TMPDIR/ctftest.$$.o"
42 ctf_makefile="Makefile.ctftest"
43 ctf_nerrs=0
44
45 usage()
46 {
47 typeset msg="$*"
48 [[ -z "$msg" ]] || echo "$msg" >&2
49 cat <<USAGE >&2
50 Usage: $ctf_arg0 [-a as] [-c cc] [-C CC] [-g flags] [-m ctfmerge] [-t ctfconvert]
51
52 Runs the CTF test suite
53
54 -a assembler Use the specified assembler, defaults to 'as'
55 -c compiler Use the specified C compiler, defaults to 'gcc'
56 -C compiler Use the specified C++ compiler, defaults to 'g++'
57 -g flags Use flags to generate debug info. Defaults to
58 "-gdwarf-2".
59 -m ctfmerge Use the specified ctfmerge, defaults to
60 'ctfmerge'
61 -t ctfconvert Use the specified ctfconvert, defaults to
62 'ctfconvert'
63 USAGE
64 exit 2
65 }
66
67
68 test_fail()
69 {
70 typeset msg="$*"
71 [[ -z "$msg" ]] && msg="failed"
72 echo "TEST FAILED: $msg" >&2
73 ((ctf_nerrs++))
74 }
75
76 fatal()
77 {
78 typeset msg="$*"
79 [[ -z "$msg" ]] && msg="failed"
80 echo "$ctf_arg0: $msg" >&2
81 rm -f "$ctf_tmp32" "$ctf_temp64"
82 exit 1
83 }
84
85 announce()
86 {
87 cat << EOF
88 Beginning CTF tests with the following settings:
89 cc: $(which $ctf_cc)
90 CC: $(which $ctf_cxx)
91 as: $(which $ctf_as)
92 ctfconvert: $(which $ctf_convert)
93 ctfmerge: $(which $ctf_merge)
94 32-bit CFLAGS: $ctf_32cflags
95 64-bit CFLAGS: $ctf_64cflags
96
97 EOF
98 }
99
100 run_one()
101 {
102 typeset source=$1 checker=$2 flags=$3
103
104 if ! "$ctf_cc" $flags -o "$ctf_temp" -c "$source"; then
105 test_fail "failed to compile $source with flags: $flags"
106 return
107 fi
108
109 if ! "$ctf_convert" "$ctf_temp"; then
110 test_fail "failed to convert CTF in $source"
111 return
112 fi
113
114 if ! "$checker" "$ctf_temp"; then
115 test_fail "check for $source, $checker, failed"
116 return
117 fi
118
119 echo "TEST PASSED: $source $flags"
120 }
121
122 #
123 # Perform a more complex build. The Makefile present will drive the
124 # building of the artifacts and the running of the tests based on the
125 # variables that we pass to it.
126 #
127 run_dir()
128 {
129 typeset dir outdir check32 check64 flags32 flags64
130
131 dir=$1
132 outdir="$TMPDIR/ctftest.$$-$(basename $d)"
133 check32=$2
134 flags32=$3
135 check64=$4
136 flags64=$5
137
138 if ! mkdir $outdir; then
139 fatal "failed to make temporary directory '$outdir'"
140 fi
141
142 if ! make -C $dir -f Makefile.ctftest \
143 BUILDDIR="$outdir" \
144 CC="$ctf_cc" \
145 CFLAGS32="$ctf_mach32" \
146 CFLAGS64="$ctf_mach64" \
147 DEBUGFLAGS="$ctf_debugflags" \
148 CTFCONVERT="$ctf_convert" \
149 CTFMERGE="$ctf_merge" \
150 build 1>/dev/null; then
151 rm -rf $outdir
152 test_fail "failed to build $dir"
153 return
154 fi
155
156 if ! make -C $dir -f Makefile.ctftest \
157 BUILDDIR="$outdir" \
158 CHECK32="$check32" \
159 CHECK64="$check64" \
160 run-test 1>/dev/null; then
161 rm -rf $outdir
162 test_fail "failed to run tests for $dir"
163 return
164 fi
188 else
189 test_fail "missing checker for $t"
190 fi
191 done
192
193 for d in $(find "$ctf_root" -maxdepth 1 -type d -name 'test-*'); do
194 [[ ! -f "$d/$ctf_makefile" ]] && continue
195 base=$(basename "$d")
196 check=$(echo "$base" | sed s/test-/check-/)
197 if [[ -f "$ctf_root/$check" ]]; then
198 run_dir $d "$ctf_root/$check" "$ctf_32cflags" \
199 "$ctf_root/$check" "$ctf_64cflags"
200 elif [[ -f "$ctf_root/$check-32" && \
201 -f "$ctf_root/$check-64" ]]; then
202 run_dir $d "$ctf_root/$check-32" "$ctf_32cflags" \
203 "$ctf_root/$check-64" "$ctf_64cflags"
204 else
205 test_fail "missing checker for $t"
206 fi
207 done
208
209 outdir="$TMPDIR/ctftest.$$"
210
211 for f in $(find "$ctf_root" -maxdepth 1 -type f -name 'ctftest-*'); do
212 if ! mkdir $outdir; then
213 fatal "failed to make temporary directory '$outdir'"
214 fi
215
216 echo "Running $f in $outdir"
217
218 (cd $outdir && $f)
219
220 if [[ $? -ne 0 ]]; then
221 test_fail "$f failed"
222 else
223 echo "TEST PASSED: $f"
224 fi
225
226 rm -rf $outdir
227 done
228 }
229
230 while getopts ":a:C:c:g:m:t:" c $@; do
231 case "$c" in
232 a)
233 ctf_as=$OPTARG
234 ;;
235 C)
236 ctf_cxx=$OPTARG
237 ;;
238 c)
239 ctf_cc=$OPTARG
240 ;;
241 g)
242 ctf_debugflags=$OPTARG
243 ;;
244 m)
245 ctf_merge=$OPTARG
246 ;;
247 t)
248 ctf_convert=$OPTARG
249 ;;
250 :)
251 usage "option requires an argument -- $OPTARG"
252 ;;
253 *)
254 usage "invalid option -- $OPTARG"
255 ;;
256 esac
257 done
258
259 ctf_32cflags="$ctf_mach32 $ctf_debugflags"
260 ctf_64cflags="$ctf_mach64 $ctf_debugflags"
261
262 export ctf_as ctf_cc ctf_cxx ctf_debugflags ctf_merge ctf_convert
263
264 announce
265
266 run_tests
267
268 if [[ $ctf_nerrs -ne 0 ]]; then
269 if [[ $ctf_nerrs -eq 1 ]]; then
270 printf "\n%s: %u test failed\n" "$ctf_arg0" "$ctf_nerrs"
271 else
272 printf "\n%s: %u tests failed\n" "$ctf_arg0" "$ctf_nerrs"
273 fi
274 exit 1
275 else
276 printf "\n%s: All tests passed successfully\n" "$ctf_arg0"
277 exit 0
278 fi
|