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