forked from UnitTestBot/usvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Add runner #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Add runner #15
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
57 changes: 0 additions & 57 deletions
57
usvm-ml-gameserver/src/main/kotlin/org.usvm/JavaMethodRunner.kt
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
This file contains hidden or 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
2 changes: 1 addition & 1 deletion
2
...c/main/kotlin/org.usvm/util/Conversion.kt → ...vm/gameserver/serialization/Conversion.kt
This file contains hidden or 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
This file contains hidden or 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,32 @@ | ||
| import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
|
|
||
| plugins { | ||
| id("usvm.kotlin-conventions") | ||
| kotlin | ||
| } | ||
|
|
||
| repositories { | ||
| mavenCentral() | ||
| } | ||
|
|
||
| tasks.test { | ||
| useJUnitPlatform() | ||
| } | ||
|
|
||
| tasks.withType<KotlinCompile> { | ||
| kotlinOptions.allWarningsAsErrors = false | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation(project(":usvm-jvm")) | ||
| implementation(project(":usvm-core")) | ||
| implementation(Libs.jacodb_api_jvm) | ||
| implementation(Libs.jacodb_core) | ||
| implementation(Libs.kotlinx_cli) | ||
|
|
||
| implementation(Libs.slf4j_simple) | ||
| implementation(Libs.logback) | ||
|
|
||
| implementation("io.github.rchowell:dotlin:1.0.2") | ||
| testImplementation(kotlin("test")) | ||
| } |
57 changes: 57 additions & 0 deletions
57
usvm-runner/src/main/kotlin/org/usvm/runner/JavaMethodRunner.kt
This file contains hidden or 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,57 @@ | ||
| package org.usvm.runner | ||
|
|
||
| import org.usvm.CoverageZone | ||
| import org.usvm.PathSelectionStrategy | ||
| import org.usvm.PathSelectorCombinationStrategy | ||
| import org.usvm.UMachineOptions | ||
| import org.usvm.machine.JcMachine | ||
| import org.usvm.machine.state.JcState | ||
| import org.usvm.runner.util.JacoDBContainer | ||
| import org.usvm.runner.util.getJcMethodByName | ||
| import org.usvm.runner.util.loadClasspathFromJar | ||
| import org.usvm.runner.util.mapsKey | ||
| import kotlin.time.Duration | ||
|
|
||
| class JavaMethodRunner(val options: UMachineOptions, classpath: String) { | ||
| val jacodbCpKey: String | ||
| get() = mapsKey | ||
|
|
||
| val cp by lazy { | ||
| val classpath = loadClasspathFromJar(classpath) | ||
| JacoDBContainer(jacodbCpKey, classpath).cp | ||
| } | ||
|
|
||
| fun cover(methodFullName: String): Pair<List<JcState>, Float> { | ||
| val (className, methodName) = extractClassAndMethod(methodFullName) | ||
| return cover(className, methodName) | ||
| } | ||
|
|
||
| fun cover(className: String, methodName: String): Pair<List<JcState>, Float> { | ||
| val jcMethod = cp.getJcMethodByName(className, methodName) | ||
|
|
||
| val (states, percentageCoverage) = JcMachine(cp, options, interpreterObserver = null).use { machine -> | ||
| machine.analyze(jcMethod.method, targets = emptyList()) | ||
| } | ||
| return states to percentageCoverage | ||
| } | ||
|
|
||
| private fun extractClassAndMethod(fullName: String): Pair<String, String> { | ||
| val parts = fullName.split('.') | ||
| val className = parts.dropLast(1).joinToString(".") | ||
| val methodName = parts.last() | ||
|
|
||
| return Pair(className, methodName) | ||
| } | ||
| } | ||
|
|
||
| val defaultOptions = UMachineOptions( | ||
| pathSelectionStrategies = listOf(PathSelectionStrategy.AI), | ||
| pathSelectorCombinationStrategy = PathSelectorCombinationStrategy.SEQUENTIAL, | ||
| coverageZone = CoverageZone.METHOD, | ||
| exceptionsPropagation = true, | ||
| solverTimeout = Duration.INFINITE, | ||
| timeout = Duration.INFINITE, | ||
| typeOperationsTimeout = Duration.INFINITE, | ||
| useSolverForForks = false, | ||
| stepLimit = 2000U | ||
| ) |
This file contains hidden or 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,63 @@ | ||
| package org.usvm.runner | ||
|
|
||
| import ch.qos.logback.classic.Level | ||
| import kotlinx.cli.ArgParser | ||
| import kotlinx.cli.ArgType | ||
| import kotlinx.cli.default | ||
| import kotlinx.cli.required | ||
| import org.slf4j.LoggerFactory | ||
| import org.usvm.statistics.BasicBlock | ||
| import org.usvm.utils.Mode | ||
| import org.usvm.utils.OnnxModelImpl | ||
|
|
||
|
|
||
| fun main(args: Array<String>) { | ||
| val parser = ArgParser("usvm.Runner") | ||
| val model by parser.option( | ||
| ArgType.String, | ||
| fullName = "model", | ||
| shortName = "m", | ||
| description = "Path to ONNX model." | ||
| ).required() | ||
|
|
||
| val path by parser.option( | ||
| ArgType.String, | ||
| fullName = "classpath", | ||
| shortName = "cp", | ||
| description = "Path to Java classpath." | ||
| ).required() | ||
|
|
||
| val mode by parser.option( | ||
| ArgType.Choice<Mode>(), | ||
| fullName = "mode", | ||
| description = "Mode to run inference in. Could be either CPU or GPU, the default is former." | ||
| ).default(Mode.CPU) | ||
|
|
||
| val methodFullName by parser.option( | ||
| ArgType.String, | ||
| fullName = "method", | ||
| description = "Full name of method to cover including package and class name." | ||
| ).required() | ||
|
|
||
| parser.parse(args) | ||
|
|
||
|
|
||
| val runner = JavaMethodRunner( | ||
| defaultOptions.copy(oracle = OnnxModelImpl<BasicBlock>(model, mode)), | ||
| classpath = path | ||
| ) | ||
|
|
||
| // setLogLevel("ROOT", Level.DEBUG) | ||
|
|
||
|
|
||
| runner.cover(methodFullName) | ||
| } | ||
|
|
||
| // evil logger hack | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? |
||
| @Suppress("unused") | ||
| private fun setLogLevel(loggerName: String, level: Level) { | ||
| val loggerContext = LoggerFactory.getILoggerFactory() as ch.qos.logback.classic.LoggerContext | ||
| val logger = loggerContext.getLogger(loggerName) | ||
| logger.level = level | ||
| } | ||
|
|
||
2 changes: 2 additions & 0 deletions
2
...src/main/kotlin/org.usvm/util/DotGraph.kt → ...n/kotlin/org/usvm/runner/util/DotGraph.kt
This file contains hidden or 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
2 changes: 1 addition & 1 deletion
2
...n/kotlin/org.usvm/util/JacoDBContainer.kt → ...n/org/usvm/runner/util/JacoDBContainer.kt
This file contains hidden or 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
2 changes: 1 addition & 1 deletion
2
...ver/src/main/kotlin/org.usvm/util/Util.kt → .../main/kotlin/org/usvm/runner/util/Util.kt
This file contains hidden or 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
This file contains hidden or 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,11 @@ | ||
| <configuration> | ||
| <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
| <encoder> | ||
| <pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> | ||
| </encoder> | ||
| </appender> | ||
| <root level="INFO"> | ||
| <appender-ref ref="STDOUT" /> | ||
| </root> | ||
| <logger name="io.netty" level="INFO"/> | ||
| </configuration> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?