• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
17from vts.testcases.kernel.api.proc import KernelProcFileTestBase
18from vts.testcases.kernel.api.proc.KernelProcFileTestBase import repeat_rule, literal_token
19
20
21class ProcCpuInfoTest(KernelProcFileTestBase.KernelProcFileTestBase):
22    '''/proc/cpuinfo displays a collection of cpu and architecture specific items.
23
24    The file consists of multiple lines of 'identifier : values' where
25    'identifier' is a space separated name that can end in some tabs, and
26    'values' are space separated items that can also in in a space.
27    Extra newlines are allowed between normal lines.
28    '''
29
30    EXPECTED_FIELDS = [
31        ['Features', ['\t']],
32        ['processor', ['\t']],
33        ['CPU', 'architecture', []],
34    ]
35
36    start = 'lines'
37
38    # Any character except for ':' and whitespace is allowed
39    t_STRING = r'[^:^ ^\t^\n]+'
40
41    # Numbers and literals are tokenized as strings instead
42    t_NUMBER = r'x'
43    t_HEX_LITERAL = r'x'
44    t_FLOAT =  r'x'
45
46    p_lines = repeat_rule('line')
47    p_string_spaces = repeat_rule('string_space', zero_ok=True)
48    p_space_items = repeat_rule('space_item', zero_ok=True)
49    p_TABs = repeat_rule('TAB', zero_ok=True)
50
51    def p_line(self, p):
52        '''line : string_spaces STRING TABs COLON space_items SPACE NEWLINE
53                | string_spaces STRING TABs COLON space_items NEWLINE
54                | NEWLINE'''
55        if len(p) == 2:
56            p[0] = []
57            return
58        p[0] = [p[1] + [p[2], p[3]], p[5], p[6]]
59
60    def p_space_item(self, p):
61        'space_item : SPACE STRING'
62        p[0] = p[2]
63
64    def p_string_space(self, p):
65        'string_space : STRING SPACE'
66        p[0] = p[1]
67
68    def result_correct(self, parse_result):
69        expected_fields = self.EXPECTED_FIELDS[:]
70        for line in parse_result:
71            if len(line) > 0:
72                if line[0] in expected_fields:
73                    expected_fields.remove(line[0])
74        return len(expected_fields) == 0
75
76    def get_path(self):
77        return "/proc/cpuinfo"
78