Exemple #1
0
class ProcStatTest(KernelProcFileTestBase.KernelProcFileTestBase):
    '''/proc/stat provides kernel and system statistics.'''

    start = 'stat'

    t_CPU = literal_token(r'cpu[0-9]*')
    t_INTR = literal_token(r'intr')
    t_CTXT = literal_token(r'ctxt')
    t_BTIME = literal_token(r'btime')
    t_PROCESSES = literal_token(r'processes')
    t_PROCS_RUNNING = literal_token(r'procs_running')
    t_PROCS_BLOCKED = literal_token(r'procs_blocked')
    t_SOFTIRQ = literal_token(r'softirq')

    p_cpus = repeat_rule('cpu')
    p_numbers = repeat_rule('NUMBER')

    t_ignore = ' '

    def p_stat(self, p):
        'stat : cpus intr ctxt btime processes procs_running procs_blocked softirq'
        p[0] = p[1:]

    def p_cpu(self, p):
        'cpu : CPU NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NEWLINE'
        p[0] = p[1:]

    def p_intr(self, p):
        'intr : INTR NUMBERs NEWLINE'
        p[0] = p[1:]

    def p_ctxt(self, p):
        'ctxt : CTXT NUMBER NEWLINE'
        p[0] = p[1:]

    def p_btime(self, p):
        'btime : BTIME NUMBER NEWLINE'
        p[0] = p[1:]

    def p_processes(self, p):
        'processes : PROCESSES NUMBER NEWLINE'
        p[0] = p[1:]

    def p_procs_running(self, p):
        'procs_running : PROCS_RUNNING NUMBER NEWLINE'
        p[0] = p[1:]

    def p_procs_blocked(self, p):
        'procs_blocked : PROCS_BLOCKED NUMBER NEWLINE'
        p[0] = p[1:]

    def p_softirq(self, p):
        'softirq : SOFTIRQ NUMBERs NEWLINE'
        p[0] = p[1:]

    def get_path(self):
        return "/proc/stat"
class ProcCpuInfoTest(KernelProcFileTestBase.KernelProcFileTestBase):
    '''/proc/cpuinfo displays a collection of cpu and architecture specific items.

    The file consists of multiple lines of 'identifier : values' where
    'identifier' is a space separated name that can end in some tabs, and
    'values' are space separated items that can also in in a space.
    Extra newlines are allowed between normal lines.
    '''

    EXPECTED_FIELDS = [
        ['Features', ['\t']],
        ['processor', ['\t']],
        ['CPU', 'architecture', []],
    ]

    start = 'lines'

    # Any character except for ':' and whitespace is allowed
    t_STRING = r'[^:^ ^\t^\n]+'

    # Numbers and literals are tokenized as strings instead
    t_NUMBER = r'x'
    t_HEX_LITERAL = r'x'
    t_FLOAT =  r'x'

    p_lines = repeat_rule('line')
    p_string_spaces = repeat_rule('string_space', zero_ok=True)
    p_space_items = repeat_rule('space_item', zero_ok=True)
    p_TABs = repeat_rule('TAB', zero_ok=True)

    def p_line(self, p):
        '''line : string_spaces STRING TABs COLON space_items SPACE NEWLINE
                | string_spaces STRING TABs COLON space_items NEWLINE
                | NEWLINE'''
        if len(p) == 2:
            p[0] = []
            return
        p[0] = [p[1] + [p[2], p[3]], p[5], p[6]]

    def p_space_item(self, p):
        'space_item : SPACE STRING'
        p[0] = p[2]

    def p_string_space(self, p):
        'string_space : STRING SPACE'
        p[0] = p[1]

    def result_correct(self, parse_result):
        expected_fields = self.EXPECTED_FIELDS[:]
        for line in parse_result:
            if len(line) > 0:
                if line[0] in expected_fields:
                    expected_fields.remove(line[0])
        return len(expected_fields) == 0

    def get_path(self):
        return "/proc/cpuinfo"
Exemple #3
0
class ProcAsoundCardsTest(KernelProcFileTestBase.KernelProcFileTestBase):
    '''/proc/asound/cards shows the list of currently configured ALSA drivers.

    List entries include index, the id string, short and long descriptions.'''

    t_LBRACKET = literal_token(r'\[')
    t_RBRACKET = literal_token(r'\]')

    t_ignore = ' '

    start = 'drivers'

    p_drivers = repeat_rule('driver')

    def p_driver(self, p):
        'driver : NUMBER id COLON STRING DASH description NEWLINE description NEWLINE'
        p[0] = [p[1], p[2], p[4], p[6], p[8]]

    def p_description(self, p):
        '''description : description STRING
                       | STRING'''
        p[0] = [p[1]] if len(p) == 2 else p[1].append(p[2])

    def p_id(self, p):
        'id : LBRACKET STRING RBRACKET'
        p[0] = p[2]

    def get_path(self):
        return "/proc/asound/cards"
class ProcDiskstatsTest(KernelProcFileTestBase.KernelProcFileTestBase):
    '''/proc/diskstats displays I/O statistics of block devices.'''

    t_ignore = ' '
    start = 'lines'
    p_lines = repeat_rule('line')

    def p_line(self, p):
        '''line : NUMBER NUMBER STRING NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NEWLINE'''
        p[0] = p[1:]

    def get_path(self):
        return "/proc/diskstats"
class ProcUidTimeInStateTest(KernelProcFileTestBase.KernelProcFileTestBase):
    '''/proc/uid_time_in_state provides the time each UID's processes spend
    executing at each available frequency.

    This is an Android specific file.
    '''

    start = 'uid_time_table'

    t_UID = literal_token(r'uid')

    p_uid_times = repeat_rule('uid_time')
    p_numbers = repeat_rule('NUMBER')

    t_ignore = ' '

    def p_uid_time_table(self, p):
        'uid_time_table : freqs uid_times'
        p[0] = p[1:]

    def p_freqs(self, p):
        'freqs : UID COLON NUMBERs NEWLINE'
        p[0] = p[3]

    def p_uid_time(self, p):
        'uid_time : NUMBER COLON NUMBERs NEWLINE'
        p[0] = [p[1], p[3]]

    def get_path(self):
        return "/proc/uid_time_in_state"

    def file_optional(self):
        # This file is optional until implemented in Android common kernel
        return True

    def result_correct(self, result):
        freqs, times = result
        return all(len(time[1]) == len(freqs) for time in times)
class ProcVmstat(KernelProcFileTestBase.KernelProcFileTestBase):
    '''/proc/vmstat shows virtual memory statistics from the kernel.'''

    t_ignore = ' '

    start = 'lines'

    p_lines = repeat_rule('line')

    def p_line(self, p):
        'line : STRING NUMBER NEWLINE'
        p[0] = [p[1], p[2]]

    def get_path(self):
        return "/proc/vmstat"
class ProcUidIoStatsTest(KernelProcFileTestBase.KernelProcFileTestBase):
    '''/proc/uid_io/stats returns a list of I/O stats for each UID in the system.

    This is an Android specific file.
    '''

    t_ignore = ' '
    start = 'lines'
    p_lines = repeat_rule('line')

    def p_line(self, p):
        '''line : NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NEWLINE'''
        p[0] = p[1:]

    def get_path(self):
        return "/proc/uid_io/stats"
Exemple #8
0
class ProcAsoundCardsTest(KernelProcFileTestBase.KernelProcFileTestBase):
    '''/proc/asound/cards shows the list of currently configured ALSA drivers.

    List entries include index, the id string, short and long descriptions.'''

    t_LBRACKET = literal_token(r'\[')
    t_RBRACKET = literal_token(r'\]')

    t_NO = literal_token(r'no')
    t_SOUNDCARDS = literal_token(r'soundcards')

    t_ignore = ' '

    start = 'soundcards'

    def p_soundcards(self, p):
        '''soundcards : DASH DASH DASH NO SOUNDCARDS DASH DASH DASH NEWLINE
                      | drivers'''
        p[0] = [p[4], p[5]] if len(p) == 10 else p[1]

    p_drivers = repeat_rule('driver')

    def p_driver(self, p):
        'driver : NUMBER id COLON STRING DASH description NEWLINE description NEWLINE'
        p[0] = [p[1], p[2], p[4], p[6], p[8]]

    def p_description(self, p):
        '''description : description word
                       | word'''
        p[0] = [p[1]] if len(p) == 2 else p[1] + [p[2]]

    def p_word(self, p):
        '''word : NUMBER
                | STRING
                | COMMA
                | PERIOD
                | FLOAT
                | DASH
                | HEX_LITERAL'''
        p[0] = p[1]

    def p_id(self, p):
        'id : LBRACKET STRING RBRACKET'
        p[0] = p[2]

    def get_path(self):
        return "/proc/asound/cards"
Exemple #9
0
class ProcMisc(KernelProcFileTestBase.KernelProcFileTestBase):
    '''/proc/misc lists miscellaneous drivers registered on the miscellaneous
    major device.
    '''

    t_ignore = ' '

    start = 'drivers'

    p_drivers = repeat_rule('driver')

    def p_line(self, p):
        'driver : NUMBER STRING NEWLINE'
        p[0] = [p[1], p[2]]

    def get_path(self):
        return "/proc/misc"
Exemple #10
0
class ProcVmallocInfoTest(KernelProcFileTestBase.KernelProcFileTestBase):
    '''/proc/vmallocinfo provides info on vmalloc'd ranges.'''

    start = 'lines'

    def t_CALLER(self, t):
        '[^ ^\t^\n^-^=^+^/]+\+0x[a-f0-9]+/0x[a-f0-9]+'
        t.value = t.value.split('+')
        return t

    t_PAGES = literal_token('pages')
    t_IOREMAP = literal_token('ioremap')
    t_MODULE = literal_token('\[[^\n^\0]*\]')
    t_VMALLOC = literal_token('vmalloc')
    t_VMAP = literal_token('vmap')
    t_USER = literal_token('user')
    t_VPAGES = literal_token('vpages')

    t_ignore = ' '

    def t_PHYS(self, t):
        r'phys=[a-f0-9]+'
        t.value = [t.value[:4], int(t.value[5:], 16)]
        return t

    p_lines = repeat_rule('line')

    def p_line(self, p):
        'line : addr_range NUMBER caller module pages phys ioremap vmalloc vmap user vpages NEWLINE'
        p[0] = p[1:]

    def p_addr_range(self, p):
        'addr_range : HEX_LITERAL DASH HEX_LITERAL'
        p[0] = [p[1], p[3]]

    def p_module(self, p):
        '''module : MODULE
                  | empty'''
        p[0] = p[1]

    def p_pages(self, p):
        '''pages : PAGES EQUALS NUMBER
                 | empty'''
        p[0] = [] if len(p) == 2 else [p[1], p[3]]

    def p_phys(self, p):
        '''phys : PHYS
                | empty'''
        p[0] = p[1]

    def p_ioremap(self, p):
        '''ioremap : IOREMAP
                   | empty'''
        p[0] = p[1]

    def p_vmalloc(self, p):
        '''vmalloc : VMALLOC
                   | empty'''
        p[0] = p[1]

    def p_vmap(self, p):
        '''vmap : VMAP
                | empty'''
        p[0] = p[1]

    def p_user(self, p):
        '''user : USER
                | empty'''
        p[0] = p[1]

    def p_vpages(self, p):
        '''vpages : VPAGES
                  | empty'''
        p[0] = p[1]

    def p_caller(self, p):
        '''caller : CALLER
                  | HEX_LITERAL
                  | empty'''
        p[0] = p[1]

    def get_path(self):
        return "/proc/vmallocinfo"
class ProcZoneInfoTest(KernelProcFileTestBase.KernelProcFileTestBase):
    '''/proc/zoneinfo displays information about memory zones.'''

    t_APAGES = literal_token(r'pages')
    t_PAGESETS = literal_token(r'pagesets')
    t_CPU = literal_token(r'cpu')
    t_VM = literal_token(r'vm')
    t_STATS = literal_token(r'stats')
    t_THRESHOLD = literal_token(r'threshold')
    t_NODE = literal_token(r'Node')
    t_ZONE = literal_token(r'zone')
    t_PROTECTION = literal_token(r'protection')
    t_PERNODE = literal_token(r'per-node')
    t_LPAREN = literal_token(r'\(')
    t_RPAREN = literal_token(r'\)')

    t_ignore = ' '

    start = 'nodes'

    p_nodes = repeat_rule('node')
    p_lines = repeat_rule('line')
    p_cpus = repeat_rule('cpu')
    p_colonlines = repeat_rule('colonline')
    p_numcommas = repeat_rule('numcomma')

    def p_node(self, p):
        'node : heading pernode APAGES lines protection PAGESETS NEWLINE cpus colonlines'
        p[0] = [p[1], p[3], p[4], p[7], p[8]]

    def p_pernode(self, p):
        '''pernode : PERNODE STATS NEWLINE lines
                   | empty'''
        p[0] = [] if len(p) == 2 else [p[1], p[4]]

    def p_protection(self, p):
        'protection : PROTECTION COLON LPAREN numcommas NUMBER RPAREN NEWLINE'
        p[0] = p[4] + [p[5]]

    def p_numcomma(self, p):
        'numcomma : NUMBER COMMA'
        p[0] = p[1]

    def p_line(self, p):
        'line : STRING NUMBER NEWLINE'
        p[0] = p[1:3]

    def p_cpu(self, p):
        'cpu : CPU COLON NUMBER NEWLINE colonline colonline colonline \
                VM STATS THRESHOLD COLON NUMBER NEWLINE'

        p[0] = [p[3], p[5], p[6], p[7], [p[10], p[12]]]

    def p_colonline(self, p):
        'colonline : STRING COLON NUMBER NEWLINE'
        p[0] = [p[1], p[3]]

    def p_heading(self, p):
        'heading : NODE NUMBER COMMA ZONE STRING NEWLINE'
        p[0] = [p[2], p[5]]

    def get_path(self):
        return "/proc/zoneinfo"