Home | History | Annotate | Download | only in kernel_sysrq_info
      1 #!/usr/bin/python
      2 #
      3 # Copyright (c) 2015 The Chromium OS Authors. All rights reserved.
      4 # Use of this source code is governed by a BSD-style license that can be
      5 # found in the LICENSE file.
      6 
      7 import os
      8 import re
      9 
     10 from autotest_lib.client.bin import test
     11 from autotest_lib.client.common_lib import error
     12 
     13 
     14 class kernel_sysrq_info(test.test):
     15     """
     16     Verify the Magic SysRq show-* commands
     17     (i.e. don't verify reBoot, Crash, kill-all-tasks, etc.)
     18     """
     19     version = 1
     20 
     21     def sysrq_trigger(self, key):
     22         """
     23         Trigger one SysRq command, and return the kernel log output
     24         @param key:     lowercase SysRq keystroke (e.g. 'm')
     25         @return         dmesg log from running the command
     26         """
     27         os.system("dmesg --clear")
     28         with open("/proc/sysrq-trigger", "w") as f:
     29             f.write(key + "\n")
     30         with os.popen("dmesg --raw") as f:
     31             return f.read()
     32 
     33     def run_once(self):
     34         test_cases = {'l': 'all active CPUs',
     35                       'm': '[0-9]+ pages.*RAM',
     36                       'p': 'Show Regs',
     37                       'q': 'Tick Device:',
     38                       't': 'init.*\s1\s',
     39                       'w': 'pid father'
     40                      }
     41 
     42         for key in test_cases:
     43             s = self.sysrq_trigger(key)
     44             if re.search(test_cases[key], s) == None:
     45                 raise error.TestFail('Unexpected output from SysRq key %s' %
     46                                      key)
     47