1c72fcc34Sopenharmony_ci#!/bin/bash 2c72fcc34Sopenharmony_ci 3c72fcc34Sopenharmony_ci# default devices 4c72fcc34Sopenharmony_cidev_playback="default" 5c72fcc34Sopenharmony_cidev_capture="default" 6c72fcc34Sopenharmony_ci 7c72fcc34Sopenharmony_cibin="alsabat" 8c72fcc34Sopenharmony_cicommands="$bin -P $dev_playback -C $dev_capture" 9c72fcc34Sopenharmony_ci 10c72fcc34Sopenharmony_cifile_sin_mono="default_mono.wav" 11c72fcc34Sopenharmony_cifile_sin_dual="default_dual.wav" 12c72fcc34Sopenharmony_cilogdir="tmp" 13c72fcc34Sopenharmony_ci 14c72fcc34Sopenharmony_ci# frequency range of signal 15c72fcc34Sopenharmony_cimaxfreq=16547 16c72fcc34Sopenharmony_ciminfreq=17 17c72fcc34Sopenharmony_ci 18c72fcc34Sopenharmony_ci# sleep time and pause time 19c72fcc34Sopenharmony_cisleep_time=5 20c72fcc34Sopenharmony_cipause_time=2 21c72fcc34Sopenharmony_ci 22c72fcc34Sopenharmony_ci# features passes vs. features all 23c72fcc34Sopenharmony_cifeature_pass=0 24c72fcc34Sopenharmony_cifeature_cnt=0 25c72fcc34Sopenharmony_ci 26c72fcc34Sopenharmony_ciinit_counter () { 27c72fcc34Sopenharmony_ci feature_pass=0 28c72fcc34Sopenharmony_ci feature_all=0 29c72fcc34Sopenharmony_ci} 30c72fcc34Sopenharmony_ci 31c72fcc34Sopenharmony_cievaluate_result () { 32c72fcc34Sopenharmony_ci feature_cnt=$((feature_cnt+1)) 33c72fcc34Sopenharmony_ci if [ $1 -eq 0 ]; then 34c72fcc34Sopenharmony_ci feature_pass=$((feature_pass+1)) 35c72fcc34Sopenharmony_ci echo "pass" 36c72fcc34Sopenharmony_ci else 37c72fcc34Sopenharmony_ci echo "fail" 38c72fcc34Sopenharmony_ci fi 39c72fcc34Sopenharmony_ci} 40c72fcc34Sopenharmony_ci 41c72fcc34Sopenharmony_ciprint_result () { 42c72fcc34Sopenharmony_ci echo "[$feature_pass/$feature_cnt] features passes." 43c72fcc34Sopenharmony_ci} 44c72fcc34Sopenharmony_ci 45c72fcc34Sopenharmony_cifeature_test () { 46c72fcc34Sopenharmony_ci echo "============================================" 47c72fcc34Sopenharmony_ci echo "$feature_cnt: ALSA $2" 48c72fcc34Sopenharmony_ci echo "-------------------------------------------" 49c72fcc34Sopenharmony_ci echo "$commands $1 --log=$logdir/$feature_cnt.log" 50c72fcc34Sopenharmony_ci $commands $1 --log=$logdir/$feature_cnt.log 51c72fcc34Sopenharmony_ci evaluate_result $? 52c72fcc34Sopenharmony_ci echo "$commands $1" >> $logdir/$((feature_cnt-1)).log 53c72fcc34Sopenharmony_ci} 54c72fcc34Sopenharmony_ci 55c72fcc34Sopenharmony_cifeature_test_power () { 56c72fcc34Sopenharmony_ci echo "============================================" 57c72fcc34Sopenharmony_ci echo "$feature_cnt: ALSA $2" 58c72fcc34Sopenharmony_ci echo "-------------------------------------------" 59c72fcc34Sopenharmony_ci echo "$commands $1 --log=$logdir/$feature_cnt.log" 60c72fcc34Sopenharmony_ci 61c72fcc34Sopenharmony_ci # run alsabat in the background 62c72fcc34Sopenharmony_ci nohup $commands $1 > $logdir/$feature_cnt.log 2>&1 & 63c72fcc34Sopenharmony_ci sleep $pause_time 64c72fcc34Sopenharmony_ci pid=`ps -aux |grep alsabat|head -1 |awk -F ' ' '{print $2}'` 65c72fcc34Sopenharmony_ci 66c72fcc34Sopenharmony_ci # stop the alsabat thread 67c72fcc34Sopenharmony_ci kill -STOP $pid > /dev/null 68c72fcc34Sopenharmony_ci sleep 4 69c72fcc34Sopenharmony_ci 70c72fcc34Sopenharmony_ci # do system S3 71c72fcc34Sopenharmony_ci rtcwake -m mem -s $sleep_time 72c72fcc34Sopenharmony_ci sleep $pause_time 73c72fcc34Sopenharmony_ci 74c72fcc34Sopenharmony_ci # resume the alasbat thread to run 75c72fcc34Sopenharmony_ci kill -CONT $pid > /dev/null 76c72fcc34Sopenharmony_ci 77c72fcc34Sopenharmony_ci # wait for alsabat to complete the analysis 78c72fcc34Sopenharmony_ci sleep $pause_time 79c72fcc34Sopenharmony_ci cat $logdir/$feature_cnt.log |grep -i "Return value is 0" > /dev/null 80c72fcc34Sopenharmony_ci evaluate_result $? 81c72fcc34Sopenharmony_ci echo "$commands $1" >> $logdir/$((feature_cnt-1)).log 82c72fcc34Sopenharmony_ci} 83c72fcc34Sopenharmony_ci 84c72fcc34Sopenharmony_ci# test items 85c72fcc34Sopenharmony_cifeature_list_test () { 86c72fcc34Sopenharmony_ci init_counter 87c72fcc34Sopenharmony_ci 88c72fcc34Sopenharmony_ci commands="$bin" 89c72fcc34Sopenharmony_ci feature_test "-c1 --saveplay $file_sin_mono" \ 90c72fcc34Sopenharmony_ci "generate mono wav file with default params" 91c72fcc34Sopenharmony_ci feature_test "-c2 --saveplay $file_sin_dual" \ 92c72fcc34Sopenharmony_ci "generate dual wav file with default params" 93c72fcc34Sopenharmony_ci sleep 5 94c72fcc34Sopenharmony_ci feature_test "-P $dev_playback" "single line mode, playback" 95c72fcc34Sopenharmony_ci feature_test "-C $dev_capture --standalone" "single line mode, capture" 96c72fcc34Sopenharmony_ci 97c72fcc34Sopenharmony_ci commands="$bin -P $dev_playback -C $dev_capture" 98c72fcc34Sopenharmony_ci feature_test "--file $file_sin_mono" "play mono wav file and detect" 99c72fcc34Sopenharmony_ci feature_test "--file $file_sin_dual" "play dual wav file and detect" 100c72fcc34Sopenharmony_ci feature_test "-c1" "configurable channel number: 1" 101c72fcc34Sopenharmony_ci feature_test "-c2 -F $minfreq:$maxfreq" "configurable channel number: 2" 102c72fcc34Sopenharmony_ci feature_test "-r44100" "configurable sample rate: 44100" 103c72fcc34Sopenharmony_ci feature_test "-r48000" "configurable sample rate: 48000" 104c72fcc34Sopenharmony_ci feature_test "-n10000" "configurable duration: in samples" 105c72fcc34Sopenharmony_ci feature_test "-n2.5s" "configurable duration: in seconds" 106c72fcc34Sopenharmony_ci feature_test "-f U8" "configurable data format: U8" 107c72fcc34Sopenharmony_ci feature_test "-f S16_LE" "configurable data format: S16_LE" 108c72fcc34Sopenharmony_ci feature_test "-f S24_3LE" "configurable data format: S24_3LE" 109c72fcc34Sopenharmony_ci feature_test "-f S32_LE" "configurable data format: S32_LE" 110c72fcc34Sopenharmony_ci feature_test "-f cd" "configurable data format: cd" 111c72fcc34Sopenharmony_ci feature_test "-f dat" "configurable data format: dat" 112c72fcc34Sopenharmony_ci feature_test "-F $maxfreq --standalone" \ 113c72fcc34Sopenharmony_ci "standalone mode: play and capture" 114c72fcc34Sopenharmony_ci latestfile=`ls -t1 /tmp/bat.wav.* | head -n 1` 115c72fcc34Sopenharmony_ci feature_test "--local -F $maxfreq --file $latestfile" \ 116c72fcc34Sopenharmony_ci "local mode: analyze local file" 117c72fcc34Sopenharmony_ci feature_test "--roundtriplatency" \ 118c72fcc34Sopenharmony_ci "round trip latency test" 119c72fcc34Sopenharmony_ci feature_test "--snr-db 26" \ 120c72fcc34Sopenharmony_ci "noise detect threshold in SNR(dB)" 121c72fcc34Sopenharmony_ci feature_test "--snr-pc 5" \ 122c72fcc34Sopenharmony_ci "noise detect threshold in noise percentage(%)" 123c72fcc34Sopenharmony_ci feature_test_power "-n5s" "power management: S3 test" 124c72fcc34Sopenharmony_ci 125c72fcc34Sopenharmony_ci print_result 126c72fcc34Sopenharmony_ci} 127c72fcc34Sopenharmony_ci 128c72fcc34Sopenharmony_ciecho "*******************************************" 129c72fcc34Sopenharmony_ciecho " BAT Test " 130c72fcc34Sopenharmony_ciecho "-------------------------------------------" 131c72fcc34Sopenharmony_ci 132c72fcc34Sopenharmony_ci# get device 133c72fcc34Sopenharmony_ciecho "usage:" 134c72fcc34Sopenharmony_ciecho " $0 <sound card>" 135c72fcc34Sopenharmony_ciecho " $0 <device-playback> <device-capture>" 136c72fcc34Sopenharmony_ci 137c72fcc34Sopenharmony_ciif [ $# -eq 2 ]; then 138c72fcc34Sopenharmony_ci dev_playback=$1 139c72fcc34Sopenharmony_ci dev_capture=$2 140c72fcc34Sopenharmony_cielif [ $# -eq 1 ]; then 141c72fcc34Sopenharmony_ci dev_playback=$1 142c72fcc34Sopenharmony_ci dev_capture=$1 143c72fcc34Sopenharmony_cifi 144c72fcc34Sopenharmony_ci 145c72fcc34Sopenharmony_ciecho "current setting:" 146c72fcc34Sopenharmony_ciecho " $0 $dev_playback $dev_capture" 147c72fcc34Sopenharmony_ci 148c72fcc34Sopenharmony_ci# run 149c72fcc34Sopenharmony_cimkdir -p $logdir 150c72fcc34Sopenharmony_cifeature_list_test 151c72fcc34Sopenharmony_ci 152c72fcc34Sopenharmony_ciecho "*******************************************" 153