[2/8] perf test: Fix shellcheck issues in the record test
Commit Message
Basically there are 3 issues:
1. quote shell expansion
2. do not use egrep
3. use upper case letters for signal names
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/tests/shell/record.sh | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
Comments
On Thu, Oct 20, 2022 at 10:26 AM Namhyung Kim <namhyung@kernel.org> wrote:
>
> Basically there are 3 issues:
>
> 1. quote shell expansion
> 2. do not use egrep
> 3. use upper case letters for signal names
>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Ian Rogers <irogers@google.com>
Thanks,
Ian
> ---
> tools/perf/tests/shell/record.sh | 18 +++++++++---------
> 1 file changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/tools/perf/tests/shell/record.sh b/tools/perf/tests/shell/record.sh
> index 747c33a1ec45..464071462809 100755
> --- a/tools/perf/tests/shell/record.sh
> +++ b/tools/perf/tests/shell/record.sh
> @@ -8,16 +8,16 @@ err=0
> perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
>
> cleanup() {
> - rm -f ${perfdata}
> - rm -f ${perfdata}.old
> - trap - exit term int
> + rm -f "${perfdata}"
> + rm -f "${perfdata}".old
> + trap - EXIT TERM INT
> }
>
> trap_cleanup() {
> cleanup
> exit 1
> }
> -trap trap_cleanup exit term int
> +trap trap_cleanup EXIT TERM INT
>
> test_per_thread() {
> echo "Basic --per-thread mode test"
> @@ -30,13 +30,13 @@ test_per_thread() {
> fi
> return
> fi
> - if ! perf record --per-thread -o ${perfdata} true 2> /dev/null
> + if ! perf record --per-thread -o "${perfdata}" true 2> /dev/null
> then
> echo "Per-thread record [Failed record]"
> err=1
> return
> fi
> - if ! perf report -i ${perfdata} -q | egrep -q true
> + if ! perf report -i "${perfdata}" -q | grep -q true
> then
> echo "Per-thread record [Failed missing output]"
> err=1
> @@ -47,7 +47,7 @@ test_per_thread() {
>
> test_register_capture() {
> echo "Register capture test"
> - if ! perf list | egrep -q 'br_inst_retired.near_call'
> + if ! perf list | grep -q 'br_inst_retired.near_call'
> then
> echo "Register capture test [Skipped missing event]"
> if [ $err -ne 1 ]
> @@ -56,7 +56,7 @@ test_register_capture() {
> fi
> return
> fi
> - if ! perf record --intr-regs=\? 2>&1 | egrep -q 'available registers: AX BX CX DX SI DI BP SP IP FLAGS CS SS R8 R9 R10 R11 R12 R13 R14 R15'
> + if ! perf record --intr-regs=\? 2>&1 | grep -q 'available registers: AX BX CX DX SI DI BP SP IP FLAGS CS SS R8 R9 R10 R11 R12 R13 R14 R15'
> then
> echo "Register capture test [Skipped missing registers]"
> return
> @@ -64,7 +64,7 @@ test_register_capture() {
> if ! perf record -o - --intr-regs=di,r8,dx,cx -e br_inst_retired.near_call:p \
> -c 1000 --per-thread true 2> /dev/null \
> | perf script -F ip,sym,iregs -i - 2> /dev/null \
> - | egrep -q "DI:"
> + | grep -q "DI:"
> then
> echo "Register capture test [Failed missing output]"
> err=1
> --
> 2.38.0.135.g90850a2211-goog
>
On 20/10/22 20:26, Namhyung Kim wrote:
> Basically there are 3 issues:
>
> 1. quote shell expansion
> 2. do not use egrep
> 3. use upper case letters for signal names
>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Reviewed-by: Adrian Hunter <adrian.hunter@intel.com>
> ---
> tools/perf/tests/shell/record.sh | 18 +++++++++---------
> 1 file changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/tools/perf/tests/shell/record.sh b/tools/perf/tests/shell/record.sh
> index 747c33a1ec45..464071462809 100755
> --- a/tools/perf/tests/shell/record.sh
> +++ b/tools/perf/tests/shell/record.sh
> @@ -8,16 +8,16 @@ err=0
> perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
>
> cleanup() {
> - rm -f ${perfdata}
> - rm -f ${perfdata}.old
> - trap - exit term int
> + rm -f "${perfdata}"
> + rm -f "${perfdata}".old
> + trap - EXIT TERM INT
> }
>
> trap_cleanup() {
> cleanup
> exit 1
> }
> -trap trap_cleanup exit term int
> +trap trap_cleanup EXIT TERM INT
>
> test_per_thread() {
> echo "Basic --per-thread mode test"
> @@ -30,13 +30,13 @@ test_per_thread() {
> fi
> return
> fi
> - if ! perf record --per-thread -o ${perfdata} true 2> /dev/null
> + if ! perf record --per-thread -o "${perfdata}" true 2> /dev/null
> then
> echo "Per-thread record [Failed record]"
> err=1
> return
> fi
> - if ! perf report -i ${perfdata} -q | egrep -q true
> + if ! perf report -i "${perfdata}" -q | grep -q true
> then
> echo "Per-thread record [Failed missing output]"
> err=1
> @@ -47,7 +47,7 @@ test_per_thread() {
>
> test_register_capture() {
> echo "Register capture test"
> - if ! perf list | egrep -q 'br_inst_retired.near_call'
> + if ! perf list | grep -q 'br_inst_retired.near_call'
> then
> echo "Register capture test [Skipped missing event]"
> if [ $err -ne 1 ]
> @@ -56,7 +56,7 @@ test_register_capture() {
> fi
> return
> fi
> - if ! perf record --intr-regs=\? 2>&1 | egrep -q 'available registers: AX BX CX DX SI DI BP SP IP FLAGS CS SS R8 R9 R10 R11 R12 R13 R14 R15'
> + if ! perf record --intr-regs=\? 2>&1 | grep -q 'available registers: AX BX CX DX SI DI BP SP IP FLAGS CS SS R8 R9 R10 R11 R12 R13 R14 R15'
> then
> echo "Register capture test [Skipped missing registers]"
> return
> @@ -64,7 +64,7 @@ test_register_capture() {
> if ! perf record -o - --intr-regs=di,r8,dx,cx -e br_inst_retired.near_call:p \
> -c 1000 --per-thread true 2> /dev/null \
> | perf script -F ip,sym,iregs -i - 2> /dev/null \
> - | egrep -q "DI:"
> + | grep -q "DI:"
> then
> echo "Register capture test [Failed missing output]"
> err=1
@@ -8,16 +8,16 @@ err=0
perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
cleanup() {
- rm -f ${perfdata}
- rm -f ${perfdata}.old
- trap - exit term int
+ rm -f "${perfdata}"
+ rm -f "${perfdata}".old
+ trap - EXIT TERM INT
}
trap_cleanup() {
cleanup
exit 1
}
-trap trap_cleanup exit term int
+trap trap_cleanup EXIT TERM INT
test_per_thread() {
echo "Basic --per-thread mode test"
@@ -30,13 +30,13 @@ test_per_thread() {
fi
return
fi
- if ! perf record --per-thread -o ${perfdata} true 2> /dev/null
+ if ! perf record --per-thread -o "${perfdata}" true 2> /dev/null
then
echo "Per-thread record [Failed record]"
err=1
return
fi
- if ! perf report -i ${perfdata} -q | egrep -q true
+ if ! perf report -i "${perfdata}" -q | grep -q true
then
echo "Per-thread record [Failed missing output]"
err=1
@@ -47,7 +47,7 @@ test_per_thread() {
test_register_capture() {
echo "Register capture test"
- if ! perf list | egrep -q 'br_inst_retired.near_call'
+ if ! perf list | grep -q 'br_inst_retired.near_call'
then
echo "Register capture test [Skipped missing event]"
if [ $err -ne 1 ]
@@ -56,7 +56,7 @@ test_register_capture() {
fi
return
fi
- if ! perf record --intr-regs=\? 2>&1 | egrep -q 'available registers: AX BX CX DX SI DI BP SP IP FLAGS CS SS R8 R9 R10 R11 R12 R13 R14 R15'
+ if ! perf record --intr-regs=\? 2>&1 | grep -q 'available registers: AX BX CX DX SI DI BP SP IP FLAGS CS SS R8 R9 R10 R11 R12 R13 R14 R15'
then
echo "Register capture test [Skipped missing registers]"
return
@@ -64,7 +64,7 @@ test_register_capture() {
if ! perf record -o - --intr-regs=di,r8,dx,cx -e br_inst_retired.near_call:p \
-c 1000 --per-thread true 2> /dev/null \
| perf script -F ip,sym,iregs -i - 2> /dev/null \
- | egrep -q "DI:"
+ | grep -q "DI:"
then
echo "Register capture test [Failed missing output]"
err=1