summaryrefslogtreecommitdiff
path: root/sim/src/regression.py
blob: 90f65e6ed23f16cf11be949c992fed061a83405b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/python
# Copyright 2005-2006 Nanorex, Inc.  See LICENSE file for details. 

"""run regression tests

how to make a regression test:

Inside one of the directories listed below, you need to create three files.
I'm going to call them test_000X.* here.  Just number them sequentially
although that doesn't really matter.

The first file is the input data file for the test run.  It will
usually be called test_000X.mmp.  If it's called something else, or
there are more than one of them (or zero of them), you can specify
that using the INPUT directive in the .test file.

The second file is the test description file: test_000X.test.
This file describes the inputs, outputs, and program arguments
for the test.  The default values should be fine for minimizer tests.
For dynamics runs you'll need to specify the program arguments:

PROGRAM simulator -f900 -x test_000X.mmp

See runtest.sh for a complete description.

The third file is the expected output.  Generate this using
runtest.sh like this (in the test directory):

../../runtest.sh test_000X.test > test_000X.out

You can change the list of output files to be included
using the OUTPUT directive in the .test file.

Check this file to make sure the output looks reasonable, then
rerun regression.sh before checking in the test_000X.* files.
"""

import os
import sys
import filecmp
from shutil import copy
from os.path import join, basename, exists
from glob import glob
import runtest

testDirs = ["tests/minimize", "tests/dynamics", "tests/rigid_organics"]

exitStatus = 0
generate = False

try:
    if sys.argv[1] == "--generate":
        generate = True
except IndexError:
    pass

if exists("/tmp/testsimulator"):
    os.remove("/tmp/testsimulator")
# Windows doesn't have symbolic links, so copy the file.
copy("simulator", "/tmp/testsimulator")

for dir in testDirs:
    for testFile in glob(join(dir, "*.test")):
        print "Running " + testFile
        base = basename(testFile[:-5])
        out = join(dir, base + ".out")
        # Why do we not pass "--generate" to runtest???
        outf = open(out + ".new", "w")
        #runtest.main((testFile,), myStdout=outf, generate=generate)
        runtest.main((testFile,), myStdout=outf)
        outf.close()

        if generate and not exists(out):
            copy(out + ".new", out)
            print "Generated new " + out

        if filecmp.cmp(out, out + ".new"):
            os.remove(out + ".new")
        else:
            print >> sys.__stderr__, "Test failed: " + testFile
            os.system("diff %s %s.new > %s.diff" % (out, out, out))
            exitStatus = 1

os.remove("/tmp/testsimulator")