perf tests: Fix test 68 zstd compression for s390
[linux-2.6-microblaze.git] / tools / perf / tests / shell / record+zstd_comp_decomp.sh
1 #!/bin/sh
2 # Zstd perf.data compression/decompression
3
4 # SPDX-License-Identifier: GPL-2.0
5
6 trace_file=$(mktemp /tmp/perf.data.XXX)
7 perf_tool=perf
8
9 skip_if_no_z_record() {
10         $perf_tool record -h 2>&1 | grep -q '\-z, \-\-compression\-level'
11 }
12
13 collect_z_record() {
14         echo "Collecting compressed record file:"
15         [[ "$(uname -m)" != s390x ]] && gflag='-g'
16         $perf_tool record -o $trace_file $gflag -z -F 5000 -- \
17                 dd count=500 if=/dev/urandom of=/dev/null
18 }
19
20 check_compressed_stats() {
21         echo "Checking compressed events stats:"
22         $perf_tool report -i $trace_file --header --stats | \
23                 grep -E "(# compressed : Zstd,)|(COMPRESSED events:)"
24 }
25
26 check_compressed_output() {
27         $perf_tool inject -i $trace_file -o $trace_file.decomp &&
28         $perf_tool report -i $trace_file --stdio | head -n -3 > $trace_file.comp.output &&
29         $perf_tool report -i $trace_file.decomp --stdio | head -n -3 > $trace_file.decomp.output &&
30         diff $trace_file.comp.output $trace_file.decomp.output
31 }
32
33 skip_if_no_z_record || exit 2
34 collect_z_record && check_compressed_stats && check_compressed_output
35 err=$?
36 rm -f $trace_file*
37 exit $err