22import cmdlinewrapper
33import difflib
44import pprint
5- import csv
5+
6+ import runhelpers
7+
68
79class DepthmapRunner ():
810 def __init__ (self , runFunc , binary ):
@@ -22,88 +24,40 @@ def diffBinaryFiles(file1, file2):
2224 gen = difflib .diff_bytes (difflib .unified_diff , [content1 ], [content2 ])
2325 return not (list (gen ))
2426
25- def checkPerformance (baseFile , testFile ):
26- """
27- Check the performance of 2 depthmap runs against each other
28- This function expects the timing from a base and test run and parses them
29- as CSV. For now, it expects the entries to be the same. It will return an
30- error message if
31- * one or both of the files are missing
32- * the number of lines or the labels don't match
33- * the test run is more than 5 seconds or 5% slower than the baseline
34- (whatever is greater)
35- """
36- if not os .path .exists (baseFile ):
37- return "Base performance timing file {0} is missing" .format (baseFile )
38- if not os .path .exists (testFile ):
39- return "Test performance timing file {0} is missing" .format (testFile )
40- with open (baseFile ) as baseHandle , open (testFile ) as testHandle :
41- baseReader = csv .DictReader (baseHandle )
42- testReader = csv .DictReader (testHandle )
43-
44- baseDone = False
45- testDone = False
46-
47- while True :
48- try :
49- baseLine = next (baseReader )
50- except StopIteration :
51- baseDone = True
52-
53- try :
54- testLine = next (testReader )
55- except StopIteration :
56- testDone = True
57-
58- if baseDone and testDone :
59- return ""
60- if baseDone and not testDone :
61- return "baseline performance file {0} has fewer lines than the test one {1}" .format (baseFile , testFile )
62- if testDone and not baseDone :
63- return "baseline performance file {0} has more lines than the test one {1}" .format (baseFile , testFile )
64-
65- if not baseLine ["action" ] == testLine ["action" ]:
66- return "performance line mismatch: base '{0}', test '{1}'" .format (baseLine ["action" ], testLine ["action" ])
67-
68- baseTime = float (baseLine ["duration" ])
69- testTime = float (testLine ["duration" ])
70-
71- allowance = max (5.0 , baseTime / 20.0 )
72- if testTime > baseTime + allowance :
73- return "Performance regression: {0} took {1}s instead of {2}s" .format (baseLine ["action" ], testLine ["duration" ], baseLine ["duration" ])
74-
75-
76-
7727class DepthmapRegressionRunner ():
7828 def __init__ (self , runFunc , baseBinary , testBinary , workingDir ):
7929 self .__baseRunner = DepthmapRunner (runFunc , baseBinary )
8030 self .__testRunner = DepthmapRunner (runFunc , testBinary )
8131 self .__workingDir = workingDir
8232
83- def runTestCase (self , name , infile , outfile , mode , simpleMode = False , subcmds = [], timingFile = "runtimes.csv" ):
84- cmd = cmdlinewrapper .DepthmapCmd ()
85- cmd .infile = infile
86- cmd .outfile = outfile
87- cmd .mode = mode
88- cmd .simpleMode = simpleMode
89- cmd .modeLines = subcmds
90- cmd .timingFile = timingFile
33+ def makeBaseDir (self , name ):
34+ return os .path .join (self .__workingDir , name + "_base" )
35+
36+ def makeTestDir (self , name ):
37+ return os .path .join (self .__workingDir , name + "_test" )
38+
39+ def runTestCase (self , name , cmd ):
40+ runhelpers .prepareDirectory (self .makeBaseDir (name ))
41+ runhelpers .prepareDirectory (self .makeTestDir (name ))
42+ return self .runTestCaseImpl (name , cmd )
9143
92- baseDir = os .path .join (self .__workingDir , name + "_base" )
44+ def runTestCaseImpl (self , name , cmd ):
45+ baseDir = self .makeBaseDir (name )
9346 (baseSuccess , baseOut ) = self .__baseRunner .runDepthmap (cmd , baseDir )
9447 if not baseSuccess :
9548 print ("Baseline run failed with arguments " + pprint .pformat (cmd .toCmdArray ()))
9649 print (baseOut )
9750 return (False , "Baseline run failed" )
98- testDir = os .path .join (self .__workingDir , name + "_test" )
51+
52+ testDir = self .makeTestDir (name )
9953 (testSuccess , testOut ) = self .__testRunner .runDepthmap (cmd , testDir )
10054 if not testSuccess :
10155 print ("Test run failed with arguments " + pprint .pformat (cmd .toCmdArray ()))
10256 print (testOut )
10357 return (False , "Test run failed" )
10458
105- baseFile = os .path .join (baseDir , outfile )
106- testFile = os .path .join (testDir , outfile )
59+ baseFile = os .path .join (baseDir , cmd . outfile )
60+ testFile = os .path .join (testDir , cmd . outfile )
10761 if not os .path .exists (baseFile ):
10862 message = "Baseline output {0} does not exist" .format (baseFile )
10963 print (message )
@@ -118,11 +72,6 @@ def runTestCase(self, name, infile, outfile, mode, simpleMode = False, subcmds =
11872 print (message )
11973 return (False , message )
12074
121- message = checkPerformance ( os .path .join (baseDir , timingFile ), os .path .join (testDir , timingFile ))
122- if message :
123- print (message )
124- return (False ,message )
125-
12675 return (True , "" )
12776
12877
0 commit comments