Skip to content

Commit

Permalink
protect equality utils from minimizer
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdullinAM committed Aug 14, 2024
1 parent f2498a6 commit 8a9704c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ import java.nio.file.Path
import java.nio.file.attribute.BasicFileAttributes
import java.util.*
import java.util.stream.Collectors
import kotlin.io.path.*
import kotlin.io.path.inputStream
import kotlin.io.path.name
import kotlin.io.path.readBytes
import kotlin.io.path.relativeTo
import kotlin.io.path.writeBytes
import kotlin.io.path.writeText
import kotlin.streams.toList
import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.seconds
Expand Down Expand Up @@ -154,21 +160,20 @@ open class CoverageReporter(
is PackageLevel -> Files.walk(jacocoInstrumentedDir)
.filter { it.isClass }
.filter { analysisLevel.pkg.isParent(it.fullyQualifiedName(jacocoInstrumentedDir).asmString) }
.collect(Collectors.toList())
.toList()

is ClassLevel -> {
val additionalValues = kexConfig
.getStringValue("kex", "collectAdditionalCoverage")
?.split(",")
?.map { Package.parse(it.trim().asmString) }
?.toSet()
?: emptySet()
val targetKlass = analysisLevel.klass.fullName.replace(Package.SEPARATOR, File.separatorChar)
val targetFiles = listOf(jacocoInstrumentedDir.resolve("$targetKlass.class"))

val additionalValues = kexConfig
.getMultipleStringValue("kex", "collectAdditionalCoverage", delimiter = ",")
.mapTo(mutableSetOf()) { Package.parse(it.trim().asmString) }
val additionalFiles = Files.walk(jacocoInstrumentedDir)
.filter { it.isClass }
.filter { additionalValues.any { value -> value.isParent(it.fullyQualifiedName(jacocoInstrumentedDir).asmString) } }
.collect(Collectors.toList())
.toList()

targetFiles + additionalFiles
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.vorpal.research.kex.jacoco.minimization

import org.vorpal.research.kex.config.kexConfig
import org.vorpal.research.kex.reanimator.codegen.javagen.EqualityUtilsPrinter
import org.vorpal.research.kex.reanimator.codegen.javagen.ReflectionUtilsPrinter
import org.vorpal.research.kex.util.compiledCodeDirectory
import org.vorpal.research.kex.util.testcaseDirectory
Expand All @@ -20,7 +21,9 @@ interface TestSuiteMinimizer {

companion object {
// there will be more
private fun protectedFiles(): Set<Path> = ReflectionUtilsPrinter.reflectionUtilsClasses()
private fun protectedFiles(): Set<Path> =
ReflectionUtilsPrinter.reflectionUtilsClasses() + EqualityUtilsPrinter.equalityUtilsClasses()

fun deleteTestCases(compiledTests: Set<Path>) {
val protectedFiles = protectedFiles()
for (compiledTestPath in compiledTests) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class EqualityUtilsPrinter(
}
}

fun equalityUtilsClasses(): Set<Path> = equalityUtilsInstances.mapTo(mutableSetOf()) { it.key.first }

@Suppress("unused")
fun invalidateAll() {
equalityUtilsInstances.clear()
Expand Down

0 comments on commit 8a9704c

Please sign in to comment.