Skip to content

Commit a7aaf80

Browse files
committed
Pass Instrumentation.Factory via Kryo instead of Instrumentation itself
1 parent ccd3f20 commit a7aaf80

29 files changed

+211
-153
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,11 @@ class UtBotSymbolicEngine(
117117
val mockStrategy: MockStrategy = NO_MOCKS,
118118
chosenClassesToMockAlways: Set<ClassId>,
119119
val applicationContext: ApplicationContext,
120-
executionInstrumentation: Instrumentation<UtConcreteExecutionResult>,
120+
executionInstrumentationFactory: Instrumentation.Factory<UtConcreteExecutionResult, Instrumentation<UtConcreteExecutionResult>>,
121121
userTaintConfigurationProvider: TaintConfigurationProvider? = null,
122122
private val solverTimeoutInMillis: Int = checkSolverTimeoutMillis,
123123
) : UtContextInitializer() {
124+
124125
private val graph = methodUnderTest.sootMethod.jimpleBody().apply {
125126
logger.trace { "JIMPLE for $methodUnderTest:\n$this" }
126127
}.graph()
@@ -189,7 +190,7 @@ class UtBotSymbolicEngine(
189190

190191
private val concreteExecutor =
191192
ConcreteExecutor(
192-
executionInstrumentation,
193+
executionInstrumentationFactory,
193194
classpath,
194195
).apply { this.classLoader = utContext.classLoader }
195196

utbot-framework/src/main/kotlin/org/utbot/external/api/UtBotJavaApi.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ import org.utbot.fuzzing.Seed
4040
import org.utbot.fuzzing.ValueProvider
4141
import org.utbot.instrumentation.ConcreteExecutor
4242
import org.utbot.instrumentation.execute
43+
import org.utbot.instrumentation.instrumentation.execution.SimpleUtExecutionInstrumentation
44+
import java.io.File
4345
import kotlin.reflect.jvm.kotlinFunction
4446

4547
object UtBotJavaApi {
@@ -71,7 +73,7 @@ object UtBotJavaApi {
7173
val testSets: MutableList<UtMethodTestSet> = generatedTestCases.toMutableList()
7274

7375
val concreteExecutor = ConcreteExecutor(
74-
UtExecutionInstrumentation,
76+
SimpleUtExecutionInstrumentation.Factory(pathsToUserClasses = classpath.split(File.pathSeparator).toSet()),
7577
classpath,
7678
)
7779

utbot-framework/src/main/kotlin/org/utbot/framework/context/ConcreteExecutionContext.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ interface ConcreteExecutionContext {
88
fun getErrors(): List<UtError>
99

1010
// TODO refactor, so this interface only includes the following:
11-
// val instrumentation: Instrumentation<UtConcreteExecutionResult>
11+
// val instrumentationFactory: UtExecutionInstrumentation.Factory<*>
1212
// fun createValueProviderOrThrow(classUnderTest: ClassId, idGenerator: IdentityPreservingIdGenerator<Int>): JavaValueProvider
1313
// fun loadContext(): ContextLoadingResult
1414
// fun Coverage.filterCoveredInstructions(classUnderTestId: ClassId): Coverage

utbot-framework/src/main/kotlin/org/utbot/framework/coverage/CoverageCalculator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import kotlinx.coroutines.runBlocking
1313
fun methodCoverage(executable: ExecutableId, executions: List<UtValueExecution<*>>, classpath: String): Coverage {
1414
val methodSignature = executable.signature
1515
val classId = executable.classId
16-
return ConcreteExecutor(CoverageInstrumentation, classpath).let { executor ->
16+
return ConcreteExecutor(CoverageInstrumentation.Factory(), classpath).let { executor ->
1717
for (execution in executions) {
1818
val args = execution.stateBefore.params.map { it.value }.toMutableList()
1919
val caller = execution.stateBefore.caller

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

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ import org.utbot.framework.util.toModel
4343
import org.utbot.framework.plugin.api.SpringSettings.*
4444
import org.utbot.framework.plugin.api.SpringTestType.*
4545
import org.utbot.instrumentation.ConcreteExecutor
46+
import org.utbot.instrumentation.instrumentation.Instrumentation
47+
import org.utbot.instrumentation.instrumentation.execution.SimpleUtExecutionInstrumentation
48+
import org.utbot.instrumentation.instrumentation.execution.UtConcreteExecutionResult
4649
import org.utbot.instrumentation.instrumentation.spring.SpringUtExecutionInstrumentation
47-
import org.utbot.instrumentation.instrumentation.execution.UtExecutionInstrumentation
4850
import org.utbot.instrumentation.tryLoadingSpringContext
4951
import org.utbot.instrumentation.warmup
5052
import org.utbot.taint.TaintConfigurationProvider
@@ -86,25 +88,29 @@ open class TestCaseGenerator(
8688
classpathWithoutDependencies = buildDirs.joinToString(File.pathSeparator)
8789
)
8890

89-
private val executionInstrumentation by lazy {
91+
private val executionInstrumentationFactory: Instrumentation.Factory<UtConcreteExecutionResult, Instrumentation<UtConcreteExecutionResult>> = run {
92+
val simpleUtExecutionInstrumentationFactory = SimpleUtExecutionInstrumentation.Factory(classpathForEngine.split(File.pathSeparator).toSet())
9093
when (applicationContext) {
91-
is SpringApplicationContext -> when (val settings = applicationContext.springSettings) {
92-
is AbsentSpringSettings -> UtExecutionInstrumentation
93-
is PresentSpringSettings -> when (applicationContext.springTestType) {
94-
UNIT_TEST -> UtExecutionInstrumentation
95-
INTEGRATION_TEST -> SpringUtExecutionInstrumentation(
96-
UtExecutionInstrumentation,
97-
settings,
98-
applicationContext.beanDefinitions,
99-
buildDirs.map { it.toURL() }.toTypedArray(),
100-
)
94+
is SpringApplicationContext -> {
95+
when (val settings = applicationContext.springSettings) {
96+
is AbsentSpringSettings -> simpleUtExecutionInstrumentationFactory
97+
is PresentSpringSettings -> when (applicationContext.springTestType) {
98+
UNIT_TEST -> simpleUtExecutionInstrumentationFactory
99+
INTEGRATION_TEST -> SpringUtExecutionInstrumentation.Factory(
100+
simpleUtExecutionInstrumentationFactory,
101+
settings,
102+
applicationContext.beanDefinitions,
103+
buildDirs.map { it.toURL() }.toTypedArray(),
104+
)
105+
}
101106
}
102107
}
103108

104-
else -> UtExecutionInstrumentation
109+
else -> simpleUtExecutionInstrumentationFactory
105110
}
106111
}
107112

113+
108114
private val classpathForEngine: String
109115
get() = (buildDirs + listOfNotNull(classpath)).joinToString(File.pathSeparator)
110116

@@ -128,7 +134,7 @@ open class TestCaseGenerator(
128134
// force pool to create an appropriate executor
129135
// TODO ensure that instrumented process that starts here is properly terminated
130136
ConcreteExecutor(
131-
executionInstrumentation,
137+
executionInstrumentationFactory,
132138
classpathForEngine,
133139
).apply {
134140
warmup()
@@ -335,7 +341,7 @@ open class TestCaseGenerator(
335341
mockStrategy = mockStrategyApi.toModel(),
336342
chosenClassesToMockAlways = chosenClassesToMockAlways,
337343
applicationContext = applicationContext,
338-
executionInstrumentation = executionInstrumentation,
344+
executionInstrumentationFactory = executionInstrumentationFactory,
339345
solverTimeoutInMillis = executionTimeEstimator.updatedSolverCheckTimeoutMillis,
340346
userTaintConfigurationProvider = userTaintConfigurationProvider,
341347
)
@@ -471,7 +477,7 @@ open class TestCaseGenerator(
471477
if (applicationContext.springContextLoadingResult == null)
472478
// force pool to create an appropriate executor
473479
applicationContext.springContextLoadingResult = ConcreteExecutor(
474-
executionInstrumentation,
480+
executionInstrumentationFactory,
475481
classpathForEngine
476482
).tryLoadingSpringContext()
477483
}

utbot-instrumentation-tests/src/test/kotlin/org/utbot/examples/TestConstructors.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class TestConstructors {
2828
@Test
2929
fun testDefaultConstructor() {
3030
ConcreteExecutor(
31-
InvokeInstrumentation(),
31+
InvokeInstrumentation.Factory(),
3232
CLASSPATH
3333
).use { executor ->
3434
val constructors = ClassWithMultipleConstructors::class.constructors
@@ -43,7 +43,7 @@ class TestConstructors {
4343
@Test
4444
fun testIntConstructors() {
4545
ConcreteExecutor(
46-
InvokeInstrumentation(),
46+
InvokeInstrumentation.Factory(),
4747
CLASSPATH
4848
).use { executor ->
4949
val constructors = ClassWithMultipleConstructors::class.constructors
@@ -65,7 +65,7 @@ class TestConstructors {
6565
@Test
6666
fun testStringConstructors() {
6767
withInstrumentation(
68-
InvokeInstrumentation(),
68+
InvokeInstrumentation.Factory(),
6969
CLASSPATH
7070
) { executor ->
7171
val constructors = ClassWithMultipleConstructors::class.constructors
@@ -86,7 +86,7 @@ class TestConstructors {
8686
@Test
8787
fun testCoverageConstructor() {
8888
withInstrumentation(
89-
CoverageInstrumentation,
89+
CoverageInstrumentation.Factory(),
9090
CLASSPATH
9191
) { executor ->
9292
val constructors = ClassWithMultipleConstructors::class.constructors
@@ -106,7 +106,7 @@ class TestConstructors {
106106
@Test
107107
fun testExecutionTraceConstructor() {
108108
withInstrumentation(
109-
ExecutionTraceInstrumentation(),
109+
ExecutionTraceInstrumentation.Factory(),
110110
CLASSPATH
111111
) { executor ->
112112
val constructors = ClassWithMultipleConstructors::class.constructors

utbot-instrumentation-tests/src/test/kotlin/org/utbot/examples/TestCoverageInstrumentation.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class TestCoverageInstrumentation {
2424
@Test
2525
fun testCatchTargetException() {
2626
ConcreteExecutor(
27-
CoverageInstrumentation,
27+
CoverageInstrumentation.Factory(),
2828
ExampleClass::class.java.protectionDomain.codeSource.location.path
2929
).use {
3030
val testObject = ExampleClass()
@@ -41,7 +41,7 @@ class TestCoverageInstrumentation {
4141
@Test
4242
fun testIfBranches() {
4343
ConcreteExecutor(
44-
CoverageInstrumentation,
44+
CoverageInstrumentation.Factory(),
4545
ExampleClass::class.java.protectionDomain.codeSource.location.path
4646
).use {
4747
val testObject = ExampleClass()
@@ -63,7 +63,7 @@ class TestCoverageInstrumentation {
6363
@Test
6464
fun testWrongArgumentsException() {
6565
ConcreteExecutor(
66-
CoverageInstrumentation,
66+
CoverageInstrumentation.Factory(),
6767
ExampleClass::class.java.protectionDomain.codeSource.location.path
6868
).use {
6969
val testObject = ExampleClass()
@@ -86,7 +86,7 @@ class TestCoverageInstrumentation {
8686
@Test
8787
fun testMultipleRunsInsideCoverage() {
8888
ConcreteExecutor(
89-
CoverageInstrumentation,
89+
CoverageInstrumentation.Factory(),
9090
ExampleClass::class.java.protectionDomain.codeSource.location.path
9191
).use {
9292
val testObject = ExampleClass()
@@ -121,7 +121,7 @@ class TestCoverageInstrumentation {
121121
@Test
122122
fun testSameResult() {
123123
ConcreteExecutor(
124-
CoverageInstrumentation,
124+
CoverageInstrumentation.Factory(),
125125
ExampleClass::class.java.protectionDomain.codeSource.location.path
126126
).use {
127127
val testObject = ExampleClass()
@@ -143,7 +143,7 @@ class TestCoverageInstrumentation {
143143
@Test
144144
fun testResult() {
145145
ConcreteExecutor(
146-
CoverageInstrumentation,
146+
CoverageInstrumentation.Factory(),
147147
ExampleClass::class.java.protectionDomain.codeSource.location.path
148148
).use {
149149
val testObject = ExampleClass()
@@ -160,7 +160,7 @@ class TestCoverageInstrumentation {
160160
@Test
161161
fun testEmptyMethod() {
162162
ConcreteExecutor(
163-
CoverageInstrumentation,
163+
CoverageInstrumentation.Factory(),
164164
ExampleClass::class.java.protectionDomain.codeSource.location.path
165165
).use {
166166
val testObject = ExampleClass()
@@ -176,7 +176,7 @@ class TestCoverageInstrumentation {
176176
@Test
177177
fun testTernaryOperator() {
178178
ConcreteExecutor(
179-
CoverageInstrumentation,
179+
CoverageInstrumentation.Factory(),
180180
StaticSubstitutionExamples::class.java.protectionDomain.codeSource.location.path
181181
).use {
182182
val testObject = StaticSubstitutionExamples()

utbot-instrumentation-tests/src/test/kotlin/org/utbot/examples/TestInvokeInstrumentation.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class TestInvokeInstrumentation {
2121
@Test
2222
fun testCatchTargetException() {
2323
ConcreteExecutor(
24-
InvokeInstrumentation(),
24+
InvokeInstrumentation.Factory(),
2525
ExampleClass::class.java.protectionDomain.codeSource.location.path
2626
).use {
2727

@@ -36,7 +36,7 @@ class TestInvokeInstrumentation {
3636
@Test
3737
fun testWrongArgumentsException() {
3838
ConcreteExecutor(
39-
InvokeInstrumentation(),
39+
InvokeInstrumentation.Factory(),
4040
ExampleClass::class.java.protectionDomain.codeSource.location.path
4141
).use {
4242
val testObject = ExampleClass()
@@ -57,7 +57,7 @@ class TestInvokeInstrumentation {
5757
@Test
5858
fun testSameResult() {
5959
ConcreteExecutor(
60-
InvokeInstrumentation(),
60+
InvokeInstrumentation.Factory(),
6161
ExampleClass::class.java.protectionDomain.codeSource.location.path
6262
).use {
6363
val testObject = ExampleClass()
@@ -73,7 +73,7 @@ class TestInvokeInstrumentation {
7373
@Test
7474
fun testEmptyMethod() {
7575
ConcreteExecutor(
76-
InvokeInstrumentation(),
76+
InvokeInstrumentation.Factory(),
7777
ExampleClass::class.java.protectionDomain.codeSource.location.path
7878
).use {
7979
val testObject = ExampleClass()
@@ -87,7 +87,7 @@ class TestInvokeInstrumentation {
8787
@Test
8888
fun testStaticMethodCall() {
8989
ConcreteExecutor(
90-
InvokeInstrumentation(),
90+
InvokeInstrumentation.Factory(),
9191
StaticExampleClass::class.java.protectionDomain.codeSource.location.path
9292
).use {
9393
val res1 = it.execute(StaticExampleClass::inc, arrayOf())
@@ -105,7 +105,7 @@ class TestInvokeInstrumentation {
105105
@Test
106106
fun testNullableMethod() {
107107
ConcreteExecutor(
108-
InvokeInstrumentation(),
108+
InvokeInstrumentation.Factory(),
109109
StaticExampleClass::class.java.protectionDomain.codeSource.location.path
110110
).use {
111111
val res1 = it.execute(
@@ -136,7 +136,7 @@ class TestInvokeInstrumentation {
136136
@Test
137137
fun testDifferentSignaturesButSameMethodNames() {
138138
ConcreteExecutor(
139-
InvokeInstrumentation(),
139+
InvokeInstrumentation.Factory(),
140140
ClassWithSameMethodNames::class.java.protectionDomain.codeSource.location.path
141141
).use {
142142
val clazz = ClassWithSameMethodNames::class

utbot-instrumentation-tests/src/test/kotlin/org/utbot/examples/TestInvokeWithStaticsInstrumentation.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class TestInvokeWithStaticsInstrumentation {
3535
@Test
3636
fun testIfBranches() {
3737
ConcreteExecutor(
38-
InvokeWithStaticsInstrumentation(),
38+
InvokeWithStaticsInstrumentation.Factory(),
3939
CLASSPATH
4040
).use {
4141
val res = it.execute(StaticExampleClass::inc, arrayOf(), null)
@@ -52,7 +52,7 @@ class TestInvokeWithStaticsInstrumentation {
5252
@Test
5353
fun testHiddenClass1() {
5454
ConcreteExecutor(
55-
InvokeWithStaticsInstrumentation(),
55+
InvokeWithStaticsInstrumentation.Factory(),
5656
CLASSPATH
5757
).use {
5858
val res = it.execute(TestedClass::slomayInts, arrayOf(), null)
@@ -71,7 +71,7 @@ class TestInvokeWithStaticsInstrumentation {
7171
@Test
7272
fun testHiddenClassRepeatCall() {
7373
ConcreteExecutor(
74-
InvokeWithStaticsInstrumentation(),
74+
InvokeWithStaticsInstrumentation.Factory(),
7575
CLASSPATH
7676
).use {
7777
val se = StaticEnvironment(
@@ -89,7 +89,7 @@ class TestInvokeWithStaticsInstrumentation {
8989
@Test
9090
fun testReferenceEquality() {
9191
ConcreteExecutor(
92-
InvokeWithStaticsInstrumentation(),
92+
InvokeWithStaticsInstrumentation.Factory(),
9393
CLASSPATH
9494
).use {
9595

0 commit comments

Comments
 (0)