OSDN Git Service

testing: more checks for memory leaks
authorMartin Renold <martinxyz@gmx.ch>
Sun, 25 Oct 2009 16:31:38 +0000 (17:31 +0100)
committerMartin Renold <martinxyz@gmx.ch>
Sun, 25 Oct 2009 16:39:54 +0000 (17:39 +0100)
lib/idletask.py
release.sh
tests/test_mypaintlib.py
tests/test_performance.py

index 688c98d..eab1bf5 100644 (file)
@@ -25,7 +25,6 @@ class Processor:
         self.finish_downto(self.max_pending)
 
     def finish_one(self):
-        print '.'
         func = self._queue.pop(0)
         func()
 
index 9d8c627..582e0ce 100755 (executable)
@@ -26,7 +26,7 @@ tar -cvjf $filename mypaint-$version
 
 cd $d
 scons debug=true
-tests/test_mypaintlib.py
+tests/test_mypaintlib.py --leak
 tests/test_performance.py -a -c 1
 
 ls -sSh $filename
index 49d92b0..cc991f7 100755 (executable)
@@ -198,32 +198,24 @@ def leakTest_fast():
     gc.collect()
     assert not gc.garbage, 'surface class leaks uncollectable garbage (regression)'
 
-def leakTest_slow():
-    # FIXME: known to fail
-    print 'memory leak test:'
+def leakTest_generic(func):
+    print 'memory leak test', func.__name__
     assert not gc.garbage, 'uncollectable garbage left over from previous tests'
 
     doc = document.Document()
-    def paint():
-        events = load('painting30sec.dat.gz')
-        t_old = events[0][0]
-        for i, (t, x, y, pressure) in enumerate(events):
-            dtime = t - t_old
-            t_old = t
-            doc.stroke_to(dtime, x, y, pressure)
-
     #gc.set_debug(gc.DEBUG_LEAK)
 
     m = []
-    for i in range(20):
-        paint()
-        doc.clear()
+    N = 20
+    for i in range(N):
+        func(doc, i)
         m2 = mem()
         m.append(m2)
-        print 'iteration %02d/100: %d pages used' % (i, m2)
+        print 'iteration %02d/%02d: %d pages used' % (i+1, N, m2)
 
-    for i in range(10,20):
-        assert m[i] == m[9], 'memory leak during paint/clear cycles'
+    print m
+    for i in range(N/2,N):
+        assert m[i] == m[9], 'looks like a memory leak in ' + func.__name__
 
     #import objgraph
     #from lib import strokemap
@@ -234,12 +226,50 @@ def leakTest_slow():
 
     # note: if gc.DEBUG_LEAK is enabled above this is expected to fail
     assert not gc.garbage
-    print 'no leaks found'
+    print 'no leak found'
+
+def leakTest_slow():
+
+    def paint(doc):
+        events = load('painting30sec.dat.gz')
+        t_old = events[0][0]
+        for i, (t, x, y, pressure) in enumerate(events):
+            dtime = t - t_old
+            t_old = t
+            doc.stroke_to(dtime, x, y, pressure)
+
+    def paint_and_clear(doc, iteration):
+        paint(doc)
+        doc.clear()
+
+    def repeated_saving(doc, iteration):
+        if iteration == 0:
+            paint(doc)
+        doc.save('test_leak.ora')
+        doc.save('test_leak.png')
+        doc.save('test_leak.jpg')
+
+    def repeated_loading(doc, iteration):
+        doc.load('bigimage.ora')
+
+    def paint_save_clear(doc, iteration):
+        paint(doc)
+        doc.save('test_leak.ora')
+        doc.clear()
+
+    leakTest_generic(paint_and_clear)
+    leakTest_generic(repeated_saving)
+    leakTest_generic(repeated_loading)
+    leakTest_generic(paint_save_clear)
 
 directPaint()
 brushPaint()
 docPaint()
 leakTest_fast()
-leakTest_slow()
+if '--leak' in sys.argv:
+    leakTest_slow()
+else:
+    print
+    print 'Skipping slow memory leak tests (use --leak to run them).'
 
 print 'Tests passed.'
index bc2ada2..bb8f902 100755 (executable)
@@ -87,7 +87,7 @@ def paint(app):
     tdw = dw.tdw
 
     for b in app.brushes:
-        if b.name == 'redbrush':
+        if b.name == brush:
             app.select_brush(b)
 
     dw.fullscreen_cb()