-
Notifications
You must be signed in to change notification settings - Fork 350
Expand file tree
/
Copy pathsof-testbench-helper.sh
More file actions
executable file
·187 lines (176 loc) · 5.15 KB
/
sof-testbench-helper.sh
File metadata and controls
executable file
·187 lines (176 loc) · 5.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/bin/bash
# SPDX-License-Identifier: BSD-3-Clause
set -e
usage() {
echo "Usage: $0 <options>"
echo "Options"
echo " -b <bits>, default 32"
echo " -c <channels>, default 2"
echo " -h shows this text"
echo " -i <input wav>, default /usr/share/sounds/alsa/Front_Center.wav"
echo " -k keep temporary files in /tmp"
echo " -m <module>, default gain"
echo " -n <pipelines>, default 1,2"
echo " -o <output wav>, default none"
echo " -p <profiling result text>, use with -x, default none"
echo " -r <rate>, default 48000"
echo " -t <force topology>, default none, e.g. production/sof-hda-generic.tplg"
echo " -v runs with valgrind, not available with -x"
echo " -x runs testbench with xt-run simulator"
echo
echo "Example: run DRC with xt-run with profiling (slow)"
echo "$0 -x -m drc -p profile-drc32.txt"
echo
echo "Example: process with native build DRC file Front_Center.wav (fast)"
echo "$0 -m drc -i /usr/share/sounds/alsa/Front_Center.wav -o ~/tmp/Front_Center_with_DRC.wav"
echo
echo "Example: check component eqiir with valgrind"
echo "$0 -v -m eqiir"
echo
}
if [ -z "${SOF_WORKSPACE}" ]; then
# fallback to the script directory default path
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
SOF_REPO=$(dirname "$SCRIPT_DIR")
SOF_WORKSPACE="$SOF_REPO/../"
echo "Using default SOF environment at $SOF_WORKSPACE"
fi
OUTWAV=
CLIP=/usr/share/sounds/alsa/Front_Center.wav
MODULE=gain
BITS=32
RATE_IN=48000
RATE_OUT=48000
CHANNELS_IN=2
CHANNELS_OUT=2
PIPELINES="1,2"
INFILE1=$(mktemp --tmpdir=/tmp in-XXXX.raw)
OUTFILE1=$(mktemp --tmpdir=/tmp out-XXXX.raw)
TRACEFILE=$(mktemp --tmpdir=/tmp trace-XXXX.txt)
PROFILEOUT=$(mktemp --tmpdir=/tmp profile-XXXX.out)
KEEP_TMP=false
XTRUN=false
PROFILE=false
TPLG0=
VALGRIND=
while getopts "b:c:hi:km:n:o:p:r:t:vx" opt; do
case "${opt}" in
b)
BITS=${OPTARG}
;;
c)
CHANNELS_IN=${OPTARG}
CHANNELS_OUT=${OPTARG}
;;
h)
usage
exit
;;
i)
CLIP=${OPTARG}
;;
k)
KEEP_TMP=true
;;
m)
MODULE=${OPTARG}
;;
n)
PIPELINES=${OPTARG}
;;
o)
OUTWAV=${OPTARG}
;;
p)
PROFILETXT=${OPTARG}
PROFILE=true
;;
r)
RATE_IN=${OPTARG}
RATE_OUT=${OPTARG}
;;
t)
TPLG0=${OPTARG}
;;
v)
VALGRIND=valgrind
;;
x)
XTRUN=true
;;
*)
usage
exit
;;
esac
done
shift $((OPTIND-1))
echo Converting clip "$CLIP" to raw input
if [[ "$BITS" == "24" ]]; then
# Sox does not support S24_4LE format
# Note gain 0.00390615 is empically find just a bit lower gain than
# 1/256 = 0.00390625 that doesn't cause sox rounding to exceed
# INT24_MIN .. INT24_MAX range.
sox --encoding signed-integer "$CLIP" -L -r "$RATE_IN" -c "$CHANNELS_IN" -b 32 "$INFILE1" vol 0.00390615
else
sox --encoding signed-integer "$CLIP" -L -r "$RATE_IN" -c "$CHANNELS_IN" -b "$BITS" "$INFILE1"
fi
TB4="$SOF_WORKSPACE/sof/tools/testbench/build_testbench/install/bin/sof-testbench4"
XTB4="$SOF_WORKSPACE/sof/tools/testbench/build_xt_testbench/sof-testbench4"
XTB4_SETUP="$SOF_WORKSPACE/sof/tools/testbench/build_xt_testbench/xtrun_env.sh"
if [ -z "$TPLG0" ]; then
TPLG="$SOF_WORKSPACE/sof/tools/build_tools/topology/topology2/development/sof-hda-benchmark-${MODULE}${BITS}.tplg"
else
TPLG="$SOF_WORKSPACE/sof/tools/build_tools/topology/topology2/$TPLG0"
fi
FMT="S${BITS}_LE"
OPTS="-r $RATE_IN -R $RATE_OUT -c $CHANNELS_IN -c $CHANNELS_OUT -b $FMT -p $PIPELINES -t $TPLG -i $INFILE1 -o $OUTFILE1"
if [ ! -f "$TPLG" ]; then
echo "Error: Topology $TPLG is not found"
echo "Build with scripts/build-tools.sh -Y"
exit 1
fi
if [[ "$XTRUN" == true ]]; then
if [ ! -x "$XTB4" ]; then
echo "Error: No executable found from $XTB4"
echo "Build with scripts/rebuild-testbench.sh -p <platform>"
exit 1
fi
echo "Running xtensa testbench"
echo " topology: $TPLG"
echo " input: $INFILE1, output: $OUTFILE1, trace: $TRACEFILE, profile: $PROFILETXT"
source "$XTB4_SETUP"
if [[ $PROFILE == true ]]; then
"$XTENSA_PATH"/xt-run --profile="$PROFILEOUT" "$XTB4" $OPTS 2> "$TRACEFILE"
"$XTENSA_PATH"/xt-gprof "$XTB4" "$PROFILEOUT" > "$PROFILETXT"
else
"$XTENSA_PATH"/xt-run "$XTB4" $OPTS 2> "$TRACEFILE"
fi
else
if [ ! -x "$TB4" ]; then
echo "Error: No executable found from $TB4"
exit 1
fi
echo "Running testbench"
echo " topology: $TPLG"
echo " input: $INFILE1, output: $OUTFILE1, trace: $TRACEFILE"
$VALGRIND "$TB4" $OPTS 2> "$TRACEFILE" || {
cat "$TRACEFILE"
exit $?
}
if [ -n "$VALGRIND" ]; then
cat "$TRACEFILE"
fi
fi
if [ -n "$OUTWAV" ]; then
echo Converting raw output to "$OUTWAV"
if [[ "$BITS" == "24" ]]; then
sox --encoding signed-integer -L -r "$RATE_OUT" -c "$CHANNELS_OUT" -b 32 "$OUTFILE1" "$OUTWAV" vol 256
else
sox --encoding signed-integer -L -r "$RATE_OUT" -c "$CHANNELS_OUT" -b "$BITS" "$OUTFILE1" "$OUTWAV"
fi
fi
if [[ "$KEEP_TMP" == false ]]; then
echo Deleting temporary files
rm -f "$INFILE1" "$OUTFILE1" "$TRACEFILE" "$PROFILEOUT"
fi