runtests.py 4.44 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
# 
# (c) Simon Marlow 2002
#

# ToDo:
#   GHCi tests
#   expect failure for some ways only

import sys
import os
import string
import getopt
13
import time
14

15 16
from testutil import *
from testglobals import *
17

18 19 20 21 22
# Readline sometimes spews out ANSI escapes for some values of TERM,
# which result in test failures. Thus set TERM to a nice, simple, safe
# value.
os.environ['TERM'] = 'vt100'

23
global config
24
config = getConfig() # get it from testglobals
25 26 27 28 29 30 31 32 33

# -----------------------------------------------------------------------------
# cmd-line options

long_options = [
  "config=",  		# config file
  "rootdir=", 		# root of tree containing tests (default: .)
  "output-summary=", 	# file in which to save the (human-readable) summary
  "only=",		# just this test (can be give multiple --only= flags)
34
  "way=",		# just this way
35
  "skipway=",		# skip this way
ei@vuokko.info's avatar
ei@vuokko.info committed
36
  "threads=",           # threads to run simultaneously
37 38 39 40 41 42 43 44 45 46 47 48 49 50
  ]

opts, args = getopt.getopt(sys.argv[1:], "e:", long_options)
       
for opt,arg in opts:
    if opt == '--config':
        execfile(arg)

    # -e is a string to execute from the command line.  For example:
    # testframe -e 'config.compiler=ghc-5.04'
    if opt == '-e':
        exec arg

    if opt == '--rootdir':
51
        config.rootdirs.append(arg)
52 53 54 55

    if opt == '--output-summary':
        config.output_summary = arg

56 57 58
    if opt == '--times-file':
        config.times_file = arg

59 60 61
    if opt == '--only':
        config.only.append(arg)

62
    if opt == '--way':
krc's avatar
krc committed
63
        if (arg not in config.run_ways and arg not in config.compile_ways and arg not in config.other_ways):
64 65 66
            sys.stderr.write("ERROR: requested way \'" +
                             arg + "\' does not exist\n")
            sys.exit(1)
67 68 69 70
        config.cmdline_ways = [arg] + config.cmdline_ways
        if (arg in config.other_ways):
            config.run_ways = [arg] + config.run_ways
            config.compile_ways = [arg] + config.compile_ways
ei@vuokko.info's avatar
ei@vuokko.info committed
71

72 73 74 75 76 77 78 79 80
    if opt == '--skipway':
        if (arg not in config.run_ways and arg not in config.compile_ways and arg not in config.other_ways):
            sys.stderr.write("ERROR: requested way \'" +
                             arg + "\' does not exist\n")
            sys.exit(1)
        config.other_ways = filter(neq(arg), config.other_ways)
        config.run_ways = filter(neq(arg), config.run_ways)
        config.compile_ways = filter(neq(arg), config.compile_ways)

ei@vuokko.info's avatar
ei@vuokko.info committed
81 82
    if opt == '--threads':
        config.threads = int(arg)
83

84 85 86
# This has to come after arg parsing as the args can change the compiler
get_compiler_info()

87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
# Can't import this earlier as we need to know if threading will be
# enabled or not
from testlib import *

global testopts_local
testopts_local.x = TestOptions()

global thisdir_testopts
thisdir_testopts = getThisDirTestOpts()

if config.use_threads:
    t.lock = threading.Lock()
    t.thread_pool = threading.Condition(t.lock)
    t.running_threads = 0

102 103 104 105 106 107
# if timeout == -1 then we try to calculate a sensible value
if config.timeout == -1:
    config.timeout = int(read_no_crs(config.top + '/timeout/calibrate.out'))

print 'Timeout is ' + str(config.timeout)

108 109 110
# -----------------------------------------------------------------------------
# The main dude

111 112 113 114
if config.rootdirs == []:
    config.rootdirs = ['.']

t_files = findTFiles(config.rootdirs)
115 116 117 118 119 120 121 122 123 124 125 126

print 'Found', len(t_files), '.T files...'

t = getTestRun()

t.start_time = chop(os.popen('date').read())
print 'Beginning test run at', t.start_time

# set stdout to unbuffered (is this the best way to do it?)
sys.stdout.flush()
sys.stdout = os.fdopen(sys.__stdout__.fileno(), "w", 0)

127 128
times = {}

129 130 131 132
for file in t_files:
    print '====> Running', file
    newTestDir(os.path.dirname(file))
    try:
133 134
        if config.use_threads:
            t.running_threads=0
135
        start = time.time()
136
        execfile(file)
137 138
        end = time.time()
        times[file] = end - start
139 140 141 142 143
        if config.use_threads:
            t.thread_pool.acquire()
            while t.running_threads>0:
                t.thread_pool.wait()
            t.thread_pool.release()
144
    except:
145
        print '*** framework failure: found an error while executing ', file, ':'
146
        t.n_framework_failures = t.n_framework_failures + 1
147
        traceback.print_exc()
ei@vuokko.info's avatar
ei@vuokko.info committed
148
        
149 150 151 152 153
summary(t, sys.stdout)

if config.output_summary != '':
    summary(t, open(config.output_summary, 'w'))

154 155 156 157 158 159
if config.times_file != '':
    h = open(config.times_file, 'w')
    for (k, v) in times.items():
        h.write(k + ',' + str(v) + '\n')
    h.close()

160 161
sys.exit(0)