From 9792670cae76e721af08c3f32bcd77720f7f62be Mon Sep 17 00:00:00 2001 From: kevin-delmas Date: Fri, 6 Dec 2024 18:03:03 +0100 Subject: [PATCH] Add automatic verification of the interference results for MySys --- src/test/resources/mySys/MySys_free_2.txt | 28 +++++++ src/test/resources/mySys/MySys_free_3.txt | 8 ++ src/test/resources/mySys/MySys_free_4.txt | 0 src/test/resources/mySys/MySys_itf_2.txt | 12 +++ src/test/resources/mySys/MySys_itf_3.txt | 8 ++ src/test/resources/mySys/MySys_itf_4.txt | 1 + .../InterferenceTestExtension.scala | 78 +++++++++++++++++++ .../mySys/MySysInterferenceTest.scala | 24 ++++++ 8 files changed, 159 insertions(+) create mode 100644 src/test/resources/mySys/MySys_free_2.txt create mode 100644 src/test/resources/mySys/MySys_free_3.txt create mode 100644 src/test/resources/mySys/MySys_free_4.txt create mode 100644 src/test/resources/mySys/MySys_itf_2.txt create mode 100644 src/test/resources/mySys/MySys_itf_3.txt create mode 100644 src/test/resources/mySys/MySys_itf_4.txt create mode 100644 src/test/scala/onera/pmlanalyzer/views/interference/InterferenceTestExtension.scala create mode 100644 src/test/scala/onera/pmlanalyzer/views/interference/examples/mySys/MySysInterferenceTest.scala diff --git a/src/test/resources/mySys/MySys_free_2.txt b/src/test/resources/mySys/MySys_free_2.txt new file mode 100644 index 0000000..fb02f9c --- /dev/null +++ b/src/test/resources/mySys/MySys_free_2.txt @@ -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 > diff --git a/src/test/resources/mySys/MySys_free_3.txt b/src/test/resources/mySys/MySys_free_3.txt new file mode 100644 index 0000000..c8c3942 --- /dev/null +++ b/src/test/resources/mySys/MySys_free_3.txt @@ -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 > diff --git a/src/test/resources/mySys/MySys_free_4.txt b/src/test/resources/mySys/MySys_free_4.txt new file mode 100644 index 0000000..e69de29 diff --git a/src/test/resources/mySys/MySys_itf_2.txt b/src/test/resources/mySys/MySys_itf_2.txt new file mode 100644 index 0000000..3b6d09f --- /dev/null +++ b/src/test/resources/mySys/MySys_itf_2.txt @@ -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 > diff --git a/src/test/resources/mySys/MySys_itf_3.txt b/src/test/resources/mySys/MySys_itf_3.txt new file mode 100644 index 0000000..ed2f866 --- /dev/null +++ b/src/test/resources/mySys/MySys_itf_3.txt @@ -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 > diff --git a/src/test/resources/mySys/MySys_itf_4.txt b/src/test/resources/mySys/MySys_itf_4.txt new file mode 100644 index 0000000..09fd669 --- /dev/null +++ b/src/test/resources/mySys/MySys_itf_4.txt @@ -0,0 +1 @@ +< t14 || t21 || t31 || t41 > diff --git a/src/test/scala/onera/pmlanalyzer/views/interference/InterferenceTestExtension.scala b/src/test/scala/onera/pmlanalyzer/views/interference/InterferenceTestExtension.scala new file mode 100644 index 0000000..1463247 --- /dev/null +++ b/src/test/scala/onera/pmlanalyzer/views/interference/InterferenceTestExtension.scala @@ -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" +} diff --git a/src/test/scala/onera/pmlanalyzer/views/interference/examples/mySys/MySysInterferenceTest.scala b/src/test/scala/onera/pmlanalyzer/views/interference/examples/mySys/MySysInterferenceTest.scala new file mode 100644 index 0000000..c5e9a6b --- /dev/null +++ b/src/test/scala/onera/pmlanalyzer/views/interference/examples/mySys/MySysInterferenceTest.scala @@ -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")) + } + } +} \ No newline at end of file