1#
2# Copyright (C) 2017 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17import logging
18from vts.testcases.kernel.api.proc import KernelProcFileTestBase
19from vts.testcases.kernel.api.proc.KernelProcFileTestBase import repeat_rule, literal_token
20
21
22class ProcAsoundCardsTest(KernelProcFileTestBase.KernelProcFileTestBase):
23    '''/proc/asound/cards shows the list of currently configured ALSA drivers.
24
25    List entries include index, the id string, short and long descriptions.'''
26
27    t_LBRACKET = literal_token(r'\[')
28    t_RBRACKET = literal_token(r'\]')
29
30    t_NO = literal_token(r'no')
31    t_SOUNDCARDS = literal_token(r'soundcards')
32
33    t_ignore = ' '
34
35    start = 'soundcards'
36
37    def p_soundcards(self, p):
38        '''soundcards : DASH DASH DASH NO SOUNDCARDS DASH DASH DASH NEWLINE
39                      | drivers'''
40        p[0] = [p[4], p[5]] if len(p) == 10 else p[1]
41
42    p_drivers = repeat_rule('driver')
43
44    def p_driver(self, p):
45        'driver : NUMBER id COLON STRING DASH description NEWLINE description NEWLINE'
46        p[0] = [p[1], p[2], p[4], p[6], p[8]]
47
48    def p_description(self, p):
49        '''description : description word
50                       | word'''
51        p[0] = [p[1]] if len(p) == 2 else p[1] + [p[2]]
52
53    def p_word(self, p):
54        '''word : NUMBER
55                | STRING
56                | COMMA
57                | PERIOD
58                | FLOAT
59                | DASH
60                | HEX_LITERAL'''
61        p[0] = p[1]
62
63    def p_id(self, p):
64        'id : LBRACKET STRING RBRACKET'
65        p[0] = p[2]
66
67    def get_path(self):
68        return "/proc/asound/cards"
69