From 66e1b9706b8c5e5177edb22a1382be58541e34cb Mon Sep 17 00:00:00 2001 From: "benjamin.lesage" Date: Fri, 12 Apr 2024 08:36:53 +0200 Subject: [PATCH 1/5] Draft test for hardware components --- .../pml/model/hardware/HardwareTest.scala | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/test/scala/onera/pmlanalyzer/pml/model/hardware/HardwareTest.scala diff --git a/src/test/scala/onera/pmlanalyzer/pml/model/hardware/HardwareTest.scala b/src/test/scala/onera/pmlanalyzer/pml/model/hardware/HardwareTest.scala new file mode 100644 index 0000000..e9019c1 --- /dev/null +++ b/src/test/scala/onera/pmlanalyzer/pml/model/hardware/HardwareTest.scala @@ -0,0 +1,29 @@ +package onera.pmlanalyzer.pml.model.hardware + +import onera.pmlanalyzer.pml.model.hardware.* +import onera.pmlanalyzer.pml.model.service.{Load, Store} +import onera.pmlanalyzer.pml.operators.* +import sourcecode.Name +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should + +class HardwareTest extends AnyFlatSpec with should.Matchers { + + /* Create a default platform to act as a container for components. */ + object PlatformFixture extends Platform(Symbol("fixture")) + + import PlatformFixture.* + + "A Hardware" should "have default services" in { + val t: Target = Target() + val s: SimpleTransporter = SimpleTransporter() + val i: Initiator = Initiator() + val v: Virtualizer = Virtualizer() + + for (h <- List(t, s, i, v)) { + exactly(1, h.services) shouldBe a [Load] + exactly(1, h.services) shouldBe a [Store] + h.services.size shouldBe 2 + } + } +} From cc1e71878a83aa8565d9a40dac9edaa261500ed8 Mon Sep 17 00:00:00 2001 From: "benjamin.lesage" Date: Fri, 12 Apr 2024 09:00:20 +0200 Subject: [PATCH 2/5] Create hardware components with no load/store services --- .../hardware/BaseHardwareNodeBuilder.scala | 56 ++++++++++++------- .../pml/model/hardware/HardwareTest.scala | 12 ++++ 2 files changed, 49 insertions(+), 19 deletions(-) diff --git a/src/main/scala/onera/pmlanalyzer/pml/model/hardware/BaseHardwareNodeBuilder.scala b/src/main/scala/onera/pmlanalyzer/pml/model/hardware/BaseHardwareNodeBuilder.scala index 2220d04..8362ed1 100644 --- a/src/main/scala/onera/pmlanalyzer/pml/model/hardware/BaseHardwareNodeBuilder.scala +++ b/src/main/scala/onera/pmlanalyzer/pml/model/hardware/BaseHardwareNodeBuilder.scala @@ -82,45 +82,63 @@ trait BaseHardwareNodeBuilder[T <: Hardware] extends PMLNodeBuilder[T] { * (the name of the value enclosing the object) * @example {{{ * val mySimpleTransporter = SimpleTransporter() - * }}} - * @param basics the set of basic services provided, if empty a default store and load services are added - * @param implicitName implicitly retrieved name from the declaration context - * @param p implicitly retrieved relation linking components to their provided services - * @param owner implicitly retrieved name of the platform + * }}} + * @param basics the set of basic services provided, if empty a default store and load services are added + * @param withDefaultServices add default Load/Store services on creation + * @param implicitName implicitly retrieved name from the declaration context + * @param p implicitly retrieved relation linking components to their provided services + * @param owner implicitly retrieved name of the platform * @return the physical component * @group publicConstructor */ - def apply(basics: Set[Service] = Set.empty)(implicit implicitName: Name, - p: ProvideRelation[Hardware, Service], - owner: Owner): T = - apply(Symbol(implicitName.value), basics) + def apply(basics: Set[Service] = Set.empty, withDefaultServices: Boolean = true)(implicit implicitName: Name, + p: ProvideRelation[Hardware, Service], + owner: Owner): T = + apply(Symbol(implicitName.value), basics, withDefaultServices) /** * A physical component can be defined by its name and the basic services it provides * A transporter is only defined by its name, so if the transporter already exists it will * simply add the services provided by basics * - * @param name the physical component name - * @param basics the set of basic services provided, if empty a default store and load services are added - * @param p implicitly retrieved relation linking components to their provided services - * @param owner implicitly retrieved name of the platform + * @param name the physical component name + * @param basics the set of basic services provided, if empty a default store and load services are added + * @param withDefaultServices add default Load/Store services on creation + * @param p implicitly retrieved relation linking components to their provided services + * @param owner implicitly retrieved name of the platform * @return the physical component * @group publicConstructor */ - def apply(name: Symbol, basics: Set[Service])(implicit - p: ProvideRelation[Hardware, Service], - owner: Owner): T = { + def apply(name: Symbol, basics: Set[Service], withDefaultServices: Boolean)(implicit + p: ProvideRelation[Hardware, Service], + owner: Owner): T = { val formattedName = formatName(name, owner) val result = _memo.getOrElseUpdate((owner.s, formattedName), builder(formattedName)) val mutableBasic = collection.mutable.Set(basics.toSeq: _*) - if (!basics.exists(_.isInstanceOf[Load])) + if (withDefaultServices && !basics.exists(_.isInstanceOf[Load])) mutableBasic += Load(Symbol(s"${formattedName.name}_load")) - if (!basics.exists(_.isInstanceOf[Store])) + if (withDefaultServices && !basics.exists(_.isInstanceOf[Store])) mutableBasic += Store(Symbol(s"${formattedName.name}_store")) p.add(result, mutableBasic) result } + /** + * A physical component can be defined by its name and the basic services it provides + * + * @param name the physical component name + * @param basics the set of basic services provided, if empty a default store and load services are added + * @param p implicitly retrieved relation linking components to their provided services + * @param owner implicitly retrieved name of the platform + * @return the physical component + * @group publicConstructor + */ + def apply(name: Symbol, basics: Set[Service])(implicit + p: ProvideRelation[Hardware, Service], + owner: Owner): T = { + apply(name, basics, true) + } + /** * A physical component can be defined only its name, the services will be defined by default * @group publicConstructor @@ -131,5 +149,5 @@ trait BaseHardwareNodeBuilder[T <: Hardware] extends PMLNodeBuilder[T] { */ def apply(name: Symbol)(implicit p: ProvideRelation[Hardware, Service], owner: Owner): T = - apply(name, Set.empty) + apply(name, Set.empty, true) } diff --git a/src/test/scala/onera/pmlanalyzer/pml/model/hardware/HardwareTest.scala b/src/test/scala/onera/pmlanalyzer/pml/model/hardware/HardwareTest.scala index e9019c1..e1ac118 100644 --- a/src/test/scala/onera/pmlanalyzer/pml/model/hardware/HardwareTest.scala +++ b/src/test/scala/onera/pmlanalyzer/pml/model/hardware/HardwareTest.scala @@ -26,4 +26,16 @@ class HardwareTest extends AnyFlatSpec with should.Matchers { h.services.size shouldBe 2 } } + + it should "have no services when specified" in { + val t: Target = Target(withDefaultServices=false) + val s: SimpleTransporter = SimpleTransporter(withDefaultServices=false) + val i: Initiator = Initiator(withDefaultServices=false) + val v: Virtualizer = Virtualizer(withDefaultServices=false) + + for (h <- List(t, s, i, v)) { + h.services shouldBe empty + } + } + } From 098c081028a7f2d6da2d15f2a2c3cf3284790f3b Mon Sep 17 00:00:00 2001 From: "benjamin.lesage" Date: Fri, 12 Apr 2024 09:12:47 +0200 Subject: [PATCH 3/5] Add tests with default services --- .../pml/model/hardware/HardwareTest.scala | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/test/scala/onera/pmlanalyzer/pml/model/hardware/HardwareTest.scala b/src/test/scala/onera/pmlanalyzer/pml/model/hardware/HardwareTest.scala index e1ac118..f46ff06 100644 --- a/src/test/scala/onera/pmlanalyzer/pml/model/hardware/HardwareTest.scala +++ b/src/test/scala/onera/pmlanalyzer/pml/model/hardware/HardwareTest.scala @@ -28,14 +28,27 @@ class HardwareTest extends AnyFlatSpec with should.Matchers { } it should "have no services when specified" in { - val t: Target = Target(withDefaultServices=false) - val s: SimpleTransporter = SimpleTransporter(withDefaultServices=false) - val i: Initiator = Initiator(withDefaultServices=false) - val v: Virtualizer = Virtualizer(withDefaultServices=false) + val t: Target = Target(withDefaultServices = false) + val s: SimpleTransporter = SimpleTransporter(withDefaultServices = false) + val i: Initiator = Initiator(withDefaultServices = false) + val v: Virtualizer = Virtualizer(withDefaultServices = false) for (h <- List(t, s, i, v)) { h.services shouldBe empty } } + it should "have only specified services when specified" in { + val t: Target = Target(Set(Load("a"), Load("b")), false) + t.services.size shouldEqual 2 + exactly(2, t.services) shouldBe a [Load] + + val s = Target(Set(Store("a")), false) + s.services.size shouldEqual 1 + exactly(1, s.services) shouldBe a[Store] + + val i = Target(Set.empty, false) + i.services.size shouldEqual 0 + } + } From f2006f60762baeb23f3f911c0d483a8550ab11a2 Mon Sep 17 00:00:00 2001 From: "benjamin.lesage" Date: Fri, 12 Apr 2024 09:22:53 +0200 Subject: [PATCH 4/5] Add default services flag support on constructors --- .../model/hardware/BaseHardwareNodeBuilder.scala | 15 +++++++++++++++ .../pml/model/hardware/HardwareTest.scala | 3 +++ 2 files changed, 18 insertions(+) diff --git a/src/main/scala/onera/pmlanalyzer/pml/model/hardware/BaseHardwareNodeBuilder.scala b/src/main/scala/onera/pmlanalyzer/pml/model/hardware/BaseHardwareNodeBuilder.scala index 8362ed1..b62d7f4 100644 --- a/src/main/scala/onera/pmlanalyzer/pml/model/hardware/BaseHardwareNodeBuilder.scala +++ b/src/main/scala/onera/pmlanalyzer/pml/model/hardware/BaseHardwareNodeBuilder.scala @@ -150,4 +150,19 @@ trait BaseHardwareNodeBuilder[T <: Hardware] extends PMLNodeBuilder[T] { def apply(name: Symbol)(implicit p: ProvideRelation[Hardware, Service], owner: Owner): T = apply(name, Set.empty, true) + + + /** + * A physical component can be defined only its name, the services will be defined by default + * + * @group publicConstructor + * @param name the physical component name + * @param withDefaultServices add default Load/Store services on creation + * @param p implicitly retrieved relation linking components to their provided services + * @param owner implicitly retrieved name of the platform + * @return the physical component + */ + def apply(name: Symbol, withDefaultServices: Boolean)(implicit p: ProvideRelation[Hardware, Service], + owner: Owner): T = + apply(name, Set.empty, withDefaultServices) } diff --git a/src/test/scala/onera/pmlanalyzer/pml/model/hardware/HardwareTest.scala b/src/test/scala/onera/pmlanalyzer/pml/model/hardware/HardwareTest.scala index f46ff06..4161317 100644 --- a/src/test/scala/onera/pmlanalyzer/pml/model/hardware/HardwareTest.scala +++ b/src/test/scala/onera/pmlanalyzer/pml/model/hardware/HardwareTest.scala @@ -49,6 +49,9 @@ class HardwareTest extends AnyFlatSpec with should.Matchers { val i = Target(Set.empty, false) i.services.size shouldEqual 0 + + val j = Target(Symbol("j"), false) + j.services.size shouldEqual 0 } } From 4d80ed0ae06634c0d5a414bf8d1bf36af0f03882 Mon Sep 17 00:00:00 2001 From: "benjamin.lesage" Date: Fri, 12 Apr 2024 16:43:29 +0200 Subject: [PATCH 5/5] Name the tested parameter explicitly in hardware test cases --- .../pmlanalyzer/pml/model/hardware/HardwareTest.scala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/scala/onera/pmlanalyzer/pml/model/hardware/HardwareTest.scala b/src/test/scala/onera/pmlanalyzer/pml/model/hardware/HardwareTest.scala index 4161317..de694ee 100644 --- a/src/test/scala/onera/pmlanalyzer/pml/model/hardware/HardwareTest.scala +++ b/src/test/scala/onera/pmlanalyzer/pml/model/hardware/HardwareTest.scala @@ -39,18 +39,18 @@ class HardwareTest extends AnyFlatSpec with should.Matchers { } it should "have only specified services when specified" in { - val t: Target = Target(Set(Load("a"), Load("b")), false) + val t: Target = Target(Set(Load("a"), Load("b")), withDefaultServices = false) t.services.size shouldEqual 2 exactly(2, t.services) shouldBe a [Load] - val s = Target(Set(Store("a")), false) + val s = Target(Set(Store("a")), withDefaultServices = false) s.services.size shouldEqual 1 exactly(1, s.services) shouldBe a[Store] - val i = Target(Set.empty, false) + val i = Target(Set.empty, withDefaultServices = false) i.services.size shouldEqual 0 - val j = Target(Symbol("j"), false) + val j = Target(Symbol("j"), withDefaultServices = false) j.services.size shouldEqual 0 }