alsabat: automation test scripts

This patch includes automated test scripts for linux audio driver
based on alsa-lib interface by using alsabat as test tool.
It supports analog and display(HDMI/DP) audio test.
The package needs the alsa-utils, alsa-lib installed environment.

Signed-off-by: Focus Luo <focus.luo@linux.intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Focus Luo 2016-08-23 00:16:49 +08:00 committed by Takashi Iwai
parent a6e9a8da9e
commit 0882d92732
11 changed files with 612 additions and 1 deletions

View file

@ -1,3 +1,4 @@
SUBDIRS=tests
bin_PROGRAMS = alsabat bin_PROGRAMS = alsabat
man_MANS = alsabat.1 man_MANS = alsabat.1
EXTRA_DIST = alsabat.1 alsabat-test.sh EXTRA_DIST = alsabat.1 alsabat-test.sh

10
bat/tests/Makefile.am Normal file
View file

@ -0,0 +1,10 @@
alsabat_script_files = analog_audio_playback_and_capture.sh \
dp_audio_playback.sh \
dp_audio_subdevice_number.sh \
hdmi_audio_playback.sh \
hdmi_audio_subdevice_number.sh \
map_test_case \
README
EXTRA_DIST = \
$(alsabat_script_files)

32
bat/tests/README Normal file
View file

@ -0,0 +1,32 @@
automated test scripts for linux audio driver
based on alsa-lib interface by using alsabat
===============================================================================
This package contains the test scripts for linux audio driver based on
alsa-lib interface by using alsabat.
It supports analog and display(HDMI/DP) audio test.
The package needs the alsa-utils, alsa-lib installed environment.
alsabat_main.sh
- the main entrance test script,
it will call the other scripts to run the tests
(test result will save in the ./log/ folder)
analog_audio_playback_and_capture.sh
- analog audio test script (please to loopback the
analog audio output to analog audio input)
hdmi_audio_playback.sh
- hdmi audio test script (please to loopback the hdmi audio output
to analog audio input)
dp_audio_playback.sh
- dp audio test script (please to loopback the dp audio
output to analog audio input)
map_test_case
- to map the test suite/cases to a test script
asound_state/
- some asound.state config reference files
based on different platforms
Focus Luo <focus.luo@linux.intel.com>
Wang,Jinliang <jinliang.wang@intel.com>
Zhang,Keqiao <keqiao.zhang@intel.com>

178
bat/tests/alsabat_main.sh Executable file
View file

@ -0,0 +1,178 @@
#!/bin/bash
#/*
# * Copyright (C) 2013-2016 Intel Corporation
# *
# * This program is free software; you can redistribute it and/or modify
# * it under the terms of the GNU General Public License as published by
# * the Free Software Foundation; either version 2 of the License, or
# * (at your option) any later version.
# *
# * This program is distributed in the hope that it will be useful,
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# * GNU General Public License for more details.
# *
# */
#set -x
#alsabat test scripts path
export ABAT_TEST_PATH=`pwd`
#alsabat test log file, path+filename
Day=`date +"%Y-%m-%d-%H-%M"`
Log_FileName="test_result-"${Day}".log"
export ABAT_TEST_LOG_FILE=${ABAT_TEST_PATH}/log/${Log_FileName}
#terminal display colour setting
ESC_GREEN="\033[32m"
ESC_RED="\033[31m"
ESC_YELLOW="\033[33;1m"
ESC_OFF="\033[0m"
#total/pass/fail test cases number
total_case_number=0
suit_number=1
pass_number=0
fail_number=0
# =========================== Public function ==========================
function get_platform_info()
{
#to get the audio card number
Card_Number=$(aplay -l | grep "HDMI 0" | cut -b 6)
cd /proc/asound/card$Card_Number/
for file in `ls`
do
if [[ $file == codec* ]]; then
#to get the hardware platform ID, currently Intel skylake,
#broadwell and haswell hardware platforms are supported
Platform_ID=`cat $file |grep "Codec:" |cut -d " " -f 3`
if [ "$Platform_ID" == "Skylake" ] \
|| [ "$Platform_ID" == "Broadwell" ] \
|| [ "$Platform_ID" == "Haswell" ]; then
echo $Platform_ID
break
exit 0
fi
else
printf '\033[1;31m %-30s %s \033[1;31m%s\n\033[0m' \
"Get platform information failed";
exit 1
fi
done
}
#printf the "pass" info in the file
show_pass()
{
echo -e "$suit_number - [$1]:test ------- PASS" >> $ABAT_TEST_LOG_FILE
printf '\033[1;33m %-30s %s \033[1;32m%s\n\033[0m' \
"$suit_number - [$1]" "-------------------------------- " "PASS";
}
#printf the "fail" info in the file
show_fail()
{
echo -e "$suit_number - [$1]:test ------- FAIL" >> $ABAT_TEST_LOG_FILE
printf '\033[1;33m %-30s %s \033[1;31m%s\n\033[0m' \
"$suit_number - [$1]" "-------------------------------- " "FAIL";
}
function run_test()
{
for TestItem in $@
do
Date=`date`
Dot="$Dot".
echo "Now doing $TestItem test$Dot"
#map test case to test script
eval item='$'$TestItem
#to check the test script existing
if [ ! -f "$item" ]; then
echo -e "\e[31m not found $TestItem script,confirm it firstly"
echo -e "\e[0m"
exit 1
fi
#to run each test script
eval "\$$TestItem"
Result=$?
#record the test result to the log file
if [ $Result -eq 0 ]; then
show_pass "$TestItem"
else
show_fail "$TestItem"
fi
suit_number=$(($suit_number + 1))
done
}
function test_suites ( )
{
#define the test suites/cases need to be run
TestProgram="verify_Analog_audio_playback_and_capture \
verify_HDMI_audio_playback verify_DP_audio_playback"
#run each test suites/test cases
run_test "$TestProgram"
# to printf the detailed test results on the screen
cat $ABAT_TEST_LOG_FILE |grep FAIL
case_number=$(($case_number - 1))
total_case_number=`cat $ABAT_TEST_LOG_FILE |grep -c "Test target frequency:"`
pass_number=`cat $ABAT_TEST_LOG_FILE |grep -c "Passed"`
fail_number=`cat $ABAT_TEST_LOG_FILE |grep -c "Failed"`
echo -e "\e[0m"
echo -e "\e[1;33m *---------------------------------------------------*\n"
echo -e " * "Total" ${total_case_number} "cases", \
"PASS:" ${pass_number} "cases", "FAIL:" ${fail_number} "cases", \
"Passrate is:" $((pass_number*100/total_case_number)) "%" *\n"
echo -e " *-------------------------------------------------------*\e[0m\n"
#the the result also will be saved on the log file
echo "Total" ${total_case_number} "cases", \
"PASS:" ${pass_number} "cases", "FAIL:" ${fail_number} "cases", \
"Passrate:" $((pass_number*100/total_case_number)) "%" >> ${ABAT_TEST_LOG_FILE}
#return 0, if the script finishs normally
exit 0
}
function main ( )
{
echo "Test results are as follows:" > ${ABAT_TEST_LOG_FILE}
get_platform_info # get hardware platform information
cd $ABAT_TEST_PATH
# make sure the log folder is exist
if [ ! -d "$ABAT_TEST_PATH/log/" ]; then
mkdir "log"
fi
#map the test cases to test scripts
source map_test_case
#setting the alsa configure environment
alsactl restore -f $ABAT_TEST_PATH/asound_state/asound.state.$Platform_ID
#Printf the user interface info
clear
echo -e "\e[1;33m"
date
echo -e "\e[0m"
echo -e "\e[1;33m *-------------------------------------------------*\n"
echo -e " *--Running the audio automated test on $Platform_ID-------*\n"
echo -e " *------------------------------------------------------*\e[0m\n"
read -p "Press enter to continue"
#run the test suites/test cases
test_suites
}
#the main entrance function
main

View file

@ -0,0 +1,84 @@
#!/bin/bash
#/*
# * Copyright (C) 2013-2016 Intel Corporation
# *
# * This program is free software; you can redistribute it and/or modify
# * it under the terms of the GNU General Public License as published by
# * the Free Software Foundation; either version 2 of the License, or
# * (at your option) any later version.
# *
# * This program is distributed in the hope that it will be useful,
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# * GNU General Public License for more details.
# *
# */
#set test freq table (HZ)
freq_table="10 31 73 155 380 977 1932 4119 8197 16197"
#set test number of channels
test_channel=2
#get Analog audio card number
card_number=$(aplay -l | grep "Analog" | cut -b 6)
if [ "$card_number" = "" ]; then
echo "Can not get Analog card number."
exit 1
fi
#get Analog audio device number
device_number=$(aplay -l | grep "Analog"| cut -d " " -f 8 |cut -b 1)
if [ "$device_number" = "" ]; then
echo "Can not get Analog device number"
exit 1
fi
device="hw:$card_number,$device_number"
echo $device
#get Analog audio record card number
record_card_number=$(arecord -l | grep "Analog" | cut -b 6)
if [ "$record_card_number" = "" ]; then
echo "Can not get record card number."
exit 1
fi
#get Analog audio record device number
record_device_number=$(arecord -l | grep "Analog"| cut -d " " -f 8 |cut -b 1)
echo $record_device_number
if [ "$record_device_number" = "" ]; then
echo "Can not get record device number"
exit 1
fi
#Notice: to loopback the analog audio output to the analog audio input
record_device="hw:$record_card_number,$record_device_number"
test_flag=0
echo -e "\e[31m Notice: to loopback the analog audio output to \
the analog audio input"
echo -e "\e[0m"
read -p "Press enter to continue"
#call alsabat to do the test for each frequency in the freq_table
for freq in $freq_table
do
alsabat -P $device -C plug$record_device -c $test_channel -F $freq
if [ $? = 0 ]; then
echo "Test target frequency:$freq for Analog playback -- Passed \
" >> $ABAT_TEST_LOG_FILE
echo "Test target frequency:$freq for Analog capture -- Passed \
" >> $ABAT_TEST_LOG_FILE
else
echo "Test target frequency:$freq for Analog playback -- Failed \
" >> $ABAT_TEST_LOG_FILE
echo "Test target frequency:$freq for Analog capture -- Failed \
" >> $ABAT_TEST_LOG_FILE
test_flag=1
fi
done
exit $test_flag

83
bat/tests/dp_audio_playback.sh Executable file
View file

@ -0,0 +1,83 @@
#!/bin/bash
#/*
# * Copyright (C) 2013-2016 Intel Corporation
# *
# * This program is free software; you can redistribute it and/or modify
# * it under the terms of the GNU General Public License as published by
# * the Free Software Foundation; either version 2 of the License, or
# * (at your option) any later version.
# *
# * This program is distributed in the hope that it will be useful,
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# * GNU General Public License for more details.
# *
# */
#set test freq table (HZ)
freq_table="10 31 73 155 380 977 1932 4119 8197 16197"
#set test number of channels
test_channel=2
#get device number for DP
DP_device_num=0
$ABAT_TEST_PATH/dp_audio_subdevice_number.sh
DP_device_num=$?
if [ $DP_device_num = 77 ]; then
echo "Prompt: Can not get device with DP audio or \
show the wrong connection type as HDMI in ELD info"
exit 1
fi
#To get DP audio device number
DP_card_number=$(aplay -l | grep "HDMI 0" | cut -b 6)
if [ "$DP_card_number" = "" ]; then
echo "Error: Can not get Display audio card."
exit 1
fi
DP_device="hw:$DP_card_number,$DP_device_num"
echo $device
sleep 2
#get Analog audio record card number
record_card_number=$(arecord -l | grep "Analog" | cut -b 6)
if [ "$record_card_number" = "" ]; then
echo "Can not get record card number."
exit 1
fi
#get Analog audio record device number
record_device_number=$(arecord -l | grep "Analog"| cut -d " " -f 8 |cut -b 1)
echo $record_device_number
if [ "$record_device_number" = "" ]; then
echo "Can not get record device number"
exit 1
fi
#Notice: to loopback the DP audio output to the analog audio input
record_device="hw:$record_card_number,$record_device_number"
test_flag=0
echo -e "\e[31m Notice: to loopback the DP audio \
output to the analog audio input"
echo -e "\e[0m"
read -p "Press enter to continue"
#call alsabat to do the test for each frequency in the freq_table
for freq in $freq_table
do
alsabat -P $DP_device -C plug$record_device -c $test_channel -F $freq
if [ $? = 0 ]; then
echo "Test target frequency:$freq for DP audio playback--Passed" \
>> $ABAT_TEST_LOG_FILE
else
echo "Test target frequency:$freq for DP audio playback--Failed" \
>> $ABAT_TEST_LOG_FILE
test_flag=1
fi
done
exit $test_flag

View file

@ -0,0 +1,68 @@
#!/bin/bash
#/*
# * Copyright (C) 2013-2016 Intel Corporation
# *
# * This program is free software; you can redistribute it and/or modify
# * it under the terms of the GNU General Public License as published by
# * the Free Software Foundation; either version 2 of the License, or
# * (at your option) any later version.
# *
# * This program is distributed in the hope that it will be useful,
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# * GNU General Public License for more details.
# *
# */
#set -x
subdevice_number=0
get_subdevice=0
#make sure the DP monitor is connected and active
# To get DisplayPort audio device number
card_number=$(aplay -l | grep "HDMI 1" | cut -b 6)
echo $card_number
if [ "$card_number" = "" ]; then
echo "Can not get Display audio card."
exit 254
fi
audio_card_dir="/proc/asound/card$card_number/"
cd $audio_card_dir
for file in `ls`
do
#To get the ELD info according to the connented monitor with DisplayPort.
if [[ $file == eld* ]]; then
let subdevice_number+=1
cat $file | grep connection_type | grep DisplayPort > /dev/null
if [ $? = 0 ]; then
echo "Get the ELD information according to the connented \
monitor with DisplayPort."
get_subdevice=1
break
fi
fi
done
#failed to get the subdevice number of DisplayPort audio
if [ $get_subdevice == 0 ]; then
exit 77
fi
#the subdevice number of DisplayPort audio is 3
if [ $subdevice_number == 1 ]; then
exit 3
#the subdevice number of DisplayPort audio is 7.
elif [ $subdevice_number == 2 ]; then
exit 7
#the subdevice number of DisplayPort audio is 8
elif [ $subdevice_number == 3 ]; then
exit 8
#default: failed to get the subdevice number of DisplayPort audio
else
exit 77
fi

View file

@ -0,0 +1,81 @@
#!/bin/bash
#/*
# * Copyright (C) 2013-2016 Intel Corporation
# *
# * This program is free software; you can redistribute it and/or modify
# * it under the terms of the GNU General Public License as published by
# * the Free Software Foundation; either version 2 of the License, or
# * (at your option) any later version.
# *
# * This program is distributed in the hope that it will be useful,
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# * GNU General Public License for more details.
# *
# */
#set test freq table (HZ)
freq_table="10 31 73 155 380 977 1932 4119 8197 16197"
#set test number of channels
test_channel=2
#get device number for HDMI
HDMI_device_num=0
$ABAT_TEST_PATH/hdmi_audio_subdevice_number.sh
HDMI_device_num=$?
if [ $HDMI_device_num = 77 ]; then
echo "Prompt: Can not get device with HDMI audio or \
show the wrong connection type as DP in ELD info"
exit 1
fi
#To get HDMI audio device number
HDMI_card_number=$(aplay -l | grep "HDMI 0" | cut -b 6)
if [ "$HDMI_card_number" = "" ]; then
echo "Error: Can not get Display audio card."
exit 1
fi
HDMI_device="hw:$HDMI_card_number,$HDMI_device_num"
echo $device
sleep 2
#get Analog audio record card number
record_card_number=$(arecord -l | grep "Analog" | cut -b 6)
if [ "$record_card_number" = "" ]; then
echo "Can not get record card number."
exit 1
fi
#get Analog audio record device number
record_device_number=$(arecord -l | grep "Analog"| cut -d " " -f 8 |cut -b 1)
if [ "$record_device_number" = "" ]; then
echo "Can not get record device number"
exit 1
fi
#Notice: to loopback the HDMI audio output to the analog audio input
record_device="hw:$record_card_number,$record_device_number"
test_flag=0
echo -e "\e[31m Notice: to loopback the HDMI audio output \
to the analog audio input"
echo -e "\e[0m"
read -p "Press enter to continue"
#call alsabat to do the test for each frequency in the freq_table
for freq in $freq_table
do
alsabat -P $HDMI_device -C plug$record_device -c $test_channel -F $freq
if [ $? = 0 ]; then
echo "Test target frequency:$freq for HDMI audio playback \
-- Passed " >> $ABAT_TEST_LOG_FILE
else
echo "Test target frequency:$freq for HDMI audio playback \
-- Failed " >> $ABAT_TEST_LOG_FILE
test_flag=1
fi
done
exit $test_flag

View file

@ -0,0 +1,65 @@
#!/bin/bash
#/*
# * Copyright (C) 2013-2016 Intel Corporation
# *
# * This program is free software; you can redistribute it and/or modify
# * it under the terms of the GNU General Public License as published by
# * the Free Software Foundation; either version 2 of the License, or
# * (at your option) any later version.
# *
# * This program is distributed in the hope that it will be useful,
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# * GNU General Public License for more details.
# *
# */
#set -x
subdevice_number=0
get_subdevice=0
#make sure the HDMI monitor is connected and active ########
# To get HDMI audio device number
card_number=$(aplay -l | grep "HDMI 0" | cut -b 6)
if [ "$card_number" = "" ]; then
echo "Can not get Display audio card."
#failed to get Display audio card.
exit 1
fi
audio_card_dir="/proc/asound/card$card_number/"
cd $audio_card_dir
for file in `ls`
do
#To get the ELD information according to the connented monitor with HDMI
if [[ $file == eld* ]]; then
let subdevice_number+=1
cat $file | grep connection_type | grep HDMI > /dev/null
if [ $? = 0 ]; then
get_subdevice=1
break
fi
fi
done
#failed to get the subdevice number of HDMI audio.
if [ $get_subdevice == 0 ]; then
exit 77
fi
#the subdevice number of HDMI audio is 3.
if [ $subdevice_number == 1 ]; then
exit 3
#the subdevice number of HDMI audio is 7.
elif [ $subdevice_number == 2 ]; then
exit 7
#the subdevice number of HDMI audio is 8.
elif [ $subdevice_number == 3 ]; then
exit 8
#default: failed to get the subdevice number of HDMI audio.
else
exit 77
fi

8
bat/tests/map_test_case Normal file
View file

@ -0,0 +1,8 @@
# Analog audio basic test
verify_Analog_audio_playback_and_capture="$ABAT_TEST_PATH/analog_audio_playback_and_capture.sh"
# Display audio basic test cases - for HDMI
verify_HDMI_audio_playback="$ABAT_TEST_PATH/hdmi_audio_playback.sh"
# Display audio basic test cases - for DP
verify_DP_audio_playback="$ABAT_TEST_PATH/dp_audio_playback.sh"

View file

@ -411,7 +411,8 @@ AC_OUTPUT(Makefile alsactl/Makefile alsactl/init/Makefile \
m4/Makefile po/Makefile.in \ m4/Makefile po/Makefile.in \
alsaconf/alsaconf alsaconf/Makefile \ alsaconf/alsaconf alsaconf/Makefile \
alsaconf/po/Makefile \ alsaconf/po/Makefile \
alsaucm/Makefile topology/Makefile bat/Makefile \ alsaucm/Makefile topology/Makefile \
bat/Makefile bat/tests/Makefile \
aplay/Makefile include/Makefile iecset/Makefile utils/Makefile \ aplay/Makefile include/Makefile iecset/Makefile utils/Makefile \
utils/alsa-utils.spec seq/Makefile seq/aconnect/Makefile \ utils/alsa-utils.spec seq/Makefile seq/aconnect/Makefile \
seq/aplaymidi/Makefile seq/aseqdump/Makefile seq/aseqnet/Makefile \ seq/aplaymidi/Makefile seq/aseqdump/Makefile seq/aseqnet/Makefile \