• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5
6# DESCRIPTION :
7#
8# This is a hardware test for interrupts. The test reloads kernel module
9# to check if the hardware issues interrupts back to the host.
10
11
12import re
13import time
14import logging
15
16from autotest_lib.client.bin import test, utils
17from autotest_lib.client.common_lib import error
18
19
20class ProcInterrupts(object):
21    """
22    Parse /proc/interrupts and provide interfaces to access number of
23    interrupts per module or per interrupt number/name
24    """
25
26    INTERRUPT_FILE='/proc/interrupts'
27
28    def __init__(self):
29        self._int_count = {}
30        with open(self.INTERRUPT_FILE) as interrupts_file:
31            lines = interrupts_file.readlines()
32
33            # First line indicates CPUs in system
34            num_cpus = len(lines.pop(0).split())
35
36            for line in lines:
37                fields = line.split()
38                count = sum(map(int, fields[1:1 + num_cpus]))
39                interrupt = fields[0].strip().split(':')[0]
40                if interrupt.isdigit():
41                    self._int_count[fields[-1]] = count
42                    logging.debug('int[%s] = %d', fields[-1], count)
43                    interrupt = int(interrupt)
44                self._int_count[interrupt] = count
45                logging.debug('int[%s] = %d', interrupt, count)
46
47    def get(self, interrupt):
48        if interrupt in self._int_count:
49            logging.debug('got int[%s] = %d', interrupt,
50                          self._int_count[interrupt])
51            return self._int_count[interrupt]
52        return 0
53
54
55class hardware_Interrupt(test.test):
56    version = 1
57
58    def run_once(self,
59                 interrupt=None,
60                 reload_module=None,
61                 min_count=1):
62        proc_int = ProcInterrupts()
63        count = proc_int.get(interrupt)
64
65        if reload_module:
66            utils.system('rmmod %s' % reload_module)
67            utils.system('modprobe %s' % reload_module)
68            # Wait for procfs update
69            time.sleep(1)
70            proc_int = ProcInterrupts()
71            count = proc_int.get(interrupt) - count
72
73        if count < min_count:
74            raise error.TestError('Interrupt test failed: int[%s] = %d < '
75                                  'min_count %d' % (interrupt, count,
76                                  min_count))
77
78