1#
2# Copyright (C) 2020 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
17from proc_tests import KernelProcFileTestBase
18from proc_tests.KernelProcFileTestBase import repeat_rule, literal_token
19
20
21class ProcAsoundCardsTest(KernelProcFileTestBase.KernelProcFileTestBase):
22    '''/proc/asound/cards shows the list of currently configured ALSA drivers.
23
24    List entries include index, the id string, short and long descriptions.'''
25
26    t_LBRACKET = literal_token(r'\[')
27    t_RBRACKET = literal_token(r'\]')
28    t_SLASH = 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                | COLON
61                | SLASH
62                | HEX_LITERAL'''
63        p[0] = p[1]
64
65    def p_id(self, p):
66        'id : LBRACKET STRING RBRACKET'
67        p[0] = p[2]
68
69    def get_path(self):
70        return "/proc/asound/cards"
71