1#!/usr/bin/python 2# 3# Copyright 2011 Google Inc. All Rights Reserved. 4 5__author__ = 'kbaclawski@google.com (Krystian Baclawski)' 6 7import logging 8import optparse 9import pickle 10import sys 11import xmlrpclib 12 13from automation.clients.helper import crosstool 14from automation.common import job_group 15from automation.common import logger 16 17 18class CrosstoolNightlyClient(object): 19 VALID_TARGETS = ['gcc-4.6.x-ubuntu_lucid-arm', 20 'gcc-4.6.x-ubuntu_lucid-x86_64', 21 'gcc-4.6.x-grtev2-armv7a-vfpv3.d16-hard', 22 'gcc-4.6.x-glibc-2.11.1-grte', 23 'gcc-4.6.x-glibc-2.11.1-powerpc'] 24 VALID_BOARDS = ['qemu', 'pandaboard', 'unix'] 25 26 def __init__(self, target, boards): 27 assert target in self.VALID_TARGETS 28 assert all(board in self.VALID_BOARDS for board in boards) 29 30 self._target = target 31 self._boards = boards 32 33 def Run(self): 34 server = xmlrpclib.Server('http://localhost:8000') 35 server.ExecuteJobGroup(pickle.dumps(self.CreateJobGroup())) 36 37 def CreateJobGroup(self): 38 factory = crosstool.JobsFactory() 39 40 checkout_crosstool_job, checkout_dir, manifests_dir = \ 41 factory.CheckoutCrosstool(self._target) 42 43 all_jobs = [checkout_crosstool_job] 44 45 # Build crosstool target 46 build_release_job, build_tree_dir = factory.BuildRelease(checkout_dir, 47 self._target) 48 all_jobs.append(build_release_job) 49 50 testruns = [] 51 52 # Perform crosstool tests 53 for board in self._boards: 54 for component in ('gcc', 'binutils'): 55 test_job, testrun_dir = factory.RunTests(checkout_dir, build_tree_dir, 56 self._target, board, component) 57 all_jobs.append(test_job) 58 testruns.append(testrun_dir) 59 60 if testruns: 61 all_jobs.append(factory.GenerateReport(testruns, manifests_dir, 62 self._target, self._boards)) 63 64 return job_group.JobGroup('Crosstool Nightly Build (%s)' % self._target, 65 all_jobs, True, False) 66 67 68@logger.HandleUncaughtExceptions 69def Main(argv): 70 valid_boards_string = ', '.join(CrosstoolNightlyClient.VALID_BOARDS) 71 72 parser = optparse.OptionParser() 73 parser.add_option( 74 '-b', 75 '--board', 76 dest='boards', 77 action='append', 78 choices=CrosstoolNightlyClient.VALID_BOARDS, 79 default=[], 80 help=('Run DejaGNU tests on selected boards: %s.' % valid_boards_string)) 81 options, args = parser.parse_args(argv) 82 83 if len(args) == 2: 84 target = args[1] 85 else: 86 logging.error('Exactly one target required as a command line argument!') 87 logging.info('List of valid targets:') 88 for pair in enumerate(CrosstoolNightlyClient.VALID_TARGETS, start=1): 89 logging.info('%d) %s', pair) 90 sys.exit(1) 91 92 option_list = [opt.dest for opt in parser.option_list if opt.dest] 93 94 kwargs = dict((option, getattr(options, option)) for option in option_list) 95 96 client = CrosstoolNightlyClient(target, **kwargs) 97 client.Run() 98 99 100if __name__ == '__main__': 101 logger.SetUpRootLogger(level=logging.DEBUG, display_flags={'name': False}) 102 Main(sys.argv) 103