tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

cov-display (1949B)


      1 #!/usr/bin/python
      2 import sys, re, os
      3 
      4 none0, some0 = 0,0
      5 branchTaken0, branchNot0 = 0,0
      6 
      7 BRANCH = False
      8 FUNC = False
      9 
     10 if sys.argv[1] == '-b':
     11     BRANCH = True
     12     del sys.argv[1]
     13 
     14 if sys.argv[1] == '-f':
     15     FUNC = True
     16     del sys.argv[1]
     17 
     18 def show(name, none, some):
     19     if some+none == 0:
     20         none = 1
     21     print name, none, some, "%.02f"%(100*(float(some)/(some+none)))
     22 
     23 
     24 file_args = sys.argv[1:]
     25 files = []
     26 for fn in file_args:
     27     if os.path.isdir(fn):
     28         files.extend(os.path.join(fn, f) for f in os.listdir(fn))
     29     else:
     30         files.append(fn)
     31 
     32 for fn in files:
     33     none = some = branchTaken = branchNot = 0
     34     inFunc = ""
     35     for line in open(fn, 'r'):
     36         m = re.match(r'^[^:]*:([^:]*):(.*)', line)
     37         if m:
     38             body = m.group(2).rstrip()
     39             lineno = m.group(1).strip()
     40         else:
     41             body = ""
     42             lineno = "?"
     43         m = re.match(r'^([A-Za-z_][A-Za-z0-9_]*)(?:, *)?\(', body)
     44         if m:
     45 	    inFunc = "%s:%s %s" %(fn,lineno,m.group(1))
     46 	elif body == "}":
     47 	    if FUNC and inFunc:
     48      	        show(inFunc, none, some)
     49                 none = some = 0
     50                 inFunc = None
     51         if re.match(r'^ *###', line):
     52             none += 1
     53         elif re.match(r'^ *\d', line):
     54             some += 1
     55         else:
     56             m = re.match(r'^branch.*taken (\d+)%', line)
     57             if m:
     58                 if int(m.group(1)) == 0:
     59                     branchNot += 1
     60                 else:
     61                     branchTaken += 1
     62 
     63     none0 += none
     64     some0 += some
     65     branchTaken0 += branchTaken
     66     branchNot0 += branchNot
     67     if FUNC:
     68        pass
     69     elif BRANCH:
     70         if branchTaken or branchNot:
     71             show(fn, branchNot, branchTaken)
     72     else:
     73         if some or none:
     74             show(fn, none, some)
     75 
     76 if BRANCH:
     77     if branchTaken0 or branchNot0:
     78         show("TOTAL", branchNot0, branchTaken0)
     79 else:
     80     if some0 or none0:
     81         show("TOTAL", none0, some0)