Skip to content

Commit

Permalink
Added mechanism to keep uppaal file for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
SimplisticCode committed Jan 2, 2024
1 parent e4054d3 commit c8dd0bb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ object VerificationAPI extends Logging {
* @return
* true if the algorithm is correct, false otherwise
*/
def verifyFMI3Algorithm(masterModel: MasterModelFMI3): Boolean = {
private def verifyFMI3Algorithm(masterModel: MasterModelFMI3): Boolean = {
SMTEncoder.verifyAlgorithm(masterModel)
}

Expand All @@ -61,13 +61,15 @@ object VerificationAPI extends Logging {
private def verifyFMI2Algorithm(
masterModel: MasterModelFMI2,
uppaalFileType: (String, ModelEncoding, Directory) => File,
isOnlineMode: Boolean = false): Boolean = {
isOnlineMode: Boolean = false,
deleteUppallFile : Boolean = true): Boolean = {
if (!isOnlineMode) {
require(VerifyTA.isInstalled, "Uppaal is not installed, please install it and add it to your PATH")
}
val uppaalFile = generateUppaalFile(masterModel, uppaalFileType)
val verificationResult = VerifyTA.verify(uppaalFile, isOnlineMode)
FileUtils.deleteQuietly(uppaalFile)
if(deleteUppallFile)
FileUtils.deleteQuietly(uppaalFile)
checkVerificationResult(verificationResult)
}

Expand All @@ -87,7 +89,8 @@ object VerificationAPI extends Logging {
def dynamicVerification(
scenarioModel: FMI2ScenarioModel,
previous_actions: List[CosimStepInstruction],
next_action: CosimStepInstruction): Verdict = {
next_action: CosimStepInstruction,
deleteUppaalFile : Boolean = true): Verdict = {
// Does the previous actions contain repeated actions?
val connectionsSrc = scenarioModel.connections.groupBy(_.srcPort)
val numberOfActionsInAlgorithm = connectionsSrc
Expand All @@ -97,13 +100,6 @@ object VerificationAPI extends Logging {
val firstAction = Math.max(previous_actions.size - actionsToCheck, 0)
val filtered_previous_actions = previous_actions.drop(firstAction)

/*
val lastIndexOfFirstAction = if (previous_actions.nonEmpty)
previous_actions.lastIndexOf(previous_actions.head)
else 0
val filtered_previous_actions = previous_actions.drop(lastIndexOfFirstAction)
*/

val masterModel = MasterModelFMI2(
"dynamic_verification",
scenarioModel,
Expand All @@ -114,11 +110,12 @@ object VerificationAPI extends Logging {

val cachedResult = lookupInCache(masterModel)
if (cachedResult.isDefined) {
logger.info("Verdict found in cache - skipping verification in Uppaal")
return Verdict(cachedResult.get, Predef.Set.empty)
}

val verdict =
if (verifyFMI2Algorithm(masterModel, ScenarioGenerator.generateDynamicNoEnabledUppaalFile, isOnlineMode = true)) {
if (verifyFMI2Algorithm(masterModel, ScenarioGenerator.generateDynamicNoEnabledUppaalFile, isOnlineMode = true, deleteUppaalFile)) {
// If the algorithm is correct, we don't need to generate a trace
Verdict(correct = true, Predef.Set.empty)
} else {
Expand Down
3 changes: 1 addition & 2 deletions src/test/scala/DynamicVerification/PositiveTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import org.scalatest.flatspec._
import org.scalatest.matchers._

class PositiveTests extends AnyFlatSpec with should.Matchers {

def generateAndVerify(resourcesFile: String): Boolean = {
val conf = getClass.getResourceAsStream(resourcesFile)
val masterModel = ScenarioLoaderFMI2.load(conf)
(1 until masterModel.cosimStep.values.head.length).forall(i => {
val previous_actions = masterModel.cosimStep.values.head.take(i)
val current_action = masterModel.cosimStep.values.head(i)
VerificationAPI.dynamicVerification(masterModel.scenario, previous_actions, current_action).correct
VerificationAPI.dynamicVerification(masterModel.scenario, previous_actions, current_action, false).correct
})
}

Expand Down

0 comments on commit c8dd0bb

Please sign in to comment.