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
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.
14 # Copyright 2018 Joyent, Inc.
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.
25 # Each test should begin with one of the following three keywords:
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
31 # For example, tst.smap.s, would be built both 32-bit and 64-bit and compared to
34 # Each input file should consist of a series of instructions in a function named
35 # 'libdis_test'. The test suite will compile this file into an object file,
36 # disassemble it, and compare it to the output file.
38 # For each input file, there should be a corresponding output file with the .out
39 # suffix instead of the .s suffix. So, if you had tst.smap.s, you should have
44 dt_arg0
=$
(basename $0)
45 dt_dis
="/usr/bin/dis -qF libdis_test"
46 dt_diff
="/usr/bin/cmp -s"
57 typeset
-A dt_platforms
62 [[ -z "$msg" ]] && msg
="failed"
63 echo "$dt_arg0: $msg" >&2
70 [[ -z "$msg" ]] ||
echo "$msg" 2>&1
72 Usage: $dt_arg0 [-n] [ -p platform=pathtoas ]... [ test ]...
74 Runs all dis for the current platform or only specified tests if listed.
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
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.
90 # Right now, we only support running this on x86 natively; however, you
91 # can run tests for other platforms with the -p option.
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
102 dt_platforms
[$dt_defarch]=$dt_defas
106 # Iterate over the set of platforms and verify that we both know about them and
107 # we can find the assembler for them.
113 for key
in ${!dt_platforms[@]}; do
115 [[ -d $dt_root/$key ]] || fatal
"encountered unknown platform: $key"
118 # This may be a path or something else.
120 bin
=${dt_platforms[$key]}
121 [[ -x $bin ]] && continue
122 which $bin >/dev
/null
2>&1 && continue
123 fatal
"failed to find command as absolute path or file: $bin"
129 typeset dir reason
source out
136 while [[ -d failure.
$dt_faildir ]]; do
140 faildir
="failure.$dt_faildir"
144 printf "%s " "failed "
145 [[ -n $reason ]] && printf "%s " $reason
146 printf "%s\n" "$faildir"
155 typeset gflags
source cmp disfile outfile extra aserr diserr
164 disfile
=$dir/libdis.out
165 diserr
=$dir/dis.stderr
168 mkdir
-p $dir || fatal
"failed to make directory $dir"
170 printf "testing %s " $source
171 [[ -n $extra ]] && printf "%s " $extra
173 if ! $gas $gflags -o $outfile $source 2>$aserr >/dev
/null
; then
174 handle_failure
$dir "(assembling)" $source $cmp
178 if ! $dt_dis $outfile >$disfile 2>$diserr; then
179 handle_failure
$dir "(disassembling)" $source $cmp
183 if ! $dt_diff $disfile $cmp; then
184 handle_failure
$dir "(comparing)" $source $cmp
190 rm -rf $dir || fatal
"failed to remove directory $dir"
194 # Run a single test. This may result in two actual tests (one 32-bit and one
199 typeset sfile base cmpfile prefix arch gas p flags
200 typeset asflags32 asflags64
204 cmpfile
=${sfile%.*}.out
208 [[ -f $cmpfile ]] || fatal
"missing output file $cmpfile"
209 gas
=${dt_platforms[$arch]}
210 [[ -n $gas ]] || fatal
"encountered test $sfile, but missing assembler"
214 asflags32
="-march=rv32g"
215 asflags64
="-march=rv64g"
218 asflags32
="-march=rv32gc"
219 asflags64
="-march=rv64gc"
229 test_one
$asflags32 $sfile $cmpfile
232 test_one
$asflags64 $sfile $cmpfile
235 test_one
$asflags32 $sfile $cmpfile "(32-bit)"
236 test_one
$asflags64 $sfile $cmpfile "(64-bit)"
242 # Iterate over all the test directories and run the specified tests
247 if [[ $# -ne 0 ]]; then
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')
257 for t
in $tests $tests32 $tests64; do
272 Tests passed: $dt_tsuc
273 Tests failed: $dt_tfail
280 cd $
(dirname $0) || fatal
"failed to cd to test root"
282 cd $dt_origwd || fatal
"failed to return to original dir"
284 while getopts ":np:" c $@
; do
294 [[ ${#split[@]} -eq 2 ]] || usage
"malformed -p option: $OPTARG"
295 dt_platforms
[${split[0]}]=${split[1]}
298 usage
"option requires an argument -- $OPTARG"
301 usage
"invalid option -- $OPTARG"
306 [[ -n $dt_nodefault && ${#dt_platforms[@]} -eq 0 ]] && fatal \
307 "no platforms specified to run tests for"
316 [[ $dt_tfail -eq 0 ]]