Home | History | Annotate | Download | only in clients
      1 #!/usr/bin/python
      2 #
      3 # Copyright 2011 Google Inc. All Rights Reserved.
      4 """chromeos.py: Build & Test ChromeOS using custom compilers."""
      5 
      6 __author__ = 'asharif (at] google.com (Ahmad Sharif)'
      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 ChromeOSNightlyClient(object):
     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, gcc_githash, p4_snapshot=''):
     28     self._board = board
     29     self._remote = remote
     30     self._gcc_githash = gcc_githash
     31     self._p4_snapshot = p4_snapshot
     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(
     53         self.CheckoutV14Dir(),
     54         cmd.Shell('python',
     55                   os.path.join(self.P4_VERSION_DIR, 'test_toolchains.py'),
     56                   '--force-mismatch',
     57                   '--clean',
     58                   '--public',  # crbug.com/145822
     59                   '--board=%s' % self._board,
     60                   '--remote=%s' % self._remote,
     61                   '--githashes=%s' % self._gcc_githash))
     62     label = 'testlabel'
     63     job = jobs.CreateLinuxJob(label, chain, timeout=24 * 60 * 60)
     64 
     65     return job_group.JobGroup(label, [job], True, False)
     66 
     67 
     68 @logger.HandleUncaughtExceptions
     69 def Main(argv):
     70   parser = optparse.OptionParser()
     71   parser.add_option('-b',
     72                     '--board',
     73                     dest='board',
     74                     help='Run performance tests on these boards')
     75   parser.add_option('-r',
     76                     '--remote',
     77                     dest='remote',
     78                     help='Run performance tests on these remotes')
     79   parser.add_option('-g',
     80                     '--gcc_githash',
     81                     dest='gcc_githash',
     82                     help='Use this gcc_githash.')
     83   parser.add_option('-p',
     84                     '--p4_snapshot',
     85                     dest='p4_snapshot',
     86                     default='',
     87                     help='Use this p4_snapshot.')
     88   options, _ = parser.parse_args(argv)
     89 
     90   if not all([options.board, options.remote, options.gcc_githash]):
     91     logging.error('Specify a board, remote and gcc_githash')
     92     return 1
     93 
     94   client = ChromeOSNightlyClient(options.board,
     95                                  options.remote,
     96                                  options.gcc_githash,
     97                                  p4_snapshot=options.p4_snapshot)
     98   client.Run()
     99   return 0
    100 
    101 
    102 if __name__ == '__main__':
    103   logger.SetUpRootLogger(level=logging.DEBUG, display_flags={'name': False})
    104   sys.exit(Main(sys.argv))
    105