3838from collections import defaultdict
3939from pprint import pprint
4040import subprocess
41+ import argparse
4142
4243from vcast_utils import dump , checkVectorCASTVersion
4344
@@ -112,9 +113,9 @@ def runCoverageResultsMP(mpFile, verbose = False, testName = "", source_root = "
112113 vcproj = VCProjectApi (mpFile )
113114 api = vcproj .project .cover_api
114115
115- return runGcovResults (api , verbose = False , testName = vcproj .project .name , source_root = source_root )
116+ return runGcovResults (api , verbose = verbose , testName = vcproj .project .name , source_root = source_root )
116117
117- def runGcovResults (api , verbose = False , testName = "" , source_root = "" ):
118+ def runGcovResults (api , verbose = False , testName = "" , source_root = "" ) :
118119
119120 fileDict = {}
120121 try :
@@ -167,11 +168,13 @@ def runGcovResults(api, verbose = False, testName = "", source_root = ""):
167168 FNDA .append ("FNDA:1" + "," + fName )
168169 else :
169170 FNDA .append ("FNDA:0" + "," + fName )
170-
171+
171172 block_count = 0
172173 branch_number = 0
173174 line_branch = []
174-
175+
176+ last_line = ""
177+
175178 for line in func .iterate_coverage ():
176179 if has_any_coverage (line ):
177180 LF += 1
@@ -182,6 +185,8 @@ def runGcovResults(api, verbose = False, testName = "", source_root = ""):
182185 lineCovered = "0"
183186 DA .append ("DA:" + str (line .line_number ) + "," + lineCovered )
184187
188+ last_line = line .text
189+
185190 newBranch = False
186191 if has_branch_coverage (line ) > 0 :
187192 BRF += 1
@@ -200,6 +205,13 @@ def runGcovResults(api, verbose = False, testName = "", source_root = ""):
200205 if newBranch :
201206 block_count += 1
202207 branch_number += 1
208+
209+
210+ if "return" not in last_line :
211+ if verbose : print ("counting last line: " , func .name , line .line_number ,last_line )
212+ DA .append ("DA:" + str (line .line_number ) + ",1" )
213+ else :
214+ if verbose : print ("not counting last line: " , func .name , line .line_number ,last_line )
203215
204216 for idx in range (0 ,len (FN )):
205217 output += FN [idx ] + "\n "
@@ -268,22 +280,34 @@ def generateCoverageResults(inFile, xml_data_dir = "xml_data", verbose = False,
268280 if not checkVectorCASTVersion (21 ):
269281 print ("Cannot create LCOV metrics. Please upgrade VectorCAST" )
270282 sys .exit ()
271-
283+
284+ parser = argparse .ArgumentParser ()
285+ parser .add_argument ('vcProjectName' , help = 'VectorCAST Project Name' , action = "store" )
286+ parser .add_argument ('-v' , '--verbose' , help = 'Enable versobe output' , dest = "verbose" , action = "store_true" , default = False )
287+ args = parser .parse_args ()
288+
272289 try :
273- inFile = sys . argv [ 1 ]
290+ inFile = args . vcProjectName
274291 if not inFile .endswith (".vcm" ):
275292 inFile += ".vcm"
276293 except :
277294 inFile = os .getenv ('VCAST_MANAGE_PROJECT_DIRECTORY' ) + ".vcm"
295+
296+ if args .verbose : print ("Running in verbose mode" )
278297
279- passed = generateCoverageResults (inFile , xml_data_dir = "xml_data" , verbose = False , source_root = "" )
298+ passed = generateCoverageResults (inFile , xml_data_dir = "xml_data" , verbose = args . verbose , source_root = "" )
280299
281- ## if opened from VectorCAST GUI...
282- if passed and not os .getenv ('VCAST_MANAGE_PROJECT_DIRECTORY' ) is None :
283- from vector .lib .core import VC_Report_Client
300+ try :
301+ ## if opened from VectorCAST GUI...
302+ if passed and not os .getenv ('VCAST_MANAGE_PROJECT_DIRECTORY' ) is None :
303+ from vector .lib .core import VC_Report_Client
304+
305+ # Open report in VectorCAST GUI
306+ report_client = VC_Report_Client .ReportClient ()
307+ if report_client .is_connected ():
308+ report_client .open_report ("out/index.html" , "lcov Results" )
309+ except :
310+ pass
311+
284312
285- # Open report in VectorCAST GUI
286- report_client = VC_Report_Client .ReportClient ()
287- if report_client .is_connected ():
288- report_client .open_report ("out/index.html" , "lcov Results" )
289313
0 commit comments