|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +## |
| 4 | +## Case Name: check alsabat |
| 5 | +## |
| 6 | +## Preconditions: |
| 7 | +## This test case requires physical loopback between playback and capture. |
| 8 | +## playback <=====> capture |
| 9 | +## nocodec : no need to use hw loopback cable, It support DSP loopback by quirk |
| 10 | +## |
| 11 | +## Description: |
| 12 | +## Run two alsabat instances concurrently, one on each specified PCM: playback |
| 13 | +## and capture. |
| 14 | +## |
| 15 | +## Warning: as of January 2024, "man alsabat" is incomplete and |
| 16 | +## documents only the "single instance" mode where a single alsabat |
| 17 | +## process performs both playback and capture. |
| 18 | +## |
| 19 | +## Case step: |
| 20 | +## 1. Specify the pcm IDs for playback and catpure |
| 21 | +## 3. run alsabat test |
| 22 | +## |
| 23 | +## Expect result: |
| 24 | +## The return value of alsabat is 0 |
| 25 | +## |
| 26 | + |
| 27 | +# remove the existing alsabat wav files |
| 28 | +rm -f /tmp/bat.wav.* |
| 29 | + |
| 30 | +# shellcheck source=case-lib/lib.sh |
| 31 | +source "$(dirname "${BASH_SOURCE[0]}")"/../case-lib/lib.sh |
| 32 | + |
| 33 | +OPT_NAME['p']='pcm_p' OPT_DESC['p']='pcm for playback. Example: hw:0,0' |
| 34 | +OPT_HAS_ARG['p']=1 OPT_VAL['p']='' |
| 35 | + |
| 36 | +OPT_NAME['C']='channel_c' OPT_DESC['C']='channel number for capture.' |
| 37 | +OPT_HAS_ARG['C']=1 OPT_VAL['C']='1' |
| 38 | + |
| 39 | +OPT_NAME['N']='channel_p' OPT_DESC['N']='channel number for playback.' |
| 40 | +OPT_HAS_ARG['N']=1 OPT_VAL['N']='2' |
| 41 | + |
| 42 | +OPT_NAME['r']='rate' OPT_DESC['r']='sample rate' |
| 43 | +OPT_HAS_ARG['r']=1 OPT_VAL['r']=48000 |
| 44 | + |
| 45 | +OPT_NAME['c']='pcm_c' OPT_DESC['c']='pcm for capture. Example: hw:1,0' |
| 46 | +OPT_HAS_ARG['c']=1 OPT_VAL['c']='' |
| 47 | + |
| 48 | +OPT_NAME['f']='format' OPT_DESC['f']='target format' |
| 49 | +OPT_HAS_ARG['f']=1 OPT_VAL['f']="S16_LE" |
| 50 | + |
| 51 | +OPT_NAME['F']='frequency' OPT_DESC['F']='target frequency' |
| 52 | +OPT_HAS_ARG['F']=1 OPT_VAL['F']=821 |
| 53 | + |
| 54 | +OPT_NAME['k']='sigmak' OPT_DESC['k']='sigma k value' |
| 55 | +OPT_HAS_ARG['k']=1 OPT_VAL['k']=2.1 |
| 56 | + |
| 57 | +OPT_NAME['n']='frames' OPT_DESC['n']='test frames' |
| 58 | +OPT_HAS_ARG['n']=1 OPT_VAL['n']=240000 |
| 59 | + |
| 60 | +OPT_NAME['s']='sof-logger' OPT_DESC['s']="Open sof-logger trace the data will store at $LOG_ROOT" |
| 61 | +OPT_HAS_ARG['s']=0 OPT_VAL['s']=1 |
| 62 | + |
| 63 | +OPT_NAME['d']='duration' OPT_DESC['d']='duration time for socwatch to collect the data' |
| 64 | +OPT_HAS_ARG['d']=1 OPT_VAL['d']=10 |
| 65 | + |
| 66 | +: "${SOCWATCH_PATH:=$HOME/socwatch}" |
| 67 | +SOCWATCH_VERSION=$(sudo "$SOCWATCH_PATH"/socwatch --version | grep Version) |
| 68 | + |
| 69 | +func_opt_parse_option "$@" |
| 70 | +setup_kernel_check_point |
| 71 | + |
| 72 | +pcm_p=${OPT_VAL['p']} |
| 73 | +pcm_c=${OPT_VAL['c']} |
| 74 | +rate=${OPT_VAL['r']} |
| 75 | +channel_c=${OPT_VAL['C']} |
| 76 | +channel_p=${OPT_VAL['N']} |
| 77 | +format=${OPT_VAL['f']} |
| 78 | +frequency=${OPT_VAL['F']} |
| 79 | +sigmak=${OPT_VAL['k']} |
| 80 | +frames=${OPT_VAL['n']} |
| 81 | +duration=${OPT_VAL['d']} |
| 82 | + |
| 83 | +analyze_socwatch_results() |
| 84 | +{ |
| 85 | + pc_states_file="$LOG_ROOT/pc_states.csv" |
| 86 | + touch "$pc_states_file" |
| 87 | + results=$(cat "$socwatch_output".csv | grep "Platform Monitoring Technology CPU Package C-States Residency Summary: Residency" -A 10) |
| 88 | + echo "$results" | tee "$pc_states_file" |
| 89 | + |
| 90 | + expected_results='{"PC0":12.00, "PC2":88, "PC6.1":0, "PC6.2":11, "PC10.1":2, "PC10.2":72, "PC10.3":0}' |
| 91 | + |
| 92 | + # Analyze if the % of the time spent in given PC state was as expected |
| 93 | + if python3 "$SCRIPT_HOME"/tools/analyze-pc-states.py "$pc_states_file" "$expected_results"; then |
| 94 | + dlogi "All Package Residency (%) values were as expected" |
| 95 | + else |
| 96 | + die "Some Package Residency (%) values different from expected!" |
| 97 | + fi |
| 98 | +} |
| 99 | + |
| 100 | +check_for_PC10_state() |
| 101 | +{ |
| 102 | + pc10_count=$(awk '/Package C-State Summary: Entry Counts/{f=1; next} f && /PC10/{print $3; exit}' "$socwatch_output".csv) |
| 103 | + if [ -z "$pc10_count" ]; then |
| 104 | + die "PC10 State not achieved" |
| 105 | + fi |
| 106 | + dlogi "Entered into PC10 State $pc10_count times" |
| 107 | + |
| 108 | + pc10_per=$(awk '/Package C-State Summary: Residency/{f=1; next} f && /PC10/{print $3; exit}' "$socwatch_output".csv) |
| 109 | + pc10_time=$(awk '/Package C-State Summary: Residency/{f=1; next} f && /PC10/{print $5; exit}' "$socwatch_output".csv) |
| 110 | + dlogi "Spent $pc10_time ms ($pc10_per %) in PC10 State" |
| 111 | + |
| 112 | + json_str=$( jq -n \ |
| 113 | + --arg id "$i" \ |
| 114 | + --arg cnt "$pc10_count" \ |
| 115 | + --arg time "$pc10_time" \ |
| 116 | + --arg per "$pc10_per" \ |
| 117 | + '{$id: {pc10_entires_count: $cnt, time_ms: $time, time_percentage: $per}}' ) |
| 118 | + |
| 119 | + results=$(jq --slurp 'add' <(echo "$results") <(echo "$json_str")) |
| 120 | +} |
| 121 | + |
| 122 | +check_the_pcms() |
| 123 | +{ |
| 124 | + aplay "-Dplug${pcm_p}" -d 1 /dev/zero -q || die "Failed to play on PCM: ${pcm_p}" |
| 125 | + arecord "-Dplug${pcm_c}" -d 1 /dev/null -q || die "Failed to capture on PCM: ${pcm_c}" |
| 126 | +} |
| 127 | + |
| 128 | +# Checks for soundfile needed for test, generates missing ones |
| 129 | +prepare_test_soundfile() |
| 130 | +{ |
| 131 | + mkdir -p "$HOME/Music" |
| 132 | + if [ ! -f "$audio_filename" ]; then |
| 133 | + generate_mp3_file "$audio_filename" |
| 134 | + fi |
| 135 | +} |
| 136 | + |
| 137 | +run_test() |
| 138 | +{ |
| 139 | + check_the_pcms |
| 140 | + # audio_filename="$HOME/Music/test.mp3" |
| 141 | + # prepare_test_soundfile |
| 142 | + |
| 143 | + socwatch_output="$LOG_ROOT/socwatch-results/socwatch_report" |
| 144 | + |
| 145 | + # play_command="cplay -D${pcm_p} -d ${duration} ${audio_filename}" |
| 146 | + play_command=(aplay -Dplug${pcm_p} -d ${duration} /dev/zero) |
| 147 | + run_with_socwatch "$socwatch_output" "${play_command[@]}" |
| 148 | + |
| 149 | + analyze_socwatch_results |
| 150 | +} |
| 151 | + |
| 152 | +main() |
| 153 | +{ |
| 154 | + export RUN_SOCWATCH=true |
| 155 | + start_test |
| 156 | + if [ "$pcm_p" = "" ]||[ "$pcm_c" = "" ]; |
| 157 | + then |
| 158 | + dloge "No playback or capture PCM specified." |
| 159 | + exit 2 |
| 160 | + fi |
| 161 | + logger_disabled || func_lib_start_log_collect |
| 162 | + |
| 163 | + run_test |
| 164 | +} |
| 165 | + |
| 166 | +{ |
| 167 | + main "$@"; exit "$?" |
| 168 | +} |
0 commit comments