def main(): global COMPILER architectures = { 'amd64': NativeTestCases, 'amd64_debian': Amd64DebianTestCases, 'arm': ArmTestCases, 'aarch64': AArch64TestCases, 'x86': X86TestCases, 'mips': MipsTestCases, 'mips64el': Mips64elTestCases, 'powerpc64le': PowerPC64leTestCases } # parse commandline selected_testcases = set() selected_architectures = set() for a in sys.argv[1:]: if a in architectures: selected_architectures.add(architectures[a]) elif a == 'all': selected_architectures.update(architectures.values()) elif a == 'release': COMPILER = COMPILER.replace('-debug', '-minsizerel') print(f'using compiler {COMPILER} ...') elif a == 'config': print_compiler_config(selected_architectures) return else: selected_testcases.add(a) if not selected_architectures: selected_architectures.add(architectures['amd64']) os.chdir(os.path.dirname(os.path.abspath(__file__))) start = time.time() suite = [] for arch in selected_architectures: suite += list(unittest.TestLoader().loadTestsFromTestCase(arch)) if len(selected_testcases) > 0: suite = [ s for s in suite if s.id().split('.')[-1] in selected_testcases ] print(f'Running {len(suite)} tests ...') # concurrent_suite = testtools.ConcurrentStreamTestSuite(lambda: ((case, None) for case in suite)) concurrent_suite = testtools.ConcurrentStreamTestSuite( lambda: partition_tests(suite, multiprocessing.cpu_count())) result = MyStreamResult(len(suite)) concurrent_suite.run(result) result.stopTestRun() duration = time.time() - start print(f'Timing: {round(duration)} seconds')
retval = 0 if serial: for stream in streams: # Calls StreamResult API. case = subunit.ByteStreamToStreamResult(stream, non_subunit_name='stdout') result = _load_case(inserter, repo, case, subunit_out, pretty_out, color, stdout, abbreviate, suppress_attachments, all_attachments) if result or retval: retval = 1 else: retval = 0 else: case = testtools.ConcurrentStreamTestSuite(make_tests) retval = _load_case(inserter, repo, case, subunit_out, pretty_out, color, stdout, abbreviate, suppress_attachments, all_attachments) return retval def _load_case(inserter, repo, case, subunit_out, pretty_out, color, stdout, abbreviate, suppress_attachments, all_attachments): if subunit_out: output_result, summary_result = output.make_result(inserter.get_id, output=stdout) elif pretty_out: outcomes = testtools.StreamToDict( functools.partial(subunit_trace.show_outcome,
class load(Command): """Load a subunit stream into a repository. Failing tests are shown on the console and a summary of the stream is printed at the end. Unless the stream is a partial stream, any existing failures are discarded. """ input_streams = ['subunit+', 'interactive?'] args = [ExistingPathArgument('streams', min=0, max=None)] options = [ optparse.Option("--partial", action="store_true", default=False, help="The stream being loaded was a partial run."), optparse.Option( "--force-init", action="store_true", default=False, help="Initialise the repository if it does not exist already"), optparse.Option("--subunit", action="store_true", default=False, help="Display results in subunit format."), optparse.Option( "--full-results", action="store_true", default=False, help="No-op - deprecated and kept only for backwards compat."), ] # Can be assigned to to inject a custom command factory. command_factory = TestCommand def run(self): path = self.ui.here try: repo = self.repository_factory.open(path) except RepositoryNotFound: if self.ui.options.force_init: repo = self.repository_factory.initialise(path) else: raise testcommand = self.command_factory(self.ui, repo) # Not a full implementation of TestCase, but we only need to iterate # back to it. Needs to be a callable - its a head fake for # testsuite.add. # XXX: Be nice if we could declare that the argument, which is a path, # is to be an input stream - and thus push this conditional down into # the UI object. if self.ui.arguments.get('streams'): opener = partial(open, mode='rb') streams = map(opener, self.ui.arguments['streams']) else: streams = self.ui.iter_streams('subunit') mktagger = lambda pos, result: testtools.StreamTagger( [result], add=['worker-%d' % pos]) def make_tests(): for pos, stream in enumerate(streams): # Calls StreamResult API. case = subunit.ByteStreamToStreamResult( stream, non_subunit_name='stdout') decorate = partial(mktagger, pos) case = testtools.DecorateTestCaseResult(case, decorate) yield (case, str(pos)) case = testtools.ConcurrentStreamTestSuite(make_tests) # One unmodified copy of the stream to repository storage inserter = repo.get_inserter(partial=self.ui.options.partial) # One copy of the stream to the UI layer after performing global # filters. try: previous_run = repo.get_latest_run() except KeyError: previous_run = None output_result, summary_result = self.ui.make_result( inserter.get_id, testcommand, previous_run=previous_run) result = testtools.CopyStreamResult([inserter, output_result]) runner_thread = None result.startTestRun() try: # Convert user input into a stdin event stream interactive_streams = list(self.ui.iter_streams('interactive')) if interactive_streams: case = InputToStreamResult(interactive_streams[0]) runner_thread = threading.Thread(target=case.run, args=(result, )) runner_thread.daemon = True runner_thread.start() case.run(result)