tarina

git clone https://git.tarina.org/tarina
Log | Files | Refs | README | LICENSE

alsabat-test.sh (4136B)


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