Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add flag in UtSettings.kt and workaround reason
  • Loading branch information
sergeypospelov committed Aug 12, 2022
commit bbcb4a8422e4448e97aec9421ab3e253eba8de80
44 changes: 32 additions & 12 deletions utbot-core/src/main/kotlin/org/utbot/common/HackUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,46 @@ inline fun <T> heuristic(reason: WorkaroundReason, block: () -> T): T = block()

/**
* Explains reason for applied workaround.
*
* Workarounds are:
* - HACK - hacks behaviour for contest. Shall be removed sometimes
* - MAKE_SYMBOLIC - Returns a new symbolic value with proper type instead of function result (i.e. for wrappers)
* - IGNORE_SORT_INEQUALITY -- Ignores pairs of particular sorts in stores and selects
* - RUN_CONCRETE -- Runs something concretely instead of symbolic run
* - REMOVE_ANONYMOUS_CLASSES -- Remove anonymous classes from the results passed to the code generation till it doesn't support their generation
* - IGNORE_MODEL_TYPES_INEQUALITY -- Ignore the fact that model before and model after have different types
* - LONG_CODE_FRAGMENTS -- Comment too long blocks of code due to JVM restrictions [65536 bytes](https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.3)
* - ARRAY_ELEMENT_TYPES_ALWAYS_NULLABLE -- Can't infer nullability for array elements from allocation statement, so make them nullable
* Note:
* - MAKE_SYMBOLIC can lose additional path constraints or branches from function call
*/
enum class WorkaroundReason {
/**
* Hacks behaviour for contest. Shall be removed sometimes
*/
HACK,
/**
* Returns a new symbolic value with proper type instead of function result (i.e. for wrappers)
*
* [MAKE_SYMBOLIC] can lose additional path constraints or branches from function call
*/
MAKE_SYMBOLIC,
/**
* Ignores pairs of particular sorts in stores and selects
*/
IGNORE_SORT_INEQUALITY,
/**
* Runs something concretely instead of symbolic run
*/
RUN_CONCRETE,
/**
* Remove anonymous classes from the results passed to the code generation till it doesn't support their generation
*/
REMOVE_ANONYMOUS_CLASSES,
/**
* Ignore the fact that model before and model after have different types
*/
IGNORE_MODEL_TYPES_INEQUALITY,
/**
* Comment too long blocks of code due to JVM restrictions [65536 bytes](https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.3)
*/
LONG_CODE_FRAGMENTS,
/**
* Can't infer nullability for array elements from allocation statement, so make them nullable
*/
ARRAY_ELEMENT_TYPES_ALWAYS_NULLABLE,
/**
* We won't branch on static field from trusted libraries and won't add them to staticsBefore. For now, it saves us
* from setting [SecurityManager] and other suspicious stuff, but it can lead to coverage regression and thus it
* requires thorough [investigation](https://github.com/UnitTestBot/UTBotJava/issues/716).
*/
IGNORE_STATICS_FROM_TRUSTED_LIBRARIES,
}
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,13 @@ object UtSettings {
*/
var skipTestGenerationForSyntheticMethods by getBooleanProperty(true)

/**
* Flag that indicates whether should we branch on and set static fields from trusted libraries or not.
*
* @see [org.utbot.common.WorkaroundReason.IGNORE_STATICS_FROM_TRUSTED_LIBRARIES]
*/
var ignoreStaticsFromTrustedLibraries by getBooleanProperty(true)

override fun toString(): String =
settingsValues
.mapKeys { it.key.name }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import kotlinx.collections.immutable.persistentSetOf
import kotlinx.collections.immutable.toPersistentList
import kotlinx.collections.immutable.toPersistentSet
import org.utbot.common.WorkaroundReason.HACK
import org.utbot.framework.UtSettings.ignoreStaticsFromTrustedLibraries

`import org.utbot.common.WorkaroundReason.IGNORE_STATICS_FROM_TRUSTED_LIBRARIES
import org.utbot.common.WorkaroundReason.REMOVE_ANONYMOUS_CLASSES
import org.utbot.common.unreachableBranch
import org.utbot.common.withAccessibility
Expand Down Expand Up @@ -1791,7 +1794,9 @@ class Traverser(
private fun isStaticFieldMeaningful(field: SootField) =
!Modifier.isSynthetic(field.modifiers) &&
// we don't want to set fields from library classes
!field.declaringClass.isFromTrustedLibrary()
workaround(IGNORE_STATICS_FROM_TRUSTED_LIBRARIES) {
!ignoreStaticsFromTrustedLibraries || !field.declaringClass.isFromTrustedLibrary()
Comment thread
sergeypospelov marked this conversation as resolved.
Outdated
}

/**
* Locates object represents static fields of particular class.
Expand Down