tsrc/scripts/codetest.py
changeset 15 ccd8e69b5392
parent 2 b31261fd4e04
child 20 e8be2c2e049d
child 22 496ad160a278
equal deleted inserted replaced
2:b31261fd4e04 15:ccd8e69b5392
     1 #
       
     2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description:
       
    15 #
       
    16 # codetest.py
       
    17 # Start EUnitExeRunner and collect relevent data's.
       
    18 
       
    19 #Import relevent modules
       
    20 import time,os,sys,re
       
    21 from ctest.DataObjM import CovObjDef
       
    22 from ctest import CTCommonDef
       
    23 from ctest.DataObjM import TaskObjDef 
       
    24 
       
    25 try:
       
    26 	
       
    27 	#Close Existing Workspace if any
       
    28 	ctob.closeWorkspace()
       
    29 	
       
    30 	#port is hardcored to 3020 which is default for codetest
       
    31 	port = int('3020')
       
    32 	
       
    33 	#Start CT Server
       
    34 	ctserverDir=os.environ.get("AMC_HOME")+'/bin/ctserver.exe'
       
    35 	os.spawnv(os.P_NOWAIT,ctserverDir,['ctserver'])
       
    36 	
       
    37 	# Create a SWIC/Native Data Source with a 30 second comm timeout.
       
    38 	ds = ctob.createCtSWIC('localhost', port, 30)
       
    39 	print ds.getName(), 'data source created...'
       
    40 	
       
    41 	# Set data source configuration information.
       
    42 	ds.setIDB('$TEMP/codetest.idb')
       
    43 	
       
    44 	# Connect to the data source.
       
    45 	ds.connect()
       
    46 	
       
    47 	# Put the data source into continuous mode.
       
    48 	ds.setContinuousMode()
       
    49 	
       
    50 	# Start data collection.
       
    51 	ds.start()
       
    52 	
       
    53 	#start EUnitExeRunner
       
    54 	print 'Starting application...'
       
    55 	myfile = open(os.environ.get("TEMP")+'\unitrunner.dat', 'r')      
       
    56 	commandList = myfile.readlines()
       
    57 	myfile.close()
       
    58 	parser = re.compile(r'\s')
       
    59 	options=parser.split(commandList[1])
       
    60 	eUnitExeRunner = commandList[0].rstrip()
       
    61 	os.spawnv(os.P_WAIT,eUnitExeRunner,options)
       
    62 	
       
    63 	print 'wait 5 seconds for data collection...'
       
    64 	# Wait for 10 seconds to allow data collection.
       
    65 	time.sleep(5)
       
    66 	
       
    67 	# Collect continuous mode data.
       
    68 	ds.collectData()
       
    69 	
       
    70 	# Stop data collection.
       
    71 	ds.stop()
       
    72 	
       
    73 	# At this point both continuous and trace data should appear in GUI.
       
    74 	# Save to a datafile
       
    75 	fileName ='$TEMP/codetest_result.dat'
       
    76 	retv = ds.saveData(fileName)
       
    77 	if retv:
       
    78 	  print '%s: data saved to %s.'%(ds.getName(), fileName)
       
    79 	else:
       
    80 	  print 'Error saving datafile!'
       
    81 	
       
    82 	ds.shutdown()
       
    83 
       
    84 except:
       
    85 	ds.shutdown()
       
    86 	sys.exit()
       
    87 	
       
    88 try :
       
    89 	# generate result
       
    90 	print 'Now generating results file......'
       
    91 	df = ctob.createCtDataFile(fileName)
       
    92 	print df.dataFileName(), ' data file loaded to workspace...'
       
    93 	
       
    94 	#Get data set objects
       
    95 	coverageObj0 = df.getCoverageObjs()[0]
       
    96 	print "Got dataset objects"
       
    97 	
       
    98 	coverageObj0.sortData('coverage',1)
       
    99 	coverageObj0.setViewFuncNameLong()
       
   100 	
       
   101 	coverageObj0.setFileCoverageMode()
       
   102 	cov_view_one = '$TEMP/codetest_file_coverage.html'
       
   103 	coverageObj0.exportView(cov_view_one, CTCommonDef.HTML_FORMAT,' ',' ' )
       
   104 	print 'Coverage details are saved in '+cov_view_one;
       
   105 	covReportFile = '$TEMP/codetest_summary.txt'
       
   106 	coverageObj0.writeCoverageReport(covReportFile, CovObjDef.OVERALL_SUMMARY)
       
   107 	print 'Overall coverage summary saved in '+covReportFile;
       
   108 	
       
   109 	covFunctionReportFile = '$TEMP/codetest_function_coverage.txt'
       
   110 	coverageObj0.writeCoverageReport(covFunctionReportFile, CovObjDef.FUNCTION_SUMMARY)
       
   111 	print 'Function coverage summary saved in '+covFunctionReportFile;
       
   112 	
       
   113 	covUnCoveredReportFile = '$TEMP/codetest_function_uncovered_statements.txt'
       
   114 	coverageObj0.writeCoverageReport(covUnCoveredReportFile, CovObjDef.UNCOVERED_ONLY)
       
   115 	print 'Uncovered coverage summary saved in '+covUnCoveredReportFile;
       
   116 
       
   117 except:
       
   118 	print 'Unable to write reports'
       
   119 	sys.exit()