Skip to content

Commit 2788630

Browse files
authored
Improver UTestRunner initialization and shutdown (#2683)
1 parent a11c3e9 commit 2788630

File tree

2 files changed

+57
-44
lines changed

2 files changed

+57
-44
lines changed

utbot-junit-contest/src/main/kotlin/org/utbot/contest/ContestEstimator.kt

Lines changed: 55 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import org.utbot.contest.Paths.evosuiteReportFile
2626
import org.utbot.contest.Paths.jarsDir
2727
import org.utbot.contest.Paths.moduleTestDir
2828
import org.utbot.contest.Paths.outputDir
29+
import org.utbot.contest.usvm.executor.UTestRunner
2930
import org.utbot.contest.usvm.runUsvmGeneration
3031
import org.utbot.features.FeatureExtractorFactoryImpl
3132
import org.utbot.features.FeatureProcessorWithStatesRepetitionFactory
@@ -263,6 +264,11 @@ interface Tool {
263264
expectedExceptions,
264265
methodNameFilter
265266
)
267+
268+
override fun close() {
269+
if (UTestRunner.isInitialized())
270+
UTestRunner.runner.close()
271+
}
266272
}
267273

268274
object EvoSuite : Tool {
@@ -351,6 +357,8 @@ interface Tool {
351357
)
352358

353359
fun moveProducedFilesIfNeeded()
360+
361+
fun close() {}
354362
}
355363

356364
fun main(args: Array<String>) {
@@ -508,52 +516,56 @@ fun runEstimator(
508516

509517
try {
510518
tools.forEach { tool ->
511-
var classIndex = 0
512-
513-
outer@ for (project in projects) {
514-
if (projectFilter != null && project.name !in projectFilter) continue
515-
516-
val statsForProject = StatsForProject(project.name)
517-
globalStats.projectStats.add(statsForProject)
518-
519-
logger.info { "------------- project [${project.name}] ---- " }
520-
521-
// take all the classes from the corresponding jar if a list of the specified classes is empty
522-
val extendedClassFqn = project.classFQNs.ifEmpty { project.classNames }
523-
524-
for (classFqn in extendedClassFqn.filter { classFqnFilter?.equals(it) ?: true }) {
525-
classIndex++
526-
if (classIndex > processedClassesThreshold) {
527-
logger.info { "Reached limit of $processedClassesThreshold classes" }
528-
break@outer
529-
}
530-
531-
try {
532-
val cut =
533-
ClassUnderTest(
534-
project.classloader.loadClass(classFqn).id,
535-
project.outputTestSrcFolder,
536-
project.unzippedDir
519+
try {
520+
var classIndex = 0
521+
522+
outer@ for (project in projects) {
523+
if (projectFilter != null && project.name !in projectFilter) continue
524+
525+
val statsForProject = StatsForProject(project.name)
526+
globalStats.projectStats.add(statsForProject)
527+
528+
logger.info { "------------- project [${project.name}] ---- " }
529+
530+
// take all the classes from the corresponding jar if a list of the specified classes is empty
531+
val extendedClassFqn = project.classFQNs.ifEmpty { project.classNames }
532+
533+
for (classFqn in extendedClassFqn.filter { classFqnFilter?.equals(it) ?: true }) {
534+
classIndex++
535+
if (classIndex > processedClassesThreshold) {
536+
logger.info { "Reached limit of $processedClassesThreshold classes" }
537+
break@outer
538+
}
539+
540+
try {
541+
val cut =
542+
ClassUnderTest(
543+
project.classloader.loadClass(classFqn).id,
544+
project.outputTestSrcFolder,
545+
project.unzippedDir
546+
)
547+
548+
logger.info { "------------- [${project.name}] ---->--- [$classIndex:$classFqn] ---------------------" }
549+
550+
tool.run(
551+
project,
552+
cut,
553+
timeLimit,
554+
fuzzingRatio,
555+
methodNameFilter,
556+
statsForProject,
557+
compiledTestDir,
558+
classFqn,
559+
project.expectedExceptions.getForClass(classFqn)
537560
)
538-
539-
logger.info { "------------- [${project.name}] ---->--- [$classIndex:$classFqn] ---------------------" }
540-
541-
tool.run(
542-
project,
543-
cut,
544-
timeLimit,
545-
fuzzingRatio,
546-
methodNameFilter,
547-
statsForProject,
548-
compiledTestDir,
549-
classFqn,
550-
project.expectedExceptions.getForClass(classFqn)
551-
)
552-
}
553-
catch (e: Throwable) {
554-
logger.warn(e) { "===================== ERROR IN [${project.name}] FOR [$classIndex:$classFqn] ============" }
561+
}
562+
catch (e: Throwable) {
563+
logger.warn(e) { "===================== ERROR IN [${project.name}] FOR [$classIndex:$classFqn] ============" }
564+
}
555565
}
556566
}
567+
} finally {
568+
tool.close()
557569
}
558570
}
559571
} finally {

utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/ContestUsvm.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ fun runUsvmGeneration(
8181
}
8282

8383
val runner by lazy {
84-
UTestRunner.initRunner(classpathFiles.map { it.absolutePath }, jcDbContainer.cp)
84+
if (!UTestRunner.isInitialized())
85+
UTestRunner.initRunner(classpathFiles.map { it.absolutePath }, jcDbContainer.cp)
8586
UTestRunner.runner
8687
}
8788

0 commit comments

Comments
 (0)