Skip to content

Commit

Permalink
Added more coverage collection to the Kex
Browse files Browse the repository at this point in the history
In the previous commits only target class are considered to fetch coverage. In this commit I introduced the collection of the coverage for all classes
  • Loading branch information
khbminus committed Jul 31, 2024
1 parent 45bde97 commit 0f7376b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ open class CoverageReporter(
open fun computeCoverage(
analysisLevel: AnalysisLevel,
testClasses: Set<Path> = this.allTestClasses
): CommonCoverageInfo {
): Set<CommonCoverageInfo> {
ktassert(this.allTestClasses.containsAll(testClasses)) {
log.error("Unexpected set of test classes")
}
Expand All @@ -114,9 +114,9 @@ open class CoverageReporter(
val coverageBuilder = getCoverageBuilderAndCleanup(classes, testClasses)

return when (analysisLevel) {
is PackageLevel -> getPackageCoverage(analysisLevel.pkg, cm, coverageBuilder)
is ClassLevel -> getClassCoverage(cm, coverageBuilder).first()
is MethodLevel -> getMethodCoverage(coverageBuilder, analysisLevel.method)!!
is PackageLevel -> setOf(getPackageCoverage(analysisLevel.pkg, cm, coverageBuilder))
is ClassLevel -> getClassCoverage(cm, coverageBuilder)
is MethodLevel -> setOf(getMethodCoverage(coverageBuilder, analysisLevel.method)!!)
}
}

Expand Down Expand Up @@ -156,8 +156,18 @@ open class CoverageReporter(
.toList()

is ClassLevel -> {
val klass = analysisLevel.klass.fullName.replace(Package.SEPARATOR, File.separatorChar)
listOf(jacocoInstrumentedDir.resolve("$klass.class"))
if (kexConfig.getBooleanValue("kex", "collectWholeCoverage", false)) {
Files.walk(jacocoInstrumentedDir)
.filter { it.isClass }
// filter stdlib-specific things
.filter { !it.fullyQualifiedName(jacocoInstrumentedDir).asmString.startsWith("java")}
.filter { !it.fullyQualifiedName(jacocoInstrumentedDir).asmString.startsWith("kotlin")}
.filter { !it.fullyQualifiedName(jacocoInstrumentedDir).asmString.startsWith("kex")}
.toList()
} else {
val klass = analysisLevel.klass.fullName.replace(Package.SEPARATOR, File.separatorChar)
listOf(jacocoInstrumentedDir.resolve("$klass.class"))
}
}

is MethodLevel -> {
Expand Down Expand Up @@ -386,7 +396,7 @@ fun reportCoverage(
coverageSaturation.toList()
)
PermanentSaturationCoverageInfo.emit()
coverageSaturation[coverageSaturation.lastKey()]!!
setOf(coverageSaturation[coverageSaturation.lastKey()]!!)
}

else -> coverageReporter.computeCoverage(analysisLevel, testClasses)
Expand All @@ -395,10 +405,12 @@ fun reportCoverage(
?.writeText(Json.encodeToString(coverageInfo))

log.info(
coverageInfo.print(kexConfig.getBooleanValue("kex", "printDetailedCoverage", false))
coverageInfo.joinToString(System.lineSeparator()) {
it.print(kexConfig.getBooleanValue("kex", "printDetailedCoverage", false))
}
)

PermanentCoverageInfo.putNewInfo(mode, analysisLevel.toString(), coverageInfo)
PermanentCoverageInfo.putNewInfo(mode, analysisLevel.toString(), coverageInfo.first())
PermanentCoverageInfo.emit()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ abstract class ConcolicTest(testDirectoryName: String) : KexRunnerTest(testDirec
}

val coverage = CoverageReporter(klass.cm, listOf(jar)).computeCoverage(ClassLevel(klass))
log.debug(coverage.print(true))
assertEquals(expectedCoverage, coverage.instructionCoverage.ratio, eps)
log.debug(coverage.first().print(true))
assertEquals(expectedCoverage, coverage.first().instructionCoverage.ratio, eps)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ abstract class SymbolicTest(
}

val coverage = CoverageReporter(klass.cm, listOf(jar)).computeCoverage(ClassLevel(klass))
log.debug(coverage.print(true))
assertEquals(expectedCoverage, coverage.instructionCoverage.ratio, eps)
log.debug(coverage.first().print(true))
assertEquals(expectedCoverage, coverage.first().instructionCoverage.ratio, eps)
}
}

0 comments on commit 0f7376b

Please sign in to comment.