Skip to content

Commit 5b46171

Browse files
authored
Usvm distribution for the contest (#2704)
1 parent 64b1e18 commit 5b46171

File tree

6 files changed

+112
-11
lines changed

6 files changed

+112
-11
lines changed

utbot-junit-contest/build.gradle

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ configurations {
2222
usvmApproximationsApi
2323
usvmInstrumentationCollector
2424
usvmInstrumentationRunner
25+
generatedTestCompile
2526
}
2627

2728
def approximationsRepo = "com.github.UnitTestBot.java-stdlib-approximations"
@@ -170,6 +171,10 @@ dependencies {
170171
implementation group: 'org.mockito', name: 'mockito-inline', version: mockitoInlineVersion
171172
implementation 'junit:junit:4.13.2'
172173

174+
generatedTestCompile group: 'org.mockito', name: 'mockito-core', version: mockitoVersion
175+
generatedTestCompile group: 'org.mockito', name: 'mockito-inline', version: mockitoInlineVersion
176+
generatedTestCompile 'junit:junit:4.13.2'
177+
173178
implementation "org.burningwave:core:12.62.7"
174179

175180
implementation group: "org.usvm", name: "usvm-core", version: usvmVersion
@@ -216,6 +221,10 @@ jar {
216221
attributes 'JAR-Type': 'Fat JAR'
217222
}
218223

224+
processResources.exclude("classes/**")
225+
processResources.exclude("projects/**")
226+
processResources.exclude("evosuite/**")
227+
219228
version '1.0'
220229

221230
dependsOn configurations.runtimeClasspath
@@ -296,3 +305,54 @@ task run(type: JavaExec) {
296305
if (javaHome.endsWith(jreSuffix)) javaHome = javaHome.dropRight(jreSuffix.length())
297306
environment "JAVA_HOME", javaHome
298307
}
308+
309+
tasks.register("generateRuntool") {
310+
dependsOn(jar, usvmInstrumentationRunnerJar)
311+
312+
doLast {
313+
def distDir = buildDir.toPath().resolve("utbot-usvm-runtool").toFile()
314+
copy {
315+
from jar.outputs
316+
into distDir
317+
rename { "utbot-usvm-tool.jar" }
318+
}
319+
320+
copy {
321+
from configurations.usvmApproximationsApi.resolvedConfiguration.files.find()
322+
into distDir
323+
rename { "usvm-api.jar" }
324+
}
325+
326+
copy {
327+
from configurations.approximations.resolvedConfiguration.files.find()
328+
into distDir
329+
rename { "usvm-approximations.jar" }
330+
}
331+
332+
copy {
333+
from configurations.usvmInstrumentationCollector.resolvedConfiguration.files.find()
334+
into distDir
335+
rename { "usvm-jvm-collectors.jar" }
336+
}
337+
338+
copy {
339+
from usvmInstrumentationRunnerJar.outputs
340+
into distDir
341+
rename { "usvm-jvm-instrumentation.jar" }
342+
}
343+
344+
copy {
345+
from projectDir.toPath().resolve("usvm-runtool")
346+
into distDir
347+
rename { "runtool" }
348+
}
349+
350+
def libsDir = distDir.toPath().resolve("lib").toFile()
351+
configurations.generatedTestCompile.resolvedConfiguration.files.forEach { f ->
352+
copy {
353+
from f
354+
into libsDir
355+
}
356+
}
357+
}
358+
}

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

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ import kotlinx.coroutines.launch
4747
import kotlinx.coroutines.newSingleThreadContext
4848
import kotlinx.coroutines.runBlocking
4949
import kotlinx.coroutines.withTimeoutOrNull
50+
import org.utbot.contest.usvm.jc.JcContainer
51+
import org.utbot.contest.usvm.runUsvmGeneration
5052
import org.utbot.framework.SummariesGenerationType
5153
import org.utbot.framework.codegen.domain.*
5254
import org.utbot.framework.codegen.generator.CodeGenerator
@@ -107,20 +109,29 @@ fun main(args: Array<String>) {
107109

108110
println("Started UtBot Contest, classfileDir = $classfileDir, classpathString=$classpathString, outputDir=$outputDir, mocks=$mockStrategyApi")
109111

112+
// TODO: tmp hack to retrieve tmp dir wrt contest rules
113+
val tmpDir = outputDir.resolveSibling("data")
114+
110115
val cpEntries = classpathString.split(File.pathSeparator).map { File(it) }
111116
val classLoader = URLClassLoader(cpEntries.map { it.toUrl() }.toTypedArray())
112117
val context = UtContext(classLoader)
113118

119+
val testCompileCp = System.getenv("UTBOT_CONTEST_TEST_COMPILE_CP")
120+
var classpathStringForTestCompile = classpathString
121+
if (!testCompileCp.isNullOrBlank()) {
122+
classpathStringForTestCompile = "$classpathStringForTestCompile${File.pathSeparator}$testCompileCp"
123+
}
114124

115125
withUtContext(context) {
116126
// Initialize the soot before a contest is started.
117127
// This saves the time budget for real work instead of soot initialization.
118128
TestCaseGenerator(listOf(classfileDir), classpathString, dependencyPath, JdkInfoService.provide())
119129

120-
logger.info().measureTime({ "warmup: kotlin reflection :: init" }) {
121-
prepareClass(ConcreteExecutorPool::class.java, "")
122-
prepareClass(Warmup::class.java, "")
123-
}
130+
// TODO usvm-sbft-merge: utbot instrumentation not used in usvm
131+
// logger.info().measureTime({ "warmup: kotlin reflection :: init" }) {
132+
// prepareClass(ConcreteExecutorPool::class.java, "")
133+
// prepareClass(Warmup::class.java, "")
134+
// }
124135

125136
println("${ContestMessage.INIT}")
126137

@@ -138,30 +149,34 @@ fun main(args: Array<String>) {
138149
val timeBudgetSec = cmd[2].toLong()
139150
val cut = ClassUnderTest(classLoader.loadClass(classUnderTestName).id, outputDir, classfileDir.toFile())
140151

141-
runGeneration(
152+
// TODO usvm-sbft-merge: usvm generator use different entrypoint
153+
runUsvmGeneration(
142154
project = "Contest",
143155
cut,
144156
timeBudgetSec,
145157
fuzzingRatio = 0.1,
146158
classpathString,
147159
runFromEstimator = false,
148160
expectedExceptions = ExpectedExceptionsForClass(),
161+
tmpDir = tmpDir,
149162
methodNameFilter = null
150163
)
151164

152165
val compiledClassFileDir = File(outputDir.absolutePath, "compiledClassFiles")
153166
compiledClassFileDir.mkdirs()
154167
compileClassAndRemoveUncompilableTests(
155168
testDir = compiledClassFileDir.absolutePath,
156-
classPath = classpathString,
169+
classPath = classpathStringForTestCompile,
157170
testClass = cut.generatedTestFile.absolutePath
158171
)
159172
compiledClassFileDir.deleteRecursively()
160173

161174
println("${ContestMessage.READY}")
162175
}
163176
}
177+
164178
ConcreteExecutor.defaultPool.close()
179+
JcContainer.close()
165180
}
166181

167182
fun setOptions() {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,9 @@ interface Tool {
312312
fuzzingRatio,
313313
project.sootClasspathString,
314314
runFromEstimator = true,
315-
expectedExceptions,
316-
methodNameFilter
315+
expectedExceptions = expectedExceptions,
316+
tmpDir = File("."),
317+
methodNameFilter = methodNameFilter
317318
)
318319

319320
override fun close() {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ fun runUsvmGeneration(
6565
classpathString: String,
6666
runFromEstimator: Boolean,
6767
expectedExceptions: ExpectedExceptionsForClass,
68+
tmpDir: File,
6869
methodNameFilter: String? = null // For debug purposes you can specify method name
6970
): StatsForClass = runBlocking {
7071
ErrorCountingLoggerAppender.resetOccurrenceCounter()
@@ -87,14 +88,15 @@ fun runUsvmGeneration(
8788
val jcContainer by lazy {
8889
JcContainer(
8990
usePersistence = true,
91+
persistenceDir = tmpDir,
9092
classpath = classpathFiles,
9193
machineOptions = UMachineOptions(
9294
// TODO usvm-sbft: if we have less than CONTEST_TEST_EXECUTION_TIMEOUT time left, we should try execute
9395
// with smaller timeout, but instrumentation currently doesn't allow to change timeout for individual runs
9496
timeout = generationTimeoutMillisWithoutCodegen.milliseconds - CONTEST_TEST_EXECUTION_TIMEOUT,
9597
pathSelectionStrategies = listOf(PathSelectionStrategy.CLOSEST_TO_UNCOVERED_RANDOM),
9698
pathSelectorFairnessStrategy = PathSelectorFairnessStrategy.COMPLETELY_FAIR,
97-
solverType = SolverType.YICES,
99+
solverType = SolverType.Z3, // TODO: usvm-ksmt: Yices doesn't work on old linux
98100
)
99101
) {
100102
// TODO usvm-sbft: we may want to tune these JcSettings for contest

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ private val logger = KotlinLogging.logger {}
2020
// TODO usvm-sbft-refactoring: copied from `usvm/usvm-jvm/test`, extract this class back to USVM project
2121
class JcContainer private constructor(
2222
usePersistence: Boolean,
23+
persistenceDir: File,
2324
classpath: List<File>,
2425
machineOptions: UMachineOptions,
2526
builder: JcSettings.() -> Unit,
@@ -38,7 +39,7 @@ class JcContainer private constructor(
3839
* 2. Faster analysis for classes from the same cp
3940
* */
4041
val persistenceLocation = if (usePersistence) {
41-
"jcdb-persistence-${cpPath.hashCode()}"
42+
persistenceDir.resolve("jcdb-persistence-${cpPath.hashCode()}").absolutePath
4243
} else {
4344
null
4445
}
@@ -83,6 +84,7 @@ class JcContainer private constructor(
8384

8485
operator fun invoke(
8586
usePersistence: Boolean,
87+
persistenceDir: File,
8688
classpath: List<File>,
8789
machineOptions: UMachineOptions,
8890
builder: JcSettings.() -> Unit,
@@ -92,7 +94,8 @@ class JcContainer private constructor(
9294
// TODO usvm-sbft: right now max cache size is 1, do we need to increase it?
9395
logger.info { "JcContainer cache miss" }
9496
close()
95-
JcContainer(usePersistence, classpath, machineOptions, builder).also { cache[cacheKey] = it }
97+
JcContainer(usePersistence, persistenceDir, classpath, machineOptions, builder)
98+
.also { cache[cacheKey] = it }
9699
}
97100
}
98101

utbot-junit-contest/usvm-runtool

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
# switch to environment JVM as needed
4+
JAVA_HOME=/usr
5+
6+
export JAVA_HOME=$JAVA_HOME
7+
8+
# Resolve tool absolute path
9+
TOOL_DIR="$(dirname -- "$(readlink -f "${BASH_SOURCE}")")"
10+
11+
# Create test compile classpath from all files in `lib` directory
12+
LIB_DIR="$TOOL_DIR/lib"
13+
export UTBOT_CONTEST_TEST_COMPILE_CP="$(find $LIB_DIR -type f -exec realpath {} \; | tr '\n' ':' | sed 's/:$//')"
14+
15+
TOOL="$TOOL_DIR/utbot-usvm-tool.jar"
16+
env usvm.jvm.api.jar.path="$TOOL_DIR/usvm-api.jar" \
17+
usvm.jvm.approximations.jar.path="$TOOL_DIR/usvm-approximations.jar" \
18+
usvm-jvm-collectors-jar="$TOOL_DIR/usvm-jvm-collectors.jar" \
19+
usvm-jvm-instrumentation-jar="$TOOL_DIR/usvm-jvm-instrumentation.jar" \
20+
$JAVA_HOME/bin/java -cp $TOOL sbst.runtool.Main

0 commit comments

Comments
 (0)