Skip to content

Commit 1bf560e

Browse files
committed
Make JcMachine's budget distributing strategy and refactor
1 parent eaf85e9 commit 1bf560e

18 files changed

+299
-281
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ commonsIOVersion=2.11.0
102102
javaxVersion=2.2
103103
jakartaVersion=3.1.0
104104
jacoDbVersion=1.3.0
105-
usvmVersion=comp-231118-1620
105+
usvmVersion=comp-231120-1719
106106

107107
# use latest Java 8 compaitable Spring and Spring Boot versions
108108
springVersion=5.3.28

utbot-junit-contest/src/main/kotlin/org/utbot/contest/ContestEstimator.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import org.utbot.contest.Paths.evosuiteReportFile
2626
import org.utbot.contest.Paths.jarsDir
2727
import org.utbot.contest.Paths.moduleTestDir
2828
import org.utbot.contest.Paths.outputDir
29-
import org.utbot.contest.usvm.executor.UTestRunner
29+
import org.utbot.contest.usvm.jc.JcContainer
3030
import org.utbot.contest.usvm.runUsvmGeneration
3131
import org.utbot.features.FeatureExtractorFactoryImpl
3232
import org.utbot.features.FeatureProcessorWithStatesRepetitionFactory
@@ -266,8 +266,7 @@ interface Tool {
266266
)
267267

268268
override fun close() {
269-
if (UTestRunner.isInitialized())
270-
UTestRunner.runner.close()
269+
JcContainer.close()
271270
}
272271
}
273272

utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/ContestUsvm.kt

Lines changed: 129 additions & 138 deletions
Large diffs are not rendered by default.

utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/EnvironmentStateKind.kt

Lines changed: 0 additions & 5 deletions
This file was deleted.

utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/InstructionIdProvider.kt

Lines changed: 0 additions & 8 deletions
This file was deleted.

utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/JacoDBContainer.kt

Lines changed: 0 additions & 44 deletions
This file was deleted.

utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/Utils.kt

Lines changed: 0 additions & 16 deletions
This file was deleted.

utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/ConverterUtils.kt renamed to utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/converter/ConverterUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utbot.contest.usvm
1+
package org.utbot.contest.usvm.converter
22

33
import org.jacodb.analysis.library.analyzers.thisInstance
44
import org.jacodb.api.JcArrayType
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.utbot.contest.usvm.converter
2+
3+
fun interface InstructionIdProvider {
4+
fun provideInstructionId(methodSignature: String, instIndex: Int): Long
5+
}
6+
7+
class SimpleInstructionIdProvider : InstructionIdProvider {
8+
private val instructionIds = mutableMapOf<Pair<String, Int>, Long>()
9+
10+
override fun provideInstructionId(methodSignature: String, instIndex: Int): Long =
11+
instructionIds.getOrPut(methodSignature to instIndex) { instructionIds.size.toLong() }
12+
}

utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/JcToUtExecutionConverter.kt renamed to utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/converter/JcToUtExecutionConverter.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utbot.contest.usvm
1+
package org.utbot.contest.usvm.converter
22

33
import mu.KotlinLogging
44
import org.jacodb.api.JcClassOrInterface
@@ -18,7 +18,7 @@ import org.usvm.instrumentation.testcase.descriptor.UTestExceptionDescriptor
1818
import org.usvm.instrumentation.util.enclosingClass
1919
import org.usvm.instrumentation.util.enclosingMethod
2020
import org.utbot.common.isPublic
21-
import org.utbot.contest.usvm.executor.JcExecution
21+
import org.utbot.contest.usvm.jc.JcExecution
2222
import org.utbot.framework.codegen.domain.builtin.UtilMethodProvider
2323
import org.utbot.framework.plugin.api.ClassId
2424
import org.utbot.framework.plugin.api.Coverage
@@ -58,7 +58,7 @@ class JcToUtExecutionConverter(
5858
private var jcToUtModelConverter: JcToUtModelConverter
5959

6060
init {
61-
val instToModelConverter = UTestInst2UtModelConverter(idGenerator, jcClasspath, utilMethodProvider)
61+
val instToModelConverter = UTestInstToUtModelConverter(idGenerator, jcClasspath, utilMethodProvider)
6262

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

utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/JcToUtModelConverter.kt renamed to utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/converter/JcToUtModelConverter.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utbot.contest.usvm
1+
package org.utbot.contest.usvm.converter
22

33
import org.jacodb.api.JcClasspath
44
import org.usvm.instrumentation.testcase.api.UTestExpression
@@ -29,10 +29,14 @@ import org.utbot.framework.plugin.api.util.jClass
2929
import org.utbot.framework.plugin.api.util.stringClassId
3030
import org.utbot.fuzzer.IdGenerator
3131

32+
enum class EnvironmentStateKind {
33+
INITIAL, FINAL
34+
}
35+
3236
class JcToUtModelConverter(
3337
private val idGenerator: IdGenerator<Int>,
3438
private val jcClasspath: JcClasspath,
35-
private val instToUtModelConverter: UTestInst2UtModelConverter,
39+
private val instToUtModelConverter: UTestInstToUtModelConverter,
3640
) {
3741
private val descriptorToModelCache = mutableMapOf<UTestValueDescriptor, UtModel>()
3842
private val refIdAndStateKindToDescriptorCache =

utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/UTestInst2UtModelConverter.kt renamed to utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/converter/UTestInstToUtModelConverter.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utbot.contest.usvm
1+
package org.utbot.contest.usvm.converter
22

33
import org.jacodb.api.JcClasspath
44
import org.usvm.instrumentation.testcase.UTest
@@ -49,7 +49,7 @@ import org.utbot.framework.plugin.api.util.classClassId
4949
import org.utbot.framework.plugin.api.util.objectClassId
5050
import org.utbot.fuzzer.IdGenerator
5151

52-
class UTestInst2UtModelConverter(
52+
class UTestInstToUtModelConverter(
5353
private val idGenerator: IdGenerator<Int>,
5454
private val jcClasspath: JcClasspath,
5555
private val utilMethodProvider: UtilMethodProvider,

utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/UTestValueDescriptorUtils.kt renamed to utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/converter/UTestValueDescriptorUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utbot.contest.usvm
1+
package org.utbot.contest.usvm.converter
22

33
import org.usvm.instrumentation.testcase.descriptor.UTestArrayDescriptor
44
import org.usvm.instrumentation.testcase.descriptor.UTestClassDescriptor

utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/UtUsvmExecution.kt renamed to utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/converter/UtUsvmExecution.kt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utbot.contest.usvm
1+
package org.utbot.contest.usvm.converter
22

33
import org.utbot.framework.plugin.api.Coverage
44
import org.utbot.framework.plugin.api.DocStatement
@@ -7,6 +7,9 @@ import org.utbot.framework.plugin.api.UtExecution
77
import org.utbot.framework.plugin.api.UtExecutionResult
88
import org.utbot.framework.plugin.api.UtExecutionWithInstrumentation
99
import org.utbot.framework.plugin.api.UtInstrumentation
10+
import org.utbot.framework.plugin.api.mapper.UtModelMapper
11+
import org.utbot.framework.plugin.api.mapper.mapModelIfExists
12+
import org.utbot.framework.plugin.api.mapper.mapModels
1013

1114
class UtUsvmExecution(
1215
stateBefore: EnvironmentModels,
@@ -64,4 +67,15 @@ class UtUsvmExecution(
6467
displayName,
6568
instrumentation,
6669
)
67-
}
70+
}
71+
72+
fun UtUsvmExecution.mapModels(mapper: UtModelMapper) = copy(
73+
stateBefore = stateBefore.mapModels(mapper),
74+
stateAfter = stateAfter.mapModels(mapper),
75+
result = result.mapModelIfExists(mapper),
76+
coverage = this.coverage,
77+
summary = this.summary,
78+
testMethodName = this.testMethodName,
79+
displayName = this.displayName,
80+
instrumentation = instrumentation.map { it.mapModels(mapper) },
81+
)

utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/executor/UTestRunner.kt

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package org.utbot.contest.usvm.jc
2+
3+
import kotlinx.coroutines.runBlocking
4+
import mu.KotlinLogging
5+
import org.jacodb.api.JcClasspath
6+
import org.jacodb.api.JcDatabase
7+
import org.jacodb.impl.JcSettings
8+
import org.jacodb.impl.features.classpaths.UnknownClasses
9+
import org.jacodb.impl.jacodb
10+
import org.usvm.UMachineOptions
11+
import org.usvm.instrumentation.executor.UTestConcreteExecutor
12+
import org.usvm.instrumentation.instrumentation.JcRuntimeTraceInstrumenterFactory
13+
import org.usvm.machine.JcMachine
14+
import java.io.File
15+
import kotlin.time.Duration.Companion.seconds
16+
17+
private val logger = KotlinLogging.logger {}
18+
19+
// TODO usvm-sbft-refactoring: copied from `usvm/usvm-jvm/test`, extract this class back to USVM project
20+
class JcContainer private constructor(
21+
classpath: List<File>,
22+
machineOptions: UMachineOptions,
23+
builder: JcSettings.() -> Unit,
24+
) : AutoCloseable {
25+
val db: JcDatabase
26+
val cp: JcClasspath
27+
val machine: JcMachine
28+
val runner: UTestConcreteExecutor
29+
30+
init {
31+
val (db, cp) = runBlocking {
32+
val db = jacodb(builder)
33+
// TODO usvm-sbft: use classpathWithApproximations here when approximation decoders are finished
34+
val cp = db.classpath(classpath, listOf(UnknownClasses))
35+
db to cp
36+
}
37+
this.db = db
38+
this.cp = cp
39+
this.machine = JcMachine(cp, machineOptions)
40+
this.runner = UTestConcreteExecutor(
41+
JcRuntimeTraceInstrumenterFactory::class,
42+
classpath.map { it.absolutePath },
43+
cp,
44+
CONTEST_TEST_EXECUTION_TIMEOUT
45+
)
46+
runBlocking {
47+
db.awaitBackgroundJobs()
48+
}
49+
}
50+
51+
override fun close() {
52+
cp.close()
53+
db.close()
54+
machine.close()
55+
runner.close()
56+
}
57+
58+
companion object : AutoCloseable {
59+
val CONTEST_TEST_EXECUTION_TIMEOUT = 1.seconds
60+
61+
private val cache = HashMap<Pair<List<File>, UMachineOptions>, JcContainer>()
62+
63+
operator fun invoke(
64+
classpath: List<File>,
65+
machineOptions: UMachineOptions,
66+
builder: JcSettings.() -> Unit,
67+
): JcContainer {
68+
val cacheKey = classpath to machineOptions
69+
return cache[cacheKey] ?: run {
70+
// TODO usvm-sbft: right now max cache size is 1, do we need to increase it?
71+
logger.info { "JcContainer cache miss" }
72+
close()
73+
JcContainer(classpath, machineOptions, builder).also { cache[cacheKey] = it }
74+
}
75+
}
76+
77+
override fun close() {
78+
cache.values.forEach { it.close() }
79+
cache.clear()
80+
}
81+
}
82+
}

utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/executor/JcExecution.kt renamed to utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/jc/JcExecution.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utbot.contest.usvm.executor
1+
package org.utbot.contest.usvm.jc
22

33
import org.jacodb.api.JcTypedMethod
44
import org.usvm.api.JcCoverage

0 commit comments

Comments
 (0)