Skip to content

Commit 19168f1

Browse files
committed
Pass Instrumentation.Factory via Kryo instead of Instrumentation itself
1 parent 7ae99b1 commit 19168f1

30 files changed

+213
-155
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import org.utbot.instrumentation.getRelevantSpringRepositories
5454
import org.utbot.instrumentation.instrumentation.Instrumentation
5555
import org.utbot.instrumentation.instrumentation.execution.UtConcreteExecutionData
5656
import org.utbot.instrumentation.instrumentation.execution.UtConcreteExecutionResult
57+
import org.utbot.instrumentation.instrumentation.execution.UtExecutionInstrumentation
5758
import org.utbot.taint.*
5859
import org.utbot.taint.model.TaintConfiguration
5960
import soot.jimple.Stmt
@@ -117,10 +118,11 @@ class UtBotSymbolicEngine(
117118
val mockStrategy: MockStrategy = NO_MOCKS,
118119
chosenClassesToMockAlways: Set<ClassId>,
119120
val applicationContext: ApplicationContext,
120-
executionInstrumentation: Instrumentation<UtConcreteExecutionResult>,
121+
executionInstrumentationFactory: UtExecutionInstrumentation.Factory<*>,
121122
userTaintConfigurationProvider: TaintConfigurationProvider? = null,
122123
private val solverTimeoutInMillis: Int = checkSolverTimeoutMillis,
123124
) : UtContextInitializer() {
125+
124126
private val graph = methodUnderTest.sootMethod.jimpleBody().apply {
125127
logger.trace { "JIMPLE for $methodUnderTest:\n$this" }
126128
}.graph()
@@ -189,7 +191,7 @@ class UtBotSymbolicEngine(
189191

190192
private val concreteExecutor =
191193
ConcreteExecutor(
192-
executionInstrumentation,
194+
executionInstrumentationFactory,
193195
classpath,
194196
).apply { this.classLoader = utContext.classLoader }
195197

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: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ 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.spring.SpringUtExecutionInstrumentation
46+
import org.utbot.instrumentation.instrumentation.execution.SimpleUtExecutionInstrumentation
4747
import org.utbot.instrumentation.instrumentation.execution.UtExecutionInstrumentation
48+
import org.utbot.instrumentation.instrumentation.spring.SpringUtExecutionInstrumentation
4849
import org.utbot.instrumentation.tryLoadingSpringContext
4950
import org.utbot.instrumentation.warmup
5051
import org.utbot.taint.TaintConfigurationProvider
@@ -86,25 +87,29 @@ open class TestCaseGenerator(
8687
classpathWithoutDependencies = buildDirs.joinToString(File.pathSeparator)
8788
)
8889

89-
private val executionInstrumentation by lazy {
90+
private val executionInstrumentationFactory: UtExecutionInstrumentation.Factory<*> = run {
91+
val simpleUtExecutionInstrumentationFactory = SimpleUtExecutionInstrumentation.Factory(classpathForEngine.split(File.pathSeparator).toSet())
9092
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-
)
93+
is SpringApplicationContext -> {
94+
when (val settings = applicationContext.springSettings) {
95+
is AbsentSpringSettings -> simpleUtExecutionInstrumentationFactory
96+
is PresentSpringSettings -> when (applicationContext.springTestType) {
97+
UNIT_TEST -> simpleUtExecutionInstrumentationFactory
98+
INTEGRATION_TEST -> SpringUtExecutionInstrumentation.Factory(
99+
simpleUtExecutionInstrumentationFactory,
100+
settings,
101+
applicationContext.beanDefinitions,
102+
buildDirs.map { it.toURL() }.toTypedArray(),
103+
)
104+
}
101105
}
102106
}
103107

104-
else -> UtExecutionInstrumentation
108+
else -> simpleUtExecutionInstrumentationFactory
105109
}
106110
}
107111

112+
108113
private val classpathForEngine: String
109114
get() = (buildDirs + listOfNotNull(classpath)).joinToString(File.pathSeparator)
110115

@@ -128,7 +133,7 @@ open class TestCaseGenerator(
128133
// force pool to create an appropriate executor
129134
// TODO ensure that instrumented process that starts here is properly terminated
130135
ConcreteExecutor(
131-
executionInstrumentation,
136+
executionInstrumentationFactory,
132137
classpathForEngine,
133138
).apply {
134139
warmup()
@@ -335,7 +340,7 @@ open class TestCaseGenerator(
335340
mockStrategy = mockStrategyApi.toModel(),
336341
chosenClassesToMockAlways = chosenClassesToMockAlways,
337342
applicationContext = applicationContext,
338-
executionInstrumentation = executionInstrumentation,
343+
executionInstrumentationFactory = executionInstrumentationFactory,
339344
solverTimeoutInMillis = executionTimeEstimator.updatedSolverCheckTimeoutMillis,
340345
userTaintConfigurationProvider = userTaintConfigurationProvider,
341346
)
@@ -471,7 +476,7 @@ open class TestCaseGenerator(
471476
if (applicationContext.springContextLoadingResult == null)
472477
// force pool to create an appropriate executor
473478
applicationContext.springContextLoadingResult = ConcreteExecutor(
474-
executionInstrumentation,
479+
executionInstrumentationFactory,
475480
classpathForEngine
476481
).tryLoadingSpringContext()
477482
}

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)