Skip to content

Commit 6f18f7a

Browse files
committed
Apply review fixes
1 parent 1fb52bb commit 6f18f7a

File tree

2 files changed

+23
-25
lines changed

2 files changed

+23
-25
lines changed

utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/converter/JcToUtExecutionConverter.kt

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,13 @@ class JcToUtExecutionConverter(
5656
private val toValueConverter = Descriptor2ValueConverter(utContext.classLoader)
5757

5858
private var jcToUtModelConverter: JcToUtModelConverter
59-
private var instrumentation: List<UtInstrumentation>
59+
private var uTestProcessResult: UTestAnalysisResult
6060

6161
init {
62-
val instToModelConverter = UTestInstToUtModelConverter(idGenerator, jcClasspath, utilMethodProvider)
63-
64-
instToModelConverter.processUTest(jcExecution.uTest).also {
65-
instrumentation = instToModelConverter.findInstrumentations()
66-
}
67-
62+
val instToModelConverter = UTestInstToUtModelConverter(jcExecution.uTest, jcClasspath, idGenerator, utilMethodProvider)
6863
jcToUtModelConverter = JcToUtModelConverter(idGenerator, jcClasspath, instToModelConverter)
64+
65+
uTestProcessResult = instToModelConverter.processUTest()
6966
}
7067

7168
fun convert(): UtExecution? {
@@ -80,7 +77,7 @@ class JcToUtExecutionConverter(
8077
jcToUtModelConverter.convert(it, EnvironmentStateKind.FINAL)
8178
} ?: UtVoidModel),
8279
coverage = coverage,
83-
instrumentation = instrumentation,
80+
instrumentation = uTestProcessResult.instrumentation,
8481
)
8582
is UTestExecutionExceptionResult -> {
8683
UtUsvmExecution(
@@ -91,7 +88,7 @@ class JcToUtExecutionConverter(
9188
jcExecution.method,
9289
),
9390
coverage = coverage,
94-
instrumentation = instrumentation,
91+
instrumentation = uTestProcessResult.instrumentation,
9592
)
9693
}
9794

utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/converter/UTestInstToUtModelConverter.kt

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import org.usvm.instrumentation.testcase.api.UTestShortExpression
3434
import org.usvm.instrumentation.testcase.api.UTestStaticMethodCall
3535
import org.usvm.instrumentation.testcase.api.UTestStringExpression
3636
import org.utbot.framework.codegen.domain.builtin.UtilMethodProvider
37-
import org.utbot.framework.plugin.api.ConstructorId
3837
import org.utbot.framework.plugin.api.ExecutableId
3938
import org.utbot.framework.plugin.api.FieldId
4039
import org.utbot.framework.plugin.api.MethodId
@@ -54,19 +53,19 @@ import org.utbot.framework.plugin.api.util.objectClassId
5453
import org.utbot.fuzzer.IdGenerator
5554

5655
class UTestInstToUtModelConverter(
57-
private val idGenerator: IdGenerator<Int>,
56+
private val uTest: UTest,
5857
private val jcClasspath: JcClasspath,
58+
private val idGenerator: IdGenerator<Int>,
5959
private val utilMethodProvider: UtilMethodProvider,
6060
) {
6161
private val exprToModelCache = mutableMapOf<UTestExpression, UtModel>()
6262
private val instrumentations = mutableListOf<UtInstrumentation>()
6363

64-
fun processUTest(uTest: UTest) {
65-
exprToModelCache.clear()
66-
instrumentations.clear()
67-
64+
fun processUTest(): UTestAnalysisResult {
6865
uTest.initStatements.forEach { uInst -> processInst(uInst) }
6966
removeInstantiationCallFromThisInstanceModificationChain(processExpr(uTest.callMethodExpression))
67+
68+
return UTestAnalysisResult(instrumentations)
7069
}
7170

7271
fun findModelByInst(expr: UTestExpression): UtModel {
@@ -75,8 +74,6 @@ class UTestInstToUtModelConverter(
7574
return alreadyCreatedModel
7675
}
7776

78-
fun findInstrumentations(): List<UtInstrumentation> = instrumentations
79-
8077
private fun removeInstantiationCallFromThisInstanceModificationChain(model: UtModel) {
8178
if (model is UtAssembleModel) {
8279
val instantiationCall = model.instantiationCall
@@ -307,11 +304,11 @@ class UTestInstToUtModelConverter(
307304
}
308305

309306
is UTestGlobalMock -> {
310-
// Daniil said that we can miss [type] and [fields] when converting to [UtInstrumentation]
311307
val methodsToExprs = uTestExpr.methods.entries
308+
val initMethodExprs = methodsToExprs.filter { it.key.isConstructor }
309+
val otherMethodsExprs = methodsToExprs.minus(initMethodExprs.toSet())
312310

313-
methodsToExprs
314-
.filter { it.key is MethodId }
311+
otherMethodsExprs
315312
.forEach { (jcMethod, uTestExprs) ->
316313
val methodId = jcMethod.toExecutableId(jcClasspath) as MethodId
317314
val valueModels = uTestExprs.map { expr -> processExpr(expr) }
@@ -323,15 +320,15 @@ class UTestInstToUtModelConverter(
323320
instrumentations += methodInstrumentation
324321
}
325322

326-
methodsToExprs
327-
.filter { it.key is ConstructorId }
323+
initMethodExprs
328324
.forEach { (jcMethod, uTestExprs) ->
329325
val valueModels = uTestExprs.map { expr -> processExpr(expr) }
330326
val methodInstrumentation = UtNewInstanceInstrumentation(
331-
// TODO usvm-sbft looking at [Traverser] ln 1682, this classId does not seem correct
332327
classId = jcMethod.enclosingClass.classId,
333328
instances = valueModels,
334-
callSites = setOf(jcMethod.enclosingClass.classId),
329+
// [UTestGlobalMock] does not have an equivalent of [callSites],
330+
// but it is used only in UtBot instrumentation. We use USVM one, so it is not a problem.
331+
callSites = emptySet(),
335332
)
336333

337334
instrumentations += methodInstrumentation
@@ -355,4 +352,8 @@ class UTestInstToUtModelConverter(
355352
is UTestArrayLengthExpression -> error("This expression type is not supported")
356353
}
357354
}
358-
}
355+
}
356+
357+
data class UTestAnalysisResult(
358+
val instrumentation: List<UtInstrumentation>,
359+
)

0 commit comments

Comments
 (0)