~inkscape.dev/inkscape-rendertest/trunk

« back to all changes in this revision

Viewing changes to runtests.py

  • Committer: Johan B. C. Engelen
  • Date: 2014-11-12 22:15:59 UTC
  • mfrom: (1.1.1 inkscape-rendertest)
  • Revision ID: j.b.c.engelen@alumnus.utwente.nl-20141112221559-f29vvnppiedx8ona
Add modified PerceptualDiff code (alpha fix)

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
parser.add_option("-d", "--directory", dest="directory", help="test directory", default=".")
12
12
parser.add_option("-i", "--inkscape", dest="inkscape", help="path to inkscape", default="inkscape")
13
13
parser.add_option("--compare-png", dest="comparepng", help="PNG comparison tool", default="")
 
14
parser.add_option("--timeout", type="int", dest="timeout", help="Time given to Inkscape to render each file (in seconds)", default=20)
14
15
(options, args) = parser.parse_args()
15
16
#args = ['bugs']
16
17
timestamp = datetime.utcnow().isoformat();
111
112
    executionlog.flush()
112
113
    executionlog.write('\n')
113
114
    return result
 
115
def executeSilentlyTimed(cmd, timeout):
 
116
    result = -1
 
117
    header = 'Executing: %s (timeout after %ds)' % cmd, timeout
 
118
    executionlog.write(header + '\n')
 
119
    executionlog.write(('-' * len(header)) + '\n')
 
120
    executionlog.flush()
 
121
    proc = subprocess.Popen(cmd, stdout=executionlog, stderr=executionlog, shell=True)
 
122
 
 
123
    st = time.time() 
 
124
    while (time.time()-st) < timeout:
 
125
        time.sleep(1)
 
126
        if proc.poll() is not None:
 
127
            break
 
128
            
 
129
    if proc.poll() is None: # timeout was reached, kill the thing
 
130
        proc.kill()
 
131
        executionlog.write('>>> KILLED INKSCAPE PROCESS <<<')
 
132
        return 666
 
133
 
 
134
    result = proc.returncode
 
135
    executionlog.flush()
 
136
    executionlog.write('\n')
 
137
    return result
 
138
 
 
139
def testRenderSVGtoPNG(name, ext):
 
140
    outputName = name + '.png'
 
141
    patchFile = os.path.join(casesDirectory, name + '-patch' + ext)
 
142
    patchOutput = os.path.join(passReferencesDirectory, name + '-patch.png')
 
143
    if os.path.exists(patchFile):
 
144
        if isNewerThan(patchFile,patchOutput):
 
145
            ensureDirectoryExists(os.path.dirname(patchOutput))
 
146
            inkscapeCmd = '%(inkscape)s -e "%(output)s" "%(input)s"' % \
 
147
                          {'inkscape': inkscapePath, 'output': patchOutput, 'input': patchFile}
 
148
            print "Rendering patch for %s" % name
 
149
            result = executeSilently(inkscapeCmd)
 
150
            if result != 0:
 
151
                return {'result': 40, 'output': outputName}
 
152
    elif os.path.exists(patchOutput):
 
153
        print "Removing old patch for %s" % name
 
154
        os.remove(patchOutput)
 
155
    output = os.path.join(newDirectory, outputName)
 
156
    ensureDirectoryExists(os.path.split(output)[0])
 
157
    inkscapeCmd = '%(inkscape)s -e "%(output)s" "%(input)s"' % \
 
158
                  {'inkscape': inkscapePath, 'output': output, 'input': os.path.join(casesDirectory,name+ext)}
 
159
    # execute inkscapeCmd, but make sure it does not take longer than x seconds
 
160
    result = executeSilentlyTimed(inkscapeCmd, )
 
161
    return {'result': result, 'output': outputName}
 
162
 
114
163
def testRender(name, ext):
115
164
    outputName = name+'.png'
116
165
    patchFile = os.path.join(casesDirectory, name+'-patch'+ext)
146
195
def extensionOf(tc):
147
196
    (path,ext) = os.path.splitext(tc)
148
197
    return ext
149
 
testHandlers = {'.svg':testRender}
 
198
 
 
199
testHandlers = {'.svg':testRenderSVGtoPNG}
150
200
resultCodes = {0: 'Pass', 1: 'Fail', 2: 'New', 3: 'No references', \
151
201
               10: 'Error', 11: 'Crash', \
152
202
               20: 'Syntax error', 21: 'Unable to stat/open file', \
153
203
               30: 'Compare error', 31: 'Compare crash',
154
 
               40: 'Error creating reference from patch'}
 
204
               40: 'Error creating reference from patch',
 
205
               666: 'Timeout'}
155
206
resultCounts = {}
156
207
for relpath in testCases:
157
208
    (name,ext) = os.path.splitext(relpath)