chromeos.py revision c7f1593f9af3ea1b9264b37628c36f3a70e1749a
1#!/usr/bin/python 2# 3# Copyright 2011 Google Inc. All Rights Reserved. 4 5"""chromeos.py: Build & Test ChromeOS using custom compilers.""" 6 7__author__ = 'asharif@google.com (Ahmad Sharif)' 8 9 10import logging 11import optparse 12import os 13import pickle 14import sys 15import xmlrpclib 16 17from automation.clients.helper import jobs 18from automation.clients.helper import perforce 19from automation.common import command as cmd 20from automation.common import job_group 21from automation.common import logger 22 23 24class ChromeOSNightlyClient(object): 25 DEPOT2_DIR = '//depot2/' 26 P4_CHECKOUT_DIR = 'perforce2/' 27 P4_VERSION_DIR = os.path.join(P4_CHECKOUT_DIR, 'gcctools/chromeos/v14') 28 29 def __init__(self, board, remote, gcc_githash, p4_snapshot=''): 30 self._board = board 31 self._remote = remote 32 self._gcc_githash = gcc_githash 33 self._p4_snapshot = p4_snapshot 34 35 def Run(self): 36 server = xmlrpclib.Server('http://localhost:8000') 37 server.ExecuteJobGroup(pickle.dumps(self.CreateJobGroup())) 38 39 def CheckoutV14Dir(self): 40 p4view = perforce.View(self.DEPOT2_DIR, [ 41 perforce.PathMapping('gcctools/chromeos/v14/...')]) 42 return self.GetP4Snapshot(p4view) 43 44 def GetP4Snapshot(self, p4view): 45 p4client = perforce.CommandsFactory(self.P4_CHECKOUT_DIR, p4view) 46 47 if self._p4_snapshot: 48 return p4client.CheckoutFromSnapshot(self._p4_snapshot) 49 else: 50 return p4client.SetupAndDo(p4client.Sync(), p4client.Remove()) 51 52 def CreateJobGroup(self): 53 chain = cmd.Chain( 54 self.CheckoutV14Dir(), 55 cmd.Shell('python', 56 os.path.join(self.P4_VERSION_DIR, 'test_toolchains.py'), 57 '--force-mismatch', 58 '--clean', 59 '--public', # crbug.com/145822 60 '--board=%s' % self._board, 61 '--remote=%s' % self._remote, 62 '--githashes=%s' % self._gcc_githash)) 63 label = 'testlabel' 64 job = jobs.CreateLinuxJob(label, chain, timeout=24*60*60) 65 66 return job_group.JobGroup(label, [job], True, False) 67 68 69@logger.HandleUncaughtExceptions 70def Main(argv): 71 parser = optparse.OptionParser() 72 parser.add_option('-b', 73 '--board', 74 dest='board', 75 help='Run performance tests on these boards') 76 parser.add_option('-r', 77 '--remote', 78 dest='remote', 79 help='Run performance tests on these remotes') 80 parser.add_option('-g', 81 '--gcc_githash', 82 dest='gcc_githash', 83 help='Use this gcc_githash.') 84 parser.add_option('-p', 85 '--p4_snapshot', 86 dest='p4_snapshot', 87 default='', 88 help='Use this p4_snapshot.') 89 options, _ = parser.parse_args(argv) 90 91 if not all([options.board, options.remote, options.gcc_githash]): 92 logging.error('Specify a board, remote and gcc_githash') 93 return 1 94 95 client = ChromeOSNightlyClient(options.board, options.remote, 96 options.gcc_githash, 97 p4_snapshot=options.p4_snapshot) 98 client.Run() 99 return 0 100 101 102if __name__ == '__main__': 103 logger.SetUpRootLogger(level=logging.DEBUG, display_flags={'name': False}) 104 sys.exit(Main(sys.argv)) 105