1 #!/usr/bin/ksh
2 #
3 # This file and its contents are supplied under the terms of the
4 # Common Development and Distribution License ("CDDL"), version 1.0.
5 # You may only use this file in accordance with the terms of version
6 # 1.0 of the CDDL.
7 #
8 # A full copy of the text of the CDDL should have accompanied this
9 # source. A copy of the CDDL is also available via the Internet at
10 # http://www.illumos.org/license/CDDL.
11 #
12
13 #
14 # Copyright 2016 Joyent, Inc.
15 #
16
17 #
18 # libdis test driver
19 #
20 # Tests are arranged by architecture. By default we'll run all of the
21 # dis tests on our current architecture only. If the -p option is passed
22 # to point to other correctly built gas instances, then we'll run those
23 # tests, verifying that the cross-dis works.
24 #
25 # Each test should begin with one of the following three keywords:
26 #
27 # tst - Run both the 32-bit and 64-bit versions
28 # 32 - Only run this with the gas 32-bit flag
29 # 64 - Only run this with the gas 64-bit flag
30 #
31 # For example, tst.smap.s, would be built both 32-bit and 64-bit and compared to
32 # its output file.
33 #
34 # Each input file should consist of a series of instructions in a function named
61 typeset msg="$*"
62 [[ -z "$msg" ]] && msg="failed"
63 echo "$dt_arg0: $msg" >&2
64 exit 1
65 }
66
67 usage()
68 {
69 typeset msg="$*"
70 [[ -z "$msg" ]] || echo "$msg" 2>&1
71 cat <<USAGE >&2
72 Usage: $dt_arg0 [-n] [ -p platform=pathtoas ]... [ test ]...
73
74 Runs all dis for the current platform or only specified tests if listed.
75
76 -n Don't run default platform tests
77 -p platform=pathtoas Run tests for platform using assembler. Should
78 either be an absolute path or a command on the
79 path.
80 USAGE
81 }
82
83 #
84 # By default, tests only run for the current platform. In other words,
85 # running on an x86 system only assumes that the tests in the i386
86 # directory should be run. If the -p option is specified, then other
87 # platforms will be run.
88 #
89 # Right now, we only support running this on x86 natively; however, you
90 # can run tests for other platforms with the -p option.
91 #
92 determine_arch()
93 {
94 typeset arch
95
96 arch=$(uname -p)
97 [[ $? -eq 0 ]] || fatal "failed to determine host architecture"
98 [[ "$arch" != "i386" ]] && fatal "dis tests are only supported on x86"
99 [[ -n "$dt_nodefault" ]] && return
100 dt_defarch="i386"
179 return
180 fi
181
182 if ! $dt_diff $disfile $cmp; then
183 handle_failure $dir "(comparing)" $source $cmp
184 return
185 fi
186
187 ((dt_tsuc++))
188 print "passed"
189 rm -rf $dir || fatal "failed to remove directory $dir"
190 }
191
192 #
193 # Run a single test. This may result in two actual tests (one 32-bit and one
194 # 64-bit) being run.
195 #
196 run_single_file()
197 {
198 typeset sfile base cmpfile prefix arch gas p flags
199 sfile=$1
200
201 base=${sfile##*/}
202 cmpfile=${sfile%.*}.out
203 prefix=${base%%.*}
204 arch=${sfile%/*}
205 arch=${arch##*/}
206 [[ -f $cmpfile ]] || fatal "missing output file $cmpfile"
207 gas=${dt_platforms[$arch]}
208 [[ -n $gas ]] || fatal "encountered test $sfile, but missing assembler"
209
210 case "$prefix" in
211 32)
212 test_one "-32" $sfile $cmpfile
213 ;;
214 64)
215 test_one "-64" $sfile $cmpfile
216 ;;
217 tst)
218 test_one "-32" $sfile $cmpfile "(32-bit)"
219 test_one "-64" $sfile $cmpfile "(64-bit)"
220 ;;
221 esac
222 }
223
224 #
225 # Iterate over all the test directories and run the specified tests
226 #
227 run_tests()
228 {
229 typeset t
230 if [[ $# -ne 0 ]]; then
231 for t in $@; do
232 run_single_file $t
233 done
234 else
235 typeset k tests tests32 tests64
236 for k in ${!dt_platforms[@]}; do
237 tests=$(find $dt_root/$k -type f -name 'tst.*.s')
238 tests32=$(find $dt_root/$k -type f -name '32.*.s')
239 tests64=$(find $dt_root/$k -type f -name '64.*.s')
253 --------------
254
255 Tests passed: $dt_tsuc
256 Tests failed: $dt_tfail
257 Tests ran: $dt_tnum
258 EOF
259 }
260
261
262 dt_origwd=$PWD
263 cd $(dirname $0) || fatal "failed to cd to test root"
264 dt_root=$PWD
265 cd $dt_origwd || fatal "failed to return to original dir"
266
267 while getopts ":np:" c $@; do
268 case "$c" in
269 n)
270 dt_nodefault="y"
271 ;;
272 p)
273 IFS="="
274 set -A split $OPTARG
275 IFS=" "
276 [[ ${#split[@]} -eq 2 ]] || usage "malformed -p option: $OPTARG"
277 dt_platforms[${split[0]}]=${split[1]}
278 ;;
279 :)
280 usage "option requires an argument -- $OPTARG"
281 ;;
282 *)
283 usage "invalid option -- $OPTARG"
284 ;;
285 esac
286 done
287
288 [[ -n $dt_nodefault && ${#dt_platforms[@]} -eq 0 ]] && fatal \
289 "no platforms specified to run tests for"
290
291 shift $((OPTIND-1))
292
293 determine_arch
294 check_platforms
295 run_tests
|
1 #!/usr/bin/ksh
2 #
3 # This file and its contents are supplied under the terms of the
4 # Common Development and Distribution License ("CDDL"), version 1.0.
5 # You may only use this file in accordance with the terms of version
6 # 1.0 of the CDDL.
7 #
8 # A full copy of the text of the CDDL should have accompanied this
9 # source. A copy of the CDDL is also available via the Internet at
10 # http://www.illumos.org/license/CDDL.
11 #
12
13 #
14 # Copyright 2018 Joyent, Inc.
15 #
16
17 #
18 # libdis test driver
19 #
20 # Tests are arranged by architecture. By default we'll run all of the
21 # dis tests on our current architecture only. If the -p option is passed
22 # to point to other correctly built gas instances, then we'll run those
23 # tests, verifying that the cross-dis works.
24 #
25 # Each test should begin with one of the following three keywords:
26 #
27 # tst - Run both the 32-bit and 64-bit versions
28 # 32 - Only run this with the gas 32-bit flag
29 # 64 - Only run this with the gas 64-bit flag
30 #
31 # For example, tst.smap.s, would be built both 32-bit and 64-bit and compared to
32 # its output file.
33 #
34 # Each input file should consist of a series of instructions in a function named
61 typeset msg="$*"
62 [[ -z "$msg" ]] && msg="failed"
63 echo "$dt_arg0: $msg" >&2
64 exit 1
65 }
66
67 usage()
68 {
69 typeset msg="$*"
70 [[ -z "$msg" ]] || echo "$msg" 2>&1
71 cat <<USAGE >&2
72 Usage: $dt_arg0 [-n] [ -p platform=pathtoas ]... [ test ]...
73
74 Runs all dis for the current platform or only specified tests if listed.
75
76 -n Don't run default platform tests
77 -p platform=pathtoas Run tests for platform using assembler. Should
78 either be an absolute path or a command on the
79 path.
80 USAGE
81 exit 2
82 }
83
84 #
85 # By default, tests only run for the current platform. In other words,
86 # running on an x86 system only assumes that the tests in the i386
87 # directory should be run. If the -p option is specified, then other
88 # platforms will be run.
89 #
90 # Right now, we only support running this on x86 natively; however, you
91 # can run tests for other platforms with the -p option.
92 #
93 determine_arch()
94 {
95 typeset arch
96
97 arch=$(uname -p)
98 [[ $? -eq 0 ]] || fatal "failed to determine host architecture"
99 [[ "$arch" != "i386" ]] && fatal "dis tests are only supported on x86"
100 [[ -n "$dt_nodefault" ]] && return
101 dt_defarch="i386"
180 return
181 fi
182
183 if ! $dt_diff $disfile $cmp; then
184 handle_failure $dir "(comparing)" $source $cmp
185 return
186 fi
187
188 ((dt_tsuc++))
189 print "passed"
190 rm -rf $dir || fatal "failed to remove directory $dir"
191 }
192
193 #
194 # Run a single test. This may result in two actual tests (one 32-bit and one
195 # 64-bit) being run.
196 #
197 run_single_file()
198 {
199 typeset sfile base cmpfile prefix arch gas p flags
200 typeset asflags32 asflags64
201 sfile=$1
202
203 base=${sfile##*/}
204 cmpfile=${sfile%.*}.out
205 prefix=${base%%.*}
206 arch=${sfile%/*}
207 arch=${arch##*/}
208 [[ -f $cmpfile ]] || fatal "missing output file $cmpfile"
209 gas=${dt_platforms[$arch]}
210 [[ -n $gas ]] || fatal "encountered test $sfile, but missing assembler"
211
212 case "$arch" in
213 "risc-v")
214 asflags32="-march=rv32g"
215 asflags64="-march=rv64g"
216 ;;
217 "risc-v-c")
218 asflags32="-march=rv32gc"
219 asflags64="-march=rv64gc"
220 ;;
221 *)
222 asflags32="-32"
223 asflags64="-64"
224 ;;
225 esac
226
227 case "$prefix" in
228 32)
229 test_one $asflags32 $sfile $cmpfile
230 ;;
231 64)
232 test_one $asflags64 $sfile $cmpfile
233 ;;
234 tst)
235 test_one $asflags32 $sfile $cmpfile "(32-bit)"
236 test_one $asflags64 $sfile $cmpfile "(64-bit)"
237 ;;
238 esac
239 }
240
241 #
242 # Iterate over all the test directories and run the specified tests
243 #
244 run_tests()
245 {
246 typeset t
247 if [[ $# -ne 0 ]]; then
248 for t in $@; do
249 run_single_file $t
250 done
251 else
252 typeset k tests tests32 tests64
253 for k in ${!dt_platforms[@]}; do
254 tests=$(find $dt_root/$k -type f -name 'tst.*.s')
255 tests32=$(find $dt_root/$k -type f -name '32.*.s')
256 tests64=$(find $dt_root/$k -type f -name '64.*.s')
270 --------------
271
272 Tests passed: $dt_tsuc
273 Tests failed: $dt_tfail
274 Tests ran: $dt_tnum
275 EOF
276 }
277
278
279 dt_origwd=$PWD
280 cd $(dirname $0) || fatal "failed to cd to test root"
281 dt_root=$PWD
282 cd $dt_origwd || fatal "failed to return to original dir"
283
284 while getopts ":np:" c $@; do
285 case "$c" in
286 n)
287 dt_nodefault="y"
288 ;;
289 p)
290 OLDIFS=$IFS
291 IFS="="
292 set -A split $OPTARG
293 IFS=$OLDIFS
294 [[ ${#split[@]} -eq 2 ]] || usage "malformed -p option: $OPTARG"
295 dt_platforms[${split[0]}]=${split[1]}
296 ;;
297 :)
298 usage "option requires an argument -- $OPTARG"
299 ;;
300 *)
301 usage "invalid option -- $OPTARG"
302 ;;
303 esac
304 done
305
306 [[ -n $dt_nodefault && ${#dt_platforms[@]} -eq 0 ]] && fatal \
307 "no platforms specified to run tests for"
308
309 shift $((OPTIND-1))
310
311 determine_arch
312 check_platforms
313 run_tests
|