Skip to content

Commit b9726de

Browse files
Introduce utbot-usvm module and use it in contest (#2715)
1 parent 928d1b0 commit b9726de

File tree

52 files changed

+424
-384
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+424
-384
lines changed

gradle.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ springVersion=5.3.28
104104
springBootVersion=2.7.13
105105
springSecurityVersion=5.8.5
106106

107+
approximationsVersion=bfce4eedde
108+
usvmVersion=72924ad
109+
107110
# configuration for build server
108111
#
109112
# the following options are passed to gradle command explicitly (see appropriate workflow):

settings.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ include("utbot-junit-contest")
3535
include("utbot-analytics")
3636
include("utbot-analytics-torch")
3737

38+
include("utbot-usvm")
39+
3840
include("utbot-cli")
3941

4042
include("utbot-api")

utbot-java-fuzzing/src/main/kotlin/org/utbot/fuzzer/IdGenerator.kt renamed to utbot-framework-api/src/main/kotlin/org/utbot/framework/fuzzer/IdGenerator.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
package org.utbot.fuzzer
1+
package org.utbot.framework.fuzzer
22

3-
import org.utbot.framework.plugin.api.UtModel
43
import java.util.*
54
import java.util.concurrent.atomic.AtomicInteger
65

@@ -80,5 +79,3 @@ class ReferencePreservingIntIdGenerator(lowerBound: Int = DEFAULT_LOWER_BOUND) :
8079
const val DEFAULT_LOWER_BOUND: Int = 1500_000_000
8180
}
8281
}
83-
84-
fun UtModel.fuzzed(block: FuzzedValue.() -> Unit = {}): FuzzedValue = FuzzedValue(this).apply(block)

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,19 @@ class BuiltinClassId(
12011201
}
12021202
}
12031203

1204+
class CgClassId(
1205+
name: String,
1206+
elementClassId: ClassId? = null,
1207+
override val typeParameters: TypeParameters = TypeParameters(),
1208+
override val isNullable: Boolean = true,
1209+
) : ClassId(name, elementClassId) {
1210+
constructor(
1211+
classId: ClassId,
1212+
typeParameters: TypeParameters = TypeParameters(),
1213+
isNullable: Boolean = true,
1214+
) : this(classId.name, classId.elementClassId, typeParameters, isNullable)
1215+
}
1216+
12041217
/**
12051218
* Field id. Contains field name.
12061219
*

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,23 @@ val ExecutableId.isMethod: Boolean
589589
val ExecutableId.isConstructor: Boolean
590590
get() = this is ConstructorId
591591

592+
fun arrayTypeOf(elementType: ClassId, isNullable: Boolean = false): ClassId {
593+
val arrayIdName = "[${elementType.arrayLikeName}"
594+
return when (elementType) {
595+
is BuiltinClassId -> BuiltinClassId(
596+
canonicalName = "${elementType.canonicalName}[]",
597+
simpleName = "${elementType.simpleName}[]",
598+
elementClassId = elementType,
599+
isNullable = isNullable
600+
)
601+
else -> ClassId(
602+
name = arrayIdName,
603+
elementClassId = elementType,
604+
isNullable = isNullable
605+
)
606+
}
607+
}
608+
592609
/**
593610
* Construct MethodId
594611
*/
Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
package org.utbot.framework.utils
2+
3+
import org.utbot.framework.plugin.api.BuiltinClassId
4+
import org.utbot.framework.plugin.api.BuiltinConstructorId
5+
import org.utbot.framework.plugin.api.BuiltinMethodId
6+
import org.utbot.framework.plugin.api.CgClassId
7+
import org.utbot.framework.plugin.api.ClassId
8+
import org.utbot.framework.plugin.api.MethodId
9+
import org.utbot.framework.plugin.api.util.arrayTypeOf
10+
import org.utbot.framework.plugin.api.util.baseStreamClassId
11+
import org.utbot.framework.plugin.api.util.booleanClassId
12+
import org.utbot.framework.plugin.api.util.builtinConstructorId
13+
import org.utbot.framework.plugin.api.util.classClassId
14+
import org.utbot.framework.plugin.api.util.id
15+
import org.utbot.framework.plugin.api.util.intClassId
16+
import org.utbot.framework.plugin.api.util.objectArrayClassId
17+
import org.utbot.framework.plugin.api.util.objectClassId
18+
import org.utbot.framework.plugin.api.util.stringClassId
19+
import org.utbot.framework.plugin.api.util.voidClassId
20+
import sun.misc.Unsafe
21+
import java.lang.invoke.MethodHandles
22+
import java.lang.invoke.MethodType
23+
import java.lang.reflect.Method
24+
25+
/**
26+
* Set of ids of all possible util methods for a given class.
27+
*
28+
* The class may actually not have some of these methods if they
29+
* are not required in the process of code generation (this is the case for [TestClassUtilMethodProvider]).
30+
*/
31+
abstract class UtilMethodProvider(val utilClassId: ClassId) {
32+
val utilMethodIds: Set<MethodId>
33+
get() = setOf(
34+
getUnsafeInstanceMethodId,
35+
createInstanceMethodId,
36+
createArrayMethodId,
37+
setFieldMethodId,
38+
setStaticFieldMethodId,
39+
getFieldValueMethodId,
40+
getStaticFieldValueMethodId,
41+
getEnumConstantByNameMethodId,
42+
deepEqualsMethodId,
43+
arraysDeepEqualsMethodId,
44+
iterablesDeepEqualsMethodId,
45+
streamsDeepEqualsMethodId,
46+
mapsDeepEqualsMethodId,
47+
hasCustomEqualsMethodId,
48+
getArrayLengthMethodId,
49+
consumeBaseStreamMethodId,
50+
buildStaticLambdaMethodId,
51+
buildLambdaMethodId,
52+
getLookupInMethodId,
53+
getLambdaCapturedArgumentTypesMethodId,
54+
getLambdaCapturedArgumentValuesMethodId,
55+
getInstantiatedMethodTypeMethodId,
56+
getLambdaMethodMethodId,
57+
getSingleAbstractMethodMethodId
58+
)
59+
60+
val getUnsafeInstanceMethodId: MethodId
61+
get() = utilClassId.utilMethodId(
62+
name = "getUnsafeInstance",
63+
returnType = Unsafe::class.id,
64+
)
65+
66+
/**
67+
* Method that creates instance using Unsafe
68+
*/
69+
val createInstanceMethodId: MethodId
70+
get() = utilClassId.utilMethodId(
71+
name = "createInstance",
72+
returnType = CgClassId(objectClassId, isNullable = true),
73+
arguments = arrayOf(stringClassId)
74+
)
75+
76+
val createArrayMethodId: MethodId
77+
get() = utilClassId.utilMethodId(
78+
name = "createArray",
79+
returnType = Array<Any>::class.id,
80+
arguments = arrayOf(stringClassId, intClassId, Array<Any>::class.id)
81+
)
82+
83+
val setFieldMethodId: MethodId
84+
get() = utilClassId.utilMethodId(
85+
name = "setField",
86+
returnType = voidClassId,
87+
arguments = arrayOf(objectClassId, stringClassId, stringClassId, objectClassId)
88+
)
89+
90+
val setStaticFieldMethodId: MethodId
91+
get() = utilClassId.utilMethodId(
92+
name = "setStaticField",
93+
returnType = voidClassId,
94+
arguments = arrayOf(Class::class.id, stringClassId, objectClassId)
95+
)
96+
97+
val getFieldValueMethodId: MethodId
98+
get() = utilClassId.utilMethodId(
99+
name = "getFieldValue",
100+
returnType = objectClassId,
101+
arguments = arrayOf(objectClassId, stringClassId, stringClassId)
102+
)
103+
104+
val getStaticFieldValueMethodId: MethodId
105+
get() = utilClassId.utilMethodId(
106+
name = "getStaticFieldValue",
107+
returnType = objectClassId,
108+
arguments = arrayOf(Class::class.id, stringClassId)
109+
)
110+
111+
val getEnumConstantByNameMethodId: MethodId
112+
get() = utilClassId.utilMethodId(
113+
name = "getEnumConstantByName",
114+
returnType = objectClassId,
115+
arguments = arrayOf(Class::class.id, stringClassId)
116+
)
117+
118+
val deepEqualsMethodId: MethodId
119+
get() = utilClassId.utilMethodId(
120+
name = "deepEquals",
121+
returnType = booleanClassId,
122+
arguments = arrayOf(objectClassId, objectClassId)
123+
)
124+
125+
val arraysDeepEqualsMethodId: MethodId
126+
get() = utilClassId.utilMethodId(
127+
name = "arraysDeepEquals",
128+
returnType = booleanClassId,
129+
arguments = arrayOf(objectClassId, objectClassId)
130+
)
131+
132+
val iterablesDeepEqualsMethodId: MethodId
133+
get() = utilClassId.utilMethodId(
134+
name = "iterablesDeepEquals",
135+
returnType = booleanClassId,
136+
arguments = arrayOf(java.lang.Iterable::class.id, java.lang.Iterable::class.id)
137+
)
138+
139+
val streamsDeepEqualsMethodId: MethodId
140+
get() = utilClassId.utilMethodId(
141+
name = "streamsDeepEquals",
142+
returnType = booleanClassId,
143+
arguments = arrayOf(java.util.stream.BaseStream::class.id, java.util.stream.BaseStream::class.id)
144+
)
145+
146+
val mapsDeepEqualsMethodId: MethodId
147+
get() = utilClassId.utilMethodId(
148+
name = "mapsDeepEquals",
149+
returnType = booleanClassId,
150+
arguments = arrayOf(java.util.Map::class.id, java.util.Map::class.id)
151+
)
152+
153+
val hasCustomEqualsMethodId: MethodId
154+
get() = utilClassId.utilMethodId(
155+
name = "hasCustomEquals",
156+
returnType = booleanClassId,
157+
arguments = arrayOf(Class::class.id)
158+
)
159+
160+
val getArrayLengthMethodId: MethodId
161+
get() = utilClassId.utilMethodId(
162+
name = "getArrayLength",
163+
returnType = intClassId,
164+
arguments = arrayOf(objectClassId)
165+
)
166+
167+
val consumeBaseStreamMethodId: MethodId
168+
get() = utilClassId.utilMethodId(
169+
name = "consumeBaseStream",
170+
returnType = voidClassId,
171+
arguments = arrayOf(baseStreamClassId)
172+
)
173+
174+
val buildStaticLambdaMethodId: MethodId
175+
get() = utilClassId.utilMethodId(
176+
name = "buildStaticLambda",
177+
returnType = objectClassId,
178+
arguments = arrayOf(
179+
classClassId,
180+
classClassId,
181+
stringClassId,
182+
arrayTypeOf(capturedArgumentClassId)
183+
)
184+
)
185+
186+
val buildLambdaMethodId: MethodId
187+
get() = utilClassId.utilMethodId(
188+
name = "buildLambda",
189+
returnType = objectClassId,
190+
arguments = arrayOf(
191+
classClassId,
192+
classClassId,
193+
stringClassId,
194+
objectClassId,
195+
arrayTypeOf(capturedArgumentClassId)
196+
)
197+
)
198+
199+
val getLookupInMethodId: MethodId
200+
get() = utilClassId.utilMethodId(
201+
name = "getLookupIn",
202+
returnType = MethodHandles.Lookup::class.id,
203+
arguments = arrayOf(classClassId)
204+
)
205+
206+
val getLambdaCapturedArgumentTypesMethodId: MethodId
207+
get() = utilClassId.utilMethodId(
208+
name = "getLambdaCapturedArgumentTypes",
209+
returnType = arrayTypeOf(classClassId),
210+
arguments = arrayOf(arrayTypeOf(capturedArgumentClassId))
211+
)
212+
213+
val getLambdaCapturedArgumentValuesMethodId: MethodId
214+
get() = utilClassId.utilMethodId(
215+
name = "getLambdaCapturedArgumentValues",
216+
returnType = objectArrayClassId,
217+
arguments = arrayOf(arrayTypeOf(capturedArgumentClassId))
218+
)
219+
220+
val getInstantiatedMethodTypeMethodId: MethodId
221+
get() = utilClassId.utilMethodId(
222+
name = "getInstantiatedMethodType",
223+
returnType = MethodType::class.id,
224+
arguments = arrayOf(Method::class.id, arrayTypeOf(classClassId))
225+
)
226+
227+
val getLambdaMethodMethodId: MethodId
228+
get() = utilClassId.utilMethodId(
229+
name = "getLambdaMethod",
230+
returnType = Method::class.id,
231+
arguments = arrayOf(classClassId, stringClassId)
232+
)
233+
234+
val getSingleAbstractMethodMethodId: MethodId
235+
get() = utilClassId.utilMethodId(
236+
name = "getSingleAbstractMethod",
237+
returnType = java.lang.reflect.Method::class.id,
238+
arguments = arrayOf(classClassId)
239+
)
240+
241+
val capturedArgumentClassId: BuiltinClassId
242+
get() = BuiltinClassId(
243+
canonicalName = "${utilClassId.name}.CapturedArgument",
244+
simpleName = "CapturedArgument"
245+
)
246+
247+
val capturedArgumentConstructorId: BuiltinConstructorId
248+
get() = builtinConstructorId(capturedArgumentClassId, classClassId, objectClassId)
249+
}
250+
251+
internal fun ClassId.utilMethodId(
252+
name: String,
253+
returnType: ClassId,
254+
vararg arguments: ClassId,
255+
// usually util methods are static, so this argument is true by default
256+
isStatic: Boolean = true
257+
): MethodId =
258+
BuiltinMethodId(this, name, returnType, arguments.toList(), isStatic = isStatic)

utbot-framework-test/src/test/kotlin/org/utbot/framework/assemble/AssembleModelGeneratorTests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import org.utbot.examples.assemble.DefaultFieldWithDirectAccessor
3737
import org.utbot.examples.assemble.DefaultFieldWithSetter
3838
import org.utbot.examples.assemble.DefaultPackagePrivateField
3939
import org.utbot.examples.assemble.StaticField
40-
import org.utbot.framework.codegen.tree.arrayTypeOf
4140
import org.utbot.framework.plugin.api.ClassId
4241
import org.utbot.framework.plugin.api.ExecutableId
4342
import org.utbot.framework.plugin.api.FieldId
@@ -50,6 +49,7 @@ import org.utbot.framework.plugin.api.UtNullModel
5049
import org.utbot.framework.plugin.api.UtPrimitiveModel
5150
import org.utbot.framework.plugin.api.util.UtContext
5251
import org.utbot.framework.plugin.api.util.UtContext.Companion.setUtContext
52+
import org.utbot.framework.plugin.api.util.arrayTypeOf
5353
import org.utbot.framework.plugin.api.util.executableId
5454
import org.utbot.framework.plugin.api.util.id
5555
import org.utbot.framework.plugin.api.util.intArrayClassId

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import org.utbot.framework.UtSettings.useDebugVisualization
3535
import org.utbot.framework.context.ApplicationContext
3636
import org.utbot.framework.context.ConcreteExecutionContext
3737
import org.utbot.framework.context.ConcreteExecutionContext.FuzzingContextParams
38+
import org.utbot.framework.fuzzer.ReferencePreservingIntIdGenerator
3839
import org.utbot.framework.plugin.api.*
3940
import org.utbot.framework.plugin.api.Step
4041
import org.utbot.framework.plugin.api.util.*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package org.utbot.framework.codegen.domain
33
import org.utbot.framework.DEFAULT_EXECUTION_TIMEOUT_IN_INSTRUMENTED_PROCESS_MS
44
import org.utbot.framework.codegen.domain.builtin.mockitoClassId
55
import org.utbot.framework.codegen.domain.builtin.ongoingStubbingClassId
6-
import org.utbot.framework.codegen.domain.models.CgClassId
76
import org.utbot.framework.codegen.tree.argumentsClassId
87
import org.utbot.framework.plugin.api.BuiltinClassId
8+
import org.utbot.framework.plugin.api.CgClassId
99
import org.utbot.framework.plugin.api.ClassId
1010
import org.utbot.framework.plugin.api.CodeGenerationSettingBox
1111
import org.utbot.framework.plugin.api.CodeGenerationSettingItem

0 commit comments

Comments
 (0)