From 0f7376b41f81c6b3752ca2c42e748930ed8ee31b Mon Sep 17 00:00:00 2001 From: Sergei Kharitontcev-Beglov Date: Wed, 31 Jul 2024 11:50:46 +0200 Subject: [PATCH] Added more coverage collection to the Kex 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 --- .../research/kex/jacoco/CoverageReporter.kt | 30 +++++++++++++------ .../research/kex/concolic/ConcolicTest.kt | 4 +-- .../research/kex/symbolic/SymbolicTest.kt | 4 +-- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/kex-runner/src/main/kotlin/org/vorpal/research/kex/jacoco/CoverageReporter.kt b/kex-runner/src/main/kotlin/org/vorpal/research/kex/jacoco/CoverageReporter.kt index e3f09f52b..39745be96 100644 --- a/kex-runner/src/main/kotlin/org/vorpal/research/kex/jacoco/CoverageReporter.kt +++ b/kex-runner/src/main/kotlin/org/vorpal/research/kex/jacoco/CoverageReporter.kt @@ -105,7 +105,7 @@ open class CoverageReporter( open fun computeCoverage( analysisLevel: AnalysisLevel, testClasses: Set = this.allTestClasses - ): CommonCoverageInfo { + ): Set { ktassert(this.allTestClasses.containsAll(testClasses)) { log.error("Unexpected set of test classes") } @@ -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)!!) } } @@ -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 -> { @@ -386,7 +396,7 @@ fun reportCoverage( coverageSaturation.toList() ) PermanentSaturationCoverageInfo.emit() - coverageSaturation[coverageSaturation.lastKey()]!! + setOf(coverageSaturation[coverageSaturation.lastKey()]!!) } else -> coverageReporter.computeCoverage(analysisLevel, testClasses) @@ -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() } } diff --git a/kex-runner/src/test/kotlin/org/vorpal/research/kex/concolic/ConcolicTest.kt b/kex-runner/src/test/kotlin/org/vorpal/research/kex/concolic/ConcolicTest.kt index c90ed0af3..77cb89fbf 100644 --- a/kex-runner/src/test/kotlin/org/vorpal/research/kex/concolic/ConcolicTest.kt +++ b/kex-runner/src/test/kotlin/org/vorpal/research/kex/concolic/ConcolicTest.kt @@ -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) } } } diff --git a/kex-runner/src/test/kotlin/org/vorpal/research/kex/symbolic/SymbolicTest.kt b/kex-runner/src/test/kotlin/org/vorpal/research/kex/symbolic/SymbolicTest.kt index aec99e3a5..3c92e02d7 100644 --- a/kex-runner/src/test/kotlin/org/vorpal/research/kex/symbolic/SymbolicTest.kt +++ b/kex-runner/src/test/kotlin/org/vorpal/research/kex/symbolic/SymbolicTest.kt @@ -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) } }