Skip to content

Commit ddaf943

Browse files
fixes to contest
1 parent dd16ada commit ddaf943

File tree

24 files changed

+325
-159
lines changed

24 files changed

+325
-159
lines changed

utbot-framework-api/src/main/kotlin/org/utbot/framework/UtSettings.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,12 @@ object UtSettings : AbstractSettings(logger, defaultKeyForSettingsPath, defaultS
245245
/**
246246
* Set to true to use grey-box fuzzing
247247
*/
248-
var useGreyBoxFuzzing: Boolean by getBooleanProperty(false)
248+
var useGreyBoxFuzzing: Boolean by getBooleanProperty(true)
249249

250250
/**
251251
* Set to true to use grey-box fuzzing in competition mode (without asserts generation)
252252
*/
253-
var greyBoxFuzzingCompetitionMode: Boolean by getBooleanProperty(false)
253+
var greyBoxFuzzingCompetitionMode: Boolean by getBooleanProperty(true)
254254

255255
/**
256256
* Set to true to use UtCompositeModels in grey-box fuzzing process

utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/util/UtContext.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import org.utbot.common.currentThreadInfo
55
import org.utbot.framework.plugin.api.util.UtContext.Companion.setUtContext
66
import kotlin.coroutines.CoroutineContext
77
import kotlinx.coroutines.ThreadContextElement
8-
import mu.KotlinLogging
8+
//import mu.KotlinLogging
99

1010
val utContext: UtContext
1111
get() = UtContext.currentContext()
@@ -75,7 +75,7 @@ inline fun <T> withUtContext(context: UtContext, block: () -> T): T = setUtConte
7575
try {
7676
return@use block.invoke()
7777
} catch (e: Exception) {
78-
KotlinLogging.logger("withUtContext").error { e }
78+
//KotlinLogging.logger("withUtContext").error { e }
7979
throw e
8080
}
8181
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ import org.utbot.framework.UtSettings.useDebugVisualization
3535
import org.utbot.framework.concrete.UtConcreteExecutionData
3636
import org.utbot.framework.concrete.UtConcreteExecutionResult
3737
import org.utbot.framework.concrete.UtExecutionInstrumentation
38-
import org.utbot.framework.concrete.constructors.UtModelConstructor
38+
import org.utbot.framework.concrete.UtFuzzingExecutionInstrumentation
3939
import org.utbot.framework.concrete.FuzzerConcreteExecutor
40+
import org.utbot.framework.concrete.constructors.UtModelConstructor
41+
import org.utbot.framework.concrete.phases.ValueConstructionContext
4042
import org.utbot.framework.plugin.api.*
4143
import org.utbot.framework.plugin.api.Step
4244
import org.utbot.framework.plugin.api.util.*
@@ -448,13 +450,14 @@ class UtBotSymbolicEngine(
448450
concreteExecutor.pathsToUserClasses,
449451
concreteExecutor.pathsToDependencyClasses
450452
)::execute,
453+
ValueConstructionContext(UtFuzzingExecutionInstrumentation.instrumentationContext, true)::constructParameters,
451454
timeBudget
452455
).fuzz()
453456
)
454457
} catch (e: CancellationException) {
455458
logger.debug { "Cancelled by timeout" }
456459
} catch (e: Throwable) {
457-
emit(UtError("Unexpected fuzzing crash", e))
460+
emit(UtError("Unexpected fuzzing crash\n${e.stackTraceToString()}", e))
458461
}
459462
return@flow
460463
}

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/domain/context/CgContext.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,8 +551,9 @@ data class CgContext(
551551
}
552552
}
553553

554+
private var nestedClassIndex = 0
554555
private fun createClassIdForNestedClass(testClassModel: TestClassModel): ClassId {
555-
val simpleName = "${testClassModel.classUnderTest.simpleName}Tests"
556+
val simpleName = "${testClassModel.classUnderTest.simpleName}Test${nestedClassIndex++}"
556557
return BuiltinClassId(
557558
canonicalName = currentTestClass.canonicalName + "." + simpleName,
558559
simpleName = simpleName,

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/renderer/CgAbstractRenderer.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ import org.utbot.framework.plugin.api.util.isArray
9797
import org.utbot.framework.plugin.api.util.isRefType
9898
import org.utbot.framework.plugin.api.util.longClassId
9999
import org.utbot.framework.plugin.api.util.shortClassId
100+
import org.utbot.framework.plugin.api.util.isPublic
100101

101102
abstract class CgAbstractRenderer(
102103
val context: CgRendererContext,
@@ -612,7 +613,15 @@ abstract class CgAbstractRenderer(
612613
is Boolean -> toStringConstant()
613614
// String is "\"" + "str" + "\"", RawString is "str"
614615
is String -> if (asRawString) "$this".escapeCharacters() else toStringConstant()
615-
else -> "$this"
616+
else -> {
617+
val t = this@toStringConstant.type
618+
val illegalType = t.toString().contains("$") || !t.isPublic
619+
if (this == null && UtSettings.greyBoxFuzzingCompetitionMode && !illegalType) {
620+
"(${this@toStringConstant.type}) null"
621+
} else {
622+
"$this"
623+
}
624+
}
616625
}
617626
}
618627

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,14 +1453,28 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte
14531453
}
14541454
}
14551455

1456-
if (statics.isNotEmpty()) {
1456+
if (UtSettings.greyBoxFuzzingCompetitionMode) {
14571457
+tryBlock {
1458+
if (statics.isNotEmpty()) {
1459+
+tryBlock {
1460+
mainBody()
1461+
}.finally {
1462+
recoverStaticFields()
1463+
}
1464+
} else {
1465+
mainBody()
1466+
}
1467+
}.catch(Throwable::class.id) {}
1468+
} else {
1469+
if (statics.isNotEmpty()) {
1470+
+tryBlock {
1471+
mainBody()
1472+
}.finally {
1473+
recoverStaticFields()
1474+
}
1475+
} else {
14581476
mainBody()
1459-
}.finally {
1460-
recoverStaticFields()
14611477
}
1462-
} else {
1463-
mainBody()
14641478
}
14651479

14661480
mockFrameworkManager.getAndClearMethodResources()?.let { resources ->

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

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.utbot.framework.codegen.tree
22

33
import org.utbot.common.isStatic
4+
import org.utbot.framework.UtSettings
45
import org.utbot.framework.codegen.domain.builtin.forName
56
import org.utbot.framework.codegen.domain.builtin.setArrayElement
67
import org.utbot.framework.codegen.domain.context.CgContext
@@ -24,15 +25,10 @@ import org.utbot.framework.codegen.tree.CgTestClassConstructor.CgComponents.getC
2425
import org.utbot.framework.codegen.tree.CgTestClassConstructor.CgComponents.getMockFrameworkManagerBy
2526
import org.utbot.framework.codegen.tree.CgTestClassConstructor.CgComponents.getNameGeneratorBy
2627
import org.utbot.framework.codegen.tree.CgTestClassConstructor.CgComponents.getStatementConstructorBy
27-
import org.utbot.framework.codegen.util.at
28+
import org.utbot.framework.codegen.util.*
2829
import org.utbot.framework.codegen.util.canBeSetFrom
2930
import org.utbot.framework.codegen.util.fieldThatIsGotWith
3031
import org.utbot.framework.codegen.util.fieldThatIsSetWith
31-
import org.utbot.framework.codegen.util.inc
32-
import org.utbot.framework.codegen.util.isAccessibleFrom
33-
import org.utbot.framework.codegen.util.lessThan
34-
import org.utbot.framework.codegen.util.nullLiteral
35-
import org.utbot.framework.codegen.util.resolve
3632
import org.utbot.framework.plugin.api.BuiltinClassId
3733
import org.utbot.framework.plugin.api.ClassId
3834
import org.utbot.framework.plugin.api.CodegenLanguage
@@ -51,19 +47,7 @@ import org.utbot.framework.plugin.api.UtNullModel
5147
import org.utbot.framework.plugin.api.UtPrimitiveModel
5248
import org.utbot.framework.plugin.api.UtReferenceModel
5349
import org.utbot.framework.plugin.api.UtVoidModel
54-
import org.utbot.framework.plugin.api.util.classClassId
55-
import org.utbot.framework.plugin.api.util.defaultValueModel
56-
import org.utbot.framework.plugin.api.util.jField
57-
import org.utbot.framework.plugin.api.util.findFieldByIdOrNull
58-
import org.utbot.framework.plugin.api.util.id
59-
import org.utbot.framework.plugin.api.util.intClassId
60-
import org.utbot.framework.plugin.api.util.isArray
61-
import org.utbot.framework.plugin.api.util.isEnum
62-
import org.utbot.framework.plugin.api.util.isPrimitiveWrapperOrString
63-
import org.utbot.framework.plugin.api.util.isStatic
64-
import org.utbot.framework.plugin.api.util.stringClassId
65-
import org.utbot.framework.plugin.api.util.supertypeOfAnonymousClass
66-
import org.utbot.framework.plugin.api.util.wrapperByPrimitive
50+
import org.utbot.framework.plugin.api.util.*
6751

6852
/**
6953
* Constructs CgValue or CgVariable given a UtModel
@@ -114,7 +98,12 @@ open class CgVariableConstructor(val context: CgContext) :
11498
}
11599
} else valueByModel.getOrPut(model) {
116100
when (model) {
117-
is UtNullModel -> nullLiteral()
101+
is UtNullModel ->
102+
if (UtSettings.greyBoxFuzzingCompetitionMode) {
103+
nullLiteralWithCast(model.classId)
104+
} else {
105+
nullLiteral()
106+
}
118107
is UtPrimitiveModel -> CgLiteral(model.classId, model.value)
119108
is UtReferenceModel -> error("Unexpected UtReferenceModel: ${model::class}")
120109
is UtVoidModel -> error("Unexpected UtVoidModel: ${model::class}")
@@ -213,7 +202,19 @@ open class CgVariableConstructor(val context: CgContext) :
213202
is UtDirectSetFieldModel -> {
214203
val instance = declareOrGet(statementModel.instance)
215204
// fields here are supposed to be accessible, so we assign them directly without any checks
216-
instance[statementModel.fieldId] `=` declareOrGet(statementModel.fieldModel)
205+
val fieldValue = declareOrGet(statementModel.fieldModel)
206+
if (statementModel.fieldId.canBeSetFrom(context) && fieldValue.type isSubtypeOf statementModel.fieldId.type) {
207+
instance[statementModel.fieldId] `=` fieldValue
208+
} else {
209+
with(statementModel) {
210+
+utilsClassId[setField](
211+
instance,
212+
fieldId.declaringClass.name,
213+
fieldId.name,
214+
fieldValue
215+
)
216+
}
217+
}
217218
}
218219
is UtExecutableCallModel -> {
219220
val call = createCgExecutableCallFromUtExecutableCall(statementModel)
@@ -332,7 +333,7 @@ open class CgVariableConstructor(val context: CgContext) :
332333
// and the size of an array is not greater than the fixed maximum size
333334
val canInitWithValues = (allPrimitives || allNulls) && elementModels.size <= MAX_ARRAY_INITIALIZER_SIZE
334335

335-
val initializer = if (canInitWithValues) {
336+
val initializer = if (canInitWithValues && !UtSettings.greyBoxFuzzingCompetitionMode) {
336337
val elements = elementModels.map { model ->
337338
when (model) {
338339
is UtPrimitiveModel -> model.value.resolve()

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/util/DslUtil.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ infix fun CgExpression.greaterThan(other: Any?): CgGreaterThan =
4646
// TODO: is it OK to use Object as a type of null literal?
4747
fun nullLiteral() = CgLiteral(objectClassId, null)
4848

49+
fun nullLiteralWithCast(classId: ClassId) = CgLiteral(classId, null)
50+
4951
fun intLiteral(num: Int) = CgLiteral(intClassId, num)
5052

5153
fun longLiteral(num: Long) = CgLiteral(longClassId, num)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import org.utbot.framework.util.ConflictTriggers
3636
import org.utbot.framework.util.SootUtils
3737
import org.utbot.framework.util.jimpleBody
3838
import org.utbot.framework.util.toModel
39+
import org.utbot.framework.util.sootMethodExists
3940
import org.utbot.greyboxfuzzer.util.CoverageCollector
4041
import org.utbot.greyboxfuzzer.util.GreyBoxFuzzingStatisticPrinter
4142
import org.utbot.instrumentation.ConcreteExecutor
@@ -237,7 +238,7 @@ open class TestCaseGenerator(
237238
if (UtSettings.useGreyBoxFuzzing) {
238239
GreyBoxFuzzingStatisticPrinter.printFuzzingStats(method2executions)
239240
}
240-
return methods.map { method ->
241+
return methods.filter { it.sootMethodExists }.map { method ->
241242
UtMethodTestSet(
242243
method,
243244
minimizeExecutions(method2executions.getValue(method)),

utbot-framework/src/main/kotlin/org/utbot/framework/util/SootUtils.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ private fun initSoot(buildDirs: List<Path>, classpath: String?, jdkInfo: JdkInfo
122122

123123
fun JimpleBody.graph() = ExceptionalUnitGraph(this)
124124

125+
val ExecutableId.sootMethodExists: Boolean
126+
get() {
127+
val clazz = Scene.v().getSootClass(classId.name)
128+
return clazz.methods.any { it.pureJavaSignature == signature }
129+
}
125130
val ExecutableId.sootMethod: SootMethod
126131
get() {
127132
val clazz = Scene.v().getSootClass(classId.name)

0 commit comments

Comments
 (0)