Skip to content

Fix soot initialization #849 #855

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.utbot.framework.plugin.api.UtPrimitiveModel
object SootUtils {
@JvmStatic
fun runSoot(clazz: Class<*>) {
org.utbot.framework.util.SootUtils.runSoot(clazz.kotlin)
org.utbot.framework.util.SootUtils.runSoot(clazz.kotlin, forceReload = false)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class AssembleModelGeneratorTests {
instanceCounter.set(0)
modelIdCounter.set(0)
statementsChain = mutableListOf()
SootUtils.runSoot(AssembleTestUtils::class)
SootUtils.runSoot(AssembleTestUtils::class, forceReload = false)
context = setUtContext(UtContext(AssembleTestUtils::class.java.classLoader))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ internal class UtBotFieldModificatorsTest {
}

private fun initAnalysis() {
SootUtils.runSoot(PrimitiveModifications::class)
SootUtils.runSoot(PrimitiveModifications::class, forceReload = false)
fieldsModificatorsSearcher = UtBotFieldsModificatorsSearcher()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,17 @@ import kotlin.reflect.KCallable
*
* Note: the instantiating of [TestCaseGenerator] may take some time,
* because it requires initializing Soot for the current [buildDir] and [classpath].
*
* @param forceSootReload forces to reinitialize Soot even if the previous buildDir equals to [buildDir] and previous
* classpath equals to [classpath]. This is the case for plugin scenario, as the source code may be modified.
*/
open class TestCaseGenerator(
private val buildDir: Path,
private val classpath: String?,
private val dependencyPaths: String,
val engineActions: MutableList<(UtBotSymbolicEngine) -> Unit> = mutableListOf(),
val isCanceled: () -> Boolean = { false },
val forceSootReload: Boolean = true
) {
private val logger: KLogger = KotlinLogging.logger {}
private val timeoutLogger: KLogger = KotlinLogging.logger(logger.name + ".timeout")
Expand All @@ -78,7 +82,7 @@ open class TestCaseGenerator(
}

timeoutLogger.trace().bracket("Soot initialization") {
SootUtils.runSoot(buildDir, classpath)
SootUtils.runSoot(buildDir, classpath, forceSootReload)
}

//warmup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,25 @@ import soot.toolkits.graph.ExceptionalUnitGraph
object SootUtils {
/**
* Runs Soot in tests if it hasn't already been done.
*
* @param forceReload forces to reinitialize Soot even if the [previousBuildDir] equals to the class buildDir.
*/
fun runSoot(clazz: KClass<*>) {
fun runSoot(clazz: KClass<*>, forceReload: kotlin.Boolean) {
val buildDir = FileUtil.locateClassPath(clazz) ?: FileUtil.isolateClassFiles(clazz)
val buildDirPath = buildDir.toPath()

runSoot(buildDirPath, null)
runSoot(buildDirPath, null, forceReload)
}

fun runSoot(buildDirPath: Path, classPath: String?) {

/**
* @param forceReload forces to reinitialize Soot even if the [previousBuildDir] equals to [buildDirPath] and
* [previousClassPath] equals to [classPath].
*/
fun runSoot(buildDirPath: Path, classPath: String?, forceReload: kotlin.Boolean) {
synchronized(this) {
if (buildDirPath != previousBuildDir || classPath != previousClassPath) {
org.utbot.framework.util.runSoot(buildDirPath, classPath)
if (buildDirPath != previousBuildDir || classPath != previousClassPath || forceReload) {
initSoot(buildDirPath, classPath)
previousBuildDir = buildDirPath
previousClassPath = classPath
}
Expand All @@ -80,7 +87,7 @@ object SootUtils {
/**
Convert code to Jimple
*/
private fun runSoot(buildDir: Path, classpath: String?) {
private fun initSoot(buildDir: Path, classpath: String?) {
G.reset()
val options = Options.v()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class TestSpecificTestCaseGenerator(
dependencyPaths: String,
engineActions: MutableList<(UtBotSymbolicEngine) -> Unit> = mutableListOf(),
isCanceled: () -> Boolean = { false },
): TestCaseGenerator(buildDir, classpath, dependencyPaths, engineActions, isCanceled) {
): TestCaseGenerator(buildDir, classpath, dependencyPaths, engineActions, isCanceled, forceSootReload = false) {

private val logger = KotlinLogging.logger {}

Expand Down