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
18c72fcc34Sopenharmony_ci#set test freq table (HZ)
19c72fcc34Sopenharmony_cifreq_table="10 31 73 155 380 977 1932 4119 8197 16197"
20c72fcc34Sopenharmony_ci
21c72fcc34Sopenharmony_ci#set test number of channels
22c72fcc34Sopenharmony_citest_channel=2
23c72fcc34Sopenharmony_ci
24c72fcc34Sopenharmony_ci#get Analog audio card number
25c72fcc34Sopenharmony_cicard_number=$(aplay -l | grep "Analog" | cut -b 6)
26c72fcc34Sopenharmony_ciif [ "$card_number" = "" ]; then
27c72fcc34Sopenharmony_ci        echo "Can not get Analog card number."
28c72fcc34Sopenharmony_ci        exit 1
29c72fcc34Sopenharmony_cifi
30c72fcc34Sopenharmony_ci
31c72fcc34Sopenharmony_ci#get Analog audio device number
32c72fcc34Sopenharmony_cidevice_number=$(aplay -l | grep "Analog"| cut -d " " -f 8 |cut -b 1)
33c72fcc34Sopenharmony_ciif [ "$device_number" = "" ]; then
34c72fcc34Sopenharmony_ci        echo "Can not get Analog device number"
35c72fcc34Sopenharmony_ci        exit 1
36c72fcc34Sopenharmony_cifi
37c72fcc34Sopenharmony_ci
38c72fcc34Sopenharmony_ci
39c72fcc34Sopenharmony_cidevice="hw:$card_number,$device_number"
40c72fcc34Sopenharmony_ciecho $device
41c72fcc34Sopenharmony_ci
42c72fcc34Sopenharmony_ci#get Analog audio record card number
43c72fcc34Sopenharmony_cirecord_card_number=$(arecord -l | grep "Analog" | cut -b 6)
44c72fcc34Sopenharmony_ciif [ "$record_card_number" = "" ]; then
45c72fcc34Sopenharmony_ci        echo "Can not get record card number."
46c72fcc34Sopenharmony_ci        exit 1
47c72fcc34Sopenharmony_cifi
48c72fcc34Sopenharmony_ci
49c72fcc34Sopenharmony_ci#get Analog audio record device number
50c72fcc34Sopenharmony_cirecord_device_number=$(arecord -l | grep "Analog"| cut -d " " -f 8 |cut -b 1)
51c72fcc34Sopenharmony_ciecho $record_device_number
52c72fcc34Sopenharmony_ciif [ "$record_device_number" = "" ]; then
53c72fcc34Sopenharmony_ci        echo "Can not get record device number"
54c72fcc34Sopenharmony_ci        exit 1
55c72fcc34Sopenharmony_cifi
56c72fcc34Sopenharmony_ci
57c72fcc34Sopenharmony_ci#Notice: to loopback the analog audio output to the analog audio input
58c72fcc34Sopenharmony_cirecord_device="hw:$record_card_number,$record_device_number"
59c72fcc34Sopenharmony_citest_flag=0
60c72fcc34Sopenharmony_ci
61c72fcc34Sopenharmony_ciecho  -e "\e[31m Notice: to loopback the analog audio output to \
62c72fcc34Sopenharmony_cithe analog audio input"
63c72fcc34Sopenharmony_ciecho -e "\e[0m"
64c72fcc34Sopenharmony_ciread -p "Press enter to continue"
65c72fcc34Sopenharmony_ci
66c72fcc34Sopenharmony_ci#call alsabat to do the test for each frequency in the freq_table
67c72fcc34Sopenharmony_cifor freq in $freq_table
68c72fcc34Sopenharmony_ci	do
69c72fcc34Sopenharmony_ci	alsabat -P $device -C plug$record_device -c $test_channel -F $freq
70c72fcc34Sopenharmony_ci		if [ $? = 0 ]; then
71c72fcc34Sopenharmony_ci			echo "Test target frequency:$freq for Analog playback -- Passed \
72c72fcc34Sopenharmony_ci" >> $ABAT_TEST_LOG_FILE
73c72fcc34Sopenharmony_ci			echo "Test target frequency:$freq for Analog capture -- Passed \
74c72fcc34Sopenharmony_ci" >> $ABAT_TEST_LOG_FILE
75c72fcc34Sopenharmony_ci		else
76c72fcc34Sopenharmony_ci			echo "Test target frequency:$freq for Analog playback -- Failed \
77c72fcc34Sopenharmony_ci" >> $ABAT_TEST_LOG_FILE
78c72fcc34Sopenharmony_ci			echo "Test target frequency:$freq for Analog capture -- Failed \
79c72fcc34Sopenharmony_ci" >> $ABAT_TEST_LOG_FILE
80c72fcc34Sopenharmony_ci			test_flag=1
81c72fcc34Sopenharmony_ci		fi
82c72fcc34Sopenharmony_ci	done
83c72fcc34Sopenharmony_ci
84c72fcc34Sopenharmony_ciexit $test_flag
85