Skip to content

Commit

Permalink
Round down percentage coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ancavar committed Oct 12, 2024
1 parent 5d18860 commit 4daf024
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions usvm-jvm/src/main/kotlin/org/usvm/machine/JcMachine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class JcMachine(

private val cfgStatistics = CfgStatisticsImpl(applicationGraph)

fun analyze(methods: List<JcMethod>, targets: List<JcTarget> = emptyList()): Pair<List<JcState>, Int> {
fun analyze(methods: List<JcMethod>, targets: List<JcTarget> = emptyList()): Pair<List<JcState>, Float> {
logger.debug("{}.analyze({})", this, methods)
val initialStates = mutableMapOf<JcMethod, JcState>()
methods.forEach {
Expand Down Expand Up @@ -204,13 +204,13 @@ class JcMachine(
stopStrategy = stopStrategy,
)

val percentageCoverage = coverageStatistics.getMethodCoverage(methods.single()).roundToInt()
val percentageCoverage = coverageStatistics.getMethodCoverage(methods.single())

return statesCollector.collectedStates to percentageCoverage

}

fun analyze(method: JcMethod, targets: List<JcTarget> = emptyList()): Pair<List<JcState>, Int> =
fun analyze(method: JcMethod, targets: List<JcTarget> = emptyList()): Pair<List<JcState>, Float> =
analyze(listOf(method), targets)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class JavaMethodRunner(gameMap: GameMap, oracle: Predictor<*>? = null) {
oracle = oracle
)

fun cover(className: String, methodName: String): Pair<List<JcState>, Int> {
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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package org.usvm.gameserver
import org.usvm.JavaMethodRunner
import org.usvm.OracleImpl
import org.usvm.statistics.BasicBlock
import kotlin.math.floor

fun randomExplorer(
inputBody: Start,
Expand All @@ -29,7 +30,7 @@ fun randomExplorer(
val tests = results.size - errors

return GameOver(
percentageCoverage.toUByte(),
floor(percentageCoverage).toUInt(),
test = tests.toUInt(),
error = errors.toUInt()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ sealed class OutputMessageBody

@Serializable
data class GameOver(
@SerialName("ActualCoverage") val percent: UByte,
@SerialName("ActualCoverage") val percent: UInt,
@SerialName("TestsCount") val test: UInt,
@SerialName("ErrorsCount") val error: UInt
) : OutputMessageBody()
Expand Down

0 comments on commit 4daf024

Please sign in to comment.