Question: Note : Can you please explain what is done inside this code.Please explain every line in easy language. def getStatementCoveragePercentage(outputFilePath): outputLines =[] with open(outputFilePath, r)

Note : Can you please explain what is done inside this code.Please explain every line in easy language.

def getStatementCoveragePercentage(outputFilePath):

outputLines =[]

with open(outputFilePath, "r") as f:

outputLines = f.readlines()

lineCoveragePercent = -1

for line in outputLines:

substr1 = "Lines executed:"

if substr1 in line:

lineCoveragePercent = line.split(":")[1].split("%")[0]

lineCoveragePercent = float(lineCoveragePercent)

return lineCoveragePercent

def randomPriorityStatementCoverageTcas(tcasDirPath, tcasCFilePath, tcasOutputFilePath, lines,benchmarkName):

globalLineCoveragePercent = -1.0

statementCoverageLines = []

visited = {}

while (len(visited) < len(lines) and globalLineCoveragePercent < 100.0):

randomIndex = random.randint(0, len(lines) - 1)

if (randomIndex in visited):

continue

visited[randomIndex] = True;

lineOriginal = lines[randomIndex];

line = lineOriginal.replace(" ", "")

command = "cd " + tcasDirPath + " ; " + tcasOutputFilePath + " "+ line + " ; gcov-11 " + tcasCFilePath + " -m -j -b 2>&1 | tee " + tcasDirPath+ "/output.txt"

process2 = subprocess.call(command, shell=True)

outputFilePath = os.path.join(tcasDirPath, "output.txt");

# coveragePercentages is a list, i.e, [lineCoveragePercent, branchCoveragePercent]

lineCoveragePercent = getStatementCoveragePercentage(outputFilePath)

if (globalLineCoveragePercent < lineCoveragePercent):

globalLineCoveragePercent = lineCoveragePercent

statementCoverageLines.append(lineOriginal)

with open(os.path.join(tcasDirPath, "randomStatementCoverage"+benchmarkName+".txt"), "w") as f2:

for statementLine in statementCoverageLines:

f2.write(statementLine)

def tcas(dirpath):

tcasDirPath = os.path.join(dirpath, "tcas")

tcasCFilePath = os.path.join(tcasDirPath, "tcas.c")

tcasOutputFilePath = os.path.join(tcasDirPath, "tcas")

testSuiteFilePath = os.path.join(tcasDirPath, "universe.txt")

process1 = subprocess.Popen(["gcc-11", "--coverage", "-Wno-return-type", "-g", "-o", tcasOutputFilePath, tcasCFilePath])

process1.wait()

lines = []

with open(testSuiteFilePath, "r") as f:

lines = f.readlines()

#removeRecords(tcasGcdaFilePath, tcasJsonFilePath)

#totalBranchCoverage(tcasDirPath, tcasCFilePath, tcasOutputFilePath, lines,'tcas')

randomPriorityStatementCoverageTcas(tcasDirPath, tcasCFilePath, tcasOutputFilePath, lines,'tcas')

tcasGcdaFilePath = os.path.join(tcasDirPath, "tcas.gcda");

tcasJsonFilePath = os.path.join(tcasDirPath, "tcas.c.gcov.json.gz")

if (not os.path.exists(tcasJsonFilePath)):

tcasJsonFilePath = os.path.join(tcasDirPath, "tcas.gcov.json.gz")

removeRecords(tcasGcdaFilePath, tcasJsonFilePath)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!