def simple_run()

in testsuite/driver/testlib.py [0:0]


def simple_run(name, way, prog, extra_run_opts):
    opts = getTestOpts()

    # figure out what to use for stdin
    if opts.stdin:
        stdin = in_testdir(opts.stdin)
    elif os.path.exists(in_testdir(name, 'stdin')):
        stdin = in_testdir(name, 'stdin')
    else:
        stdin = None

    stdout = in_testdir(name, 'run.stdout')
    if opts.combined_output:
        stderr = subprocess.STDOUT
    else:
        stderr = in_testdir(name, 'run.stderr')

    my_rts_flags = rts_flags(way)

    # Collect stats if necessary:
    # isStatsTest and not isCompilerStatsTest():
    #   assume we are running a ghc compiled program. Collect stats.
    # isStatsTest and way == 'ghci':
    #   assume we are running a program via ghci. Collect stats
    stats_file = name + '.stats'
    if isStatsTest() and (not isCompilerStatsTest() or way == 'ghci'):
        stats_args = ' +RTS -V0 -t' + stats_file + ' --machine-readable -RTS'
    else:
        stats_args = ''

    # Put extra_run_opts last: extra_run_opts('+RTS foo') should work.
    cmd = prog + stats_args + ' ' + my_rts_flags + ' ' + extra_run_opts

    if opts.cmd_wrapper != None:
        cmd = opts.cmd_wrapper(cmd)

    cmd = 'cd "{opts.testdir}" && {cmd}'.format(**locals())

    # run the command
    exit_code = runCmd(cmd, stdin, stdout, stderr, opts.run_timeout_multiplier)

    # check the exit code
    if exit_code != opts.exit_code:
        if config.verbose >= 1 and _expect_pass(way):
            print('Wrong exit code for ' + name + '(' + way + ')' + '(expected', opts.exit_code, ', actual', exit_code, ')')
            dump_stdout(name)
            dump_stderr(name)
        return failBecause('bad exit code')

    if not (opts.ignore_stderr or stderr_ok(name, way) or opts.combined_output):
        return failBecause('bad stderr')
    if not (opts.ignore_stdout or stdout_ok(name, way)):
        return failBecause('bad stdout')

    check_hp = '-h' in my_rts_flags and opts.check_hp
    check_prof = '-p' in my_rts_flags

    # exit_code > 127 probably indicates a crash, so don't try to run hp2ps.
    if check_hp and (exit_code <= 127 or exit_code == 251) and not check_hp_ok(name):
        return failBecause('bad heap profile')
    if check_prof and not check_prof_ok(name, way):
        return failBecause('bad profile')

    return check_stats(name, way, stats_file, opts.stats_range_fields)