|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# SPDX-License-Identifier: BSD-3-Clause |
| 4 | +# Copyright(c) 2025 Intel Corporation. All rights reserved. |
| 5 | + |
| 6 | +source "$(dirname "${BASH_SOURCE[0]}")"/../case-lib/lib.sh |
| 7 | + |
| 8 | +OPT_NAME['t']='tplg' OPT_DESC['t']="tplg file, default value is env TPLG: $TPLG" |
| 9 | +OPT_HAS_ARG['t']=1 OPT_VAL['t']="$TPLG" |
| 10 | + |
| 11 | +OPT_NAME['r']='round' OPT_DESC['r']='round count' |
| 12 | +OPT_HAS_ARG['r']=1 OPT_VAL['r']=1 |
| 13 | + |
| 14 | +OPT_NAME['d']='duration' OPT_DESC['d']='arecord duration in second' |
| 15 | +OPT_HAS_ARG['d']=1 OPT_VAL['d']=2 |
| 16 | + |
| 17 | +OPT_NAME['l']='loop' OPT_DESC['l']='option of speaker-test' |
| 18 | +OPT_HAS_ARG['l']=1 OPT_VAL['l']=3 |
| 19 | + |
| 20 | +OPT_NAME['s']='sof-logger' OPT_DESC['s']="Open sof-logger trace the data will store at $LOG_ROOT" |
| 21 | +OPT_HAS_ARG['s']=0 OPT_VAL['s']=1 |
| 22 | + |
| 23 | +OPT_NAME['x']='relay' OPT_DESC['x']='name of usbrelay switch, default value is HURTM_2' |
| 24 | +OPT_HAS_ARG['x']=1 OPT_VAL['x']="HURTM_2" |
| 25 | + |
| 26 | +func_opt_parse_option "$@" |
| 27 | + |
| 28 | +tplg=${OPT_VAL['t']} |
| 29 | +duration=${OPT_VAL['d']} |
| 30 | +relay=${OPT_VAL['x']} |
| 31 | +tcnt=${OPT_VAL['l']} |
| 32 | +round_cnt=${OPT_VAL['r']} |
| 33 | + |
| 34 | +FIVE_SECONDS=5 |
| 35 | + |
| 36 | +check_control_switch_state() |
| 37 | +{ |
| 38 | + # Check the state of the switch using amixer. |
| 39 | + # The switch name is passed as the first argument, and the expected state (on/off) |
| 40 | + # is passed as the second argument. |
| 41 | + # Returns 0 if the state matches, 1 otherwise. |
| 42 | + local switch_name="$1" |
| 43 | + local expected_switch_state="$2" |
| 44 | + local switch_state |
| 45 | + |
| 46 | + switch_state=$(echo -e $(amixer -c 0 contents | grep -i "$switch_name .* *jack" -A 2) | sed -n '1s/^.*values=//p') |
| 47 | + dlogi "$switch_name switch is: $switch_state" |
| 48 | + |
| 49 | + if [[ "$expected_switch_state" == "$switch_state" ]]; then |
| 50 | + return 0 |
| 51 | + else |
| 52 | + return 1 |
| 53 | + fi |
| 54 | +} |
| 55 | + |
| 56 | +# func_check_dsp_status() |
| 57 | +# { |
| 58 | +# dlogi "wait dsp power status to become suspended" |
| 59 | +# for i in $(seq 1 $1) |
| 60 | +# do |
| 61 | +# # Here we pass a hardcoded 0 to python script, and need to ensure |
| 62 | +# # DSP is the first audio pci device in 'lspci', this is true unless |
| 63 | +# # we have a third-party pci sound card installed. |
| 64 | +# [[ $(sof-dump-status.py --dsp_status 0) == "suspended" ]] && break |
| 65 | +# sleep 1 |
| 66 | +# if [ $i -eq $1 ]; then |
| 67 | +# die "dsp is not suspended after $1s, end test" |
| 68 | +# fi |
| 69 | +# done |
| 70 | +# dlogi "dsp suspended in ${i}s" |
| 71 | +# } |
| 72 | + |
| 73 | +main() |
| 74 | +{ |
| 75 | + # logger_disabled || func_lib_start_log_collect |
| 76 | + start_test |
| 77 | + |
| 78 | + setup_kernel_check_point |
| 79 | + func_pipeline_export "$tplg" "type:playback" |
| 80 | + |
| 81 | + # check if usbrelay tool is installed |
| 82 | + command -v usbrelay >/dev/null 2>&1 || { |
| 83 | + skip_test "usbrelay command not found. Please install usbrelay to control the mic privacy switch." |
| 84 | + } |
| 85 | + |
| 86 | + dlogi "Current DSP status is $(sof-dump-status.py --dsp_status 0)" || { |
| 87 | + skip_test "platform doesn't support runtime pm, skip test case" |
| 88 | + } |
| 89 | + |
| 90 | + # dlogi "Reset - plug jack audio" |
| 91 | + # usbrelay_switch "$relay" 0 |
| 92 | + |
| 93 | + for round in $(seq 1 "$round_cnt") |
| 94 | + do |
| 95 | + for idx in $(seq 0 $((PIPELINE_COUNT - 1))) |
| 96 | + do |
| 97 | + initialize_audio_params "$idx" |
| 98 | + |
| 99 | + [[ "$pcm" == *Jack* ]] || { |
| 100 | + dlogi "PCM $pcm is not a Jack, skipping..." |
| 101 | + continue |
| 102 | + } |
| 103 | + |
| 104 | + dlogi "===== Testing: (Round: $round/$round_cnt) (PCM: $pcm [$dev]<$type>) =====" |
| 105 | + dlogi "DEVICE: $dev, TYPE: $type, PCM: $pcm, RATE: $rate, CHANNEL: $channel" |
| 106 | + |
| 107 | + # aplay_opts -D"$dev" -r "$rate" -c "$channel" -f "$fmt" -d "$duration" "/dev/zero" -q || { |
| 108 | + # func_lib_lsof_error_dump "$snd" |
| 109 | + # die "aplay on PCM $dev failed." |
| 110 | + # } |
| 111 | + |
| 112 | + dlogi "Current DSP status is $(sof-dump-status.py --dsp_status 0)" |
| 113 | + |
| 114 | + dlogi "Unplug jack audio." |
| 115 | + usbrelay_switch "$relay" 1 |
| 116 | + |
| 117 | + dlogi "Wait for $FIVE_SECONDS to ensure jack detection is off" |
| 118 | + sleep $FIVE_SECONDS |
| 119 | + |
| 120 | + check_control_switch_state "headset" "off" || { |
| 121 | + die "unplug headset jack failed." |
| 122 | + } |
| 123 | + |
| 124 | + check_control_switch_state "headphone" 'off' || { |
| 125 | + die "unplug headphone jack failed." |
| 126 | + } |
| 127 | + |
| 128 | + dlogi "Current DSP status is $(sof-dump-status.py --dsp_status 0)" |
| 129 | + |
| 130 | + dlogi "Plug jack audio." |
| 131 | + usbrelay_switch "$relay" 0 |
| 132 | + |
| 133 | + dlogi "Wait for $FIVE_SECONDS to ensure jack detection is on" |
| 134 | + sleep $FIVE_SECONDS |
| 135 | + |
| 136 | + check_control_switch_state "headset" "on" || { |
| 137 | + die "Plug headset jack failed." |
| 138 | + } |
| 139 | + |
| 140 | + check_control_switch_state "headphone" "on" || { |
| 141 | + die "Plug headphone jack failed." |
| 142 | + } |
| 143 | + done |
| 144 | + done |
| 145 | + |
| 146 | + sof-kernel-log-check.sh "$KERNEL_CHECKPOINT" |
| 147 | +} |
| 148 | + |
| 149 | +{ |
| 150 | + main "$@"; exit "$?" |
| 151 | +} |
0 commit comments