1c72fcc34Sopenharmony_ci#!/bin/bash
2c72fcc34Sopenharmony_ci
3c72fcc34Sopenharmony_ci#/*
4c72fcc34Sopenharmony_ci# * Copyright (C) 2013-2016 Intel Corporation
5c72fcc34Sopenharmony_ci# *
6c72fcc34Sopenharmony_ci# * This program is free software; you can redistribute it and/or modify
7c72fcc34Sopenharmony_ci# * it under the terms of the GNU General Public License as published by
8c72fcc34Sopenharmony_ci# * the Free Software Foundation; either version 2 of the License, or
9c72fcc34Sopenharmony_ci# * (at your option) any later version.
10c72fcc34Sopenharmony_ci# *
11c72fcc34Sopenharmony_ci# * This program is distributed in the hope that it will be useful,
12c72fcc34Sopenharmony_ci# * but WITHOUT ANY WARRANTY; without even the implied warranty of
13c72fcc34Sopenharmony_ci# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14c72fcc34Sopenharmony_ci# * GNU General Public License for more details.
15c72fcc34Sopenharmony_ci# *
16c72fcc34Sopenharmony_ci# */
17c72fcc34Sopenharmony_ci#set -x
18c72fcc34Sopenharmony_ci
19c72fcc34Sopenharmony_ci#alsabat test scripts path
20c72fcc34Sopenharmony_ciexport ABAT_TEST_PATH=`pwd`
21c72fcc34Sopenharmony_ci
22c72fcc34Sopenharmony_ci#alsabat test log file, path+filename
23c72fcc34Sopenharmony_ciDay=`date +"%Y-%m-%d-%H-%M"`
24c72fcc34Sopenharmony_ciLog_FileName="test_result-"${Day}".log"
25c72fcc34Sopenharmony_ciexport ABAT_TEST_LOG_FILE=${ABAT_TEST_PATH}/log/${Log_FileName}
26c72fcc34Sopenharmony_ci
27c72fcc34Sopenharmony_ci#terminal display colour setting
28c72fcc34Sopenharmony_ciESC_GREEN="\033[32m"
29c72fcc34Sopenharmony_ciESC_RED="\033[31m"
30c72fcc34Sopenharmony_ciESC_YELLOW="\033[33;1m"
31c72fcc34Sopenharmony_ciESC_OFF="\033[0m"
32c72fcc34Sopenharmony_ci
33c72fcc34Sopenharmony_ci#total/pass/fail test cases number
34c72fcc34Sopenharmony_citotal_case_number=0
35c72fcc34Sopenharmony_cisuit_number=1
36c72fcc34Sopenharmony_cipass_number=0
37c72fcc34Sopenharmony_cifail_number=0
38c72fcc34Sopenharmony_ci# =========================== Public function  ==========================
39c72fcc34Sopenharmony_ci
40c72fcc34Sopenharmony_cifunction get_platform_info()
41c72fcc34Sopenharmony_ci{
42c72fcc34Sopenharmony_ci	#to get the audio card number
43c72fcc34Sopenharmony_ci	Card_Number=$(aplay -l | grep "HDMI 0" | cut -b 6)
44c72fcc34Sopenharmony_ci	cd /proc/asound/card$Card_Number/
45c72fcc34Sopenharmony_ci	for file in `ls`
46c72fcc34Sopenharmony_ci	do
47c72fcc34Sopenharmony_ci		if [[ $file == codec* ]]; then
48c72fcc34Sopenharmony_ci			#to get the hardware platform ID, currently Intel skylake,
49c72fcc34Sopenharmony_ci			#broadwell and haswell hardware platforms are supported
50c72fcc34Sopenharmony_ci			Platform_ID=`cat $file |grep "Codec:" |cut -d " " -f 3`
51c72fcc34Sopenharmony_ci			if [ "$Platform_ID" == "Skylake" ] \
52c72fcc34Sopenharmony_ci				|| [ "$Platform_ID" == "Broadwell" ] \
53c72fcc34Sopenharmony_ci				|| [ "$Platform_ID" == "Haswell" ]; then
54c72fcc34Sopenharmony_ci				echo $Platform_ID
55c72fcc34Sopenharmony_ci				break
56c72fcc34Sopenharmony_ci				exit 0
57c72fcc34Sopenharmony_ci			fi
58c72fcc34Sopenharmony_ci		else
59c72fcc34Sopenharmony_ci			printf '\033[1;31m %-30s %s \033[1;31m%s\n\033[0m' \
60c72fcc34Sopenharmony_ci						"Get platform information failed";
61c72fcc34Sopenharmony_ci			exit 1
62c72fcc34Sopenharmony_ci		fi
63c72fcc34Sopenharmony_ci	done
64c72fcc34Sopenharmony_ci}
65c72fcc34Sopenharmony_ci
66c72fcc34Sopenharmony_ci#printf the "pass" info in the file
67c72fcc34Sopenharmony_cishow_pass()
68c72fcc34Sopenharmony_ci{
69c72fcc34Sopenharmony_ci	echo -e "$suit_number - [$1]:test ------- PASS" >> $ABAT_TEST_LOG_FILE
70c72fcc34Sopenharmony_ci	printf '\033[1;33m %-30s %s \033[1;32m%s\n\033[0m' \
71c72fcc34Sopenharmony_ci"$suit_number -	[$1]" "--------------------------------  " "PASS";
72c72fcc34Sopenharmony_ci}
73c72fcc34Sopenharmony_ci
74c72fcc34Sopenharmony_ci#printf the "fail" info in the file
75c72fcc34Sopenharmony_cishow_fail()
76c72fcc34Sopenharmony_ci{
77c72fcc34Sopenharmony_ci	echo -e "$suit_number - [$1]:test ------- FAIL" >> $ABAT_TEST_LOG_FILE
78c72fcc34Sopenharmony_ci	printf '\033[1;33m %-30s %s \033[1;31m%s\n\033[0m' \
79c72fcc34Sopenharmony_ci"$suit_number - [$1]" "--------------------------------  " "FAIL";
80c72fcc34Sopenharmony_ci}
81c72fcc34Sopenharmony_ci
82c72fcc34Sopenharmony_ci
83c72fcc34Sopenharmony_cifunction run_test()
84c72fcc34Sopenharmony_ci{
85c72fcc34Sopenharmony_ci	for TestItem in $@
86c72fcc34Sopenharmony_ci		do
87c72fcc34Sopenharmony_ci			Date=`date`
88c72fcc34Sopenharmony_ci			Dot="$Dot".
89c72fcc34Sopenharmony_ci			echo "Now doing $TestItem test$Dot"
90c72fcc34Sopenharmony_ci
91c72fcc34Sopenharmony_ci			#map test case to test script
92c72fcc34Sopenharmony_ci			eval item='$'$TestItem
93c72fcc34Sopenharmony_ci
94c72fcc34Sopenharmony_ci			#to check the test script existing
95c72fcc34Sopenharmony_ci			if  [ ! -f "$item" ]; then
96c72fcc34Sopenharmony_ci				echo -e "\e[31m not found $TestItem script,confirm it firstly"
97c72fcc34Sopenharmony_ci				echo -e "\e[0m"
98c72fcc34Sopenharmony_ci				exit 1
99c72fcc34Sopenharmony_ci			fi
100c72fcc34Sopenharmony_ci
101c72fcc34Sopenharmony_ci			#to run each test script
102c72fcc34Sopenharmony_ci			eval "\$$TestItem"
103c72fcc34Sopenharmony_ci			Result=$?
104c72fcc34Sopenharmony_ci			#record the test result to the log file
105c72fcc34Sopenharmony_ci			if [ $Result -eq 0 ]; then
106c72fcc34Sopenharmony_ci				show_pass "$TestItem"
107c72fcc34Sopenharmony_ci			else
108c72fcc34Sopenharmony_ci				show_fail "$TestItem"
109c72fcc34Sopenharmony_ci			fi
110c72fcc34Sopenharmony_ci			suit_number=$(($suit_number + 1))
111c72fcc34Sopenharmony_ci
112c72fcc34Sopenharmony_ci		done
113c72fcc34Sopenharmony_ci}
114c72fcc34Sopenharmony_ci
115c72fcc34Sopenharmony_cifunction test_suites ( )
116c72fcc34Sopenharmony_ci{
117c72fcc34Sopenharmony_ci	#define the test suites/cases need to be run
118c72fcc34Sopenharmony_ci	TestProgram="verify_Analog_audio_playback_and_capture \
119c72fcc34Sopenharmony_ci				verify_HDMI_audio_playback verify_DP_audio_playback"
120c72fcc34Sopenharmony_ci
121c72fcc34Sopenharmony_ci	#run each test suites/test cases
122c72fcc34Sopenharmony_ci	run_test "$TestProgram"
123c72fcc34Sopenharmony_ci
124c72fcc34Sopenharmony_ci	# to printf the detailed test results on the screen
125c72fcc34Sopenharmony_ci	cat $ABAT_TEST_LOG_FILE |grep FAIL
126c72fcc34Sopenharmony_ci	case_number=$(($case_number - 1))
127c72fcc34Sopenharmony_ci	total_case_number=`cat $ABAT_TEST_LOG_FILE |grep -c "Test target frequency:"`
128c72fcc34Sopenharmony_ci	pass_number=`cat $ABAT_TEST_LOG_FILE |grep -c "Passed"`
129c72fcc34Sopenharmony_ci	fail_number=`cat $ABAT_TEST_LOG_FILE |grep -c "Failed"`
130c72fcc34Sopenharmony_ci	echo -e "\e[0m"
131c72fcc34Sopenharmony_ci	echo -e "\e[1;33m *---------------------------------------------------*\n"
132c72fcc34Sopenharmony_ci	echo -e " * "Total" ${total_case_number} "cases", \
133c72fcc34Sopenharmony_ci"PASS:" ${pass_number} "cases", "FAIL:" ${fail_number} "cases", \
134c72fcc34Sopenharmony_ci"Passrate is:" $((pass_number*100/total_case_number)) "%" *\n"
135c72fcc34Sopenharmony_ci	echo -e " *-------------------------------------------------------*\e[0m\n"
136c72fcc34Sopenharmony_ci
137c72fcc34Sopenharmony_ci	#the the result also will be saved on the log file
138c72fcc34Sopenharmony_ci	echo "Total" ${total_case_number} "cases", \
139c72fcc34Sopenharmony_ci"PASS:" ${pass_number} "cases", "FAIL:" ${fail_number} "cases",  \
140c72fcc34Sopenharmony_ci"Passrate:" $((pass_number*100/total_case_number)) "%" >> ${ABAT_TEST_LOG_FILE}
141c72fcc34Sopenharmony_ci
142c72fcc34Sopenharmony_ci	#return 0, if the script finishs normally
143c72fcc34Sopenharmony_ci	exit 0
144c72fcc34Sopenharmony_ci}
145c72fcc34Sopenharmony_ci
146c72fcc34Sopenharmony_cifunction main ( )
147c72fcc34Sopenharmony_ci{
148c72fcc34Sopenharmony_ci	echo "Test results are as follows:" > ${ABAT_TEST_LOG_FILE}
149c72fcc34Sopenharmony_ci	get_platform_info # get hardware platform information
150c72fcc34Sopenharmony_ci	cd $ABAT_TEST_PATH
151c72fcc34Sopenharmony_ci
152c72fcc34Sopenharmony_ci	# make sure the log folder is exist
153c72fcc34Sopenharmony_ci	if [ ! -d "$ABAT_TEST_PATH/log/" ]; then
154c72fcc34Sopenharmony_ci		mkdir "log"
155c72fcc34Sopenharmony_ci	fi
156c72fcc34Sopenharmony_ci
157c72fcc34Sopenharmony_ci	#map the test cases to test scripts
158c72fcc34Sopenharmony_ci	source map_test_case
159c72fcc34Sopenharmony_ci
160c72fcc34Sopenharmony_ci	#setting the alsa configure environment
161c72fcc34Sopenharmony_ci	alsactl restore -f $ABAT_TEST_PATH/asound_state/asound.state.$Platform_ID
162c72fcc34Sopenharmony_ci
163c72fcc34Sopenharmony_ci	#Printf the user interface info
164c72fcc34Sopenharmony_ci	clear
165c72fcc34Sopenharmony_ci	echo -e "\e[1;33m"
166c72fcc34Sopenharmony_ci	date
167c72fcc34Sopenharmony_ci	echo -e "\e[0m"
168c72fcc34Sopenharmony_ci	echo -e "\e[1;33m *-------------------------------------------------*\n"
169c72fcc34Sopenharmony_ci	echo -e " *--Running the audio automated test on $Platform_ID-------*\n"
170c72fcc34Sopenharmony_ci	echo -e " *------------------------------------------------------*\e[0m\n"
171c72fcc34Sopenharmony_ci	read -p "Press enter to continue"
172c72fcc34Sopenharmony_ci
173c72fcc34Sopenharmony_ci	#run the test suites/test cases
174c72fcc34Sopenharmony_ci	test_suites
175c72fcc34Sopenharmony_ci}
176c72fcc34Sopenharmony_ci
177c72fcc34Sopenharmony_ci#the main entrance function
178c72fcc34Sopenharmony_cimain
179