Beispiel #1
0
def worker(test_queue, done_queue, worker_id, addr, authkey):
    """This is used by concurrent test processes. It takes a test
    off of the test_queue, runs it, then puts the Test object
    on the done_queue.
    """
    if addr is None:
        server = None
    else:
        server = get_client_manager(addr, authkey)

    # need a unique profile output file for each worker process
    testflo.profile._prof_file = 'profile_%s.out' % worker_id

    test_count = 0
    for test in iter(test_queue.get, 'STOP'):

        try:
            test_count += 1
            done_queue.put(test.run(server, addr, authkey))
        except:
            # we generally shouldn't get here, but just in case,
            # handle it so that the main process doesn't hang at the
            # end when it tries to join all of the concurrent processes.
            done_queue.put(test)

    # don't save anything unless we actually ran a test
    if test_count > 0:
        save_coverage()
        save_profile()
Beispiel #2
0
 def __init__(self, options, addr, authkey):
     self.stop = options.stop
     if addr is None:
         self._server = self._addr = self._authkey = None
     else:
         self._server = get_client_manager(addr, authkey)
         self._addr = addr
         self._authkey = authkey
     setup_coverage(options)
Beispiel #3
0
    import sys
    import os
    import traceback

    from mpi4py import MPI
    from testflo.test import Test
    from testflo.cover import save_coverage
    from testflo.qman import get_client_manager
    from testflo.util import get_addr_auth_from_args

    exitcode = 0  # use 0 for exit code of all ranks != 0 because otherwise,
    # MPI will terminate other processes

    address, authkey = get_addr_auth_from_args(sys.argv[2:])

    manager = get_client_manager(address, authkey)

    try:
        try:
            comm = MPI.COMM_WORLD
            test = Test(sys.argv[1])
            test.nocapture = True  # so we don't lose stdout
            test.run()
        except:
            print(traceback.format_exc())
            test.status = "FAIL"
            test.err_msg = traceback.format_exc()

        # collect results
        results = comm.gather(test, root=0)
        if comm.rank == 0:
Beispiel #4
0
def main(args=None):
    # FIXME: get rid of this
    if args is None:
        args = sys.argv[1:]

    options = get_options(args)

    options.skip_dirs = []

    # read user prefs from ~/.testflo file.
    # create one if it doesn't exist
    homedir = os.path.expanduser('~')
    rcfile = os.path.join(homedir, '.testflo')
    if not os.path.isfile(rcfile):
        with open(rcfile, 'w') as f:
            f.write("""[testflo]
skip_dirs=site-packages,
    dist-packages,
    build,
    contrib
""")
    read_config_file(rcfile, options)
    if options.cfg:
        read_config_file(options.cfg, options)

    tests = options.tests
    if options.testfile:
        tests += list(read_test_file(options.testfile))

    if not tests:
        tests = [os.getcwd()]

    def dir_exclude(d):
        for skip in options.skip_dirs:
            if fnmatch(os.path.basename(d), skip):
                return True
        return False

    setup_coverage(options)
    setup_profile(options)

    if options.benchmark:
        options.num_procs = 1
        options.isolated = True
        discoverer = TestDiscoverer(module_pattern=six.text_type('benchmark*.py'),
                                    func_pattern=six.text_type('benchmark*'),
                                    dir_exclude=dir_exclude)
        benchmark_file = open(options.benchmarkfile, 'a')
    else:
        discoverer = TestDiscoverer(dir_exclude=dir_exclude)
        benchmark_file = open(os.devnull, 'a')

    try:
        retval = 0
        server_proc = None

        if options.isolated or not options.nompi:
            addr = get_open_address()
            authkey = 'foo'

            cmd = [sys.executable,
                   os.path.join(os.path.dirname(__file__), 'qman.py')]
            if sys.platform == 'win32':
                cmd.extend((addr, authkey))
            else:
                cmd.extend((addr[0], str(addr[1]), authkey))

            server_proc = subprocess.Popen(cmd, env=os.environ)

            # make sure the server is up before we continue onward
            retries = 10
            man = None
            while retries:
                try:
                    man = get_client_manager(addr, authkey)
                    break
                except:
                    msg = traceback.format_exc()
                    time.sleep(0.5)
                    retries -= 1

            if man is None:
                raise ConnectionRefusedError("Can't connect to queue server: %s"
                                             % msg)
            del man
        else:
            addr = authkey = None

        with open(options.outfile, 'w') as report, benchmark_file as bdata:
            pipeline = [
                discoverer.get_iter,
            ]

            if options.dryrun:
                pipeline.extend([
                    dryrun,
                ])
            else:
                runner = ConcurrentTestRunner(options, addr, authkey)

                pipeline.append(runner.get_iter)

                if options.benchmark:
                    pipeline.append(BenchmarkWriter(stream=bdata).get_iter)

                pipeline.extend([
                    ResultPrinter(verbose=options.verbose).get_iter,
                    ResultSummary(options).get_iter,
                ])
                if not options.noreport:
                    # print verbose results and summary to a report file
                    pipeline.extend([
                        ResultPrinter(report, verbose=True).get_iter,
                        ResultSummary(options, stream=report).get_iter,
                    ])

            if options.maxtime > 0:
                pipeline.append(TimeFilter(options.maxtime).get_iter)

            if options.save_fails:
                pipeline.append(FailFilter().get_iter)

            retval = run_pipeline(tests, pipeline)

            finalize_coverage(options)
            finalize_profile(options)
    finally:
        if server_proc is not None and (options.isolated or not options.nompi):
            try:
                server_proc.terminate()
            except:
                # send msg to stdout instead of stderr to avoid failures when
                # testing under PowerShell.
                print("failed to terminate queue server")

    return retval