summaryrefslogtreecommitdiff
path: root/opendc-simulator/opendc-simulator-power/src/test
diff options
context:
space:
mode:
authorDante Niewenhuis <d.niewenhuis@hotmail.com>2024-10-25 13:32:41 +0200
committerGitHub <noreply@github.com>2024-10-25 13:32:41 +0200
commit5a365dbc068f2a8cdfa9813c39cc84bb30e15637 (patch)
tree72716d562787b85e03cdc7fe1d30c827054d25a0 /opendc-simulator/opendc-simulator-power/src/test
parent27f5b7dcb05aefdab9b762175d538931face0aba (diff)
Rewrote the FlowEngine (#256)
* Removed unused components. Updated tests. Improved checkpointing model Improved model, started with SimPowerSource implemented FailureModels and Checkpointing First working version midway commit first update All simulation are now run with a single CPU and single MemoryUnit. multi CPUs are combined into one. This is for performance and explainability. * fixed merge conflicts * Updated M3SA paths. * Fixed small typo
Diffstat (limited to 'opendc-simulator/opendc-simulator-power/src/test')
-rw-r--r--opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimPduTest.kt133
-rw-r--r--opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimPowerSourceTest.kt155
-rw-r--r--opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimUpsTest.kt108
-rw-r--r--opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/TestInlet.kt49
4 files changed, 0 insertions, 445 deletions
diff --git a/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimPduTest.kt b/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimPduTest.kt
deleted file mode 100644
index 9df72c49..00000000
--- a/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimPduTest.kt
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Copyright (c) 2021 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package org.opendc.simulator.power
-
-import kotlinx.coroutines.yield
-import org.junit.jupiter.api.Assertions.assertEquals
-import org.junit.jupiter.api.Test
-import org.junit.jupiter.api.assertThrows
-import org.opendc.simulator.flow2.FlowEngine
-import org.opendc.simulator.kotlin.runSimulation
-
-/**
- * Test suite for the [SimPdu] class.
- */
-internal class SimPduTest {
- @Test
- fun testZeroOutlets() =
- runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, 100.0f)
- val pdu = SimPdu(graph)
- source.connect(pdu)
-
- yield()
-
- assertEquals(0.0f, source.powerDraw)
- }
-
- @Test
- fun testSingleOutlet() =
- runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, 100.0f)
- val pdu = SimPdu(graph)
- source.connect(pdu)
- pdu.newOutlet().connect(TestInlet(graph))
-
- yield()
-
- assertEquals(100.0f, source.powerDraw)
- }
-
- @Test
- fun testDoubleOutlet() =
- runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, 200.0f)
- val pdu = SimPdu(graph)
- source.connect(pdu)
-
- pdu.newOutlet().connect(TestInlet(graph))
- pdu.newOutlet().connect(TestInlet(graph))
-
- yield()
-
- assertEquals(200.0f, source.powerDraw)
- }
-
- @Test
- fun testDisconnect() =
- runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, 300.0f)
- val pdu = SimPdu(graph)
- source.connect(pdu)
-
- val outlet = pdu.newOutlet()
- outlet.connect(TestInlet(graph))
- outlet.disconnect()
-
- yield()
-
- assertEquals(0.0f, source.powerDraw)
- }
-
- @Test
- fun testLoss() =
- runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, 500.0f)
- // https://download.schneider-electric.com/files?p_Doc_Ref=SPD_NRAN-66CK3D_EN
- val pdu = SimPdu(graph, 1.5f, 0.015f)
- source.connect(pdu)
- pdu.newOutlet().connect(TestInlet(graph))
-
- yield()
-
- assertEquals(251.5f, source.powerDraw, 0.01f)
- }
-
- @Test
- fun testOutletClose() =
- runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, 100.0f)
- val pdu = SimPdu(graph)
- source.connect(pdu)
- val outlet = pdu.newOutlet()
- outlet.close()
-
- yield()
-
- assertThrows<IllegalStateException> {
- outlet.connect(TestInlet(graph))
- }
- }
-}
diff --git a/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimPowerSourceTest.kt b/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimPowerSourceTest.kt
deleted file mode 100644
index bbc9ad92..00000000
--- a/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimPowerSourceTest.kt
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Copyright (c) 2021 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package org.opendc.simulator.power
-
-import io.mockk.every
-import io.mockk.mockk
-import kotlinx.coroutines.yield
-import org.junit.jupiter.api.Assertions.assertAll
-import org.junit.jupiter.api.Assertions.assertEquals
-import org.junit.jupiter.api.Assertions.assertFalse
-import org.junit.jupiter.api.Assertions.assertNull
-import org.junit.jupiter.api.Assertions.assertTrue
-import org.junit.jupiter.api.Test
-import org.junit.jupiter.api.assertDoesNotThrow
-import org.junit.jupiter.api.assertThrows
-import org.opendc.simulator.flow2.FlowEngine
-import org.opendc.simulator.kotlin.runSimulation
-
-/**
- * Test suite for the [SimPowerSource]
- */
-internal class SimPowerSourceTest {
- @Test
- fun testInitialState() =
- runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, 100.0f)
-
- yield()
-
- assertAll(
- { assertFalse(source.isConnected) },
- { assertNull(source.inlet) },
- { assertEquals(100.0f, source.capacity) },
- )
- }
-
- @Test
- fun testDisconnectIdempotent() =
- runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, 100.0f)
-
- assertDoesNotThrow { source.disconnect() }
- assertFalse(source.isConnected)
- }
-
- @Test
- fun testConnect() =
- runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, 100.0f)
- val inlet = TestInlet(graph)
-
- source.connect(inlet)
-
- yield()
-
- assertAll(
- { assertTrue(source.isConnected) },
- { assertEquals(inlet, source.inlet) },
- { assertTrue(inlet.isConnected) },
- { assertEquals(source, inlet.outlet) },
- { assertEquals(100.0f, source.powerDraw) },
- )
- }
-
- @Test
- fun testDisconnect() =
- runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, 100.0f)
- val inlet = TestInlet(graph)
-
- source.connect(inlet)
- source.disconnect()
-
- yield()
-
- assertEquals(0.0f, inlet.flowOutlet.capacity)
- }
-
- @Test
- fun testDisconnectAssertion() =
- runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, 100.0f)
-
- val inlet = mockk<SimPowerInlet>(relaxUnitFun = true)
- every { inlet.isConnected } returns false
- every { inlet.flowOutlet } returns TestInlet(graph).flowOutlet
-
- source.connect(inlet)
- inlet.outlet = null
-
- assertThrows<AssertionError> {
- source.disconnect()
- }
- }
-
- @Test
- fun testOutletAlreadyConnected() =
- runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, 100.0f)
- val inlet = TestInlet(graph)
-
- source.connect(inlet)
- assertThrows<IllegalStateException> {
- source.connect(TestInlet(graph))
- }
-
- assertEquals(inlet, source.inlet)
- }
-
- @Test
- fun testInletAlreadyConnected() =
- runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, 100.0f)
- val inlet = mockk<SimPowerInlet>(relaxUnitFun = true)
- every { inlet.isConnected } returns true
-
- assertThrows<IllegalStateException> {
- source.connect(inlet)
- }
- }
-}
diff --git a/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimUpsTest.kt b/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimUpsTest.kt
deleted file mode 100644
index cbd23887..00000000
--- a/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimUpsTest.kt
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright (c) 2021 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package org.opendc.simulator.power
-
-import kotlinx.coroutines.yield
-import org.junit.jupiter.api.Assertions.assertAll
-import org.junit.jupiter.api.Assertions.assertEquals
-import org.junit.jupiter.api.Test
-import org.opendc.simulator.flow2.FlowEngine
-import org.opendc.simulator.kotlin.runSimulation
-
-/**
- * Test suite for the [SimUps] class.
- */
-internal class SimUpsTest {
- @Test
- fun testSingleInlet() =
- runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, 200.0f)
- val ups = SimUps(graph)
- source.connect(ups.newInlet())
- ups.connect(TestInlet(graph))
-
- yield()
-
- assertEquals(100.0f, source.powerDraw)
- }
-
- @Test
- fun testDoubleInlet() =
- runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source1 = SimPowerSource(graph, 200.0f)
- val source2 = SimPowerSource(graph, 200.0f)
- val ups = SimUps(graph)
- source1.connect(ups.newInlet())
- source2.connect(ups.newInlet())
-
- ups.connect(TestInlet(graph))
-
- yield()
-
- assertAll(
- { assertEquals(50.0f, source1.powerDraw) },
- { assertEquals(50.0f, source2.powerDraw) },
- )
- }
-
- @Test
- fun testLoss() =
- runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, 500.0f)
- // https://download.schneider-electric.com/files?p_Doc_Ref=SPD_NRAN-66CK3D_EN
- val ups = SimUps(graph, 4.0f, 0.05f)
- source.connect(ups.newInlet())
- ups.connect(TestInlet(graph))
-
- yield()
-
- assertEquals(109.0f, source.powerDraw, 0.01f)
- }
-
- @Test
- fun testDisconnect() =
- runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source1 = SimPowerSource(graph, 200.0f)
- val source2 = SimPowerSource(graph, 200.0f)
- val ups = SimUps(graph)
- source1.connect(ups.newInlet())
- source2.connect(ups.newInlet())
-
- val inlet = TestInlet(graph)
-
- ups.connect(inlet)
- ups.disconnect()
-
- yield()
-
- assertEquals(0.0f, inlet.flowOutlet.capacity)
- }
-}
diff --git a/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/TestInlet.kt b/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/TestInlet.kt
deleted file mode 100644
index 1c06acf4..00000000
--- a/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/TestInlet.kt
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 2022 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package org.opendc.simulator.power
-
-import org.opendc.simulator.flow2.FlowGraph
-import org.opendc.simulator.flow2.FlowStage
-import org.opendc.simulator.flow2.FlowStageLogic
-import org.opendc.simulator.flow2.Outlet
-
-/**
- * A test inlet.
- */
-class TestInlet(graph: FlowGraph) : SimPowerInlet(), FlowStageLogic {
- private val stage = graph.newStage(this)
- val flowOutlet = stage.getOutlet("out")
-
- init {
- flowOutlet.push(100.0f)
- }
-
- override fun onUpdate(
- ctx: FlowStage,
- now: Long,
- ): Long = Long.MAX_VALUE
-
- override fun getFlowOutlet(): Outlet {
- return flowOutlet
- }
-}