diff --git a/case-lib/hijack.sh b/case-lib/hijack.sh index 8de65fce..6f14e954 100644 --- a/case-lib/hijack.sh +++ b/case-lib/hijack.sh @@ -199,6 +199,10 @@ function func_exit_handler() fi } + # Only run when changing topology was initiated during the test + if [[ -n "$new_tplg_filename" ]]; then + restore_topology + fi print_test_result_exit "$exit_status" } diff --git a/case-lib/lib.sh b/case-lib/lib.sh index f7cb4b35..e8d6a90d 100644 --- a/case-lib/lib.sh +++ b/case-lib/lib.sh @@ -1425,3 +1425,55 @@ reboot_wrapper() echo "Reboot command" && sleep 5 sudo reboot now } + +check_topology() { + # Confirm topology on the dut + tplg_file=$(sudo journalctl -q -k | grep -i 'loading topology' | awk -F: '{ topo=$NF; } END { print topo }') + echo "Updated topology loaded: $tplg_file" +} + +# Function to check and update topology filename, reload drivers, and confirm update +update_topology_filename() { + firmware_dir="/lib/firmware/" + modprobe_file="/etc/modprobe.d/tplg_filename.conf" + remove_script="$SCRIPT_HOME/tools/kmod/sof_remove.sh" + insert_script="$SCRIPT_HOME/tools/kmod/sof_insert.sh" + if ! find "$firmware_dir" -type f -name "$new_tplg_filename" -print -quit | grep -q .; then + echo "File $new_tplg_filename does not exist in $firmware_dir or its subdirectories, exiting." + exit 1 + fi + if [[ -f "$modprobe_file" ]]; then + old_topology=$(sudo cat "$modprobe_file") + echo "Old topology: $old_topology" + fi + # Check if the remove and insert scripts exist + if [[ ! -f "$remove_script" ]]; then + echo "Error: File $remove_script does not exist. Exiting." + exit 1 + fi + + if [[ ! -f "$insert_script" ]]; then + echo "Error: File $insert_script does not exist. Exiting." + exit 1 + fi + + if [[ -n "$new_tplg_filename" ]]; then + echo "options snd-sof-pci tplg_filename=$new_tplg_filename" | sudo tee "$modprobe_file" > /dev/null + echo "Updated topology filename to: $new_tplg_filename" + + # Reload drivers + echo "Reloading drivers" + sudo "$remove_script" + sudo "$insert_script" + check_topology + fi +} + +# Restore the original topology after the test +restore_topology() { + echo "$old_topology" | sudo tee "$modprobe_file" > /dev/null + echo "Restored original topology: $old_topology" + sudo "$remove_script" + sudo "$insert_script" + check_topology +} diff --git a/test-case/check-capture.sh b/test-case/check-capture.sh index 444e5d4c..f834b5aa 100755 --- a/test-case/check-capture.sh +++ b/test-case/check-capture.sh @@ -21,32 +21,38 @@ set -e # shellcheck source=case-lib/lib.sh source "$(dirname "${BASH_SOURCE[0]}")"/../case-lib/lib.sh -OPT_NAME['t']='tplg' OPT_DESC['t']='tplg file, default value is env TPLG: $''TPLG' -OPT_HAS_ARG['t']=1 OPT_VAL['t']="$TPLG" +OPT_NAME['t']='tplg' OPT_DESC['t']='tplg file, default value is env TPLG: $''TPLG' +OPT_HAS_ARG['t']=1 OPT_VAL['t']="$TPLG" -OPT_NAME['r']='round' OPT_DESC['r']='round count' -OPT_HAS_ARG['r']=1 OPT_VAL['r']=1 +OPT_NAME['r']='round' OPT_DESC['r']='round count' +OPT_HAS_ARG['r']=1 OPT_VAL['r']=1 -OPT_NAME['d']='duration' OPT_DESC['d']='arecord duration in second' -OPT_HAS_ARG['d']=1 OPT_VAL['d']=10 +OPT_NAME['d']='duration' OPT_DESC['d']='arecord duration in second' +OPT_HAS_ARG['d']=1 OPT_VAL['d']=10 -OPT_NAME['l']='loop' OPT_DESC['l']='loop count' -OPT_HAS_ARG['l']=1 OPT_VAL['l']=3 +OPT_NAME['l']='loop' OPT_DESC['l']='loop count' +OPT_HAS_ARG['l']=1 OPT_VAL['l']=3 -OPT_NAME['o']='output' OPT_DESC['o']='output dir' -OPT_HAS_ARG['o']=1 OPT_VAL['o']="$LOG_ROOT/wavs" +OPT_NAME['o']='output' OPT_DESC['o']='output dir' +OPT_HAS_ARG['o']=1 OPT_VAL['o']="$LOG_ROOT/wavs" -OPT_NAME['f']='file' OPT_DESC['f']='file name prefix' -OPT_HAS_ARG['f']=1 OPT_VAL['f']='' +OPT_NAME['f']='file' OPT_DESC['f']='file name prefix' +OPT_HAS_ARG['f']=1 OPT_VAL['f']='' -OPT_NAME['s']='sof-logger' OPT_DESC['s']="Open sof-logger trace the data will store at $LOG_ROOT" -OPT_HAS_ARG['s']=0 OPT_VAL['s']=1 +OPT_NAME['s']='sof-logger' OPT_DESC['s']="Open sof-logger trace the data will store at $LOG_ROOT" +OPT_HAS_ARG['s']=0 OPT_VAL['s']=1 -OPT_NAME['F']='fmts' OPT_DESC['F']='Iterate all supported formats' -OPT_HAS_ARG['F']=0 OPT_VAL['F']=0 +OPT_NAME['F']='fmts' OPT_DESC['F']='Iterate all supported formats' +OPT_HAS_ARG['F']=0 OPT_VAL['F']=0 OPT_NAME['S']='filter_string' OPT_DESC['S']="run this case on specified pipelines" -OPT_HAS_ARG['S']=1 OPT_VAL['S']="id:any" +OPT_HAS_ARG['S']=1 OPT_VAL['S']="id:any" + +OPT_NAME['R']='samplerate' OPT_DESC['R']='sample rate' +OPT_HAS_ARG['R']=1 OPT_VAL['R']=48000 # Default sample rate + +OPT_NAME['T']='tplg_filename' OPT_DESC['T']='new topology filename' +OPT_HAS_ARG['T']=1 OPT_VAL['T']='' # Default empty func_opt_parse_option "$@" @@ -56,7 +62,12 @@ duration=${OPT_VAL['d']} loop_cnt=${OPT_VAL['l']} out_dir=${OPT_VAL['o']} file_prefix=${OPT_VAL['f']} +samplerate=${OPT_VAL['R']} # Use the sample rate specified by the -R option +new_tplg_filename=${OPT_VAL['T']} # New topology filename +if [[ -n "$new_tplg_filename" ]]; then + update_topology_filename +fi start_test logger_disabled || func_lib_start_log_collect @@ -90,7 +101,7 @@ do dlogi "using $file as capture output" fi - if ! arecord_opts -D"$dev" -r "$rate" -c "$channel" -f "$fmt_elem" -d "$duration" "$file" -v -q; + if ! arecord_opts -D"$dev" -r "$samplerate" -c "$channel" -f "$fmt_elem" -d "$duration" "$file" -v -q; then func_lib_lsof_error_dump "$snd" die "arecord on PCM $dev failed at $i/$loop_cnt." @@ -99,6 +110,5 @@ do done done done - sof-kernel-log-check.sh "$KERNEL_CHECKPOINT" exit $?