1# Copyright 2018 the V8 project authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5from . import base 6from ..local.variants import ALL_VARIANTS, ALL_VARIANT_FLAGS 7from .result import GroupedResult 8 9 10STANDARD_VARIANT = set(["default"]) 11 12 13class VariantProc(base.TestProcProducer): 14 """Processor creating variants. 15 16 For each test it keeps generator that returns variant, flags and id suffix. 17 It produces variants one at a time, so it's waiting for the result of one 18 variant to create another variant of the same test. 19 It maintains the order of the variants passed to the init. 20 21 There are some cases when particular variant of the test is not valid. To 22 ignore subtests like that, StatusFileFilterProc should be placed somewhere 23 after the VariantProc. 24 """ 25 26 def __init__(self, variants): 27 super(VariantProc, self).__init__('VariantProc') 28 self._next_variant = {} 29 self._variant_gens = {} 30 self._variants = variants 31 32 def setup(self, requirement=base.DROP_RESULT): 33 super(VariantProc, self).setup(requirement) 34 35 # VariantProc is optimized for dropping the result and it should be placed 36 # in the chain where it's possible. 37 assert requirement == base.DROP_RESULT 38 39 def _next_test(self, test): 40 gen = self._variants_gen(test) 41 self._next_variant[test.procid] = gen 42 self._try_send_new_subtest(test, gen) 43 44 def _result_for(self, test, subtest, result): 45 gen = self._next_variant[test.procid] 46 self._try_send_new_subtest(test, gen) 47 48 def _try_send_new_subtest(self, test, variants_gen): 49 for variant, flags, suffix in variants_gen: 50 subtest = self._create_subtest(test, '%s-%s' % (variant, suffix), 51 variant=variant, flags=flags) 52 self._send_test(subtest) 53 return 54 55 del self._next_variant[test.procid] 56 self._send_result(test, None) 57 58 def _variants_gen(self, test): 59 """Generator producing (variant, flags, procid suffix) tuples.""" 60 return self._get_variants_gen(test).gen(test) 61 62 def _get_variants_gen(self, test): 63 key = test.suite.name 64 variants_gen = self._variant_gens.get(key) 65 if not variants_gen: 66 variants_gen = test.suite.get_variants_gen(self._variants) 67 self._variant_gens[key] = variants_gen 68 return variants_gen 69