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
18#set test freq table (HZ)
19freq_table="10 31 73 155 380 977 1932 4119 8197 16197"
20
21#set test number of channels
22test_channel=2
23
24#get device number for HDMI
25HDMI_device_num=0
26$ABAT_TEST_PATH/hdmi_audio_subdevice_number.sh
27HDMI_device_num=$?
28if [ $HDMI_device_num = 77 ]; then
29	echo "Prompt: Can not get device with HDMI audio or \
30show the wrong connection type as DP in ELD info"
31	exit 1
32fi
33
34#To get HDMI audio device number
35HDMI_card_number=$(aplay -l | grep "HDMI 0" | cut -b 6)
36if [ "$HDMI_card_number" = "" ]; then
37        echo "Error: Can not get Display audio card."
38        exit 1
39fi
40
41HDMI_device="hw:$HDMI_card_number,$HDMI_device_num"
42echo $device
43sleep 2
44
45#get Analog audio record card number
46record_card_number=$(arecord -l | grep "Analog" | cut -b 6)
47if [ "$record_card_number" = "" ]; then
48        echo "Can not get record card number."
49        exit 1
50fi
51
52#get Analog audio record device number
53record_device_number=$(arecord -l | grep "Analog"| cut -d " " -f 8 |cut -b 1)
54if [ "$record_device_number" = "" ]; then
55        echo "Can not get record device number"
56        exit 1
57fi
58
59#Notice: to loopback the HDMI audio output to the analog audio input
60record_device="hw:$record_card_number,$record_device_number"
61test_flag=0
62
63echo -e "\e[31m Notice: to loopback the HDMI audio output \
64to the analog audio input"
65echo -e "\e[0m"
66read -p "Press enter to continue"
67#call alsabat to do the test for each frequency in the freq_table
68for freq in $freq_table
69	do
70		alsabat -P $HDMI_device -C plug$record_device -c $test_channel -F $freq
71		if [ $? = 0 ]; then
72			echo "Test target frequency:$freq for HDMI audio playback \
73-- Passed    " >> $ABAT_TEST_LOG_FILE
74		else
75			echo "Test target frequency:$freq for HDMI audio playback \
76-- Failed    " >> $ABAT_TEST_LOG_FILE
77			test_flag=1
78		fi
79	done
80
81exit $test_flag
82