Skip to content

Commit 1fe386c

Browse files
Fix soot initialization #849 (#855)
1 parent 68a65ea commit 1fe386c

File tree

6 files changed

+22
-11
lines changed

6 files changed

+22
-11
lines changed

utbot-framework-test/src/main/java/org/utbot/examples/manual/KotlinWrappers.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import org.utbot.framework.plugin.api.UtPrimitiveModel
88
object SootUtils {
99
@JvmStatic
1010
fun runSoot(clazz: Class<*>) {
11-
org.utbot.framework.util.SootUtils.runSoot(clazz.kotlin)
11+
org.utbot.framework.util.SootUtils.runSoot(clazz.kotlin, forceReload = false)
1212
}
1313
}
1414

utbot-framework-test/src/test/kotlin/org/utbot/framework/assemble/AssembleModelGeneratorTests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class AssembleModelGeneratorTests {
7070
instanceCounter.set(0)
7171
modelIdCounter.set(0)
7272
statementsChain = mutableListOf()
73-
SootUtils.runSoot(AssembleTestUtils::class)
73+
SootUtils.runSoot(AssembleTestUtils::class, forceReload = false)
7474
context = setUtContext(UtContext(AssembleTestUtils::class.java.classLoader))
7575
}
7676

utbot-framework-test/src/test/kotlin/org/utbot/framework/modificators/UtBotFieldModificatorsTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ internal class UtBotFieldModificatorsTest {
169169
}
170170

171171
private fun initAnalysis() {
172-
SootUtils.runSoot(PrimitiveModifications::class)
172+
SootUtils.runSoot(PrimitiveModifications::class, forceReload = false)
173173
fieldsModificatorsSearcher = UtBotFieldsModificatorsSearcher()
174174
}
175175

utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,17 @@ import kotlin.reflect.KCallable
5252
*
5353
* Note: the instantiating of [TestCaseGenerator] may take some time,
5454
* because it requires initializing Soot for the current [buildDir] and [classpath].
55+
*
56+
* @param forceSootReload forces to reinitialize Soot even if the previous buildDir equals to [buildDir] and previous
57+
* classpath equals to [classpath]. This is the case for plugin scenario, as the source code may be modified.
5558
*/
5659
open class TestCaseGenerator(
5760
private val buildDir: Path,
5861
private val classpath: String?,
5962
private val dependencyPaths: String,
6063
val engineActions: MutableList<(UtBotSymbolicEngine) -> Unit> = mutableListOf(),
6164
val isCanceled: () -> Boolean = { false },
65+
val forceSootReload: Boolean = true
6266
) {
6367
private val logger: KLogger = KotlinLogging.logger {}
6468
private val timeoutLogger: KLogger = KotlinLogging.logger(logger.name + ".timeout")
@@ -78,7 +82,7 @@ open class TestCaseGenerator(
7882
}
7983

8084
timeoutLogger.trace().bracket("Soot initialization") {
81-
SootUtils.runSoot(buildDir, classpath)
85+
SootUtils.runSoot(buildDir, classpath, forceSootReload)
8286
}
8387

8488
//warmup

utbot-framework/src/main/kotlin/org/utbot/framework/util/SootUtils.kt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,25 @@ import soot.toolkits.graph.ExceptionalUnitGraph
5555
object SootUtils {
5656
/**
5757
* Runs Soot in tests if it hasn't already been done.
58+
*
59+
* @param forceReload forces to reinitialize Soot even if the [previousBuildDir] equals to the class buildDir.
5860
*/
59-
fun runSoot(clazz: KClass<*>) {
61+
fun runSoot(clazz: KClass<*>, forceReload: kotlin.Boolean) {
6062
val buildDir = FileUtil.locateClassPath(clazz) ?: FileUtil.isolateClassFiles(clazz)
6163
val buildDirPath = buildDir.toPath()
6264

63-
runSoot(buildDirPath, null)
65+
runSoot(buildDirPath, null, forceReload)
6466
}
6567

66-
fun runSoot(buildDirPath: Path, classPath: String?) {
68+
69+
/**
70+
* @param forceReload forces to reinitialize Soot even if the [previousBuildDir] equals to [buildDirPath] and
71+
* [previousClassPath] equals to [classPath].
72+
*/
73+
fun runSoot(buildDirPath: Path, classPath: String?, forceReload: kotlin.Boolean) {
6774
synchronized(this) {
68-
if (buildDirPath != previousBuildDir || classPath != previousClassPath) {
69-
org.utbot.framework.util.runSoot(buildDirPath, classPath)
75+
if (buildDirPath != previousBuildDir || classPath != previousClassPath || forceReload) {
76+
initSoot(buildDirPath, classPath)
7077
previousBuildDir = buildDirPath
7178
previousClassPath = classPath
7279
}
@@ -80,7 +87,7 @@ object SootUtils {
8087
/**
8188
Convert code to Jimple
8289
*/
83-
private fun runSoot(buildDir: Path, classpath: String?) {
90+
private fun initSoot(buildDir: Path, classpath: String?) {
8491
G.reset()
8592
val options = Options.v()
8693

utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/TestSpecificTestCaseGenerator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class TestSpecificTestCaseGenerator(
3131
dependencyPaths: String,
3232
engineActions: MutableList<(UtBotSymbolicEngine) -> Unit> = mutableListOf(),
3333
isCanceled: () -> Boolean = { false },
34-
): TestCaseGenerator(buildDir, classpath, dependencyPaths, engineActions, isCanceled) {
34+
): TestCaseGenerator(buildDir, classpath, dependencyPaths, engineActions, isCanceled, forceSootReload = false) {
3535

3636
private val logger = KotlinLogging.logger {}
3737

0 commit comments

Comments
 (0)