def testAdvanced(self):
        step = annotator.AdvancedAnnotationStep(stream=self.buf,
                                                flush_before=None)
        stream = annotator.AdvancedAnnotationStream(stream=self.buf,
                                                    flush_before=None)
        stream.step_cursor('one')
        step.step_started()
        stream.step_cursor('two')
        step.step_started()
        stream.step_cursor('one')
        step.step_closed()
        stream.step_cursor('two')
        step.step_closed()

        result = [
            '@@@STEP_CURSOR one@@@',
            '@@@STEP_STARTED@@@',
            '@@@STEP_CURSOR two@@@',
            '@@@STEP_STARTED@@@',
            '@@@STEP_CURSOR one@@@',
            '@@@STEP_CLOSED@@@',
            '@@@STEP_CURSOR two@@@',
            '@@@STEP_CLOSED@@@',
        ]

        self.assertEquals(result, self._getLines())
示例#2
0
def main(args):
    """Note: this is solely to run the current master's code and can totally
  differ from the underlying script flags.

  To update these flags:
  - Update the following code to support both the previous flag and the new
    flag.
  - Change scripts/master/factory/swarm_commands.py to pass the new flag.
  - Restart all the masters using swarming.
  - Remove the old flag from this code.
  """
    client = swarming_utils.find_client(os.getcwd())
    if not client:
        print >> sys.stderr, 'Failed to find swarm(ing)_client'
        return 1
    version = swarming_utils.get_version(client)
    if version < (0, 3):
        print >> sys.stderr, (
            '%s is version %s which is too old. Please run the test locally' %
            (client, '.'.join(version)))
        return 1

    parser = optparse.OptionParser(description=sys.modules[__name__].__doc__)
    parser.add_option('--verbose', action='store_true')
    parser.add_option('--swarming')
    parser.add_option('--isolate-server')
    chromium_utils.AddPropertiesOptions(parser)
    options, args = parser.parse_args(args)
    if args:
        parser.error('Unsupported args: %s' % args)
    if not options.swarming or not options.isolate_server:
        parser.error('Require both --swarming and --isolate-server')

    logging.basicConfig(
        level=logging.DEBUG if options.verbose else logging.ERROR)
    # Loads the other flags implicitly.
    slave_os, priority, steps, builder, build_number = process_build_properties(
        options)
    logging.info('To run: %s, %s, %s', slave_os, priority, steps)
    if not steps:
        print('Nothing to trigger')
        annotator.AdvancedAnnotationStep(sys.stdout, False).step_warnings()
        return 0
    print('Selected tests:')
    print('\n'.join(' %s' % s for s in sorted(steps)))
    selected_os = swarming_utils.OS_MAPPING[slave_os]
    print('Selected OS: %s' % selected_os)
    return drive_many(client, version, options.swarming,
                      options.isolate_server, priority, {'os': selected_os},
                      steps, builder, build_number)
示例#3
0
def _drive_many(client, version, swarming_server, isolate_server, priority,
                dimensions, steps, builder, build_number, out):
    """Internal version, exposed so it can be hooked in test."""
    stream = annotator.AdvancedAnnotationStream(sys.stdout, False)
    for step_name in sorted(steps):
        # Seeds the step first before doing the cursors otherwise it is interleaved
        # in the logs of other steps.
        stream.seed_step(step_name)

    threads = []
    # Create the boxes in buildbot in order for consistency.
    steps_annotations = {}
    for step_name, isolated_hash in sorted(steps.iteritems()):
        env = {}
        # TODO(maruel): Propagate GTEST_FILTER.
        #if gtest_filter not in (None, '', '.', '*'):
        #  env['GTEST_FILTER'] = gtest_filter
        shards = swarming_utils.TESTS_SHARDS.get(step_name, 1)
        # This will be the key in steps_annotations.
        # TODO(maruel): Work around bug swarming:73 by using unique swarming task
        # name. This is done by including the builder name and the build number.
        # This is not something we want to keep long term because we lose the
        # benefit of skipping running the exact same executable twice for no good
        # reason.
        task_name = '%s/%s/%s/%s/%d' % (step_name, dimensions['os'],
                                        isolated_hash, builder, build_number)
        t = threading.Thread(target=drive_one,
                             args=(client, version, swarming_server,
                                   isolate_server, priority, dimensions,
                                   task_name, step_name, isolated_hash, env,
                                   shards, out))
        t.daemon = True
        t.start()
        threads.append(t)
        # It is important data to surface through buildbot.
        steps_annotations[step_name] = annotator.AdvancedAnnotationStep(
            sys.stdout, False)
        stream.step_cursor(step_name)
        steps_annotations[step_name].step_started()
        steps_annotations[step_name].step_text(dimensions['os'])
        steps_annotations[step_name].step_text(isolated_hash)
    sys.stdout.flush()
    collect(stream, steps_annotations, step_name, out)
    return 0