3 # Copyright (c) 2013-2018, Intel Corporation
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are met:
8 # * Redistributions of source code must retain the above copyright notice,
9 # this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above copyright notice,
11 # this list of conditions and the following disclaimer in the documentation
12 # and/or other materials provided with the distribution.
13 # * Neither the name of Intel Corporation nor the names of its contributors
14 # may be used to endorse or promote products derived from this software
15 # without specific prior written permission.
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 # POSSIBILITY OF SUCH DAMAGE.
29 # This script executes ptt tests and compares the output of tools, like
30 # ptxed or ptdump, with the expected output from the ptt testfile.
33 [[ $verbose != 0 ]] && echo -e "$@" >&2
43 line=`grep -i ^org "$1"`
44 [[ $? != 0 ]] && return $?
45 echo $line | sed "s/org *//"
50 usage: $0 [<options>] <pttfile>...
54 -v print commands as they are executed
55 -c cpu[,cpu] comma-separated list of cpu's for the tests (see pttc -h, for valid values)
56 -f exit with 1 if any of the tests failed
57 -l only list .diff files
58 -g specify the pttc command (default: pttc)
59 -G specify additional arguments to pttc
60 -d specify the ptdump command (default: ptdump)
61 -D specify additional arguments to ptdump
62 -x specify the ptxed command (default: ptxed)
63 -X specify additional arguments to ptxed
65 <pttfile> annotated yasm file ending in .ptt
78 while getopts "hvc:flg:G:d:D:x:X:" option; do
88 cpus=`echo $OPTARG | sed "s/,/ /g"`
122 if [[ $# == 0 ]]; then
131 sed -n 's/[ \t]*;[ \t]*opt:ptdump[ \t][ \t]*\(.*\)[ \t]*/\1/p' "$1"
135 sed -n 's/[ \t]*;[ \t]*opt:ptxed[ \t][ \t]*\(.*\)[ \t]*/\1/p' "$1"
139 info "\n# run-ptt-test $@"
143 base=`basename "${ptt%%.ptt}"`
145 if [[ -n "$cpu" ]]; then
149 # the following are the files that are generated by pttc
155 # execute pttc - remove the extra \r in Windows line endings
156 files=`run "$pttc_cmd" $pttc_arg $cpu "$ptt" | sed 's/\r\n/\n/g'`
158 if [[ $ret != 0 ]]; then
159 echo "$ptt: $pttc_cmd $pttc_arg failed with $ret" >&2
166 for file in $files; do
170 sb_part=${sb_base#$base-}
171 sb_prefix=${sb_part%%,*}
172 sb_options=${sb_part#$sb_prefix}
173 sb_prio=${sb_prefix##*-}
174 sb_prefix2=${sb_prefix%-$sb_prio}
175 sb_format=${sb_prefix2##*-}
177 sb+=`echo $sb_options | sed -e "s/,/ --$sb_format:/g" -e "s/=/ /g"`
178 sb+=" --$sb_format:$sb_prio $file"
184 echo "$ptt: unexpected $pttc_cmd output '$file'"
191 if [[ -z $exps ]]; then
192 echo "$ptt: $pttc_cmd $pttc_arg did not produce any .exp file" >&2
197 # loop over all .exp files determine the tool, generate .out
198 # files and compare .exp and .out file with diff.
199 # all differences will be
201 exp_base=${exp%%.exp}
204 tool=${exp_base##$base-}
208 addr=`asm2addr "$ptt"`
209 if [[ $? != 0 ]]; then
210 echo "$ptt: org directive not found in test file" >&2
214 local opts=`ptt-ptxed-opts "$ptt"`
215 opts+=" --no-inst --check"
216 run "$ptxed_cmd" $ptxed_arg --raw $bin:$addr $cpu $opts --pt $pt $sb > $out
219 local opts=`ptt-ptdump-opts "$ptt"`
220 run "$ptdump_cmd" $ptdump_arg $cpu $opts $sb $pt > $out
223 echo "$ptt: unknown tool '$tool'"
228 if run diff -ub $exp $out > $diff; then
231 if [[ $exit_fails != 0 ]]; then
235 if [[ $list != 0 ]]; then
245 sed -n 's/[ \t]*;[ \t]*cpu[ \t][ \t]*\(.*\)[ \t]*/\1/p' "$1"
252 # if no cpus are given on the command-line,
253 # use the cpu directives from the pttfile.
254 if [[ -z $cpus ]]; then
255 cpus=`ptt-cpus "$ptt"`
258 # if there are no cpu directives in the pttfile,
259 # run the test without any cpu settings.
260 if [[ -z $cpus ]]; then
265 # otherwise run for each cpu the test.
267 run-ptt-test "$ptt" $i