Home | History | Annotate | Download | only in clients
      1 #!/usr/bin/python
      2 #
      3 # Copyright 2012 Google Inc. All Rights Reserved.
      4 """dejagnu_compiler.py: Run dejagnu test."""
      5 
      6 __author__ = 'shenhan (at] google.com  (Han Shen)'
      7 
      8 import logging
      9 import optparse
     10 import os
     11 import pickle
     12 import sys
     13 import xmlrpclib
     14 
     15 from automation.clients.helper import jobs
     16 from automation.clients.helper import perforce
     17 from automation.common import command as cmd
     18 from automation.common import job_group
     19 from automation.common import logger
     20 
     21 
     22 class DejagnuCompilerNightlyClient:
     23   DEPOT2_DIR = '//depot2/'
     24   P4_CHECKOUT_DIR = 'perforce2/'
     25   P4_VERSION_DIR = os.path.join(P4_CHECKOUT_DIR, 'gcctools/chromeos/v14')
     26 
     27   def __init__(self, board, remote, p4_snapshot, cleanup):
     28     self._board = board
     29     self._remote = remote
     30     self._p4_snapshot = p4_snapshot
     31     self._cleanup = cleanup
     32 
     33   def Run(self):
     34     server = xmlrpclib.Server('http://localhost:8000')
     35     server.ExecuteJobGroup(pickle.dumps(self.CreateJobGroup()))
     36 
     37   def CheckoutV14Dir(self):
     38     p4view = perforce.View(self.DEPOT2_DIR, [
     39         perforce.PathMapping('gcctools/chromeos/v14/...')
     40     ])
     41     return self.GetP4Snapshot(p4view)
     42 
     43   def GetP4Snapshot(self, p4view):
     44     p4client = perforce.CommandsFactory(self.P4_CHECKOUT_DIR, p4view)
     45 
     46     if self._p4_snapshot:
     47       return p4client.CheckoutFromSnapshot(self._p4_snapshot)
     48     else:
     49       return p4client.SetupAndDo(p4client.Sync(), p4client.Remove())
     50 
     51   def CreateJobGroup(self):
     52     chain = cmd.Chain(self.CheckoutV14Dir(), cmd.Shell(
     53         'python', os.path.join(self.P4_VERSION_DIR, 'test_gcc_dejagnu.py'),
     54         '--board=%s' % self._board, '--remote=%s' % self._remote,
     55         '--cleanup=%s' % self._cleanup))
     56     label = 'dejagnu'
     57     job = jobs.CreateLinuxJob(label, chain, timeout=8 * 60 * 60)
     58     return job_group.JobGroup(label,
     59                               [job],
     60                               cleanup_on_failure=True,
     61                               cleanup_on_completion=True)
     62 
     63 
     64 @logger.HandleUncaughtExceptions
     65 def Main(argv):
     66   parser = optparse.OptionParser()
     67   parser.add_option('-b',
     68                     '--board',
     69                     dest='board',
     70                     help='Run performance tests on these boards')
     71   parser.add_option('-r',
     72                     '--remote',
     73                     dest='remote',
     74                     help='Run performance tests on these remotes')
     75   parser.add_option('-p',
     76                     '--p4_snapshot',
     77                     dest='p4_snapshot',
     78                     help=('For development only. '
     79                           'Use snapshot instead of checking out.'))
     80   parser.add_option('--cleanup',
     81                     dest='cleanup',
     82                     default='mount',
     83                     help=('Cleanup test directory, values could be one of '
     84                           '"mount", "chroot" or "chromeos"'))
     85   options, _ = parser.parse_args(argv)
     86 
     87   if not all([options.board, options.remote]):
     88     logging.error('Specify a board and remote.')
     89     return 1
     90 
     91   client = DejagnuCompilerNightlyClient(options.board, options.remote,
     92                                         options.p4_snapshot, options.cleanup)
     93   client.Run()
     94   return 0
     95 
     96 
     97 if __name__ == '__main__':
     98   sys.exit(Main(sys.argv))
     99