Add 'Function coverage' column to coverage report 06/153806/2 accepted/tizen/unified/20171005.125936 submit/tizen/20171005.093519
authorDmitriy Nikiforov <d.nikiforov@samsung.com>
Fri, 29 Sep 2017 15:49:57 +0000 (18:49 +0300)
committerDmitriy Nikiforov <d.nikiforov@samsung.com>
Wed, 4 Oct 2017 14:20:17 +0000 (17:20 +0300)
Function coverage reflects the ratio of all at least partly covered functions
to all instrumented functions in file or in total.

Previous 'Coverage' column is renamed to 'Edge coverage'.

Change-Id: I578ddeb651843cddd9bad7639911489cc353def2

scripts/coverage-report-dump.py

index 9c16f4f9ba38db604b190cd3fea9e121ea050a1d..6440028e32ee947be154bf68a1af1333facbd8b8 100755 (executable)
@@ -37,7 +37,11 @@ INDEX_PAGE_TMPL = """
 </head>
 <body>
     <table>
-      <tr><th>File</th><th>Coverage</th></tr>
+      <tr>
+        <th>File</th>
+        <th title=\"Ratio of covered edge points to all edge points in file.\">Edge Coverage</th>
+        <th width=200 align=\"right\" title=\"Ratio of all at least partly covered functions to \
+all instrumented functions in file or in total.\">Functions Coverage</th></tr>
       <tr><td><em>Files with 0 coverage are not shown.</em></td></tr>
 $filenames
     </table>
@@ -104,23 +108,34 @@ class SymcovData:
         """Build a filename->pct coverage."""
         result = dict()
         all_points = set()
+        all_funcs_cnt = 0
+        cov_funcs_cnt = 0
         for filename, fns in self.point_symbol_info.items():
             file_points = []
+            cov_file_funcs_cnt = 0
             for fn, points in fns.items():
+                all_funcs_cnt += 1
+                if len(set(points) & self.covered_points) > 0:
+                    cov_funcs_cnt += 1
+                    cov_file_funcs_cnt += 1
                 file_points.extend(points.keys())
             covered_points = self.covered_points & set(file_points)
             all_points |= set(file_points)
-            result[filename] = int(math.ceil(
-                len(covered_points) * 100 / len(file_points)))
+            result[filename] = (
+                int(math.ceil(len(covered_points) * 100 / len(file_points))),
+                int(math.ceil(cov_file_funcs_cnt * 100 / len(fns)))
+            )
+
+        result[SymcovData.TOTAL_COV_KEY] = (
+            int(math.ceil(len(self.covered_points) * 100 / len(all_points))),
+            int(math.ceil(cov_funcs_cnt * 100 / all_funcs_cnt))
+        )
 
-        result[SymcovData.TOTAL_COV_KEY] = int(math.ceil(
-            len(self.covered_points) * 100 / len(all_points)))
         return result
 
     def total_coverage(self):
         return self.file_coverage[SymcovData.TOTAL_COV_KEY]
 
-
 def format_pct(pct):
     pct_str = str(max(0, min(100, pct)))
     zeroes = '0' * (3 - len(pct_str))
@@ -189,22 +204,25 @@ class DumpCov():
                 if filename.startswith(tuple(exclude_headers)) and\
                    filename.endswith((".h", ".hpp")):
                     continue
-            file_coverage = self.__symcov_data.file_coverage[filename]
-            if not file_coverage:
+            edge_coverage, funcs_coverage = self.__symcov_data.file_coverage[filename]
+            if not edge_coverage:
                 continue
             filelist.append(
                 "<tr><td><a href=\"./{name}.html\">{name}</a></td>"
-                "<td>{coverage}%</td></tr>".format(
+                "<td align=\"right\">{edge}%</td><td align=\"right\">{funcs}%</td></tr>".format(
                     name=self.__html_chars_escape(filename),
-                    coverage=format_pct(file_coverage)))
+                    edge=format_pct(edge_coverage),
+                    funcs=format_pct(funcs_coverage)))
             # TODO: Print it pretty
-            print("{:<76} {}%".format(filename, file_coverage))
+            print("{:<76} {}% {}%".format(filename, edge_coverage, funcs_coverage))
             self.__dump_src_file(filename)
 
+        total_edge, total_funcs = self.__symcov_data.total_coverage()
         filelist.append(
-            "<tr><td><b>Total coverage</b></td>"
-            "<td>{coverage}%</td></tr>".format(
-                coverage=format_pct(self.__symcov_data.total_coverage())))
+            "<tr><td><b>Total</b></td>"
+            "<td align=\"right\">{edge}%</td><td align=\"right\">{funcs}%</td></tr>".format(
+                edge=format_pct(total_edge),
+                funcs=format_pct(total_funcs)))
 
         response = string.Template(INDEX_PAGE_TMPL).safe_substitute(
             filenames='\n'.join(filelist))