drm/nouveau: consume the return of large GSP message
[drm/drm-misc.git] / tools / perf / tests / shell / buildid.sh
blob3383ca3399d4c59c6cc4a8497b6d2ab291e7b85c
1 #!/bin/sh
2 # build id cache operations
3 # SPDX-License-Identifier: GPL-2.0
5 # skip if there's no readelf
6 if ! [ -x "$(command -v readelf)" ]; then
7 echo "failed: no readelf, install binutils"
8 exit 2
9 fi
11 # skip if there's no compiler
12 if ! [ -x "$(command -v cc)" ]; then
13 echo "failed: no compiler, install gcc"
14 exit 2
17 # check what we need to test windows binaries
18 add_pe=1
19 run_pe=1
20 if ! perf version --build-options | grep -q 'libbfd: .* on '; then
21 echo "WARNING: perf not built with libbfd. PE binaries will not be tested."
22 add_pe=0
23 run_pe=0
25 if ! which wine > /dev/null; then
26 echo "WARNING: wine not found. PE binaries will not be run."
27 run_pe=0
30 # set up wine
31 if [ ${run_pe} -eq 1 ]; then
32 wineprefix=$(mktemp -d /tmp/perf.wineprefix.XXX)
33 export WINEPREFIX=${wineprefix}
34 # clear display variables to prevent wine from popping up dialogs
35 unset DISPLAY
36 unset WAYLAND_DISPLAY
39 ex_md5=$(mktemp /tmp/perf.ex.MD5.XXX)
40 ex_sha1=$(mktemp /tmp/perf.ex.SHA1.XXX)
41 ex_pe=$(dirname $0)/../pe-file.exe
43 echo 'int main(void) { return 0; }' | cc -Wl,--build-id=sha1 -o ${ex_sha1} -x c -
44 echo 'int main(void) { return 0; }' | cc -Wl,--build-id=md5 -o ${ex_md5} -x c -
46 echo "test binaries: ${ex_sha1} ${ex_md5} ${ex_pe}"
48 check()
50 case $1 in
51 *.exe)
52 # We don't have a tool that can pull a nicely formatted build-id out of
53 # a PE file, but we can extract the whole section with objcopy and
54 # format it ourselves. The .buildid section is a Debug Directory
55 # containing a CodeView entry:
56 # https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#debug-directory-image-only
57 # https://github.com/dotnet/runtime/blob/da94c022576a5c3bbc0e896f006565905eb137f9/docs/design/specs/PE-COFF.md
58 # The build-id starts at byte 33 and must be rearranged into a GUID.
59 id=`objcopy -O binary --only-section=.buildid $1 /dev/stdout | \
60 cut -c 33-48 | hexdump -ve '/1 "%02x"' | \
61 sed 's@^\(..\)\(..\)\(..\)\(..\)\(..\)\(..\)\(..\)\(..\)\(.*\)0a$@\4\3\2\1\6\5\8\7\9@'`
64 id=`readelf -n ${1} 2>/dev/null | grep 'Build ID' | awk '{print $3}'`
66 esac
67 echo "build id: ${id}"
69 id_file=${id#??}
70 id_dir=${id%$id_file}
71 link=$build_id_dir/.build-id/$id_dir/$id_file
72 echo "link: ${link}"
74 if [ ! -h $link ]; then
75 echo "failed: link ${link} does not exist"
76 exit 1
79 file=${build_id_dir}/.build-id/$id_dir/`readlink ${link}`/elf
80 echo "file: ${file}"
82 # Check for file permission of original file
83 # in case of pe-file.exe file
84 echo $1 | grep ".exe"
85 if [ $? -eq 0 ]; then
86 if [ -x $1 ] && [ ! -x $file ]; then
87 echo "failed: file ${file} executable does not exist"
88 exit 1
91 if [ ! -x $file ] && [ ! -e $file ]; then
92 echo "failed: file ${file} does not exist"
93 exit 1
95 elif [ ! -x $file ]; then
96 echo "failed: file ${file} does not exist"
97 exit 1
100 diff ${file} ${1}
101 if [ $? -ne 0 ]; then
102 echo "failed: ${file} do not match"
103 exit 1
106 ${perf} buildid-cache -l | grep ${id}
107 if [ $? -ne 0 ]; then
108 echo "failed: ${id} is not reported by \"perf buildid-cache -l\""
109 exit 1
112 echo "OK for ${1}"
115 test_add()
117 build_id_dir=$(mktemp -d /tmp/perf.debug.XXX)
118 perf="perf --buildid-dir ${build_id_dir}"
120 ${perf} buildid-cache -v -a ${1}
121 if [ $? -ne 0 ]; then
122 echo "failed: add ${1} to build id cache"
123 exit 1
126 check ${1}
128 rm -rf ${build_id_dir}
131 test_record()
133 data=$(mktemp /tmp/perf.data.XXX)
134 build_id_dir=$(mktemp -d /tmp/perf.debug.XXX)
135 log_out=$(mktemp /tmp/perf.log.out.XXX)
136 log_err=$(mktemp /tmp/perf.log.err.XXX)
137 perf="perf --buildid-dir ${build_id_dir}"
139 echo "running: perf record $*"
140 ${perf} record --buildid-all -o ${data} "$@" 1>${log_out} 2>${log_err}
141 if [ $? -ne 0 ]; then
142 echo "failed: record $*"
143 echo "see log: ${log_err}"
144 exit 1
147 args="$*"
148 check ${args##* }
150 rm -f ${log_out} ${log_err}
151 rm -rf ${build_id_dir}
152 rm -rf ${data}
155 # add binaries manual via perf buildid-cache -a
156 test_add ${ex_sha1}
157 test_add ${ex_md5}
158 if [ ${add_pe} -eq 1 ]; then
159 test_add ${ex_pe}
162 # add binaries via perf record post processing
163 test_record ${ex_sha1}
164 test_record ${ex_md5}
165 if [ ${run_pe} -eq 1 ]; then
166 test_record wine ${ex_pe}
169 # cleanup
170 rm ${ex_sha1} ${ex_md5}
171 if [ ${run_pe} -eq 1 ]; then
172 rm -r ${wineprefix}
175 exit 0