-
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
·204 lines (191 loc) · 5.73 KB
/
sof-testbench-helper.sh
File metadata and controls
executable file
·204 lines (191 loc) · 5.73 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/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 data directory"
echo " -m <module>, default gain"
echo " -n <pipelines>, default 1,2"
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
echo This script must be run from the sof firmware toplevel or workspace directory
}
# First check for the workspace environment variable
if [ -z "$SOF_WORKSPACE" ]; then
# Environment variable is empty or unset so use default
BASE_DIR="$HOME/work/sof"
else
# Environment variable exists and has a value
BASE_DIR="$SOF_WORKSPACE"
fi
cd "$BASE_DIR"
# check we are in the workspace directory
if [ ! -d "sof" ]; then
echo "Error: can't find SOF firmware directory. Please check your installation."
exit 1
fi
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"
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))
# Get the current date and time in a specific format (YYYYMMDD_HHMMSS)
timestamp=$(date +"%Y%m%d_%H%M%S")
# Combine the prefix and timestamp to create the filename
INFILE1="$PWD/testbench_data/in-${MODULE}-${timestamp}.raw"
OUTFILE1="$PWD/testbench_data/out-${MODULE}-${timestamp}.raw"
TRACEFILE="$PWD/testbench_data/trace-${MODULE}-${timestamp}.txt"
PROFILEOUT="$PWD/testbench_data/profile-${MODULE}-${timestamp}.out"
OUTWAV="$PWD/testbench_data/outwav-${MODULE}-${timestamp}.wav"
# make the data directory if it doesn't exist
mkdir -p $PWD/testbench_data
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
TOOLSDIR="$PWD/build_tools/testbench"
TB4="$PWD/build-testbench/install/bin/sof-testbench4"
XTB4="$PWD/build-xt-testbench/sof-testbench4"
XTB4_SETUP="$PWD/build-xt-testbench/xtrun_env.sh"
if [ -z "$TPLG0" ]; then
TPLG="$PWD/build_tools/topology/topology2/development/sof-hda-benchmark-${MODULE}${BITS}.tplg"
else
TPLG="$PWD/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
# Generate the outwav if we are keeping our data files for inspection.
if [[ "$KEEP_TMP" == false ]]; then
echo Deleting temporary files
rm -f "$INFILE1" "$OUTFILE1" "$TRACEFILE" "$PROFILEOUT"
else
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