Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
6d4f05c
Some awful attempts
EgorkaKulikov Oct 28, 2023
4aa8a10
Initially implemented a converter of UTestInst to UtModel
EgorkaKulikov Oct 30, 2023
ddcf870
Refactor JcToUtModelConverter basing on UTestInst2UtModel converter
EgorkaKulikov Oct 31, 2023
9532b8a
Some steps to implement JcToUtExecutionConverter
EgorkaKulikov Oct 31, 2023
d79ea8b
Implement minimalistic jc to ut execution conversion, enable codegen
IlyaMuravjov Nov 1, 2023
8e30b30
Some improvements
EgorkaKulikov Nov 1, 2023
5935d7b
DeepMapper for models is used
EgorkaKulikov Nov 3, 2023
535abb0
Corrections
EgorkaKulikov Nov 3, 2023
509cb73
Some improvements to JcToUtModelConverter
EgorkaKulikov Nov 3, 2023
21bde03
Further improvements to JcToUtModelConverter
EgorkaKulikov Nov 3, 2023
6471f07
Another converter little improvement
EgorkaKulikov Nov 3, 2023
c14067f
Improve `UtExecutionFailure` creation
IlyaMuravjov Nov 3, 2023
20967a9
Finish implementing `JcToUtModelConverter`
IlyaMuravjov Nov 5, 2023
bf6d497
Refactor nullability in `JcToUtModelConverter` and `JcToUtExecutionCo…
IlyaMuravjov Nov 5, 2023
1a893ad
First version of JC to UT converters without overusing `Descriptor2Va…
IlyaMuravjov Nov 5, 2023
1717235
Processed forgotten call method expression
EgorkaKulikov Nov 7, 2023
f2debe4
Make conversion more class-friendly (do not fail if one method cause …
EgorkaKulikov Nov 7, 2023
c191ed3
Make it possible to use samples in ContestEstimator
EgorkaKulikov Nov 7, 2023
e61cef4
Tested on all primitives
EgorkaKulikov Nov 7, 2023
bb82a6b
contrflow tests added
EgorkaKulikov Nov 7, 2023
13ee51e
More test classes added
EgorkaKulikov Nov 7, 2023
b01d6b3
Add `build/output/test/samples` to `utbot-junit-contest` test projects
IlyaMuravjov Nov 8, 2023
61c1608
Steps to avoid duplicating statements
EgorkaKulikov Nov 8, 2023
f455f99
Merge remote-tracking branch 'origin/egor/jc_to_ut_models_converter' …
EgorkaKulikov Nov 8, 2023
a31d6b1
Make it working correct on IntExamples.max
EgorkaKulikov Nov 8, 2023
98b4398
Remove OptimizeImportsProcessor (seems it was not called, but a sourc…
EgorkaKulikov Nov 8, 2023
0ca848a
Process UTestStaticMethodCall
EgorkaKulikov Nov 8, 2023
9442c72
Comment out includes for IDE related projects in `settings.gradle.kts`
IlyaMuravjov Nov 8, 2023
f37c1eb
Avoid using burningwave to export modules on Java 8
IlyaMuravjov Nov 8, 2023
cea02dd
Fix review comments
EgorkaKulikov Nov 8, 2023
813c2d6
Fix review comments
EgorkaKulikov Nov 9, 2023
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
Make it working correct on IntExamples.max
  • Loading branch information
EgorkaKulikov committed Nov 8, 2023
commit a31d6b1ce6c0dbb3a9a59854fc08dfb4df8cd010
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ class JcToUtExecutionConverter(
) {
private val toValueConverter = Descriptor2ValueConverter(utContext.classLoader)

private var modelConverter: JcToUtModelConverter
private var jcToUtModelConverter: JcToUtModelConverter

init {
val instToModelConverter = UTestInst2UtModelConverter(idGenerator, utilMethodProvider)
val uTestProcessResult = instToModelConverter.processUTest(jcExecution.uTest)

modelConverter = JcToUtModelConverter(idGenerator, uTestProcessResult)
instToModelConverter.processUTest(jcExecution.uTest)
jcToUtModelConverter = JcToUtModelConverter(idGenerator, instToModelConverter)
}

fun convert(): UtExecution? {
Expand All @@ -58,17 +58,17 @@ class JcToUtExecutionConverter(

val utUsvmExecution: UtUsvmExecution = when (val executionResult = jcExecution.uTestExecutionResult) {
is UTestExecutionSuccessResult -> UtUsvmExecution(
stateBefore = convertState(executionResult.initialState, jcExecution.method, modelConverter),
stateAfter = convertState(executionResult.resultState, jcExecution.method, modelConverter),
stateBefore = convertState(executionResult.initialState, jcExecution.method, jcToUtModelConverter),
stateAfter = convertState(executionResult.resultState, jcExecution.method, jcToUtModelConverter),
// TODO usvm-sbft: ask why `UTestExecutionSuccessResult.result` is nullable
result = UtExecutionSuccess(executionResult.result?.let { modelConverter.convert(it) } ?: UtVoidModel),
result = UtExecutionSuccess(executionResult.result?.let { jcToUtModelConverter.convert(it) } ?: UtVoidModel),
coverage = coverage,
instrumentation = instrumentation,
)
is UTestExecutionExceptionResult -> {
UtUsvmExecution(
stateBefore = convertState(executionResult.initialState, jcExecution.method, modelConverter),
stateAfter = convertState(executionResult.resultState, jcExecution.method, modelConverter),
stateBefore = convertState(executionResult.initialState, jcExecution.method, jcToUtModelConverter),
stateAfter = convertState(executionResult.resultState, jcExecution.method, jcToUtModelConverter),
result = createExecutionFailureResult(
executionResult.cause,
jcExecution.method,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ import org.usvm.instrumentation.testcase.descriptor.UTestRefDescriptor
import org.usvm.instrumentation.testcase.descriptor.UTestValueDescriptor
import org.utbot.framework.plugin.api.FieldId
import org.utbot.framework.plugin.api.UtArrayModel
import org.utbot.framework.plugin.api.UtAssembleModel
import org.utbot.framework.plugin.api.UtClassRefModel
import org.utbot.framework.plugin.api.UtCompositeModel
import org.utbot.framework.plugin.api.UtEnumConstantModel
import org.utbot.framework.plugin.api.UtExecutableCallModel
import org.utbot.framework.plugin.api.UtModel
import org.utbot.framework.plugin.api.UtNullModel
import org.utbot.framework.plugin.api.UtPrimitiveModel
Expand All @@ -28,29 +26,14 @@ import org.utbot.fuzzer.IdGenerator

class JcToUtModelConverter(
private val idGenerator: IdGenerator<Int>,
uTestProcessResult: UTestProcessResult,
private val instToUtModelConverter: UTestInst2UtModelConverter,
) {
private val descriptorToModelCache = mutableMapOf<UTestValueDescriptor, UtModel>()
private val refIdToDescriptorCache = mutableMapOf<Int, UTestValueDescriptor>()

private val exprToModelCache = uTestProcessResult.exprToModelCache
private val instantiationCallToAssembleModelCache = uTestProcessResult.instantiationCallToAssembleModelCache

fun convert(valueDescriptor: UTestValueDescriptor): UtModel = descriptorToModelCache.getOrPut(valueDescriptor) {
valueDescriptor.origin?.let {
val alreadyCreatedModel = exprToModelCache.getValue(it as UTestExpression)

if (alreadyCreatedModel is UtAssembleModel ) {
val instantiationCall = alreadyCreatedModel.instantiationCall
if (instantiationCall is UtExecutableCallModel) {
val instantiatedWithCallModel = instantiationCallToAssembleModelCache.getValue(instantiationCall)
val modificationsChain = (instantiatedWithCallModel.modificationsChain as MutableList)

modificationsChain.remove(alreadyCreatedModel.instantiationCall)
}
}

return alreadyCreatedModel
valueDescriptor.origin?.let { originExpr ->
return instToUtModelConverter.findModelByInst(originExpr as UTestExpression)
}

if (valueDescriptor is UTestRefDescriptor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,37 @@ import org.utbot.framework.plugin.api.util.classClassId
import org.utbot.framework.plugin.api.util.objectClassId
import org.utbot.fuzzer.IdGenerator

data class UTestProcessResult(
val exprToModelCache: Map<UTestExpression, UtModel>,
val instantiationCallToAssembleModelCache: Map<UtExecutableCallModel, UtAssembleModel>,
val instrumentations: List<UtInstrumentation>,
)

class UTestInst2UtModelConverter(
private val idGenerator: IdGenerator<Int>,
private val utilMethodProvider: UtilMethodProvider,
) {
private val exprToModelCache = mutableMapOf<UTestExpression, UtModel>()
private val instantiationCallToAssembleModelCache = mutableMapOf<UtExecutableCallModel, UtAssembleModel>()
private val instrumentations = mutableListOf<UtInstrumentation>()

fun processUTest(uTest: UTest): UTestProcessResult {
fun processUTest(uTest: UTest) {
exprToModelCache.clear()
instrumentations.clear()

uTest.initStatements.forEach { uInst -> processInst(uInst) }
processInst(uTest.callMethodExpression)
removeInstantiationCallFromThisInstanceModificationChain(processExpr(uTest.callMethodExpression))
}

return UTestProcessResult(exprToModelCache, instantiationCallToAssembleModelCache, instrumentations)
fun findModelByInst(expr: UTestExpression): UtModel {
val alreadyCreatedModel = exprToModelCache.getValue(expr)
removeInstantiationCallFromThisInstanceModificationChain(alreadyCreatedModel)
return alreadyCreatedModel
}

private fun removeInstantiationCallFromThisInstanceModificationChain(model: UtModel) {
if (model is UtAssembleModel) {
val instantiationCall = model.instantiationCall
if (instantiationCall is UtExecutableCallModel) {
val instanceModel = instantiationCall.instance as? UtAssembleModel
instanceModel?.let {
(it.modificationsChain as MutableList).remove(instantiationCall)
}
}
}
}

private fun processInst(uTestInst: UTestInst) {
Expand Down Expand Up @@ -136,8 +145,6 @@ class UTestInst2UtModelConverter(
instantiationCall = createInstanceCall,
)

instantiationCallToAssembleModelCache[createInstanceCall] = newModel

newModel
}

Expand All @@ -157,8 +164,6 @@ class UTestInst2UtModelConverter(
instantiationCall = constructorCall,
)

instantiationCallToAssembleModelCache[constructorCall] = newModel

newModel
}

Expand All @@ -183,8 +188,6 @@ class UTestInst2UtModelConverter(
instantiationCall = methodCall,
)

instantiationCallToAssembleModelCache[methodCall] = newModel

newModel
}

Expand Down Expand Up @@ -240,8 +243,6 @@ class UTestInst2UtModelConverter(
instantiationCall = getFieldCall,
)

instantiationCallToAssembleModelCache[getFieldCall] = newModel

newModel
}

Expand All @@ -262,8 +263,6 @@ class UTestInst2UtModelConverter(
instantiationCall = getStaticFieldCall,
)

instantiationCallToAssembleModelCache[getStaticFieldCall] = newModel

newModel
}

Expand Down