Skip to content

Supporting arrays classId in Contests #2680

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ fun runUsvmGeneration(
try {
JcToUtExecutionConverter(
jcExecution = it,
jcClasspath = jcDbContainer.cp,
idGenerator = idGenerator,
instructionIdProvider = instructionIdProvider,
utilMethodProvider = codeGenerator.context.utilMethodProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package org.utbot.contest.usvm

import org.jacodb.analysis.library.analyzers.thisInstance
import org.jacodb.api.JcClassOrInterface
import org.jacodb.api.JcClasspath
import org.jacodb.api.JcField
import org.jacodb.api.JcMethod
import org.jacodb.api.JcType
import org.jacodb.api.TypeName
import org.jacodb.api.ext.findClassOrNull
import org.usvm.instrumentation.testcase.api.UTestInst
import org.usvm.instrumentation.testcase.descriptor.UTestObjectDescriptor
import org.usvm.instrumentation.testcase.descriptor.UTestValueDescriptor
Expand All @@ -21,15 +23,17 @@ import org.utbot.framework.plugin.api.util.id
import org.utbot.framework.plugin.api.util.objectClassId
import org.utbot.framework.plugin.api.util.utContext

fun JcMethod.toExecutableId(): ExecutableId {
fun JcMethod.toExecutableId(classpath: JcClasspath): ExecutableId {
val type = this.thisInstance.type.classId
val parameters = this.parameters.map { it.type.classId }
val parameters = this.parameters.map { it.type.findClassId(classpath) }

if (isConstructor) {
return ConstructorId(type, parameters)
}

return MethodId(type, this.name, this.returnType.classId, parameters)
val returnClassId = this.returnType.findClassId(classpath)

return MethodId(type, this.name, returnClassId, parameters)
}

val JcType?.classId: ClassId
Expand All @@ -39,9 +43,9 @@ val JcType?.classId: ClassId
val JcClassOrInterface.classId: ClassId
get() = this.toJavaClass(utContext.classLoader).id

//TODO usvm-sbft: incorrectly converts types of com.google.common.util.concurrent.AtomicDoubleArray.<init> parameters
val TypeName.classId: ClassId
get() = ClassId(this.typeName)
fun TypeName.findClassId(classpath: JcClasspath): ClassId =
classpath.findTypeOrNull(this.typeName)?.classId
?: error("Can not construct classId for $this")

val JcField.fieldId: FieldId
get() = toJavaField(utContext.classLoader)!!.fieldId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.utbot.contest.usvm

import mu.KotlinLogging
import org.jacodb.api.JcClassOrInterface
import org.jacodb.api.JcClasspath
import org.jacodb.api.JcTypedMethod
import org.jacodb.api.cfg.JcInst
import org.jacodb.api.ext.jcdbSignature
Expand Down Expand Up @@ -36,6 +37,7 @@ private val logger = KotlinLogging.logger {}

class JcToUtExecutionConverter(
private val jcExecution: JcExecution,
private val jcClasspath: JcClasspath,
private val idGenerator: IdGenerator<Int>,
private val instructionIdProvider: InstructionIdProvider,
utilMethodProvider: UtilMethodProvider,
Expand All @@ -45,10 +47,10 @@ class JcToUtExecutionConverter(
private var jcToUtModelConverter: JcToUtModelConverter

init {
val instToModelConverter = UTestInst2UtModelConverter(idGenerator, utilMethodProvider)
val instToModelConverter = UTestInst2UtModelConverter(idGenerator, jcClasspath, utilMethodProvider)

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

fun convert(): UtExecution? {
Expand Down Expand Up @@ -129,7 +131,7 @@ class JcToUtExecutionConverter(
.associate { (jcField, uTestDescr) ->
jcField.fieldId to modelConverter.convert(uTestDescr)
}
val executableId: ExecutableId = method.method.toExecutableId()
val executableId: ExecutableId = method.method.toExecutableId(jcClasspath)
return EnvironmentModels(thisInstance, parameters, statics, executableId)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.utbot.contest.usvm

import org.jacodb.api.JcClasspath
import org.usvm.instrumentation.testcase.api.UTestExpression
import org.usvm.instrumentation.testcase.descriptor.UTestArrayDescriptor
import org.usvm.instrumentation.testcase.descriptor.UTestClassDescriptor
Expand Down Expand Up @@ -27,6 +28,7 @@ import java.lang.Throwable

class JcToUtModelConverter(
private val idGenerator: IdGenerator<Int>,
private val jcClasspath: JcClasspath,
private val instToUtModelConverter: UTestInst2UtModelConverter,
) {
private val descriptorToModelCache = mutableMapOf<UTestValueDescriptor, UtModel>()
Expand Down Expand Up @@ -57,7 +59,7 @@ class JcToUtModelConverter(
fields += valueDescriptor.fields
.entries
.associate { (jcField, fieldDescr) ->
val fieldId = FieldId(jcField.type.classId, jcField.name)
val fieldId = FieldId(jcField.type.findClassId(jcClasspath), jcField.name)
val fieldModel = convert(fieldDescr)
fieldId to fieldModel
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.utbot.contest.usvm

import org.jacodb.api.JcClasspath
import org.usvm.instrumentation.testcase.UTest
import org.usvm.instrumentation.testcase.api.UTestAllocateMemoryCall
import org.usvm.instrumentation.testcase.api.UTestArithmeticExpression
Expand Down Expand Up @@ -50,6 +51,7 @@ import org.utbot.fuzzer.IdGenerator

class UTestInst2UtModelConverter(
private val idGenerator: IdGenerator<Int>,
private val jcClasspath: JcClasspath,
private val utilMethodProvider: UtilMethodProvider,
) {
private val exprToModelCache = mutableMapOf<UTestExpression, UtModel>()
Expand Down Expand Up @@ -101,7 +103,7 @@ class UTestInst2UtModelConverter(
val instanceModel = processExpr(instanceExpr)
require(instanceModel is UtAssembleModel)

val fieldType = uTestInst.field.type.classId
val fieldType = uTestInst.field.type.findClassId(jcClasspath)
val fieldName = uTestInst.field.name
val setValueModel = processExpr(uTestInst.value)

Expand Down Expand Up @@ -147,7 +149,7 @@ class UTestInst2UtModelConverter(
is UTestConstructorCall -> {
val constructorCall = UtExecutableCallModel(
instance = null,
executable = uTestExpr.method.toExecutableId(),
executable = uTestExpr.method.toExecutableId(jcClasspath),
params = uTestExpr.args.map { arg ->
processExpr(arg)
},
Expand All @@ -167,7 +169,7 @@ class UTestInst2UtModelConverter(

val methodCall = UtExecutableCallModel(
instance = instanceModel,
executable = uTestExpr.method.toExecutableId(),
executable = uTestExpr.method.toExecutableId(jcClasspath),
params = uTestExpr.args.map { arg -> processExpr(arg) },
)

Expand All @@ -188,7 +190,7 @@ class UTestInst2UtModelConverter(
modelName = "",
instantiationCall = UtExecutableCallModel(
instance = null,
executable = uTestExpr.method.toExecutableId(),
executable = uTestExpr.method.toExecutableId(jcClasspath),
params = uTestExpr.args.map { arg -> processExpr(arg) },
),
)
Expand Down Expand Up @@ -234,7 +236,7 @@ class UTestInst2UtModelConverter(
executable = utilMethodProvider.getFieldValueMethodId,
params = listOf(
instanceModel,
UtPrimitiveModel(uTestExpr.field.type.classId.name),
UtPrimitiveModel(uTestExpr.field.type),
UtPrimitiveModel(uTestExpr.field.name),
),
)
Expand All @@ -252,7 +254,7 @@ class UTestInst2UtModelConverter(
instance = null,
executable = utilMethodProvider.getStaticFieldValueMethodId,
params = listOf(
UtPrimitiveModel(uTestExpr.field.type.classId.name),
UtPrimitiveModel(uTestExpr.field.type),
UtPrimitiveModel(uTestExpr.field.name),
),
)
Expand Down Expand Up @@ -287,7 +289,7 @@ class UTestInst2UtModelConverter(
mocks += uTestExpr.methods
.entries
.associate { (jcMethod, uTestExprs) ->
val executableId: ExecutableId = jcMethod.toExecutableId()
val executableId: ExecutableId = jcMethod.toExecutableId(jcClasspath)
val models = uTestExprs.map { expr ->
processExpr(expr)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ org.utbot.examples.wrappers.DoubleWrapper
org.utbot.examples.wrappers.CharacterWrapper
org.utbot.examples.wrappers.ByteWrapper
org.utbot.examples.wrappers.BooleanWrapper
org.utbot.examples.arrays.PrimitiveArrays