Skip to content

Commit

Permalink
Add automatic verification of the interference results for MySys
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-delmas committed Dec 12, 2024
1 parent 712864c commit 320f87b
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/test/resources/mySys/MySys_free_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
< t13 || t26 >
< t11 || t26 >
< t13 || t22 >
< t11 || t22 >
< t11 || t23 >
< t13 || t23 >
< t14 || t26 >
< t26 || t41 >
< t11 || t41 >
< t13 || t41 >
< t13 || t24 >
< t12 || t26 >
< t11 || t24 >
< t11 || t21 >
< t13 || t21 >
< t14 || t21 >
< t12 || t21 >
< t24 || t41 >
< t12 || t41 >
< t21 || t41 >
< t12 || t31 >
< t11 || t31 >
< t13 || t31 >
< t14 || t31 >
< t13 || t25 >
< t11 || t25 >
< t14 || t22 >
< t12 || t25 >
8 changes: 8 additions & 0 deletions src/test/resources/mySys/MySys_free_3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
< t11 || t26 || t41 >
< t13 || t26 || t41 >
< t13 || t21 || t41 >
< t11 || t21 || t41 >
< t12 || t26 || t41 >
< t11 || t24 || t41 >
< t13 || t24 || t41 >
< t12 || t21 || t41 >
Empty file.
12 changes: 12 additions & 0 deletions src/test/resources/mySys/MySys_itf_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
< t14 || t23 >
< t12 || t24 >
< t21 || t31 >
< t31 || t41 >
< t22 || t41 >
< t14 || t41 >
< t23 || t41 >
< t25 || t41 >
< t14 || t25 >
< t12 || t22 >
< t14 || t24 >
< t12 || t23 >
8 changes: 8 additions & 0 deletions src/test/resources/mySys/MySys_itf_3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
< t14 || t23 || t41 >
< t14 || t22 || t41 >
< t14 || t25 || t41 >
< t12 || t23 || t41 >
< t14 || t24 || t41 >
< t12 || t22 || t41 >
< t14 || t31 || t41 >
< t21 || t31 || t41 >
1 change: 1 addition & 0 deletions src/test/resources/mySys/MySys_itf_4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
< t14 || t21 || t31 || t41 >
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/** *****************************************************************************
* Copyright (c) 2021. ONERA
* This file is part of PML Analyzer
*
* PML Analyzer is free software ;
* you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation ;
* either version 2 of the License, or (at your option) any later version.
*
* PML Analyzer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY ;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this program ;
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* **************************************************************************** */

package onera.pmlanalyzer.views.interference

import onera.pmlanalyzer.pml.exporters.FileManager
import onera.pmlanalyzer.pml.operators.*
import onera.pmlanalyzer.views.interference.operators.*
import onera.pmlanalyzer.views.interference.operators.Analyse.ConfiguredPlatform

import scala.concurrent.ExecutionContext.Implicits.*
import scala.concurrent.Future
import scala.io.Source
import scala.language.postfixOps

object InterferenceTestExtension {

extension (x:ConfiguredPlatform) {

def test(max: Int, expectedResultsDirectoryPath: String): Future[Seq[Seq[ScenarioComparison]]] = {
x.computeKInterference(List(max, x.initiators.size).min, ignoreExistingAnalysisFiles = true, verboseResultFile = false) map {
resultFiles => {
for {
i <- 2 to List(max, x.initiators.size).min
fileITF <- FileManager.extractResource(s"$expectedResultsDirectoryPath/${x.fullName}_itf_$i.txt")
fileFree <- FileManager.extractResource(s"$expectedResultsDirectoryPath/${x.fullName}_free_$i.txt")
rITFFile <- resultFiles.find(_.getName == s"${x.fullName}_itf_$i.txt")
rFreeFile <- resultFiles.find(_.getName == s"${x.fullName}_free_$i.txt")
} yield {
List(fileITF, fileFree)
.zip(List(rITFFile, rFreeFile))
.flatMap(p => {
val expected = PostProcess.parseScenarioFile(p._1)
val found = PostProcess.parseScenarioFile(Source.fromFile(p._2))
expected.diff(found).map(s => Missing(s)) ++ found.diff(expected).map(s => Unknown(s))
})
}
}
}
}
}

def failureMessage(diff: Seq[ScenarioComparison]): String = {
if (diff.nonEmpty)
s"""${diff.size} scenarios of size ${diff.head.s.size} are incorrect:
|${diff.mkString("\n")}

|""".stripMargin
else
""
}
}

sealed trait ScenarioComparison {
val s: Seq[String]
}

case class Missing(s: Seq[String]) extends ScenarioComparison {
override def toString: String = s.mkString("||") + " not found"
}

case class Unknown(s: Seq[String]) extends ScenarioComparison {
override def toString: String = s.mkString("||") + " not expected"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package onera.pmlanalyzer.views.interference.examples.mySys

import onera.pmlanalyzer.pml.examples.mySys.MySysExport.MySys
import onera.pmlanalyzer.views.interference.InterferenceTestExtension
import onera.pmlanalyzer.views.interference.operators.*
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should
import onera.pmlanalyzer.views.interference.InterferenceTestExtension.*

import scala.concurrent.Await
import scala.concurrent.duration.DurationInt
import scala.language.postfixOps

class MySysInterferenceTest extends AnyFlatSpec with should.Matchers {

private val expectedResultsDirectoryPath = "mySys"

"For MySys, the interference analysis" should "find the verified interference" in {
val diff = Await.result(MySys.test(4, expectedResultsDirectoryPath), 10 minutes)
if (diff.exists(_.nonEmpty)) {
fail(diff.map(InterferenceTestExtension.failureMessage).mkString("\n"))
}
}
}

0 comments on commit 320f87b

Please sign in to comment.