]> git.donarmstrong.com Git - lilypond.git/commitdiff
updates for coverage scripts
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Wed, 3 Jan 2007 19:54:44 +0000 (20:54 +0100)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Wed, 3 Jan 2007 19:54:44 +0000 (20:54 +0100)
buildscripts/build-coverage.sh
buildscripts/coverage.py

index 13a073188b78e8c5fd928da575143846ee74b427..6f48d18f0e20ae2f0383a37c8880bc7d514a4d82 100755 (executable)
@@ -10,18 +10,23 @@ fi
 
 if test "$fresh" = "yes";
 then
-  ./configure --enable-config=cov --disable-optimising
-  make conf=cov -j2 clean
-  perl -i~ -pe 's/-pipe /-fprofile-arcs -ftest-coverage -pipe /g' config-cov.make
-  perl -i~ -pe 's/ -ldl / -lgcov -ldl /g' config-cov.make
+  ./configure --enable-config=cov --disable-optimising \
+   &&   make conf=cov -j2 clean \
+   &&   perl -i~ -pe 's/-pipe /-fprofile-arcs -ftest-coverage -pipe /g' config-cov.make \
+   &&   perl -i~ -pe 's/ -ldl / -lgcov -ldl /g' config-cov.make
 else
   find -name '*.gcda' -exec rm  '{}' ';'
 fi
 
 
-make conf=cov -j2
-make conf=cov test-clean LILYPOND_JOBS=          
-make conf=cov test LILYPOND_JOBS= >& out-cov/test-run.log
+make conf=cov -j2 &&  \
+  make conf=cov test-real-clean LILYPOND_JOBS= && \
+  make conf=cov test LILYPOND_JOBS= >& out-cov/test-run.log
+
+if test "$?" != "0"; then
+  tail -100 out-cov/test-run.log
+  exit 1
+fi
 
 rm -rf out-cov
 mkdir out-cov
@@ -36,4 +41,10 @@ do
    gcov -o ../lily/out-cov/  -p $a > $a.gcov-summary
 done 
 
-python buildscripts/coverage.py
+cat <<EOF
+
+now run 
+
+         python buildscripts/coverage.py
+
+EOF
index 62a68cb0bb0566a651243d0c028942132d6ea433..f4397e10e0eaacf0bc292db788685165b3012fc0 100644 (file)
 import os
 import glob
 import re
-
-os.chdir ('out-cov')
+import sys
+import optparse
 
 #File 'accidental-engraver.cc'
 #Lines executed:87.70% of 252
 
-results = []
-for f in glob.glob ('*.gcov-summary'):
-    str = open (f).read ()
-    m = re.search ("File '([^']+.cc)'\s*Lines executed:([0-9.]+)% of ([0-9]+)", str)
-
-    if m and '/usr/lib' in m.group (1):
-        continue
-   
-    if m:
-        cov = float (m.group (2))
-        lines = int (m.group (3))
-        pain = lines * (100.0 - cov)
-        file = m.group (1)
-        tup = (pain, locals ().copy())
+def summary (args):
+    results = []
+    for f in args:
+        str = open (f).read ()
+        m = re.search ("File '([^']+.cc)'\s*Lines executed:([0-9.]+)% of ([0-9]+)", str)
+
+        if m and '/usr/lib' in m.group (1):
+            continue
+
+        if m:
+            cov = float (m.group (2))
+            lines = int (m.group (3))
+            pain = lines * (100.0 - cov)
+            file = m.group (1)
+            tup = (pain, locals ().copy())
+
+            results.append(tup)
+
+    results.sort ()
+    results.reverse()
+
+    print 'files sorted by number of untested lines (decreasing)'
+    print
+    print '%5s (%6s): %s' % ('cov %', 'lines', 'file')
+    print '----------------------------------------------'
+
+    for (pain, d) in results:
+        print '%(cov)5.2f (%(lines)6d): %(file)s' % d
+
+
+
+def read_gcov (f):
+    ls = []
+
+    in_lines = [l for l in open (f).readlines ()]
+    (count_len, line_num_len) = tuple (map (len, in_lines[0].split( ':')[:2]))
+    
+    for l in in_lines:
+        c = l[:count_len].strip ()
+        l = l[count_len+1:]
+        n = int (l[:line_num_len].strip ())
+
+        if n == 0:
+            continue
+        
+        l = l[line_num_len+1:]
+
+        ls.append ((c,n,l))
         
-        results.append(tup)
+    return ls
 
-results.sort ()
-results.reverse()
+def get_chunks (ls):
+    chunks = []
+    chunk = []
+    for (c,n,l) in ls:
+        if '#' in c:
+            chunk.append ((n,l))
+        elif c.strip () != '-' or l == '}\n':
+            if chunk:
+                chunks.append (chunk)
+                chunk = []
+            
+    return chunks
 
-print 'files sorted by number of untested lines (decreasing)'
-print
-print '%5s (%6s): %s' % ('cov %', 'lines', 'file')
-print '----------------------------------------------'
+def is_exception_chunk (ch):
+    for (n,l) in ch:
+        for stat in  ('warning', 'error'):
+            if stat in l:
+                return True
+    return False
 
-for (pain, d) in results:
-    print '%(cov)5.2f (%(lines)6d): %(file)s' % d
+def print_chunk (ch, lines):
+    nums = [n-1 for (n, l) in ch]
+    for (c, n, l) in lines[min (nums):max (nums)+1]:
+        sys.stdout.write ('%8s:%8d:%s' % (c,n,l))
+
+
+def extract_uncovered (file):
+    try:
+        ls = read_gcov (file)
+    except IOError, s :
+        print s
+        return
+        
+    cs = get_chunks (ls)
+    cs = [c for c in cs if not is_exception_chunk (c)]
+    print '\n'.join (['%d' % x for (a,x,b) in ls])
+    for c in cs:
+        print 'Uncovered chunk in', file
+        print_chunk (c, ls)
+        print '\n\n: '
+    
 
+def main ():
+    p = optparse.OptionParser (usage="usage coverage.py [options] files",
+                               description="")
+    p.add_option ("--summary",
+                  action='store_true',
+                  default=False,
+                  dest="summary")
+    
+    p.add_option ("--uncovered",
+                  default=False,
+                  action='store_true',
+                  dest="uncovered")
+
+    
+    (options, args) = p.parse_args ()
+    
+
+    if options.summary:
+        summary (['%s.gcov-summary' % s for s in args])
+
+    if options.uncovered:
+        for a in args:
+            extract_uncovered ('%s.gcov' % a)
+        
+        
+if __name__ == '__main__':
+    main ()