Skip to content

Commit e343606

Browse files
committed
Add usvm check param
1 parent f4d23b4 commit e343606

5 files changed

Lines changed: 45 additions & 8 deletions

File tree

utbot-cli-python/src/main/kotlin/org/utbot/cli/language/python/sbft/SbftGenerateTestsCommand.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ class SbftGenerateTestsCommand : CliktCommand(
105105
help = "(required) Path to usvm directory (ONLY FOR USVM)."
106106
).required()
107107

108+
private val checkUsvm by option("--check-usvm", help = "Check usvm (ONLY FOR USVM).")
109+
.flag(default = false)
110+
108111
private fun getPythonMethods(): List<List<PythonMethodHeader>> {
109112
val parsedModule = PythonParser(sourceFileContent).Module()
110113

@@ -150,7 +153,7 @@ class SbftGenerateTestsCommand : CliktCommand(
150153
return
151154
}
152155

153-
val pythonMethodGroups = getPythonMethods()
156+
val pythonMethodGroups = getPythonMethods().let { if (checkUsvm) it.take(1) else it }
154157

155158
val globalImportCollection = mutableSetOf<PythonImport>()
156159
val globalCodeCollection = mutableListOf<String>()
@@ -172,6 +175,7 @@ class SbftGenerateTestsCommand : CliktCommand(
172175
coverageOutputFormat = CoverageOutputFormat.Lines,
173176
usvmConfig = UsvmConfig(javaCmd, usvmDirectory),
174177
prohibitedExceptions = if (prohibitedExceptions == listOf("-")) emptyList() else prohibitedExceptions,
178+
checkUsvm = checkUsvm,
175179
)
176180

177181
val processor = SbftCliProcessor(config)

utbot-python/src/main/kotlin/org/utbot/python/PythonTestCaseGenerator.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class PythonTestCaseGenerator(
1818
private val withMinimization = configuration.withMinimization
1919

2020
fun generate(method: PythonMethod, until: Long): List<PythonTestSet> {
21-
2221
logger.info { "Start test generation for ${method.name}" }
2322
val engine = GlobalPythonEngine(
2423
method = method,
@@ -27,7 +26,11 @@ class PythonTestCaseGenerator(
2726
until,
2827
)
2928
try {
30-
engine.run()
29+
if (configuration.checkUsvm) {
30+
engine.debugUsvmRun()
31+
} else {
32+
engine.run()
33+
}
3134
} catch (_: OutOfMemoryError) {
3235
logger.debug { "Out of memory error. Stop test generation process" }
3336
}

utbot-python/src/main/kotlin/org/utbot/python/PythonTestGenerationConfig.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class PythonTestGenerationConfig(
3232
val coverageOutputFormat: CoverageOutputFormat = CoverageOutputFormat.Lines,
3333
val usvmConfig: UsvmConfig = UsvmConfig.defaultConfig,
3434
val prohibitedExceptions: List<String> = defaultProhibitedExceptions,
35+
val checkUsvm: Boolean = false,
3536
) {
3637
companion object {
3738
val defaultProhibitedExceptions = listOf(

utbot-python/src/main/kotlin/org/utbot/python/engine/GlobalPythonEngine.kt

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class GlobalPythonEngine(
5656
).start()
5757
}
5858

59-
private fun runSymbolic() {
59+
private fun runSymbolic(debug: Boolean = false) {
6060
val usvmPythonConfig = USVMPythonConfig(
6161
StandardLayout(File(configuration.usvmConfig.usvmDirectory)),
6262
configuration.usvmConfig.javaCmd,
@@ -79,13 +79,19 @@ class GlobalPythonEngine(
7979
method.containingPythonClass.pythonName()
8080
)
8181
}
82-
SymbolicEngine(
82+
val engine = SymbolicEngine(
8383
usvmPythonConfig,
8484
configuration,
85-
).analyze(
86-
USVMPythonRunConfig(config, configuration.timeout, configuration.timeoutForRun * 3),
87-
receiver
8885
)
86+
val usvmConfig = USVMPythonRunConfig(config, configuration.timeout, configuration.timeoutForRun * 3)
87+
if (debug) {
88+
engine.debugRun(usvmConfig)
89+
} else {
90+
engine.analyze(
91+
usvmConfig,
92+
receiver
93+
)
94+
}
8995
logger.info { "Symbolic: stop receiver" }
9096
receiver.close()
9197
}
@@ -113,6 +119,18 @@ class GlobalPythonEngine(
113119
symbolic.join()
114120
}
115121

122+
fun debugUsvmRun() {
123+
val symbolic = thread(
124+
start = true,
125+
isDaemon = true,
126+
name = "Symbolic"
127+
) {
128+
logger.info { " ...... Checking symbolic ...... " }
129+
runSymbolic(debug = true)
130+
}
131+
symbolic.join()
132+
}
133+
116134
private fun constructHintCollector(
117135
mypyStorage: MypyInfoBuild,
118136
typeStorage: PythonTypeHintsStorage,

utbot-python/src/main/kotlin/org/utbot/python/engine/symbolic/SymbolicEngine.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.utbot.python.engine.symbolic
22

33
import mu.KotlinLogging
4+
import org.usvm.runner.DebugRunner
45
import org.usvm.runner.PythonSymbolicAnalysisRunnerImpl
56
import org.usvm.runner.USVMPythonConfig
67
import org.usvm.runner.USVMPythonRunConfig
@@ -43,4 +44,14 @@ class SymbolicEngine(
4344
it.analyze(runConfig, receiver, symbolicCancellation)
4445
}
4546
}
47+
48+
fun debugRun(runConfig: USVMPythonRunConfig) {
49+
val debugRunner = DebugRunner(usvmPythonConfig)
50+
try {
51+
debugRunner.runProcessAndPrintInfo(runConfig)
52+
} catch (ex: Exception) {
53+
logger.error { ex.message }
54+
logger.error { ex.stackTrace }
55+
}
56+
}
4657
}

0 commit comments

Comments
 (0)