Message ID | 20230119113054.31742-1-atrajeev@linux.vnet.ibm.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | [V2] tools/perf/tests: Fix string substitutions in build id test | expand |
From: Athira Rajeev > Sent: 19 January 2023 11:31 ... > diff --git a/tools/perf/tests/shell/buildid.sh b/tools/perf/tests/shell/buildid.sh > index aaf851108ca3..43e43e131be7 100755 > --- a/tools/perf/tests/shell/buildid.sh > +++ b/tools/perf/tests/shell/buildid.sh > @@ -66,7 +66,7 @@ check() > esac > echo "build id: ${id}" > > - link=${build_id_dir}/.build-id/${id:0:2}/${id:2} > + link=${build_id_dir}/.build-id/$(echo ${id}|cut -c 1-2)/$(echo ${id}|cut -c 3-) > echo "link: ${link}" That is horrid, why not just use valid shell substitutions, eg: id_file=${id#??} id_dir=${id%$id_file} link=$build_id_dir/.build-id/$id_dir/$id_file ... > - check ${@: -1} > + check $last Since this is the end of the shell function you can avoid the eval by doing: shift $(($# - 1)) check $1 or maybe: args="$*" check ${args##* } Those should be ok in all posix shells. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
> On 19-Jan-2023, at 5:32 PM, David Laight <David.Laight@ACULAB.COM> wrote: > > From: Athira Rajeev >> Sent: 19 January 2023 11:31 > ... >> diff --git a/tools/perf/tests/shell/buildid.sh b/tools/perf/tests/shell/buildid.sh >> index aaf851108ca3..43e43e131be7 100755 >> --- a/tools/perf/tests/shell/buildid.sh >> +++ b/tools/perf/tests/shell/buildid.sh >> @@ -66,7 +66,7 @@ check() >> esac >> echo "build id: ${id}" >> >> - link=${build_id_dir}/.build-id/${id:0:2}/${id:2} >> + link=${build_id_dir}/.build-id/$(echo ${id}|cut -c 1-2)/$(echo ${id}|cut -c 3-) >> echo "link: ${link}" > > That is horrid, why not just use valid shell substitutions, eg: > id_file=${id#??} > id_dir=${id%$id_file} > link=$build_id_dir/.build-id/$id_dir/$id_file > > ... >> - check ${@: -1} >> + check $last > > Since this is the end of the shell function you can avoid the eval > by doing: > shift $(($# - 1)) > check $1 > or maybe: > args="$*" > check ${args##* } > > Those should be ok in all posix shells. > > David > Hi David, Thanks for the review. I will post a V3 addressing these changes. Athira > - > Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK > Registration No: 1397386 (Wales)
diff --git a/tools/perf/tests/shell/buildid.sh b/tools/perf/tests/shell/buildid.sh index aaf851108ca3..43e43e131be7 100755 --- a/tools/perf/tests/shell/buildid.sh +++ b/tools/perf/tests/shell/buildid.sh @@ -66,7 +66,7 @@ check() esac echo "build id: ${id}" - link=${build_id_dir}/.build-id/${id:0:2}/${id:2} + link=${build_id_dir}/.build-id/$(echo ${id}|cut -c 1-2)/$(echo ${id}|cut -c 3-) echo "link: ${link}" if [ ! -h $link ]; then @@ -74,7 +74,7 @@ check() exit 1 fi - file=${build_id_dir}/.build-id/${id:0:2}/`readlink ${link}`/elf + file=${build_id_dir}/.build-id/$(echo ${id}|cut -c 1-2)/`readlink ${link}`/elf echo "file: ${file}" # Check for file permission of original file @@ -130,20 +130,22 @@ test_record() { data=$(mktemp /tmp/perf.data.XXX) build_id_dir=$(mktemp -d /tmp/perf.debug.XXX) - log=$(mktemp /tmp/perf.log.XXX) + log_out=$(mktemp /tmp/perf.log.out.XXX) + log_err=$(mktemp /tmp/perf.log.err.XXX) perf="perf --buildid-dir ${build_id_dir}" + eval last=\${$#} echo "running: perf record $@" - ${perf} record --buildid-all -o ${data} $@ &> ${log} + ${perf} record --buildid-all -o ${data} $@ 1>${log_out} 2>${log_err} if [ $? -ne 0 ]; then echo "failed: record $@" - echo "see log: ${log}" + echo "see log: ${log_err}" exit 1 fi - check ${@: -1} + check $last - rm -f ${log} + rm -f ${log_out} ${log_err} rm -rf ${build_id_dir} rm -rf ${data} }