Home | History | Annotate | Download | only in hardware_ch7036
      1 # -*- coding: utf-8 -*-
      2 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
      3 # Use of this source code is governed by a BSD-style license that can be
      4 # found in the LICENSE file.
      5 
      6 
      7 import logging
      8 import os
      9 import re
     10 import time
     11 
     12 from autotest_lib.client.bin import test
     13 from autotest_lib.client.common_lib import error, utils
     14 
     15 
     16 _DPMS_DOWN = ['standby', 'suspend', 'stop']
     17 _LOG_CHECKLIST = ['Found device', 'CH7036 MCU ver']
     18 _SERVER = 'chrontel'
     19 _XENV = 'LD_LIBRARY_PATH=/usr/local/lib ' + \
     20     'XAUTHORITY=/var/run/chromelogin.auth DISPLAY=:0'
     21 
     22 
     23 def run_cmd(cmd):
     24     try:
     25         cmd_out = utils.system_output(cmd, retain_output=True)
     26     except error.CmdError, e:
     27         logging.debug(e)
     28         raise error.TestFail(cmd)
     29     return cmd_out
     30 
     31 
     32 def check_server(server):
     33     ups_str = run_cmd('initctl status %s' % (server))
     34     ups_list = ups_str.strip().split()
     35     if ups_list[1] != 'start/running,':
     36         raise error.TestFail('%s not running :: %s' % (server, ups_list[1]))
     37     return ups_list[3]
     38 
     39 
     40 def stress_server():
     41     # Make sure it responds favorably to DPMS events
     42     utils.assert_has_X_server()
     43     for dpms_verb in _DPMS_DOWN:
     44         run_cmd("%s xset dpms force %s" % (_XENV, dpms_verb))
     45         time.sleep(5)
     46         run_cmd("%s xset dpms force on" % (_XENV))
     47         time.sleep(5)
     48 
     49 
     50 def check_log():
     51     # two listings (stdout, stderr) + header
     52     lsof_out = run_cmd('lsof -c /ch7036_monitor/ ' + \
     53                            '-a -u root -a +D /var/log | tail -1')
     54     if not lsof_out:
     55         raise error.TestFail('Unable to locate logfile in lsof output')
     56 
     57     lsof_list = lsof_out.rstrip().split()
     58     log = lsof_list[8]
     59     log.rstrip()
     60     logging.debug('log = %s' % (log))
     61     if not os.path.isfile(log):
     62         raise error.TestFail('no log at %s' % (log))
     63 
     64     fd = open(log)
     65     found = dict((k, False) for k in _LOG_CHECKLIST)
     66     found_cnt = 0
     67     for ln in fd:
     68         ln.rstrip()
     69         for k in found:
     70             if re.search(k, ln, re.I):
     71                 logging.debug(ln)
     72                 found[k] = True
     73                 found_cnt += 1
     74         if found_cnt == len(found):
     75             break
     76 
     77     if found_cnt < len(found):
     78         errs = ''
     79         for k in found:
     80             if not found[k]:
     81                 errs += "%s " % (k)
     82         raise error.TestFail('Failed to validate log for %s' % (errs))
     83     fd.close()
     84     return log
     85 
     86 
     87 class hardware_ch7036(test.test):
     88     version = 1
     89 
     90 
     91     def run_once(self):
     92         pid1 = check_server(_SERVER)
     93         stress_server()
     94         self._log = check_log()
     95         pid2 = check_server(_SERVER)
     96         logging.debug("pids %s %s" % (pid1, pid2))
     97         if pid1 != pid2:
     98             raise error.TestFail('Appears server %s restarted (%s != %s)' %
     99                                  (_SERVER, pid1, pid2))
    100