From 4daf024e8036991f1b51b4c5715f4482bd63f758 Mon Sep 17 00:00:00 2001 From: ancavar Date: Sat, 12 Oct 2024 21:39:43 +0300 Subject: [PATCH] Round down percentage coverage --- usvm-jvm/src/main/kotlin/org/usvm/machine/JcMachine.kt | 6 +++--- .../src/main/kotlin/org.usvm/JavaMethodRunner.kt | 2 +- .../src/main/kotlin/org.usvm/gameserver/Explorer.kt | 3 ++- .../src/main/kotlin/org.usvm/gameserver/Messages.kt | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/usvm-jvm/src/main/kotlin/org/usvm/machine/JcMachine.kt b/usvm-jvm/src/main/kotlin/org/usvm/machine/JcMachine.kt index f949ab76d0..581f6cf1ed 100644 --- a/usvm-jvm/src/main/kotlin/org/usvm/machine/JcMachine.kt +++ b/usvm-jvm/src/main/kotlin/org/usvm/machine/JcMachine.kt @@ -58,7 +58,7 @@ class JcMachine( private val cfgStatistics = CfgStatisticsImpl(applicationGraph) - fun analyze(methods: List, targets: List = emptyList()): Pair, Int> { + fun analyze(methods: List, targets: List = emptyList()): Pair, Float> { logger.debug("{}.analyze({})", this, methods) val initialStates = mutableMapOf() methods.forEach { @@ -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 = emptyList()): Pair, Int> = + fun analyze(method: JcMethod, targets: List = emptyList()): Pair, Float> = analyze(listOf(method), targets) /** diff --git a/usvm-ml-gameserver/src/main/kotlin/org.usvm/JavaMethodRunner.kt b/usvm-ml-gameserver/src/main/kotlin/org.usvm/JavaMethodRunner.kt index 5556f6cc41..348237985d 100644 --- a/usvm-ml-gameserver/src/main/kotlin/org.usvm/JavaMethodRunner.kt +++ b/usvm-ml-gameserver/src/main/kotlin/org.usvm/JavaMethodRunner.kt @@ -45,7 +45,7 @@ class JavaMethodRunner(gameMap: GameMap, oracle: Predictor<*>? = null) { oracle = oracle ) - fun cover(className: String, methodName: String): Pair, Int> { + fun cover(className: String, methodName: String): Pair, Float> { val jcMethod = cp.getJcMethodByName(className, methodName) val (states, percentageCoverage) = JcMachine(cp, options, interpreterObserver = null).use { machine -> diff --git a/usvm-ml-gameserver/src/main/kotlin/org.usvm/gameserver/Explorer.kt b/usvm-ml-gameserver/src/main/kotlin/org.usvm/gameserver/Explorer.kt index 1cef5f383e..1e64efd797 100644 --- a/usvm-ml-gameserver/src/main/kotlin/org.usvm/gameserver/Explorer.kt +++ b/usvm-ml-gameserver/src/main/kotlin/org.usvm/gameserver/Explorer.kt @@ -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, @@ -29,7 +30,7 @@ fun randomExplorer( val tests = results.size - errors return GameOver( - percentageCoverage.toUByte(), + floor(percentageCoverage).toUInt(), test = tests.toUInt(), error = errors.toUInt() ) diff --git a/usvm-ml-gameserver/src/main/kotlin/org.usvm/gameserver/Messages.kt b/usvm-ml-gameserver/src/main/kotlin/org.usvm/gameserver/Messages.kt index 8e4c82d5c4..2276de2bd5 100644 --- a/usvm-ml-gameserver/src/main/kotlin/org.usvm/gameserver/Messages.kt +++ b/usvm-ml-gameserver/src/main/kotlin/org.usvm/gameserver/Messages.kt @@ -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()