Solver optimizations by CaelmBleidd · Pull Request #1265 · UnitTestBot/UTBotJava · GitHub
Skip to content
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
@@ -1,5 +1,6 @@
package org.utbot.examples.arrays

import org.junit.jupiter.api.Disabled
import org.utbot.tests.infrastructure.UtValueTestCaseChecker
import org.utbot.tests.infrastructure.DoNotCalculate
import org.utbot.tests.infrastructure.atLeast
Expand Down Expand Up @@ -268,10 +269,13 @@ internal class ArrayOfArraysTest : UtValueTestCaseChecker(testClass = ArrayOfArr
}

@Test
@Disabled("https://github.com/UnitTestBot/UTBotJava/issues/1267")
fun testArrayWithItselfAnAsElement() {
check(
ArrayOfArrays::arrayWithItselfAnAsElement,
eq(2),
{ a, r -> a !== a[0] && r == null },
{ a, r -> a === a[0] && a.contentDeepEquals(r) },
coverage = atLeast(percents = 94)
// because of the assumption
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,24 @@ package org.utbot.examples.mixed
import org.utbot.tests.infrastructure.UtValueTestCaseChecker
import org.utbot.tests.infrastructure.DoNotCalculate
import org.junit.jupiter.api.Test
import org.utbot.framework.plugin.api.CodegenLanguage
import org.utbot.testcheckers.eq
import org.utbot.tests.infrastructure.Compilation

internal class PrivateConstructorExampleTest : UtValueTestCaseChecker(testClass = PrivateConstructorExample::class) {
// TODO parameterized tests disabled due to https://github.com/UnitTestBot/UTBotJava/issues/1266
internal class PrivateConstructorExampleTest : UtValueTestCaseChecker(
testClass = PrivateConstructorExample::class,
pipelines = listOf(
TestLastStage(
CodegenLanguage.JAVA,
parameterizedModeLastStage = Compilation
),
TestLastStage(
CodegenLanguage.KOTLIN,
parameterizedModeLastStage = Compilation
)
)
) {

/**
* Two branches need to be covered:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import org.utbot.engine.pc.mkInt
import org.utbot.engine.pc.select
import org.utbot.engine.pc.store
import org.utbot.engine.symbolic.asHardConstraint
import org.utbot.engine.types.OBJECT_TYPE
import org.utbot.engine.types.TypeRegistry
import org.utbot.framework.plugin.api.ClassId
import org.utbot.framework.plugin.api.UtArrayModel
import org.utbot.framework.plugin.api.UtCompositeModel
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.utbot.engine

import org.utbot.engine.types.OBJECT_TYPE
import org.utbot.engine.types.STRING_TYPE
import soot.ArrayType
import soot.IntType
import soot.PrimType
Expand Down
33 changes: 28 additions & 5 deletions utbot-framework/src/main/kotlin/org/utbot/engine/DataClasses.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package org.utbot.engine

import org.utbot.common.WorkaroundReason
import org.utbot.common.workaround
import org.utbot.engine.TypeRegistry.Companion.objectTypeStorage
import org.utbot.api.mock.UtMock
import org.utbot.engine.overrides.UtOverrideMock
import org.utbot.engine.types.TypeRegistry.Companion.objectTypeStorage
import org.utbot.engine.pc.UtAddrExpression
import org.utbot.engine.pc.UtBoolExpression
import org.utbot.engine.pc.UtFalse
import org.utbot.engine.pc.UtInstanceOfExpression
import org.utbot.engine.pc.UtIsExpression
import org.utbot.engine.pc.UtTrue
import org.utbot.engine.pc.mkAnd
import org.utbot.engine.pc.mkOr
import org.utbot.engine.symbolic.*
import org.utbot.engine.types.TypeResolver
import org.utbot.framework.plugin.api.FieldId
import org.utbot.framework.plugin.api.UtInstrumentation
import soot.RefType
Expand Down Expand Up @@ -125,6 +127,9 @@ class TypeStorage private constructor(val leastCommonType: Type, val possibleCon
"(leastCommonType=$leastCommonType, ${possibleConcreteTypes.size} possibleTypes=${possibleConcreteTypes.take(10)})"
}

operator fun component1(): Type = leastCommonType
operator fun component2(): Set<Type> = possibleConcreteTypes

companion object {
/**
* Constructs a type storage with particular leastCommonType and set of possibleConcreteTypes.
Expand Down Expand Up @@ -307,7 +312,16 @@ data class TypeConstraint(
/**
* Returns a conjunction of the [isConstraint] and [correctnessConstraint]. Suitable for an object creation.
*/
fun all(): UtBoolExpression = mkAnd(isOrNullConstraint(), correctnessConstraint)
fun all(): UtBoolExpression {
// There is no need in constraint for UtMock and UtOverrideMock instances
val sootClass = (isConstraint.type as? RefType)?.sootClass

if (sootClass == utMockClass || sootClass == utOverrideMockClass) {
return UtTrue
}

return mkAnd(isOrNullConstraint(), correctnessConstraint)
}

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

return if (isConstraint.typeStorage.isObjectTypeStorage()) UtTrue else isConstraint
}

override fun hashCode(): Int = this.hashcode

Expand All @@ -344,3 +364,6 @@ data class TypeConstraint(
* should be initialized. We don't need to initialize fields that are not accessed in the method being tested.
*/
data class InstanceFieldReadOperation(val addr: UtAddrExpression, val fieldId: FieldId)

private val utMockClassName: String = UtMock::class.java.name
private val utOverrideMockClassName: String = UtOverrideMock::class.java.name
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import soot.SootMethod
import soot.jimple.Stmt
import java.util.Objects
import org.utbot.engine.symbolic.Assumption
import org.utbot.framework.plugin.api.UtSymbolicExecution

const val RETURN_DECISION_NUM = -1
const val CALL_DECISION_NUM = -2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import org.utbot.engine.pc.UtFp32Sort
import org.utbot.engine.pc.UtFp64Sort
import org.utbot.engine.pc.UtIntSort
import org.utbot.engine.pc.UtLongSort
import org.utbot.engine.pc.UtSeqSort
import org.utbot.engine.pc.UtShortSort
import org.utbot.engine.pc.UtSolverStatusKind
import org.utbot.engine.pc.UtSolverStatusSAT
Expand Down Expand Up @@ -67,6 +66,7 @@ import java.util.Queue
import java.util.concurrent.ConcurrentHashMap
import kotlinx.collections.immutable.PersistentMap
import kotlinx.collections.immutable.persistentHashMapOf
import org.utbot.engine.types.OBJECT_TYPE

val JIdentityStmt.lines: String
get() = tags.joinToString { "$it" }
Expand Down
Loading