Skip to content

Commit 9a08b82

Browse files
committed
Solver optimizations
1 parent 145da7d commit 9a08b82

File tree

25 files changed

+871
-683
lines changed

25 files changed

+871
-683
lines changed

utbot-framework-api/src/main/kotlin/org/utbot/framework/UtSettings.kt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,35 @@ object UtSettings : AbstractSettings(
395395
* therefore, you will be unable to test UtBot classes.
396396
*/
397397
var removeUtBotClassesFromHierarchy by getBooleanProperty(true)
398+
399+
/**
400+
* Use this option to enable calculation and logging of MD5 for dropped states by statistics.
401+
* Example of such logging:
402+
* Dropping state (lastStatus=UNDEFINED) by the distance statistics. MD5: 5d0bccc242e87d53578ca0ef64aa5864
403+
*
404+
* Default value is false.
405+
*/
406+
var enableLoggingForDroppedStates by getBooleanProperty(false)
407+
408+
/**
409+
* If this option set in true, depending on the number of possible types for
410+
* a particular object will be used either type system based on conjunction
411+
* or on bit vectors.
412+
*
413+
* @see useBitVecBasedTypeSystem
414+
*/
415+
var useBitVecBasedTypeSystem by getBooleanProperty(true)
416+
417+
/**
418+
* The number of types on which the choice of the type system depends.
419+
*/
420+
var maxTypeNumberForEnumeration by getIntProperty(64)
421+
422+
/**
423+
* The threshold for numbers of types for which they will be encoded into solver.
424+
* It is used to do not encode big type storages due to significand performance degradation.
425+
*/
426+
var maxNumberOfTypesToEncode by getIntProperty(512)
398427
}
399428

400429
/**

utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/ArrayOfArraysTest.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.utbot.examples.arrays
22

3+
import org.junit.jupiter.api.Disabled
34
import org.utbot.tests.infrastructure.UtValueTestCaseChecker
45
import org.utbot.tests.infrastructure.DoNotCalculate
56
import org.utbot.tests.infrastructure.atLeast
@@ -268,10 +269,13 @@ internal class ArrayOfArraysTest : UtValueTestCaseChecker(testClass = ArrayOfArr
268269
}
269270

270271
@Test
272+
@Disabled("https://github.com/UnitTestBot/UTBotJava/issues/1267")
271273
fun testArrayWithItselfAnAsElement() {
272274
check(
273275
ArrayOfArrays::arrayWithItselfAnAsElement,
274276
eq(2),
277+
{ a, r -> a !== a[0] && r == null },
278+
{ a, r -> a === a[0] && a.contentDeepEquals(r) },
275279
coverage = atLeast(percents = 94)
276280
// because of the assumption
277281
)

utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/PrivateConstructorExampleTest.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,24 @@ package org.utbot.examples.mixed
33
import org.utbot.tests.infrastructure.UtValueTestCaseChecker
44
import org.utbot.tests.infrastructure.DoNotCalculate
55
import org.junit.jupiter.api.Test
6+
import org.utbot.framework.plugin.api.CodegenLanguage
67
import org.utbot.testcheckers.eq
8+
import org.utbot.tests.infrastructure.Compilation
79

8-
internal class PrivateConstructorExampleTest : UtValueTestCaseChecker(testClass = PrivateConstructorExample::class) {
10+
// TODO parameterized tests disabled due to https://github.com/UnitTestBot/UTBotJava/issues/1266
11+
internal class PrivateConstructorExampleTest : UtValueTestCaseChecker(
12+
testClass = PrivateConstructorExample::class,
13+
pipelines = listOf(
14+
TestLastStage(
15+
CodegenLanguage.JAVA,
16+
parameterizedModeLastStage = Compilation
17+
),
18+
TestLastStage(
19+
CodegenLanguage.KOTLIN,
20+
parameterizedModeLastStage = Compilation
21+
)
22+
)
23+
) {
924

1025
/**
1126
* Two branches need to be covered:

utbot-framework/src/main/kotlin/org/utbot/engine/ArrayObjectWrappers.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import org.utbot.engine.pc.mkInt
1818
import org.utbot.engine.pc.select
1919
import org.utbot.engine.pc.store
2020
import org.utbot.engine.symbolic.asHardConstraint
21+
import org.utbot.engine.types.OBJECT_TYPE
22+
import org.utbot.engine.types.TypeRegistry
2123
import org.utbot.framework.plugin.api.ClassId
2224
import org.utbot.framework.plugin.api.UtArrayModel
2325
import org.utbot.framework.plugin.api.UtCompositeModel

utbot-framework/src/main/kotlin/org/utbot/engine/ConstructedSootMethods.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.utbot.engine
22

3+
import org.utbot.engine.types.OBJECT_TYPE
4+
import org.utbot.engine.types.STRING_TYPE
35
import soot.ArrayType
46
import soot.IntType
57
import soot.PrimType

utbot-framework/src/main/kotlin/org/utbot/engine/DataClasses.kt

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
package org.utbot.engine
22

3-
import org.utbot.common.WorkaroundReason
4-
import org.utbot.common.workaround
5-
import org.utbot.engine.TypeRegistry.Companion.objectTypeStorage
3+
import org.utbot.api.mock.UtMock
4+
import org.utbot.engine.overrides.UtOverrideMock
5+
import org.utbot.engine.types.TypeRegistry.Companion.objectTypeStorage
66
import org.utbot.engine.pc.UtAddrExpression
77
import org.utbot.engine.pc.UtBoolExpression
8+
import org.utbot.engine.pc.UtFalse
89
import org.utbot.engine.pc.UtInstanceOfExpression
910
import org.utbot.engine.pc.UtIsExpression
1011
import org.utbot.engine.pc.UtTrue
1112
import org.utbot.engine.pc.mkAnd
1213
import org.utbot.engine.pc.mkOr
1314
import org.utbot.engine.symbolic.*
15+
import org.utbot.engine.types.TypeResolver
1416
import org.utbot.framework.plugin.api.FieldId
1517
import org.utbot.framework.plugin.api.UtInstrumentation
1618
import soot.RefType
@@ -125,6 +127,9 @@ class TypeStorage private constructor(val leastCommonType: Type, val possibleCon
125127
"(leastCommonType=$leastCommonType, ${possibleConcreteTypes.size} possibleTypes=${possibleConcreteTypes.take(10)})"
126128
}
127129

130+
operator fun component1(): Type = leastCommonType
131+
operator fun component2(): Set<Type> = possibleConcreteTypes
132+
128133
companion object {
129134
/**
130135
* Constructs a type storage with particular leastCommonType and set of possibleConcreteTypes.
@@ -307,7 +312,16 @@ data class TypeConstraint(
307312
/**
308313
* Returns a conjunction of the [isConstraint] and [correctnessConstraint]. Suitable for an object creation.
309314
*/
310-
fun all(): UtBoolExpression = mkAnd(isOrNullConstraint(), correctnessConstraint)
315+
fun all(): UtBoolExpression {
316+
// There is no need in constraint for UtMock and UtOverrideMock instances
317+
val className = (isConstraint.type as? RefType)?.sootClass?.toString()
318+
319+
if (className == utMockClassName || className == utOverrideMockClassName) {
320+
return UtTrue
321+
}
322+
323+
return mkAnd(isOrNullConstraint(), correctnessConstraint)
324+
}
311325

312326
/**
313327
* Returns a condition that either the object is an instance of the types in [isConstraint], or it is null.
@@ -319,7 +333,13 @@ data class TypeConstraint(
319333
* For example, it is suitable for instanceof checks or negation of equality with some types.
320334
* NOTE: for Object we always return UtTrue.
321335
*/
322-
fun isConstraint(): UtBoolExpression = if (isConstraint.typeStorage.isObjectTypeStorage()) UtTrue else isConstraint
336+
fun isConstraint(): UtBoolExpression {
337+
if (isConstraint.typeStorage.possibleConcreteTypes.isEmpty()) {
338+
return UtFalse
339+
}
340+
341+
return if (isConstraint.typeStorage.isObjectTypeStorage()) UtTrue else isConstraint
342+
}
323343

324344
override fun hashCode(): Int = this.hashcode
325345

@@ -344,3 +364,6 @@ data class TypeConstraint(
344364
* should be initialized. We don't need to initialize fields that are not accessed in the method being tested.
345365
*/
346366
data class InstanceFieldReadOperation(val addr: UtAddrExpression, val fieldId: FieldId)
367+
368+
private val utMockClassName: String = UtMock::class.java.name
369+
private val utOverrideMockClassName: String = UtOverrideMock::class.java.name

utbot-framework/src/main/kotlin/org/utbot/engine/ExecutionState.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import soot.SootMethod
1818
import soot.jimple.Stmt
1919
import java.util.Objects
2020
import org.utbot.engine.symbolic.Assumption
21-
import org.utbot.framework.plugin.api.UtSymbolicExecution
2221

2322
const val RETURN_DECISION_NUM = -1
2423
const val CALL_DECISION_NUM = -2

utbot-framework/src/main/kotlin/org/utbot/engine/Extensions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import org.utbot.engine.pc.UtFp32Sort
1414
import org.utbot.engine.pc.UtFp64Sort
1515
import org.utbot.engine.pc.UtIntSort
1616
import org.utbot.engine.pc.UtLongSort
17-
import org.utbot.engine.pc.UtSeqSort
1817
import org.utbot.engine.pc.UtShortSort
1918
import org.utbot.engine.pc.UtSolverStatusKind
2019
import org.utbot.engine.pc.UtSolverStatusSAT
@@ -67,6 +66,7 @@ import java.util.Queue
6766
import java.util.concurrent.ConcurrentHashMap
6867
import kotlinx.collections.immutable.PersistentMap
6968
import kotlinx.collections.immutable.persistentHashMapOf
69+
import org.utbot.engine.types.OBJECT_TYPE
7070

7171
val JIdentityStmt.lines: String
7272
get() = tags.joinToString { "$it" }

utbot-framework/src/main/kotlin/org/utbot/engine/Hierarchy.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.utbot.engine
22

3+
import org.utbot.engine.types.TypeRegistry
34
import org.utbot.framework.plugin.api.ClassId
45
import org.utbot.framework.plugin.api.id
56
import soot.RefType

0 commit comments

Comments
 (0)