From 6cdaddbef11ff70871566fe61bb7b6eb023c9acb Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Sat, 1 Mar 2025 19:24:13 +0000 Subject: [PATCH 1/6] scripts: testbench: check for workspace environment variable Allow both scripts to be executed from the SOF FW directory or the parent SOF workspace directory using an environment variable or the default SOF workspace. This simplifies usage and opens the way for vscode integration. Signed-off-by: Liam Girdwood --- .github/workflows/testbench.yml | 2 ++ scripts/sof-testbench-build-profile.sh | 22 ++++++++++++++++++---- scripts/sof-testbench-helper.sh | 26 +++++++++++++++++++------- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/.github/workflows/testbench.yml b/.github/workflows/testbench.yml index d54b1db331db..fde7540a9aa2 100644 --- a/.github/workflows/testbench.yml +++ b/.github/workflows/testbench.yml @@ -34,6 +34,8 @@ permissions: jobs: build-and-test: runs-on: ubuntu-24.04 + env: + SOF_WORKSPACE=$HOME:/work/sof/sof steps: - name: Checkout SOF repository (PR source) diff --git a/scripts/sof-testbench-build-profile.sh b/scripts/sof-testbench-build-profile.sh index 73a880a353b9..3d9025823d0d 100755 --- a/scripts/sof-testbench-build-profile.sh +++ b/scripts/sof-testbench-build-profile.sh @@ -9,6 +9,7 @@ usage() { echo " -h shows this text" echo " -p sets platform for scripts/rebuild-testbench.sh" echo + echo "This script must be run from the sof firmware toplevel or workspace directory" } MODULES_S32_44K_48K="asrc src" @@ -16,13 +17,26 @@ MODULES_S32="dcblock drc drc_multiband dolby-dax eqfir eqiir gain level_multipli sound_dose stft_process_1536_240_ template_comp tdfb" MODULES_S24="aria" -if [ -z "${SOF_WORKSPACE}" ]; then - echo "Error: environment variable SOF_WORKSPACE need to be set to top level sof directory" +# This script can be executed from the sof firmware toplevel or workspace directory +# First check for the worksapce 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 +#set default values PLATFORM=none -PDIR=$SOF_WORKSPACE/sof/tools/testbench/profile +PDIR=$PWD/sof/tools/testbench/profile while getopts "hp:d:" opt; do case "${opt}" in @@ -45,7 +59,7 @@ done shift $((OPTIND-1)) # Build -SCRIPTS=$SOF_WORKSPACE/sof/scripts +SCRIPTS=$PWD/sof/scripts mkdir -p "$PDIR" "$SCRIPTS"/rebuild-testbench.sh -p "$PLATFORM" HELPER="$SCRIPTS"/sof-testbench-helper.sh diff --git a/scripts/sof-testbench-helper.sh b/scripts/sof-testbench-helper.sh index ea7a6590ee67..e228809604fe 100755 --- a/scripts/sof-testbench-helper.sh +++ b/scripts/sof-testbench-helper.sh @@ -30,10 +30,22 @@ usage() { 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 } -if [ -z "${SOF_WORKSPACE}" ]; then - echo "Error: environment variable SOF_WORKSPACE need to be set to top level sof 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 @@ -122,13 +134,13 @@ 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" +TB4="$PWD/sof/tools/testbench/build_testbench/install/bin/sof-testbench4" +XTB4="$PWD/sof/tools/testbench/build_xt_testbench/sof-testbench4" +XTB4_SETUP="$PWD/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" + TPLG="$PWD/sof/tools/build_tools/topology/topology2/development/sof-hda-benchmark-${MODULE}${BITS}.tplg" else - TPLG="$SOF_WORKSPACE/sof/tools/build_tools/topology/topology2/$TPLG0" + TPLG="$PWD/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" From 36f1735b652247e30d3b8ea562e3cf994ff653e4 Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Sun, 2 Mar 2025 16:39:31 +0000 Subject: [PATCH 2/6] scripts: build tools: dont build in src dir Dont built binaries in the source directory, build in the workspace. Signed-off-by: Liam Girdwood --- .gitignore | 1 - scripts/build-tools.sh | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 043112c6ff78..19a711f69af2 100644 --- a/.gitignore +++ b/.gitignore @@ -50,7 +50,6 @@ tools/test/audio/zeros_in.raw __pycache__ -build*/ # Eclipse project metadata .settings diff --git a/scripts/build-tools.sh b/scripts/build-tools.sh index 6304265820cd..558a0e52c23a 100755 --- a/scripts/build-tools.sh +++ b/scripts/build-tools.sh @@ -98,7 +98,7 @@ main() CMAKE_ONLY BUILD_ALL SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd) SOF_REPO=$(dirname "$SCRIPT_DIR") - : "${BUILD_TOOLS_DIR:=$SOF_REPO/tools/build_tools}" + : "${BUILD_TOOLS_DIR:=$SOF_REPO/../build-tools-tplg}" : "${NO_PROCESSORS:=$(nproc)}" BUILD_ALL=false From 7e8c9e31a8eba71e203d24571ef238884dc20cf8 Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Sun, 2 Mar 2025 17:21:26 +0000 Subject: [PATCH 3/6] scripts: testbench_helper: fix indentation Fix the indentation. Signed-off-by: Liam Girdwood --- scripts/sof-testbench-helper.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/sof-testbench-helper.sh b/scripts/sof-testbench-helper.sh index e228809604fe..5eb1892546a3 100755 --- a/scripts/sof-testbench-helper.sh +++ b/scripts/sof-testbench-helper.sh @@ -84,7 +84,7 @@ while getopts "b:c:hi:km:n:o:p:r:R:t:vx" opt; do i) CLIP=${OPTARG} ;; - k) + k) KEEP_TMP=true ;; m) @@ -112,7 +112,7 @@ while getopts "b:c:hi:km:n:o:p:r:R:t:vx" opt; do v) VALGRIND=valgrind ;; - x) + x) XTRUN=true ;; *) From 1b4fdf30e9d39ed874e521b4d8f7004d82a34b65 Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Mon, 3 Mar 2025 13:11:34 +0000 Subject: [PATCH 4/6] scripts: testbench: move build output outside of source directory Move all testbench build and test collateral outside of the SOF source directory to the workspace directory. Signed-off-by: Liam Girdwood --- scripts/rebuild-testbench.sh | 32 +++++++++++++++++++------- scripts/sof-testbench-build-profile.sh | 2 +- scripts/sof-testbench-helper.sh | 12 +++++----- tools/test/audio/comp_run.sh | 8 +++---- 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/scripts/rebuild-testbench.sh b/scripts/rebuild-testbench.sh index 996d16f45a8c..5f2348510841 100755 --- a/scripts/rebuild-testbench.sh +++ b/scripts/rebuild-testbench.sh @@ -5,16 +5,32 @@ # stop on most errors set -e -SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd) -SOF_REPO=$(dirname "$SCRIPT_DIR") -TESTBENCH_DIR="$SOF_REPO"/tools/testbench +# This script can be executed from the sof firmware toplevel or workspace directory +# First check for the worksapce 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 + +TESTBENCH_DIR=$BASE_DIR/sof/tools/testbench # Defaults BUILD_BACKEND='make' BUILD_TYPE=native -BUILD_DIR_NAME=build_testbench +BUILD_DIR_NAME=$BASE_DIR/build_testbench BUILD_TARGET=install : "${SOF_AFL:=$HOME/sof/work/AFL/afl-gcc}" +SCRIPT_DIR=$BASE_DIR/sof/scripts print_usage() { @@ -59,7 +75,7 @@ setup_xtensa_tools_build() { BUILD_TYPE=xt BUILD_TARGET= - BUILD_DIR_NAME=build_xt_testbench + BUILD_DIR_NAME=$BASE_DIR/build_xt_testbench # check needed environment variables test -n "${XTENSA_TOOLS_ROOT}" || die "XTENSA_TOOLS_ROOT need to be set.\n" @@ -90,7 +106,7 @@ setup_xtensa_tools_build() export_xtensa_setup() { - export_dir=$TESTBENCH_DIR/$BUILD_DIR_NAME + export_dir=$BUILD_DIR_NAME export_script=$export_dir/xtrun_env.sh xtbench=$export_dir/sof-testbench4 xtbench_run="XTENSA_CORE=$XTENSA_CORE \$XTENSA_TOOLS_ROOT/$install_bin/xt-run $xtbench" @@ -114,14 +130,14 @@ Success! For temporary, interactive Kconfiguration use: - $BUILD_BACKEND -C $TESTBENCH_DIR/$BUILD_DIR_NAME/sof_ep/build/ menuconfig + $BUILD_BACKEND -C $BUILD_DIR_NAME/sof_ep/build/ menuconfig Permanent configuration is "src/arch/host/configs/library_defconfig". For instant, incremental build: $src_env_msg - $BUILD_BACKEND -C $TESTBENCH_DIR/$BUILD_DIR_NAME/ -j$(nproc) + $BUILD_BACKEND -C $BUILD_DIR_NAME/ -j$(nproc) EOF0 diff --git a/scripts/sof-testbench-build-profile.sh b/scripts/sof-testbench-build-profile.sh index 3d9025823d0d..591fde72bf24 100755 --- a/scripts/sof-testbench-build-profile.sh +++ b/scripts/sof-testbench-build-profile.sh @@ -36,7 +36,7 @@ fi #set default values PLATFORM=none -PDIR=$PWD/sof/tools/testbench/profile +PDIR=$PWD/testbench/profile while getopts "hp:d:" opt; do case "${opt}" in diff --git a/scripts/sof-testbench-helper.sh b/scripts/sof-testbench-helper.sh index 5eb1892546a3..a6d63b61bc68 100755 --- a/scripts/sof-testbench-helper.sh +++ b/scripts/sof-testbench-helper.sh @@ -133,14 +133,14 @@ if [[ "$BITS" == "24" ]]; then else sox --encoding signed-integer "$CLIP" -L -r "$RATE_IN" -c "$CHANNELS_IN" -b "$BITS" "$INFILE1" fi - -TB4="$PWD/sof/tools/testbench/build_testbench/install/bin/sof-testbench4" -XTB4="$PWD/sof/tools/testbench/build_xt_testbench/sof-testbench4" -XTB4_SETUP="$PWD/sof/tools/testbench/build_xt_testbench/xtrun_env.sh" +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/sof/tools/build_tools/topology/topology2/development/sof-hda-benchmark-${MODULE}${BITS}.tplg" + TPLG="$PWD/build_tools/topology/topology2/development/sof-hda-benchmark-${MODULE}${BITS}.tplg" else - TPLG="$PWD/sof/tools/build_tools/topology/topology2/$TPLG0" + 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" diff --git a/tools/test/audio/comp_run.sh b/tools/test/audio/comp_run.sh index 096ff2c341c0..6beaf74f5fa0 100755 --- a/tools/test/audio/comp_run.sh +++ b/tools/test/audio/comp_run.sh @@ -132,13 +132,13 @@ run_testbench () parse_args "$@" # Path to topologies -TPLG_DIR=../../build_tools/test/topology +TPLG_DIR=../../../../build_tools/test/topology # Testbench path and executable if [[ -z $XTRUN ]]; then - PATH_TESTBENCH=../../testbench/build_testbench/install/bin/$TESTBENCH + PATH_TESTBENCH=../../../../build_testbench/install/bin/$TESTBENCH else - BUILD_DIR=../../testbench/build_xt_testbench + BUILD_DIR=../../../../build_xt_testbench PATH_TESTBENCH="$BUILD_DIR"/$TESTBENCH source "$BUILD_DIR"/xtrun_env.sh XTRUN_CMD=$XTENSA_PATH/$XTRUN @@ -168,7 +168,7 @@ PIPELINES= [[ $DIRECTION == "playback" ]] && PIPELINES="-p 1,2" [[ $DIRECTION == "capture" ]] && PIPELINES="-p 3,4" TPLGFN=sof-hda-benchmark-${COMP}${BITS_IN}.tplg - TPLG_DIR="../../build_tools/topology/topology2/development" + TPLG_DIR="../../../../build_tools/topology/topology2/development" TPLG_BUILD_TIP="Please run scripts/build-tools.sh" } From b3a3123b3ffb1709d3c5b6375c2aa38db832c194 Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Mon, 3 Mar 2025 14:00:55 +0000 Subject: [PATCH 5/6] scripts: testbench: move test files outside of source directory Move the test data files outside of the source directory and add more context to their names for easier lookup. Do the same with the outfile and generate it if we keep the temporary files. Signed-off-by: Liam Girdwood --- scripts/sof-testbench-helper.sh | 38 ++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/scripts/sof-testbench-helper.sh b/scripts/sof-testbench-helper.sh index a6d63b61bc68..9eee24387b3b 100755 --- a/scripts/sof-testbench-helper.sh +++ b/scripts/sof-testbench-helper.sh @@ -10,10 +10,9 @@ usage() { echo " -c , default 2" echo " -h shows this text" echo " -i , default /usr/share/sounds/alsa/Front_Center.wav" - echo " -k keep temporary files in /tmp" + echo " -k keep temporary files in data directory" echo " -m , default gain" echo " -n , default 1,2" - echo " -o , default none" echo " -p , use with -x, default none" echo " -r , input rate, default 48000" echo " -R , output rate, default 48000" @@ -49,7 +48,6 @@ if [ ! -d "sof" ]; then exit 1 fi -OUTWAV= CLIP=/usr/share/sounds/alsa/Front_Center.wav MODULE=gain BITS=32 @@ -58,10 +56,6 @@ 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 @@ -123,6 +117,19 @@ while getopts "b:c:hi:km:n:o:p:r:R:t:vx" opt; do 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 @@ -184,16 +191,17 @@ else fi fi -if [ -n "$OUTWAV" ]; then +# 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 + 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" + 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 From 43838ef81671fbb32c42b4b6c9e8b8e90eb61347 Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Mon, 7 Apr 2025 18:48:51 +0100 Subject: [PATCH 6/6] build-tools: deploy: Add deployment option for topology2 Add a simple deployment option fro topology2 to copy topologies to the staging build directory. Simple today as only Intel use tplg2. Signed-off-by: Liam Girdwood --- scripts/build-tools.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/scripts/build-tools.sh b/scripts/build-tools.sh index 558a0e52c23a..1891a12a3b37 100755 --- a/scripts/build-tools.sh +++ b/scripts/build-tools.sh @@ -16,7 +16,7 @@ Attention: the list of selected shortcuts below is _not_ exhaustive. To build _everything_ don't select any particular target; this will build CMake's default target "ALL". -usage: $0 [-c|-f|-h|-l|-p|-t|-T|-X|-Y|-A] +usage: $0 [-c|-f|-h|-l|-p|-t|-T|-X|-Y|-A|-d] -h Display help -c Rebuild ctl/ @@ -27,6 +27,7 @@ usage: $0 [-c|-f|-h|-l|-p|-t|-T|-X|-Y|-A] -Y Rebuild topology2 only -t Rebuild test/topology/ (or tools/test/topology/tplg-build.sh directly) -A Clone and rebuild local ALSA lib and utils. + -d Deployment build -C No build, only CMake re-configuration. Shows CMake targets. EOFUSAGE @@ -100,6 +101,7 @@ main() SOF_REPO=$(dirname "$SCRIPT_DIR") : "${BUILD_TOOLS_DIR:=$SOF_REPO/../build-tools-tplg}" : "${NO_PROCESSORS:=$(nproc)}" + DEPLOY_DIR="$SOF_REPO/../build-sof-staging" BUILD_ALL=false if [ $# -eq 0 ]; then @@ -113,6 +115,7 @@ main() DO_BUILD_tests=false DO_BUILD_topologies1=false DO_BUILD_topologies2=false + DO_DEPLOYMENT=false CMAKE_ONLY=false # better safe than sorry @@ -120,7 +123,7 @@ main() # eval is a sometimes necessary evil # shellcheck disable=SC2034 - while getopts "cfhlptTCXYA" OPTION; do + while getopts "cfhlptTCXYAd" OPTION; do case "$OPTION" in c) DO_BUILD_ctl=true ;; l) DO_BUILD_logger=true ;; @@ -131,6 +134,7 @@ main() Y) DO_BUILD_topologies2=true ;; C) CMAKE_ONLY=true ;; A) DO_BUILD_alsa=true ;; + d) DO_DEPLOYMENT=true ;; h) print_usage; exit 1;; *) print_usage; exit 1;; esac @@ -174,6 +178,14 @@ main() fi done + if "$DO_DEPLOYMENT"; then + # copy Intel topology2 files to output directory + # This will need updated when other uses topology2 + cp -ap "$BUILD_TOOLS_DIR"/topology/topology2/production/*.tplg \ + $DEPLOY_DIR/lib/firmware/intel/sof-ipc4-tplg/ + echo "Deployment build done" + fi + warn_if_incremental_build }