From a948a03f0a53ec6b2389615bf4eda16764b0cdae Mon Sep 17 00:00:00 2001 From: IlyaMuravjov Date: Mon, 13 Nov 2023 13:57:46 +0300 Subject: [PATCH] Improver `UTestRunner` initialization and shutdown --- .../org/utbot/contest/ContestEstimator.kt | 98 +++++++++++-------- .../org/utbot/contest/usvm/ContestUsvm.kt | 3 +- 2 files changed, 57 insertions(+), 44 deletions(-) diff --git a/utbot-junit-contest/src/main/kotlin/org/utbot/contest/ContestEstimator.kt b/utbot-junit-contest/src/main/kotlin/org/utbot/contest/ContestEstimator.kt index 40abcdcdac..f955a7bdc8 100644 --- a/utbot-junit-contest/src/main/kotlin/org/utbot/contest/ContestEstimator.kt +++ b/utbot-junit-contest/src/main/kotlin/org/utbot/contest/ContestEstimator.kt @@ -26,6 +26,7 @@ import org.utbot.contest.Paths.evosuiteReportFile import org.utbot.contest.Paths.jarsDir import org.utbot.contest.Paths.moduleTestDir import org.utbot.contest.Paths.outputDir +import org.utbot.contest.usvm.executor.UTestRunner import org.utbot.contest.usvm.runUsvmGeneration import org.utbot.features.FeatureExtractorFactoryImpl import org.utbot.features.FeatureProcessorWithStatesRepetitionFactory @@ -263,6 +264,11 @@ interface Tool { expectedExceptions, methodNameFilter ) + + override fun close() { + if (UTestRunner.isInitialized()) + UTestRunner.runner.close() + } } object EvoSuite : Tool { @@ -351,6 +357,8 @@ interface Tool { ) fun moveProducedFilesIfNeeded() + + fun close() {} } fun main(args: Array) { @@ -508,52 +516,56 @@ fun runEstimator( try { tools.forEach { tool -> - var classIndex = 0 - - outer@ for (project in projects) { - if (projectFilter != null && project.name !in projectFilter) continue - - val statsForProject = StatsForProject(project.name) - globalStats.projectStats.add(statsForProject) - - logger.info { "------------- project [${project.name}] ---- " } - - // take all the classes from the corresponding jar if a list of the specified classes is empty - val extendedClassFqn = project.classFQNs.ifEmpty { project.classNames } - - for (classFqn in extendedClassFqn.filter { classFqnFilter?.equals(it) ?: true }) { - classIndex++ - if (classIndex > processedClassesThreshold) { - logger.info { "Reached limit of $processedClassesThreshold classes" } - break@outer - } - - try { - val cut = - ClassUnderTest( - project.classloader.loadClass(classFqn).id, - project.outputTestSrcFolder, - project.unzippedDir + try { + var classIndex = 0 + + outer@ for (project in projects) { + if (projectFilter != null && project.name !in projectFilter) continue + + val statsForProject = StatsForProject(project.name) + globalStats.projectStats.add(statsForProject) + + logger.info { "------------- project [${project.name}] ---- " } + + // take all the classes from the corresponding jar if a list of the specified classes is empty + val extendedClassFqn = project.classFQNs.ifEmpty { project.classNames } + + for (classFqn in extendedClassFqn.filter { classFqnFilter?.equals(it) ?: true }) { + classIndex++ + if (classIndex > processedClassesThreshold) { + logger.info { "Reached limit of $processedClassesThreshold classes" } + break@outer + } + + try { + val cut = + ClassUnderTest( + project.classloader.loadClass(classFqn).id, + project.outputTestSrcFolder, + project.unzippedDir + ) + + logger.info { "------------- [${project.name}] ---->--- [$classIndex:$classFqn] ---------------------" } + + tool.run( + project, + cut, + timeLimit, + fuzzingRatio, + methodNameFilter, + statsForProject, + compiledTestDir, + classFqn, + project.expectedExceptions.getForClass(classFqn) ) - - logger.info { "------------- [${project.name}] ---->--- [$classIndex:$classFqn] ---------------------" } - - tool.run( - project, - cut, - timeLimit, - fuzzingRatio, - methodNameFilter, - statsForProject, - compiledTestDir, - classFqn, - project.expectedExceptions.getForClass(classFqn) - ) - } - catch (e: Throwable) { - logger.warn(e) { "===================== ERROR IN [${project.name}] FOR [$classIndex:$classFqn] ============" } + } + catch (e: Throwable) { + logger.warn(e) { "===================== ERROR IN [${project.name}] FOR [$classIndex:$classFqn] ============" } + } } } + } finally { + tool.close() } } } finally { diff --git a/utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/ContestUsvm.kt b/utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/ContestUsvm.kt index 5b57c784ac..8b9f008e78 100644 --- a/utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/ContestUsvm.kt +++ b/utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/ContestUsvm.kt @@ -81,7 +81,8 @@ fun runUsvmGeneration( } val runner by lazy { - UTestRunner.initRunner(classpathFiles.map { it.absolutePath }, jcDbContainer.cp) + if (!UTestRunner.isInitialized()) + UTestRunner.initRunner(classpathFiles.map { it.absolutePath }, jcDbContainer.cp) UTestRunner.runner }