Print this page
OS-7095 Want risc-v disassembler
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/test/util-tests/tests/dis/distest.ksh
+++ new/usr/src/test/util-tests/tests/dis/distest.ksh
1 1 #!/usr/bin/ksh
2 2 #
3 3 # This file and its contents are supplied under the terms of the
|
↓ open down ↓ |
3 lines elided |
↑ open up ↑ |
4 4 # Common Development and Distribution License ("CDDL"), version 1.0.
5 5 # You may only use this file in accordance with the terms of version
6 6 # 1.0 of the CDDL.
7 7 #
8 8 # A full copy of the text of the CDDL should have accompanied this
9 9 # source. A copy of the CDDL is also available via the Internet at
10 10 # http://www.illumos.org/license/CDDL.
11 11 #
12 12
13 13 #
14 -# Copyright 2016 Joyent, Inc.
14 +# Copyright 2018 Joyent, Inc.
15 15 #
16 16
17 17 #
18 18 # libdis test driver
19 19 #
20 20 # Tests are arranged by architecture. By default we'll run all of the
21 21 # dis tests on our current architecture only. If the -p option is passed
22 22 # to point to other correctly built gas instances, then we'll run those
23 23 # tests, verifying that the cross-dis works.
24 24 #
25 25 # Each test should begin with one of the following three keywords:
26 26 #
27 27 # tst - Run both the 32-bit and 64-bit versions
28 28 # 32 - Only run this with the gas 32-bit flag
29 29 # 64 - Only run this with the gas 64-bit flag
30 30 #
31 31 # For example, tst.smap.s, would be built both 32-bit and 64-bit and compared to
32 32 # its output file.
33 33 #
34 34 # Each input file should consist of a series of instructions in a function named
35 35 # 'libdis_test'. The test suite will compile this file into an object file,
36 36 # disassemble it, and compare it to the output file.
37 37 #
38 38 # For each input file, there should be a corresponding output file with the .out
39 39 # suffix instead of the .s suffix. So, if you had tst.smap.s, you should have
40 40 # tst.smap.out.
41 41 #
42 42
43 43 unalias -a
44 44 dt_arg0=$(basename $0)
45 45 dt_dis="/usr/bin/dis -qF libdis_test"
46 46 dt_diff="/usr/bin/cmp -s"
47 47 dt_defas="gas"
48 48 dt_defarch=
49 49 dt_nodefault=
50 50 dt_tests=
51 51 dt_tnum=0
52 52 dt_tfail=0
53 53 dt_tsuc=0
54 54 dt_origwd=
55 55 dt_root=
56 56 dt_faildir=0
57 57 typeset -A dt_platforms
58 58
59 59 fatal()
60 60 {
61 61 typeset msg="$*"
62 62 [[ -z "$msg" ]] && msg="failed"
63 63 echo "$dt_arg0: $msg" >&2
64 64 exit 1
65 65 }
66 66
67 67 usage()
68 68 {
69 69 typeset msg="$*"
70 70 [[ -z "$msg" ]] || echo "$msg" 2>&1
|
↓ open down ↓ |
46 lines elided |
↑ open up ↑ |
71 71 cat <<USAGE >&2
72 72 Usage: $dt_arg0 [-n] [ -p platform=pathtoas ]... [ test ]...
73 73
74 74 Runs all dis for the current platform or only specified tests if listed.
75 75
76 76 -n Don't run default platform tests
77 77 -p platform=pathtoas Run tests for platform using assembler. Should
78 78 either be an absolute path or a command on the
79 79 path.
80 80 USAGE
81 + exit 2
81 82 }
82 83
83 84 #
84 85 # By default, tests only run for the current platform. In other words,
85 86 # running on an x86 system only assumes that the tests in the i386
86 87 # directory should be run. If the -p option is specified, then other
87 88 # platforms will be run.
88 89 #
89 90 # Right now, we only support running this on x86 natively; however, you
90 91 # can run tests for other platforms with the -p option.
91 92 #
92 93 determine_arch()
93 94 {
94 95 typeset arch
95 96
96 97 arch=$(uname -p)
97 98 [[ $? -eq 0 ]] || fatal "failed to determine host architecture"
98 99 [[ "$arch" != "i386" ]] && fatal "dis tests are only supported on x86"
99 100 [[ -n "$dt_nodefault" ]] && return
100 101 dt_defarch="i386"
101 102 dt_platforms[$dt_defarch]=$dt_defas
102 103 }
103 104
104 105 #
105 106 # Iterate over the set of platforms and verify that we both know about them and
106 107 # we can find the assembler for them.
107 108 #
108 109 check_platforms()
109 110 {
110 111 typeset key
111 112
112 113 for key in ${!dt_platforms[@]}; do
113 114 typeset bin
114 115 [[ -d $dt_root/$key ]] || fatal "encountered unknown platform: $key"
115 116
116 117 #
117 118 # This may be a path or something else.
118 119 #
119 120 bin=${dt_platforms[$key]}
120 121 [[ -x $bin ]] && continue
121 122 which $bin >/dev/null 2>&1 && continue
122 123 fatal "failed to find command as absolute path or file: $bin"
123 124 done
124 125 }
125 126
126 127 handle_failure()
127 128 {
128 129 typeset dir reason source out
129 130 dir=$1
130 131 reason=$2
131 132 source=$3
132 133 out=$4
133 134 faildir=
134 135
135 136 while [[ -d failure.$dt_faildir ]]; do
136 137 ((dt_faildir++))
137 138 done
138 139
139 140 faildir="failure.$dt_faildir"
140 141 mv $dir $faildir
141 142 cp $source $faildir/
142 143 cp $out $faildir/
143 144 printf "%s " "failed "
144 145 [[ -n $reason ]] && printf "%s " $reason
145 146 printf "%s\n" "$faildir"
146 147 ((dt_tfail++))
147 148 }
148 149
149 150 #
150 151 # Check
151 152 #
152 153 test_one()
153 154 {
154 155 typeset gflags source cmp disfile outfile extra aserr diserr
155 156 dir="dis.$$"
156 157 gflags=$1
157 158 source=$2
158 159 cmp=$3
159 160 extra=$4
160 161
161 162 outfile=$dir/dis.o
162 163 aserr=$dir/as.stderr
163 164 disfile=$dir/libdis.out
164 165 diserr=$dir/dis.stderr
165 166
166 167 ((dt_tnum++))
167 168 mkdir -p $dir || fatal "failed to make directory $dir"
168 169
169 170 printf "testing %s " $source
170 171 [[ -n $extra ]] && printf "%s " $extra
171 172 printf "... "
172 173 if ! $gas $gflags -o $outfile $source 2>$aserr >/dev/null; then
173 174 handle_failure $dir "(assembling)" $source $cmp
174 175 return
175 176 fi
176 177
177 178 if ! $dt_dis $outfile >$disfile 2>$diserr; then
178 179 handle_failure $dir "(disassembling)" $source $cmp
179 180 return
180 181 fi
181 182
182 183 if ! $dt_diff $disfile $cmp; then
183 184 handle_failure $dir "(comparing)" $source $cmp
184 185 return
185 186 fi
186 187
187 188 ((dt_tsuc++))
188 189 print "passed"
|
↓ open down ↓ |
98 lines elided |
↑ open up ↑ |
189 190 rm -rf $dir || fatal "failed to remove directory $dir"
190 191 }
191 192
192 193 #
193 194 # Run a single test. This may result in two actual tests (one 32-bit and one
194 195 # 64-bit) being run.
195 196 #
196 197 run_single_file()
197 198 {
198 199 typeset sfile base cmpfile prefix arch gas p flags
200 + typeset asflags32 asflags64
199 201 sfile=$1
200 202
201 203 base=${sfile##*/}
202 204 cmpfile=${sfile%.*}.out
203 205 prefix=${base%%.*}
204 206 arch=${sfile%/*}
205 207 arch=${arch##*/}
206 208 [[ -f $cmpfile ]] || fatal "missing output file $cmpfile"
207 209 gas=${dt_platforms[$arch]}
208 210 [[ -n $gas ]] || fatal "encountered test $sfile, but missing assembler"
209 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 +
210 227 case "$prefix" in
211 228 32)
212 - test_one "-32" $sfile $cmpfile
229 + test_one $asflags32 $sfile $cmpfile
213 230 ;;
214 231 64)
215 - test_one "-64" $sfile $cmpfile
232 + test_one $asflags64 $sfile $cmpfile
216 233 ;;
217 234 tst)
218 - test_one "-32" $sfile $cmpfile "(32-bit)"
219 - test_one "-64" $sfile $cmpfile "(64-bit)"
235 + test_one $asflags32 $sfile $cmpfile "(32-bit)"
236 + test_one $asflags64 $sfile $cmpfile "(64-bit)"
220 237 ;;
221 238 esac
222 239 }
223 240
224 241 #
225 242 # Iterate over all the test directories and run the specified tests
226 243 #
227 244 run_tests()
228 245 {
229 246 typeset t
230 247 if [[ $# -ne 0 ]]; then
231 248 for t in $@; do
232 249 run_single_file $t
233 250 done
234 251 else
235 252 typeset k tests tests32 tests64
236 253 for k in ${!dt_platforms[@]}; do
237 254 tests=$(find $dt_root/$k -type f -name 'tst.*.s')
238 255 tests32=$(find $dt_root/$k -type f -name '32.*.s')
239 256 tests64=$(find $dt_root/$k -type f -name '64.*.s')
240 257 for t in $tests $tests32 $tests64; do
241 258 run_single_file $t
242 259 done
243 260 done
244 261 fi
245 262 }
246 263
247 264 goodbye()
248 265 {
249 266 cat <<EOF
250 267
251 268 --------------
252 269 libdis Results
253 270 --------------
254 271
255 272 Tests passed: $dt_tsuc
256 273 Tests failed: $dt_tfail
257 274 Tests ran: $dt_tnum
258 275 EOF
259 276 }
260 277
261 278
262 279 dt_origwd=$PWD
|
↓ open down ↓ |
33 lines elided |
↑ open up ↑ |
263 280 cd $(dirname $0) || fatal "failed to cd to test root"
264 281 dt_root=$PWD
265 282 cd $dt_origwd || fatal "failed to return to original dir"
266 283
267 284 while getopts ":np:" c $@; do
268 285 case "$c" in
269 286 n)
270 287 dt_nodefault="y"
271 288 ;;
272 289 p)
290 + OLDIFS=$IFS
273 291 IFS="="
274 292 set -A split $OPTARG
275 - IFS=" "
293 + IFS=$OLDIFS
276 294 [[ ${#split[@]} -eq 2 ]] || usage "malformed -p option: $OPTARG"
277 295 dt_platforms[${split[0]}]=${split[1]}
278 296 ;;
279 297 :)
280 298 usage "option requires an argument -- $OPTARG"
281 299 ;;
282 300 *)
283 301 usage "invalid option -- $OPTARG"
284 302 ;;
285 303 esac
286 304 done
287 305
288 306 [[ -n $dt_nodefault && ${#dt_platforms[@]} -eq 0 ]] && fatal \
289 307 "no platforms specified to run tests for"
290 308
291 309 shift $((OPTIND-1))
292 310
293 311 determine_arch
294 312 check_platforms
295 313 run_tests
296 314 goodbye
297 315
298 316 [[ $dt_tfail -eq 0 ]]
|
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX