Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 19ab8f5

Browse files
Allow Fuzzer use all class under test public methods #2344 (#2444)
1 parent 5089489 commit 19ab8f5

File tree

37 files changed

+330
-112
lines changed

37 files changed

+330
-112
lines changed

‎settings.gradle.kts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ rootProject.name = "utbot"
2828
include("utbot-core")
2929
include("utbot-framework")
3030
include("utbot-framework-api")
31+
include("utbot-modificators-analyzer")
3132
include("utbot-intellij")
3233
include("utbot-sample")
3334
include("utbot-java-fuzzing")

‎utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,7 @@ sealed class UtStatementCallModel(
826826
override val instance: UtReferenceModel?,
827827
open val statement: StatementId,
828828
open val params: List<UtModel>,
829+
var thrownConcreteException: ClassId? = null
829830
): UtStatementModel(instance) {
830831
override fun toString() = withToStringThreadLocalReentrancyGuard {
831832
buildString {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.utbot.framework.util
2+
3+
import org.utbot.framework.plugin.api.ExecutableId
4+
import org.utbot.framework.plugin.api.classId
5+
import org.utbot.framework.plugin.api.id
6+
import org.utbot.framework.plugin.api.util.constructorId
7+
import org.utbot.framework.plugin.api.util.methodId
8+
import soot.SootMethod
9+
10+
/**
11+
* Gets method or constructor id of SootMethod.
12+
*/
13+
val SootMethod.executableId: ExecutableId
14+
get() = when {
15+
isConstructor -> constructorId(
16+
classId = declaringClass.id,
17+
arguments = parameterTypes.map { it.classId }.toTypedArray()
18+
)
19+
else -> methodId(
20+
classId = declaringClass.id,
21+
name = name,
22+
returnType = returnType.classId,
23+
arguments = parameterTypes.map { it.classId }.toTypedArray()
24+
)
25+
}

‎utbot-framework-test/src/test/kotlin/org/utbot/framework/modificators/UtBotFieldModificatorsTest.kt‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import org.utbot.examples.modificators.StronglyConnectedComponents
1212
import org.utbot.examples.modificators.coupling.ClassA
1313
import org.utbot.examples.modificators.coupling.ClassB
1414
import org.utbot.examples.modificators.hierarchy.InheritedModifications
15-
import org.utbot.framework.modifications.AnalysisMode
16-
import org.utbot.framework.modifications.AnalysisMode.AllModificators
17-
import org.utbot.framework.modifications.AnalysisMode.SettersAndDirectAccessors
18-
import org.utbot.framework.modifications.UtBotFieldsModificatorsSearcher
15+
import org.utbot.modifications.AnalysisMode
16+
import org.utbot.modifications.AnalysisMode.AllModificators
17+
import org.utbot.modifications.AnalysisMode.SettersAndDirectAccessors
18+
import org.utbot.modifications.UtBotFieldsModificatorsSearcher
1919
import org.utbot.framework.plugin.api.util.UtContext
2020
import org.utbot.framework.plugin.api.util.id
2121
import kotlin.reflect.KClass
@@ -24,9 +24,9 @@ import org.junit.jupiter.api.Assertions.assertEquals
2424
import org.junit.jupiter.api.Assertions.assertTrue
2525
import org.junit.jupiter.api.BeforeEach
2626
import org.junit.jupiter.api.Test
27-
import org.utbot.common.nameOfPackage
2827
import org.utbot.framework.plugin.services.JdkInfoDefaultProvider
2928
import org.utbot.framework.util.SootUtils
29+
import org.utbot.modifications.ModificationTransformationMode
3030

3131
internal class UtBotFieldModificatorsTest {
3232
private lateinit var fieldsModificatorsSearcher: UtBotFieldsModificatorsSearcher
@@ -176,7 +176,9 @@ internal class UtBotFieldModificatorsTest {
176176
forceReload = false,
177177
jdkInfo = JdkInfoDefaultProvider().info
178178
)
179-
fieldsModificatorsSearcher = UtBotFieldsModificatorsSearcher()
179+
fieldsModificatorsSearcher = UtBotFieldsModificatorsSearcher(
180+
modificationTransformationMode = ModificationTransformationMode.WriteOnly
181+
)
180182
}
181183

182184
private fun runUpdate(classes: Set<KClass<*>>) {
@@ -193,7 +195,7 @@ internal class UtBotFieldModificatorsTest {
193195

194196
//We use sorting here to make comparing with sorted in advance expected collections easier
195197
private fun runFieldModificatorsSearch(analysisMode: AnalysisMode) =
196-
fieldsModificatorsSearcher.findModificators(analysisMode)
198+
fieldsModificatorsSearcher.getFieldToModificators(analysisMode)
197199
.map { (key, value) ->
198200
val modificatorNames = value.filterNot { it.name.startsWith("direct_set_") }.map { it.name }
199201
key.name to modificatorNames.toSortedSet()

‎utbot-framework/build.gradle‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ dependencies {
1414
api project(':utbot-summary')
1515
api project(':utbot-framework-api')
1616
api project(':utbot-rd')
17+
api project(':utbot-modificators-analyzer')
1718

1819
implementation group: 'com.jetbrains.rd', name: 'rd-framework', version: rdVersion
1920
implementation group: 'com.jetbrains.rd', name: 'rd-core', version: rdVersion

‎utbot-framework/src/main/kotlin/org/utbot/engine/OptionalWrapper.kt‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import org.utbot.framework.plugin.api.UtAssembleModel
1616
import org.utbot.framework.plugin.api.UtExecutableCallModel
1717
import org.utbot.framework.plugin.api.UtNullModel
1818
import org.utbot.framework.plugin.api.UtPrimitiveModel
19-
import org.utbot.framework.plugin.api.UtStatementModel
2019
import org.utbot.framework.plugin.api.classId
2120
import org.utbot.framework.plugin.api.id
2221
import org.utbot.framework.plugin.api.util.defaultValueModel

‎utbot-framework/src/main/kotlin/org/utbot/engine/StreamWrappers.kt‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@ import org.utbot.framework.plugin.api.UtExecutableCallModel
1313
import org.utbot.framework.plugin.api.UtModel
1414
import org.utbot.framework.plugin.api.UtNullModel
1515
import org.utbot.framework.plugin.api.UtPrimitiveModel
16-
import org.utbot.framework.plugin.api.UtStatementModel
1716
import org.utbot.framework.plugin.api.classId
1817
import org.utbot.framework.plugin.api.util.defaultValueModel
1918
import org.utbot.framework.plugin.api.util.doubleArrayClassId
2019
import org.utbot.framework.plugin.api.util.doubleClassId
2120
import org.utbot.framework.plugin.api.util.doubleStreamClassId
22-
import org.utbot.framework.plugin.api.util.id
2321
import org.utbot.framework.plugin.api.util.intArrayClassId
2422
import org.utbot.framework.plugin.api.util.intClassId
2523
import org.utbot.framework.plugin.api.util.intStreamClassId

‎utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ class UtBotSymbolicEngine(
537537

538538
emit(
539539
UtFuzzedExecution(
540-
stateBefore = stateBefore,
540+
stateBefore = concreteExecutionResult.stateBefore,
541541
stateAfter = concreteExecutionResult.stateAfter,
542542
result = concreteExecutionResult.result,
543543
coverage = concreteExecutionResult.coverage,

‎utbot-framework/src/main/kotlin/org/utbot/framework/assemble/AssembleModelGenerator.kt‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import org.utbot.engine.ResolvedExecution
77
import org.utbot.engine.ResolvedModels
88
import org.utbot.framework.UtSettings
99
import org.utbot.framework.codegen.util.isAccessibleFrom
10-
import org.utbot.framework.modifications.AnalysisMode.SettersAndDirectAccessors
11-
import org.utbot.framework.modifications.ConstructorAnalyzer
12-
import org.utbot.framework.modifications.ConstructorAssembleInfo
13-
import org.utbot.framework.modifications.UtBotFieldsModificatorsSearcher
10+
import org.utbot.modifications.AnalysisMode.SettersAndDirectAccessors
11+
import org.utbot.modifications.ConstructorAnalyzer
12+
import org.utbot.modifications.ConstructorAssembleInfo
13+
import org.utbot.modifications.UtBotFieldsModificatorsSearcher
1414
import org.utbot.framework.plugin.api.ClassId
1515
import org.utbot.framework.plugin.api.ConstructorId
1616
import org.utbot.framework.plugin.api.DirectFieldAccessId
@@ -48,6 +48,7 @@ import org.utbot.framework.plugin.api.util.jClass
4848
import org.utbot.framework.util.nextModelName
4949
import java.lang.reflect.Constructor
5050
import java.util.IdentityHashMap
51+
import org.utbot.modifications.ModificationTransformationMode
5152

5253
/**
5354
* Creates [UtAssembleModel] from any [UtModel] or it's inner models if possible
@@ -72,7 +73,10 @@ class AssembleModelGenerator(private val basePackageName: String) {
7273
//Call chain of statements to create assemble model
7374
private var callChain = mutableListOf<UtStatementModel>()
7475

75-
private val modificatorsSearcher = UtBotFieldsModificatorsSearcher()
76+
private val modificatorsSearcher =
77+
UtBotFieldsModificatorsSearcher(
78+
modificationTransformationMode = ModificationTransformationMode.WriteOnly
79+
)
7680
private val constructorAnalyzer = ConstructorAnalyzer()
7781

7882
/**
@@ -492,7 +496,7 @@ class AssembleModelGenerator(private val basePackageName: String) {
492496
* Finds setters and direct accessors for fields of particular class.
493497
*/
494498
private fun findSettersAndDirectAccessors(classId: ClassId): Map<FieldId, StatementId> {
495-
val allModificatorsOfClass = modificatorsSearcher.findModificators(SettersAndDirectAccessors)
499+
val allModificatorsOfClass = modificatorsSearcher.getFieldToModificators(SettersAndDirectAccessors)
496500

497501
return allModificatorsOfClass
498502
.mapNotNull { (fieldId, possibleModificators) ->

‎utbot-framework/src/main/kotlin/org/utbot/framework/codegen/tree/CgVariableConstructor.kt‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,13 @@ open class CgVariableConstructor(val context: CgContext) :
260260
is UtStatementCallModel -> {
261261
val call = createCgExecutableCallFromUtExecutableCall(statementModel)
262262
val equivalentFieldAccess = replaceCgExecutableCallWithFieldAccessIfNeeded(call)
263-
if (equivalentFieldAccess != null)
264-
+equivalentFieldAccess
265-
else
266-
+call
263+
val thrownException = statementModel.thrownConcreteException
264+
265+
if (equivalentFieldAccess != null) +equivalentFieldAccess
266+
else if (thrownException != null) {
267+
+tryBlock { +call }
268+
.catch(thrownException) { /* do nothing */ }
269+
} else +call
267270
}
268271
}
269272
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /