Skip to content

Commit

Permalink
Fix review comments relative to soot
Browse files Browse the repository at this point in the history
  • Loading branch information
volivan239 committed Sep 28, 2022
1 parent acb88a0 commit afd95ca
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ open class TestCaseGenerator(
if (!isCanceled()) {
checkFrameworkDependencies(dependencyPaths)

logger.trace("Initializing ${this.javaClass.name} with buildDir = $buildDirs, classpath = $classpath")
logger.trace("Initializing ${this.javaClass.name} with buildDirs = ${buildDirs.joinToString(File.pathSeparator)}, classpath = $classpath")


if (disableCoroutinesDebug) {
Expand Down
142 changes: 53 additions & 89 deletions utbot-framework/src/main/kotlin/org/utbot/framework/util/SootUtils.kt
Original file line number Diff line number Diff line change
@@ -1,43 +1,7 @@
package org.utbot.framework.util

import org.utbot.api.mock.UtMock
import org.utbot.common.FileUtil
import org.utbot.engine.UtNativeStringWrapper
import org.utbot.engine.jimpleBody
import org.utbot.engine.overrides.Boolean
import org.utbot.engine.overrides.Byte
import org.utbot.engine.overrides.Character
import org.utbot.engine.overrides.Class
import org.utbot.engine.overrides.Integer
import org.utbot.engine.overrides.Long
import org.utbot.engine.overrides.PrintStream
import org.utbot.engine.overrides.Short
import org.utbot.engine.overrides.System
import org.utbot.engine.overrides.UtArrayMock
import org.utbot.engine.overrides.UtLogicMock
import org.utbot.engine.overrides.UtOverrideMock
import org.utbot.engine.overrides.collections.AbstractCollection
import org.utbot.engine.overrides.collections.AssociativeArray
import org.utbot.engine.overrides.collections.Collection
import org.utbot.engine.overrides.collections.List as UtList
import org.utbot.engine.overrides.collections.RangeModifiableUnlimitedArray
import org.utbot.engine.overrides.collections.UtArrayList
import org.utbot.engine.overrides.collections.UtGenericAssociative
import org.utbot.engine.overrides.collections.UtGenericStorage
import org.utbot.engine.overrides.collections.UtHashMap
import org.utbot.engine.overrides.collections.UtHashSet
import org.utbot.engine.overrides.collections.UtLinkedList
import org.utbot.engine.overrides.collections.UtLinkedListWithNullableCheck
import org.utbot.engine.overrides.collections.UtOptional
import org.utbot.engine.overrides.collections.UtOptionalDouble
import org.utbot.engine.overrides.collections.UtOptionalInt
import org.utbot.engine.overrides.collections.UtOptionalLong
import org.utbot.engine.overrides.stream.Arrays
import org.utbot.engine.overrides.stream.Stream
import org.utbot.engine.overrides.stream.UtStream
import org.utbot.engine.overrides.strings.UtString
import org.utbot.engine.overrides.strings.UtStringBuffer
import org.utbot.engine.overrides.strings.UtStringBuilder
import org.utbot.engine.pureJavaSignature
import org.utbot.framework.plugin.api.ExecutableId
import org.utbot.framework.plugin.services.JdkInfo
Expand All @@ -60,7 +24,7 @@ object SootUtils {
* code.
* @param forceReload forces to reinitialize Soot even if the [previousBuildDirs] equals to the class buildDir.
*/
fun runSoot(clazz: java.lang.Class<*>, forceReload: kotlin.Boolean, jdkInfo: JdkInfo) {
fun runSoot(clazz: Class<*>, forceReload: Boolean, jdkInfo: JdkInfo) {
val buildDir = FileUtil.locateClassPath(clazz) ?: FileUtil.isolateClassFiles(clazz)
val buildDirPath = buildDir.toPath()

Expand All @@ -74,7 +38,7 @@ object SootUtils {
* @param forceReload forces to reinitialize Soot even if the [previousBuildDirs] equals to [buildDirPaths] and
* [previousClassPath] equals to [classPath].
*/
fun runSoot(buildDirPaths: List<Path>, classPath: String?, forceReload: kotlin.Boolean, jdkInfo: JdkInfo) {
fun runSoot(buildDirPaths: List<Path>, classPath: String?, forceReload: Boolean, jdkInfo: JdkInfo) {
synchronized(this) {
if (buildDirPaths != previousBuildDirs || classPath != previousClassPath || forceReload) {
initSoot(buildDirPaths, classPath, jdkInfo)
Expand Down Expand Up @@ -107,7 +71,7 @@ private fun initSoot(buildDirs: List<Path>, classpath: String?, jdkInfo: JdkInfo
+ if (!classpath.isNullOrEmpty()) File.pathSeparator + "$classpath" else ""
)
set_src_prec(Options.src_prec_only_class)
set_process_dir(buildDirs.map { "$it" })
set_process_dir(buildDirs.map { it.toString() })
set_keep_line_number(true)
set_ignore_classpath_errors(true) // gradle/build/resources/main does not exists, but it's not a problem
set_output_format(Options.output_format_jimple)
Expand Down Expand Up @@ -143,60 +107,60 @@ fun jimpleBody(method: ExecutableId): JimpleBody =
method.sootMethod.jimpleBody()


private fun addBasicClasses(vararg classes: java.lang.Class<*>) {
private fun addBasicClasses(vararg classes: Class<*>) {
classes.forEach {
Scene.v().addBasicClass(it.name, SootClass.BODIES)
}
}

private val classesToLoad = arrayOf(
AbstractCollection::class,
UtMock::class,
UtOverrideMock::class,
UtLogicMock::class,
UtArrayMock::class,
Boolean::class,
Byte::class,
Character::class,
Class::class,
Integer::class,
Long::class,
Short::class,
System::class,
UtOptional::class,
UtOptionalInt::class,
UtOptionalLong::class,
UtOptionalDouble::class,
UtArrayList::class,
UtArrayList.UtArrayListIterator::class,
UtLinkedList::class,
UtLinkedListWithNullableCheck::class,
UtLinkedList.UtLinkedListIterator::class,
UtLinkedList.ReverseIteratorWrapper::class,
UtHashSet::class,
UtHashSet.UtHashSetIterator::class,
UtHashMap::class,
UtHashMap.Entry::class,
UtHashMap.LinkedEntryIterator::class,
UtHashMap.LinkedEntrySet::class,
UtHashMap.LinkedHashIterator::class,
UtHashMap.LinkedKeyIterator::class,
UtHashMap.LinkedKeySet::class,
UtHashMap.LinkedValueIterator::class,
UtHashMap.LinkedValues::class,
RangeModifiableUnlimitedArray::class,
AssociativeArray::class,
UtGenericStorage::class,
UtGenericAssociative::class,
PrintStream::class,
UtNativeStringWrapper::class,
UtString::class,
UtStringBuilder::class,
UtStringBuffer::class,
Stream::class,
Arrays::class,
Collection::class,
UtList::class,
UtStream::class,
UtStream.UtStreamIterator::class
org.utbot.engine.overrides.collections.AbstractCollection::class,
org.utbot.api.mock.UtMock::class,
org.utbot.engine.overrides.UtOverrideMock::class,
org.utbot.engine.overrides.UtLogicMock::class,
org.utbot.engine.overrides.UtArrayMock::class,
org.utbot.engine.overrides.Boolean::class,
org.utbot.engine.overrides.Byte::class,
org.utbot.engine.overrides.Character::class,
org.utbot.engine.overrides.Class::class,
org.utbot.engine.overrides.Integer::class,
org.utbot.engine.overrides.Long::class,
org.utbot.engine.overrides.Short::class,
org.utbot.engine.overrides.System::class,
org.utbot.engine.overrides.collections.UtOptional::class,
org.utbot.engine.overrides.collections.UtOptionalInt::class,
org.utbot.engine.overrides.collections.UtOptionalLong::class,
org.utbot.engine.overrides.collections.UtOptionalDouble::class,
org.utbot.engine.overrides.collections.UtArrayList::class,
org.utbot.engine.overrides.collections.UtArrayList.UtArrayListIterator::class,
org.utbot.engine.overrides.collections.UtLinkedList::class,
org.utbot.engine.overrides.collections.UtLinkedListWithNullableCheck::class,
org.utbot.engine.overrides.collections.UtLinkedList.UtLinkedListIterator::class,
org.utbot.engine.overrides.collections.UtLinkedList.ReverseIteratorWrapper::class,
org.utbot.engine.overrides.collections.UtHashSet::class,
org.utbot.engine.overrides.collections.UtHashSet.UtHashSetIterator::class,
org.utbot.engine.overrides.collections.UtHashMap::class,
org.utbot.engine.overrides.collections.UtHashMap.Entry::class,
org.utbot.engine.overrides.collections.UtHashMap.LinkedEntryIterator::class,
org.utbot.engine.overrides.collections.UtHashMap.LinkedEntrySet::class,
org.utbot.engine.overrides.collections.UtHashMap.LinkedHashIterator::class,
org.utbot.engine.overrides.collections.UtHashMap.LinkedKeyIterator::class,
org.utbot.engine.overrides.collections.UtHashMap.LinkedKeySet::class,
org.utbot.engine.overrides.collections.UtHashMap.LinkedValueIterator::class,
org.utbot.engine.overrides.collections.UtHashMap.LinkedValues::class,
org.utbot.engine.overrides.collections.RangeModifiableUnlimitedArray::class,
org.utbot.engine.overrides.collections.AssociativeArray::class,
org.utbot.engine.overrides.collections.UtGenericStorage::class,
org.utbot.engine.overrides.collections.UtGenericAssociative::class,
org.utbot.engine.overrides.PrintStream::class,
org.utbot.engine.UtNativeStringWrapper::class,
org.utbot.engine.overrides.strings.UtString::class,
org.utbot.engine.overrides.strings.UtStringBuilder::class,
org.utbot.engine.overrides.strings.UtStringBuffer::class,
org.utbot.engine.overrides.stream.Stream::class,
org.utbot.engine.overrides.stream.Arrays::class,
org.utbot.engine.overrides.collections.Collection::class,
org.utbot.engine.overrides.collections.List::class,
org.utbot.engine.overrides.stream.UtStream::class,
org.utbot.engine.overrides.stream.UtStream.UtStreamIterator::class
).map { it.java }.toTypedArray()

0 comments on commit afd95ca

Please sign in to comment.