~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/perf/tests/shell/buildid.sh

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #!/bin/sh
  2 # build id cache operations
  3 # SPDX-License-Identifier: GPL-2.0
  4 
  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
 10 
 11 # skip if there's no compiler
 12 if ! [ -x "$(command -v cc)" ]; then
 13         echo "failed: no compiler, install gcc"
 14         exit 2
 15 fi
 16 
 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
 24 fi
 25 if ! which wine > /dev/null; then
 26         echo "WARNING: wine not found. PE binaries will not be run."
 27         run_pe=0
 28 fi
 29 
 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
 37 fi
 38 
 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
 42 
 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 -
 45 
 46 echo "test binaries: ${ex_sha1} ${ex_md5} ${ex_pe}"
 47 
 48 check()
 49 {
 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@'`
 62                 ;;
 63         *)
 64                 id=`readelf -n ${1} 2>/dev/null | grep 'Build ID' | awk '{print $3}'`
 65                 ;;
 66         esac
 67         echo "build id: ${id}"
 68 
 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}"
 73 
 74         if [ ! -h $link ]; then
 75                 echo "failed: link ${link} does not exist"
 76                 exit 1
 77         fi
 78 
 79         file=${build_id_dir}/.build-id/$id_dir/`readlink ${link}`/elf
 80         echo "file: ${file}"
 81 
 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
 89                 fi
 90 
 91                 if [ ! -x $file ] && [ ! -e $file ]; then
 92                         echo "failed: file ${file} does not exist"
 93                         exit 1
 94                 fi
 95         elif [ ! -x $file ]; then
 96                 echo "failed: file ${file} does not exist"
 97                 exit 1
 98         fi
 99 
100         diff ${file} ${1}
101         if [ $? -ne 0 ]; then
102                 echo "failed: ${file} do not match"
103                 exit 1
104         fi
105 
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
110         fi
111 
112         echo "OK for ${1}"
113 }
114 
115 test_add()
116 {
117         build_id_dir=$(mktemp -d /tmp/perf.debug.XXX)
118         perf="perf --buildid-dir ${build_id_dir}"
119 
120         ${perf} buildid-cache -v -a ${1}
121         if [ $? -ne 0 ]; then
122                 echo "failed: add ${1} to build id cache"
123                 exit 1
124         fi
125 
126         check ${1}
127 
128         rm -rf ${build_id_dir}
129 }
130 
131 test_record()
132 {
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}"
138 
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
145         fi
146 
147         args="$*"
148         check ${args##* }
149 
150         rm -f ${log_out} ${log_err}
151         rm -rf ${build_id_dir}
152         rm -rf ${data}
153 }
154 
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}
160 fi
161 
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}
167 fi
168 
169 # cleanup
170 rm ${ex_sha1} ${ex_md5}
171 if [ ${run_pe} -eq 1 ]; then
172         rm -r ${wineprefix}
173 fi
174 
175 exit 0

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php