-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
tochilinak
committed
Nov 1, 2023
1 parent
6bcb46b
commit 14bfe7b
Showing
4 changed files
with
74 additions
and
49 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
usvm-python/usvm-python-runner/src/main/kotlin/org/usvm/runner/DebugRunner.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.usvm.runner | ||
|
||
class DebugRunner(config: USVMPythonConfig): USVMPythonRunner(config) { | ||
fun runProcessAndPrintInfo(runConfig: USVMPythonRunConfig) { | ||
val builder = setupEnvironment(runConfig) | ||
builder.redirectError(ProcessBuilder.Redirect.INHERIT) | ||
builder.redirectOutput(ProcessBuilder.Redirect.INHERIT) | ||
val process = builder.start() | ||
process.waitFor() | ||
println("Exit status: ${process.exitValue()}") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
usvm-python/usvm-python-runner/src/main/kotlin/org/usvm/runner/USVMPythonRunner.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.usvm.runner | ||
|
||
import java.io.File | ||
import java.net.InetSocketAddress | ||
import java.nio.channels.ServerSocketChannel | ||
|
||
open class USVMPythonRunner(private val config: USVMPythonConfig): AutoCloseable { | ||
protected val serverSocketChannel: ServerSocketChannel = ServerSocketChannel.open() | ||
private val port: InetSocketAddress | ||
|
||
init { | ||
serverSocketChannel.socket().bind(InetSocketAddress(0)) | ||
port = serverSocketChannel.localAddress as? InetSocketAddress | ||
?: error("Couldn't cast SocketAddress ${serverSocketChannel.localAddress} to InetSocketAddress") | ||
println("Port: ${port.port}") | ||
} | ||
|
||
override fun close() { | ||
serverSocketChannel.close() | ||
} | ||
|
||
protected fun setupEnvironment(runConfig: USVMPythonRunConfig): ProcessBuilder { | ||
val layout = config.distributionLayout | ||
val functionConfig = when (runConfig.callableConfig) { | ||
is USVMPythonFunctionConfig -> runConfig.callableConfig | ||
} | ||
val args = listOf( | ||
config.javaCmd, | ||
"-Xss50m", | ||
"-Xmx2g", | ||
"-Dapproximations.path=${layout.approximationsPath.canonicalPath}", | ||
"-Djava.library.path=${layout.nativeLibPath.canonicalPath}", | ||
"-jar", | ||
layout.jarPath.canonicalPath, | ||
config.mypyBuildDir, | ||
port.port.toString(), | ||
functionConfig.module, | ||
functionConfig.name, | ||
runConfig.timeoutPerRunMs.toString(), | ||
runConfig.timeoutMs.toString() | ||
) + config.roots.toList() | ||
|
||
val processBuilder = ProcessBuilder(args) | ||
|
||
val env = processBuilder.environment() | ||
env["LD_LIBRARY_PATH"] = "${File(layout.cpythonPath, "lib").canonicalPath}:${layout.cpythonPath.canonicalPath}" | ||
env["LD_PRELOAD"] = File(layout.cpythonPath, "lib/libpython3.so").canonicalPath | ||
env["PYTHONHOME"] = layout.cpythonPath.canonicalPath | ||
|
||
return processBuilder | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters