|
39 | 39 | from pprint import pprint |
40 | 40 | import subprocess |
41 | 41 | import argparse |
42 | | -import inspect |
43 | 42 |
|
44 | 43 | from vcast_utils import dump, checkVectorCASTVersion, getVectorCASTEncoding, checkProjectResults |
45 | 44 | try: |
46 | 45 | from safe_open import open |
47 | 46 | except: |
48 | 47 | pass |
49 | 48 |
|
50 | | -from vector.apps.DataAPI.coverdb import SourceFunction |
51 | | - |
52 | | -orig_iter = SourceFunction.iterate_coverage # snapshot original method |
53 | | - |
54 | 49 | try: |
55 | 50 | import math |
56 | 51 | INF = math.inf |
57 | 52 | except Exception: |
58 | 53 | INF = float("inf") # Py2-compatible |
59 | | - |
60 | 54 | encFmt = getVectorCASTEncoding() |
61 | 55 |
|
62 | 56 | fileList = [] |
63 | 57 |
|
64 | | -# specifically for 2022sp8 issue with start/end being None |
65 | | -def _safe_iterate_coverage(self, **kwargs): |
66 | | - |
67 | | - # Drop-in wrapper for SourceFile.iterate_coverage() |
68 | | - # - Accepts any kwargs (future-proof) |
69 | | - # - Provides sane defaults for start/end |
70 | | - # - Adds encoding only if supported |
71 | | - # - Filters kwargs to match the original method's signature (no TypeError) |
72 | | - |
73 | | - |
74 | | - # Always present in VC versions |
75 | | - kwargs.setdefault("aggregate", True) |
76 | | - |
77 | | - # Pull caller/attributes (don't coerce yet) |
78 | | - start = kwargs.get("start", getattr(self, "start_line", None)) |
79 | | - end = kwargs.get("end", getattr(self, "end_line", None)) |
80 | | - |
81 | | - # --- IMPORTANT: handle the "both missing" case FIRST --- |
82 | | - if start is None and end is None: |
83 | | - start = 0 |
84 | | - try: |
85 | | - if getattr(self, "instrumented_files", None): |
86 | | - end = os.path.getsize(self.instrumented_files[0].display_path) |
87 | | - else: |
88 | | - end = INF |
89 | | - except Exception: |
90 | | - end = INF |
91 | | - |
92 | | - # Now handle single-None cases (keep legitimate 0) |
93 | | - if start is None: |
94 | | - start = 0 |
95 | | - if end is None: |
96 | | - end = INF |
97 | | - |
98 | | - kwargs["start"] = start |
99 | | - kwargs["end"] = end |
100 | | - |
101 | | - # Let caller override; otherwise provide encoding |
102 | | - kwargs.setdefault("encoding", encFmt) |
103 | | - |
104 | | - # Filter kwargs to what the current VectorCAST build supports |
105 | | - try: |
106 | | - sig = inspect.signature(orig_iter) # Py3 |
107 | | - valid = set(sig.parameters.keys()) |
108 | | - except Exception: |
109 | | - spec = inspect.getargspec(orig_iter) # Py2 |
110 | | - valid = set(spec.args) |
111 | | - |
112 | | - safe_kwargs = {k: v for k, v in kwargs.items() if k in valid} |
113 | | - |
114 | | - for line in orig_iter(self, **safe_kwargs): |
115 | | - yield line |
116 | | - |
117 | | -def lcov_iterate_coverage(sf, **kwargs): |
118 | | - # Your safe wrapper logic here |
119 | | - return _safe_iterate_coverage(sf, **kwargs) |
120 | | - |
121 | 58 | def getCoveredFunctionCount(source): |
122 | 59 | if len(source.functions) == 0: |
123 | 60 | return 0,0 |
@@ -205,23 +142,25 @@ def get_function_name_line_number(file_path, function, initial_guess): |
205 | 142 |
|
206 | 143 | def runCoverageResultsMP(mpFile, verbose = False, testName = "", source_root = ""): |
207 | 144 |
|
208 | | - vcproj = VCProjectApi(mpFile) |
| 145 | + with VCProjectApi(mpFile) as vcproj: |
209 | 146 |
|
210 | | - anyLocalResults, anyImportedResults = checkProjectResults(vcproj) |
| 147 | + anyLocalResults, anyImportedResults = checkProjectResults(vcproj) |
211 | 148 |
|
212 | | - if anyImportedResults: |
213 | | - importedResultsError = " ** LCOV results does not processing imported results at this time\n\n" |
214 | | - print(importedResultsError) |
215 | | - return importedResultsError |
216 | | - |
217 | | - if not anyLocalResults: |
218 | | - localResultsError = " ** No local results in project to process\n\n" |
219 | | - print(localResultsError) |
220 | | - return localResultsError |
| 149 | + if anyImportedResults: |
| 150 | + importedResultsError = " ** LCOV results does not processing imported results at this time\n\n" |
| 151 | + print(importedResultsError) |
| 152 | + return importedResultsError |
| 153 | + |
| 154 | + if not anyLocalResults: |
| 155 | + localResultsError = " ** No local results in project to process\n\n" |
| 156 | + print(localResultsError) |
| 157 | + return localResultsError |
221 | 158 |
|
222 | | - api = vcproj.project.cover_api |
| 159 | + api = vcproj.project.cover_api |
| 160 | + |
| 161 | + results = runGcovResults(api, verbose = verbose, testName = vcproj.project.name, source_root=source_root) |
223 | 162 |
|
224 | | - return runGcovResults(api, verbose = verbose, testName = vcproj.project.name, source_root=source_root) |
| 163 | + return results |
225 | 164 |
|
226 | 165 | def runGcovResults(api, verbose = False, testName = "", source_root = "") : |
227 | 166 |
|
@@ -305,7 +244,7 @@ def runGcovResults(api, verbose = False, testName = "", source_root = "") : |
305 | 244 |
|
306 | 245 | lastLine = None |
307 | 246 |
|
308 | | - for line in lcov_iterate_coverage(func): |
| 247 | + for line in func.iterate_coverage(): |
309 | 248 | if has_any_coverage(line): |
310 | 249 | lastLine = line |
311 | 250 | LF += 1 |
|
0 commit comments