Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
fb0adca
Draft: model synthesis
Jun 20, 2022
11c47d9
m
AbdullinAM Jun 20, 2022
4aaa8e5
first prototype, needs debugging and tuning
AbdullinAM Jun 22, 2022
9c63ba0
prototype
AbdullinAM Jun 28, 2022
707fa6d
refactor
AbdullinAM Jun 29, 2022
10c4193
very early prototype
AbdullinAM Jul 8, 2022
4285a5c
UtConstraintModel implemented
AbdullinAM Jul 12, 2022
22e2266
partial UtConstraint to UtExpression convertion
AbdullinAM Jul 14, 2022
6b47a9a
working prototypes
AbdullinAM Jul 19, 2022
a75a840
bugfixes + expression support in constraints
AbdullinAM Jul 21, 2022
fb392f6
m
AbdullinAM Jul 26, 2022
5f35311
everything kind of works, but some constraints need to be added
AbdullinAM Jul 27, 2022
ba9bb62
first working protoype with arrays
AbdullinAM Aug 1, 2022
065924f
renaming
AbdullinAM Aug 1, 2022
8cc7515
first tests and fixes
AbdullinAM Aug 2, 2022
4a14606
more expressions supported
AbdullinAM Aug 3, 2022
bbf525b
some cleanup + more expressions supported
AbdullinAM Aug 8, 2022
850b530
cleanup
AbdullinAM Aug 8, 2022
8799691
support for multidimensional arrays + fix for array generation
AbdullinAM Aug 9, 2022
60df4a4
first support of lists
AbdullinAM Aug 10, 2022
8963a7e
support sets
AbdullinAM Aug 10, 2022
1578c96
small refactorings
AbdullinAM Aug 11, 2022
1dd4b25
maps
AbdullinAM Aug 12, 2022
313757d
some cleanup and parameters
AbdullinAM Aug 12, 2022
faa0047
test write fix
AbdullinAM Aug 12, 2022
94740c9
m
AbdullinAM Aug 22, 2022
9920283
Merge branch 'main' into abdullin/constraint-model-synthesis
AbdullinAM Aug 22, 2022
fd22077
merge with master
AbdullinAM Aug 24, 2022
4e97b5f
first prototype of constraint scoring selector
AbdullinAM Aug 26, 2022
2544b31
m
AbdullinAM Aug 30, 2022
e585371
fixes
AbdullinAM Aug 31, 2022
d2564e9
Merge branch 'main' into abdullin/constraint-model-synthesis
AbdullinAM Sep 7, 2022
bb1acbc
Merge branch 'main' into abdullin/constraint-model-synthesis
AbdullinAM Sep 7, 2022
c6fbeb0
Split constraint models into a set of non-intersecting subsets before…
AbdullinAM Sep 12, 2022
2553ef7
m
AbdullinAM Sep 12, 2022
e943a16
some cleanup
AbdullinAM Sep 13, 2022
cd5fff8
more cleanup
AbdullinAM Sep 13, 2022
c2a7d31
order models in the subsets
AbdullinAM Sep 13, 2022
d1b09c8
simple caching of synthesis unit contexts
AbdullinAM Sep 13, 2022
eedccb9
option to enable/disable caching of synthesis contexts
AbdullinAM Sep 14, 2022
11eea4d
m
AbdullinAM Sep 14, 2022
9712e70
tests
AbdullinAM Sep 14, 2022
1c6b679
unit tests fixed
AbdullinAM Sep 19, 2022
4e37763
Merge branch 'main' into abdullin/constraint-model-synthesis
AbdullinAM Sep 28, 2022
34ed6fe
merge with main
AbdullinAM Sep 28, 2022
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
prototype
  • Loading branch information
AbdullinAM committed Jun 28, 2022
commit 9c63ba0ca5ac1f60fd84b48e131ab3e86c0a7f25
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,8 @@ import org.utbot.engine.pc.select
import org.utbot.engine.pc.store
import org.utbot.engine.selectors.*
import org.utbot.engine.selectors.nurs.NonUniformRandomSearch
import org.utbot.engine.selectors.strategies.DefaultScoringStrategy
import org.utbot.engine.selectors.strategies.GraphViz
import org.utbot.engine.selectors.strategies.ScoringStrategy
import org.utbot.engine.selectors.strategies.ScoringStrategyBuilder
import org.utbot.engine.symbolic.HardConstraint
import org.utbot.engine.symbolic.SoftConstraint
import org.utbot.engine.symbolic.SymbolicState
Expand Down Expand Up @@ -232,7 +231,7 @@ var nextDefaultModelId = 1500_000_000
private fun pathSelector(
graph: InterProceduralUnitGraph,
typeRegistry: TypeRegistry,
scoringStrategy: ScoringStrategy,
scoringStrategy: ScoringStrategyBuilder,
) = when (pathSelectorType) {
PathSelectorType.COVERED_NEW_SELECTOR -> coveredNewSelector(graph) {
withStepsLimit(pathSelectorStepsLimit)
Expand All @@ -258,7 +257,7 @@ private fun pathSelector(
PathSelectorType.RANDOM_PATH_SELECTOR -> randomPathSelector(graph, StrategyOption.DISTANCE) {
withStepsLimit(pathSelectorStepsLimit)
}
PathSelectorType.SCORING_PATH_SELECTOR -> scoringPathSelector(graph, scoringStrategy) {
PathSelectorType.SCORING_PATH_SELECTOR -> scoringPathSelector(graph, scoringStrategy.build(graph, typeRegistry)) {
withStepsLimit(pathSelectorStepsLimit)
}
}
Expand All @@ -273,7 +272,7 @@ class UtBotSymbolicEngine(
chosenClassesToMockAlways: Set<ClassId>,
private val solverTimeoutInMillis: Int = checkSolverTimeoutMillis,
private val postConditionConstructor: PostConditionConstructor = EmptyPostCondition,
scoringStrategy: ScoringStrategy = DefaultScoringStrategy
scoringStrategy: ScoringStrategyBuilder = ScoringStrategyBuilder()
) : UtContextInitializer() {

private val methodUnderAnalysisStmts: Set<Stmt> = graph.stmts.toSet()
Expand Down Expand Up @@ -387,6 +386,12 @@ class UtBotSymbolicEngine(
method = globalGraph.method(initStmt),
state = initState
)

environment = with(environment) {
val softConstraintsUpdate = postConditionConstructor.constructSoftPostCondition(this@UtBotSymbolicEngine)
copy(state = state.copy(symbolicState = state.symbolicState + softConstraintsUpdate))
}

pathSelector.use {

while (currentCoroutineContext().isActive) {
Expand All @@ -403,7 +408,8 @@ class UtBotSymbolicEngine(
}

stateSelectedCount++
pathLogger.trace { "traverse<$methodUnderTest>: choosing next state($stateSelectedCount), " +
pathLogger.trace {
"traverse<$methodUnderTest>: choosing next state($stateSelectedCount), " +
"queue size=${(pathSelector as? NonUniformRandomSearch)?.size ?: -1}"
}

Expand Down Expand Up @@ -888,7 +894,8 @@ class UtBotSymbolicEngine(
}

val initializedStaticFieldsMemoryUpdate = MemoryUpdate(
initializedStaticFields = staticFields.associate { it.first.fieldId to it.second.single() }.toPersistentMap(),
initializedStaticFields = staticFields.associate { it.first.fieldId to it.second.single() }
.toPersistentMap(),
meaningfulStaticFields = meaningfulStaticFields.map { it.first.fieldId }.toPersistentSet()
)

Expand Down Expand Up @@ -1232,7 +1239,12 @@ class UtBotSymbolicEngine(
?: error("Exception wasn't caught, stmt: $current, line: ${current.lines}")
val nextState = environment.state.updateQueued(
globalGraph.succ(current),
SymbolicStateUpdate(localMemoryUpdates = localMemoryUpdate(localVariable to value, CAUGHT_EXCEPTION to null))
SymbolicStateUpdate(
localMemoryUpdates = localMemoryUpdate(
localVariable to value,
CAUGHT_EXCEPTION to null
)
)
)
pathSelector.offer(nextState)
}
Expand Down Expand Up @@ -1447,7 +1459,8 @@ class UtBotSymbolicEngine(
queuedSymbolicStateUpdates += MemoryUpdate(mockInfos = persistentListOf(MockInfoEnriched(mockInfo)))

// add typeConstraint for mocked object. It's a declared type of the object.
queuedSymbolicStateUpdates += typeRegistry.typeConstraint(addr, mockedObject.typeStorage).all().asHardConstraint()
queuedSymbolicStateUpdates += typeRegistry.typeConstraint(addr, mockedObject.typeStorage).all()
.asHardConstraint()
queuedSymbolicStateUpdates += mkEq(typeRegistry.isMock(mockedObject.addr), UtTrue).asHardConstraint()

return mockedObject
Expand Down Expand Up @@ -1485,7 +1498,8 @@ class UtBotSymbolicEngine(
queuedSymbolicStateUpdates += MemoryUpdate(mockInfos = persistentListOf(MockInfoEnriched(mockInfo)))

// add typeConstraint for mocked object. It's a declared type of the object.
queuedSymbolicStateUpdates += typeRegistry.typeConstraint(addr, mockedObject.typeStorage).all().asHardConstraint()
queuedSymbolicStateUpdates += typeRegistry.typeConstraint(addr, mockedObject.typeStorage).all()
.asHardConstraint()
queuedSymbolicStateUpdates += mkEq(typeRegistry.isMock(mockedObject.addr), UtTrue).asHardConstraint()

return mockedObject
Expand Down Expand Up @@ -1520,7 +1534,8 @@ class UtBotSymbolicEngine(
createObject(addr, refType, useConcreteType = true)
}
} else {
queuedSymbolicStateUpdates += typeRegistry.typeConstraint(addr, TypeStorage(refType)).all().asHardConstraint()
queuedSymbolicStateUpdates += typeRegistry.typeConstraint(addr, TypeStorage(refType)).all()
.asHardConstraint()

objectValue(refType, addr, StringWrapper()).also {
initStringLiteral(it, this.value)
Expand Down Expand Up @@ -1643,7 +1658,11 @@ class UtBotSymbolicEngine(
val arrayType = type.arrayType
val arrayValue = createNewArray(value.length.toPrimitiveValue(), arrayType, type).also {
val defaultValue = arrayType.defaultSymValue
queuedSymbolicStateUpdates += arrayUpdateWithValue(it.addr, arrayType, defaultValue as UtArrayExpressionBase)
queuedSymbolicStateUpdates += arrayUpdateWithValue(
it.addr,
arrayType,
defaultValue as UtArrayExpressionBase
)
}
queuedSymbolicStateUpdates += objectUpdate(
stringWrapper.copy(typeStorage = TypeStorage(utStringClass.type)),
Expand Down Expand Up @@ -1807,7 +1826,8 @@ class UtBotSymbolicEngine(
return objectValue.copy(addr = nullObjectAddr)
}

val typeConstraint = typeRegistry.typeConstraint(castedObject.addr, castedObject.typeStorage).isOrNullConstraint()
val typeConstraint =
typeRegistry.typeConstraint(castedObject.addr, castedObject.typeStorage).isOrNullConstraint()

// When we do downCast, we should add possible equality to null
// to avoid situation like this:
Expand Down Expand Up @@ -1963,7 +1983,8 @@ class UtBotSymbolicEngine(
)

if (objectValue.type.isJavaLangObject()) {
queuedSymbolicStateUpdates += typeRegistry.zeroDimensionConstraint(objectValue.addr).asSoftConstraint()
queuedSymbolicStateUpdates += typeRegistry.zeroDimensionConstraint(objectValue.addr)
.asSoftConstraint()
}

objectValue
Expand Down Expand Up @@ -2839,7 +2860,11 @@ class UtBotSymbolicEngine(
return listOf(
MethodResult(
newArray,
memoryUpdates = arrayUpdateWithValue(newArray.addr, arrayType, selectArrayExpressionFromMemory(src))
memoryUpdates = arrayUpdateWithValue(
newArray.addr,
arrayType,
selectArrayExpressionFromMemory(src)
)
)
)
}
Expand Down Expand Up @@ -3326,8 +3351,18 @@ class UtBotSymbolicEngine(
is JMulExpr -> when (sort.type) {
is ByteType -> lowerIntMulOverflowCheck(left, right, Byte.MIN_VALUE.toInt(), Byte.MAX_VALUE.toInt())
is ShortType -> lowerIntMulOverflowCheck(left, right, Short.MIN_VALUE.toInt(), Short.MAX_VALUE.toInt())
is IntType -> higherIntMulOverflowCheck(left, right, Int.SIZE_BITS, Int.MIN_VALUE.toLong()) { it: UtExpression -> it.toIntValue() }
is LongType -> higherIntMulOverflowCheck(left, right, Long.SIZE_BITS, Long.MIN_VALUE) { it: UtExpression -> it.toLongValue() }
is IntType -> higherIntMulOverflowCheck(
left,
right,
Int.SIZE_BITS,
Int.MIN_VALUE.toLong()
) { it: UtExpression -> it.toIntValue() }
is LongType -> higherIntMulOverflowCheck(
left,
right,
Long.SIZE_BITS,
Long.MIN_VALUE
) { it: UtExpression -> it.toLongValue() }
else -> null
}
else -> null
Expand Down Expand Up @@ -3543,11 +3578,19 @@ class UtBotSymbolicEngine(
//choose types that have biggest priority
resolvedParameters
.filterIsInstance<ReferenceValue>()
.forEach { queuedSymbolicStateUpdates += constructConstraintForType(it, it.possibleConcreteTypes).asSoftConstraint() }
.forEach {
queuedSymbolicStateUpdates += constructConstraintForType(
it,
it.possibleConcreteTypes
).asSoftConstraint()
}

val returnValue = (symbolicResult as? SymbolicSuccess)?.value as? ObjectValue
if (returnValue != null) {
queuedSymbolicStateUpdates += constructConstraintForType(returnValue, returnValue.possibleConcreteTypes).asSoftConstraint()
queuedSymbolicStateUpdates += constructConstraintForType(
returnValue,
returnValue.possibleConcreteTypes
).asSoftConstraint()

workaround(REMOVE_ANONYMOUS_CLASSES) {
val sootClass = returnValue.type.sootClass
Expand All @@ -3565,7 +3608,8 @@ class UtBotSymbolicEngine(
}

if (!isInNestedMethod()) {
val postConditionUpdates = postConditionConstructor.constructPostCondition(this@UtBotSymbolicEngine, symbolicResult)
val postConditionUpdates =
postConditionConstructor.constructPostCondition(this@UtBotSymbolicEngine, symbolicResult)
queuedSymbolicStateUpdates += postConditionUpdates
}

Expand Down Expand Up @@ -3622,7 +3666,15 @@ class UtBotSymbolicEngine(
Predictors.testName.provide(state.path, predictedTestName, "")

val resolver =
Resolver(hierarchy, updatedMemory, typeRegistry, typeResolver, holder, methodUnderTest.declaringClass.packageName, softMaxArraySize)
Resolver(
hierarchy,
updatedMemory,
typeRegistry,
typeResolver,
holder,
methodUnderTest.declaringClass.packageName,
softMaxArraySize
)

val (modelsBefore, modelsAfter, instrumentation) = resolver.resolveModels(resolvedParameters)

Expand Down Expand Up @@ -3713,7 +3765,7 @@ class UtBotSymbolicEngine(
queuedSymbolicStateUpdates
)
} finally {
queuedSymbolicStateUpdates = prevSymbolicStateUpdate
queuedSymbolicStateUpdates = prevSymbolicStateUpdate
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,11 @@ class ScoringPathSelectorBuilder internal constructor(
val scoringStrategy: ScoringStrategy,
context: PathSelectorContext = PathSelectorContext(graph)
) : PathSelectorBuilder<ScoringPathSelector>(graph, context) {
var seed: Int = 42
override fun build() = ScoringPathSelector(
withDistanceStrategy(),
scoringStrategy,
requireNotNull(context.stoppingStrategy) { "StoppingStrategy isn't specified" },
scoringStrategy
seed
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,22 @@
package org.utbot.engine.selectors

import org.utbot.engine.*
import org.utbot.engine.selectors.strategies.ChoosingStrategy
import org.utbot.engine.selectors.nurs.NonUniformRandomSearch
import org.utbot.engine.selectors.strategies.ScoringStrategy
import org.utbot.engine.selectors.strategies.StoppingStrategy
import java.util.PriorityQueue

open class ScoringPathSelector(
choosingStrategy: ChoosingStrategy,
class ScoringPathSelector(
override val choosingStrategy: ScoringStrategy,
stoppingStrategy: StoppingStrategy,
protected val scoringStrategy: ScoringStrategy,
) : BasePathSelector(choosingStrategy, stoppingStrategy) {
private val states = PriorityQueue<ExecutionState> { a, b ->
val aScore = scoringStrategy.score(a)
val bScore = scoringStrategy.score(b)
aScore.compareTo(bScore)
}
seed: Int? = 42
) : NonUniformRandomSearch(choosingStrategy, stoppingStrategy, seed) {

override fun offerImpl(state: ExecutionState) {
scoringStrategy.score(state)
states.add(state)
init {
choosingStrategy.subscribe(this)
}

override fun pollImpl(): ExecutionState? {
return states.poll()
}
override val ExecutionState.cost: Double
get() = choosingStrategy[this]

override fun peekImpl(): ExecutionState? {
return states.firstOrNull()
}

override fun removeImpl(state: ExecutionState): Boolean {
return states.remove(state)
}

override fun isEmpty() = states.isEmpty()

override val name = "ScoringSelector"

override fun close() {
states.forEach {
it.close()
}
}
override val name = "ScoringPathSelector"
}
Loading