@@ -36,33 +36,37 @@ import org.usvm.instrumentation.testcase.api.UTestStringExpression
36
36
import org.utbot.framework.codegen.domain.builtin.UtilMethodProvider
37
37
import org.utbot.framework.plugin.api.ExecutableId
38
38
import org.utbot.framework.plugin.api.FieldId
39
+ import org.utbot.framework.plugin.api.MethodId
39
40
import org.utbot.framework.plugin.api.UtArrayModel
40
41
import org.utbot.framework.plugin.api.UtAssembleModel
41
42
import org.utbot.framework.plugin.api.UtClassRefModel
42
43
import org.utbot.framework.plugin.api.UtCompositeModel
43
44
import org.utbot.framework.plugin.api.UtExecutableCallModel
44
45
import org.utbot.framework.plugin.api.UtInstrumentation
45
46
import org.utbot.framework.plugin.api.UtModel
47
+ import org.utbot.framework.plugin.api.UtNewInstanceInstrumentation
46
48
import org.utbot.framework.plugin.api.UtNullModel
47
49
import org.utbot.framework.plugin.api.UtPrimitiveModel
50
+ import org.utbot.framework.plugin.api.UtStaticMethodInstrumentation
48
51
import org.utbot.framework.plugin.api.util.classClassId
49
52
import org.utbot.framework.plugin.api.util.objectClassId
53
+ import org.utbot.framework.plugin.api.util.voidClassId
50
54
import org.utbot.fuzzer.IdGenerator
51
55
52
56
class UTestInstToUtModelConverter (
53
- private val idGenerator : IdGenerator < Int > ,
57
+ private val uTest : UTest ,
54
58
private val jcClasspath : JcClasspath ,
59
+ private val idGenerator : IdGenerator <Int >,
55
60
private val utilMethodProvider : UtilMethodProvider ,
56
61
) {
57
62
private val exprToModelCache = mutableMapOf<UTestExpression , UtModel >()
58
63
private val instrumentations = mutableListOf<UtInstrumentation >()
59
64
60
- fun processUTest (uTest : UTest ) {
61
- exprToModelCache.clear()
62
- instrumentations.clear()
63
-
65
+ fun processUTest (): UTestAnalysisResult {
64
66
uTest.initStatements.forEach { uInst -> processInst(uInst) }
65
67
removeInstantiationCallFromThisInstanceModificationChain(processExpr(uTest.callMethodExpression))
68
+
69
+ return UTestAnalysisResult (instrumentations)
66
70
}
67
71
68
72
fun findModelByInst (expr : UTestExpression ): UtModel {
@@ -301,7 +305,43 @@ class UTestInstToUtModelConverter(
301
305
}
302
306
303
307
is UTestGlobalMock -> {
304
- // TODO usvm-sbft: collect instrumentations here
308
+ val methodsToExprs = uTestExpr.methods.entries
309
+ val initMethodExprs = methodsToExprs.filter { it.key.isConstructor }
310
+ val otherMethodsExprs = methodsToExprs.minus(initMethodExprs.toSet())
311
+
312
+ otherMethodsExprs
313
+ .forEach { (jcMethod, uTestExprs) ->
314
+ val methodId = jcMethod.toExecutableId(jcClasspath) as MethodId
315
+ val valueModels = uTestExprs.map { expr -> processExpr(expr) }
316
+ val methodInstrumentation = UtStaticMethodInstrumentation (
317
+ methodId = methodId,
318
+ values = valueModels,
319
+ )
320
+
321
+ instrumentations + = methodInstrumentation
322
+ }
323
+
324
+ initMethodExprs
325
+ .forEach { (jcMethod, uTestExprs) ->
326
+ // TODO usvm-sbft-merge: it can be .map { expr -> processExpr(expr) } here
327
+ // However, there's no special treatment for cases when <init> method occurs in a global mock
328
+ val valueModels = uTestExprs.map { _ -> UtCompositeModel (
329
+ id= idGenerator.createId(),
330
+ classId = voidClassId,
331
+ isMock = true ,
332
+ )
333
+ }
334
+ val methodInstrumentation = UtNewInstanceInstrumentation (
335
+ classId = jcMethod.enclosingClass.classId,
336
+ instances = valueModels,
337
+ // [UTestGlobalMock] does not have an equivalent of [callSites],
338
+ // but it is used only in UtBot instrumentation. We use USVM one, so it is not a problem.
339
+ callSites = emptySet(),
340
+ )
341
+
342
+ instrumentations + = methodInstrumentation
343
+ }
344
+
305
345
// UtClassRefModel is returned here for consistency with [Descriptor2ValueConverter]
306
346
// which returns Class<*> instance for [UTestGlobalMock] descriptors.
307
347
UtClassRefModel (
@@ -320,4 +360,8 @@ class UTestInstToUtModelConverter(
320
360
is UTestArrayLengthExpression -> error(" This expression type is not supported" )
321
361
}
322
362
}
323
- }
363
+ }
364
+
365
+ data class UTestAnalysisResult (
366
+ val instrumentation : List <UtInstrumentation >,
367
+ )
0 commit comments