diff options
Diffstat (limited to 'simulator/opendc-simulator/opendc-simulator-compute/src/test')
3 files changed, 23 insertions, 39 deletions
diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimHypervisorTest.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimHypervisorTest.kt index 2c87421f..a067dd2e 100644 --- a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimHypervisorTest.kt +++ b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimHypervisorTest.kt @@ -26,7 +26,6 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.flow.toList import kotlinx.coroutines.launch -import kotlinx.coroutines.test.runBlockingTest import kotlinx.coroutines.yield import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.BeforeEach @@ -39,7 +38,7 @@ import org.opendc.simulator.compute.model.ProcessingNode import org.opendc.simulator.compute.model.ProcessingUnit import org.opendc.simulator.compute.power.ConstantPowerModel import org.opendc.simulator.compute.workload.SimTraceWorkload -import org.opendc.simulator.core.DelayControllerClockAdapter +import org.opendc.simulator.core.runBlockingSimulation /** * Test suite for the [SimHypervisor] class. @@ -61,8 +60,7 @@ internal class SimHypervisorTest { * Test overcommitting of resources via the hypervisor with a single VM. */ @Test - fun testOvercommittedSingle() = runBlockingTest { - val clock = DelayControllerClockAdapter(this) + fun testOvercommittedSingle() = runBlockingSimulation { val listener = object : SimHypervisor.Listener { var totalRequestedWork = 0L var totalGrantedWork = 0L @@ -116,7 +114,7 @@ internal class SimHypervisorTest { { assertEquals(1023300, listener.totalGrantedWork, "Granted Burst does not match") }, { assertEquals(90000, listener.totalOvercommittedWork, "Overcommissioned Burst does not match") }, { assertEquals(listOf(0.0, 0.00875, 1.0, 0.0, 0.0571875, 0.0), res) { "VM usage is correct" } }, - { assertEquals(1200000, currentTime) { "Current time is correct" } } + { assertEquals(1200000, clock.millis()) { "Current time is correct" } } ) } @@ -124,8 +122,7 @@ internal class SimHypervisorTest { * Test overcommitting of resources via the hypervisor with two VMs. */ @Test - fun testOvercommittedDual() = runBlockingTest { - val clock = DelayControllerClockAdapter(this) + fun testOvercommittedDual() = runBlockingSimulation { val listener = object : SimHypervisor.Listener { var totalRequestedWork = 0L var totalGrantedWork = 0L @@ -195,7 +192,7 @@ internal class SimHypervisorTest { { assertEquals(2082000, listener.totalRequestedWork, "Requested Burst does not match") }, { assertEquals(1062000, listener.totalGrantedWork, "Granted Burst does not match") }, { assertEquals(1020000, listener.totalOvercommittedWork, "Overcommissioned Burst does not match") }, - { assertEquals(1200000, currentTime) } + { assertEquals(1200000, clock.millis()) } ) } } diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt index 64524452..205f2eca 100644 --- a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt +++ b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt @@ -24,7 +24,6 @@ package org.opendc.simulator.compute import kotlinx.coroutines.* import kotlinx.coroutines.flow.toList -import kotlinx.coroutines.test.runBlockingTest import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test @@ -37,7 +36,7 @@ import org.opendc.simulator.compute.model.ProcessingNode import org.opendc.simulator.compute.model.ProcessingUnit import org.opendc.simulator.compute.power.ConstantPowerModel import org.opendc.simulator.compute.workload.SimFlopsWorkload -import org.opendc.simulator.core.DelayControllerClockAdapter +import org.opendc.simulator.core.runBlockingSimulation /** * Test suite for the [SimBareMetalMachine] class. @@ -57,23 +56,21 @@ class SimMachineTest { } @Test - fun testFlopsWorkload() = runBlockingTest { - val clock = DelayControllerClockAdapter(this) + fun testFlopsWorkload() = runBlockingSimulation { val machine = SimBareMetalMachine(coroutineContext, clock, machineModel, PerformanceScalingGovernor(), SimpleScalingDriver(ConstantPowerModel(0.0))) try { machine.run(SimFlopsWorkload(2_000, utilization = 1.0)) // Two cores execute 1000 MFlOps per second (1000 ms) - assertEquals(1000, currentTime) + assertEquals(1000, clock.millis()) } finally { machine.close() } } @Test - fun testDualSocketMachine() = runBlockingTest { - val clock = DelayControllerClockAdapter(this) + fun testDualSocketMachine() = runBlockingSimulation { val cpuNode = machineModel.cpus[0].node val machineModel = SimMachineModel( cpus = List(cpuNode.coreCount * 2) { ProcessingUnit(cpuNode, it % 2, 1000.0) }, @@ -85,15 +82,14 @@ class SimMachineTest { machine.run(SimFlopsWorkload(2_000, utilization = 1.0)) // Two sockets with two cores execute 2000 MFlOps per second (500 ms) - assertEquals(500, currentTime) + assertEquals(500, clock.millis()) } finally { machine.close() } } @Test - fun testUsage() = runBlockingTest { - val clock = DelayControllerClockAdapter(this) + fun testUsage() = runBlockingSimulation { val machine = SimBareMetalMachine(coroutineContext, clock, machineModel, PerformanceScalingGovernor(), SimpleScalingDriver(ConstantPowerModel(0.0))) val res = mutableListOf<Double>() @@ -110,8 +106,7 @@ class SimMachineTest { } @Test - fun testClose() = runBlockingTest { - val clock = DelayControllerClockAdapter(this) + fun testClose() = runBlockingSimulation { val machine = SimBareMetalMachine(coroutineContext, clock, machineModel, PerformanceScalingGovernor(), SimpleScalingDriver(ConstantPowerModel(0.0))) machine.close() diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimSpaceSharedHypervisorTest.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimSpaceSharedHypervisorTest.kt index fc2bc720..ef6f536d 100644 --- a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimSpaceSharedHypervisorTest.kt +++ b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimSpaceSharedHypervisorTest.kt @@ -25,7 +25,6 @@ package org.opendc.simulator.compute import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.toList import kotlinx.coroutines.launch -import kotlinx.coroutines.test.runBlockingTest import kotlinx.coroutines.yield import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.BeforeEach @@ -40,7 +39,7 @@ import org.opendc.simulator.compute.power.ConstantPowerModel import org.opendc.simulator.compute.workload.SimFlopsWorkload import org.opendc.simulator.compute.workload.SimRuntimeWorkload import org.opendc.simulator.compute.workload.SimTraceWorkload -import org.opendc.simulator.core.DelayControllerClockAdapter +import org.opendc.simulator.core.runBlockingSimulation /** * A test suite for the [SimSpaceSharedHypervisor]. @@ -62,8 +61,7 @@ internal class SimSpaceSharedHypervisorTest { * Test a trace workload. */ @Test - fun testTrace() = runBlockingTest { - val clock = DelayControllerClockAdapter(this) + fun testTrace() = runBlockingSimulation { val usagePm = mutableListOf<Double>() val usageVm = mutableListOf<Double>() @@ -103,7 +101,7 @@ internal class SimSpaceSharedHypervisorTest { { assertEquals(listOf(0.0, 0.00875, 1.0, 0.0, 0.0571875, 0.0), usagePm) { "Correct PM usage" } }, // Temporary limitation is that VMs do not emit usage information // { assertEquals(listOf(0.0, 0.00875, 1.0, 0.0, 0.0571875, 0.0), usageVm) { "Correct VM usage" } }, - { assertEquals(5 * 60L * 4000, currentTime) { "Took enough time" } } + { assertEquals(5 * 60L * 4000, clock.millis()) { "Took enough time" } } ) } @@ -111,8 +109,7 @@ internal class SimSpaceSharedHypervisorTest { * Test runtime workload on hypervisor. */ @Test - fun testRuntimeWorkload() = runBlockingTest { - val clock = DelayControllerClockAdapter(this) + fun testRuntimeWorkload() = runBlockingSimulation { val duration = 5 * 60L * 1000 val workload = SimRuntimeWorkload(duration) val machine = SimBareMetalMachine( @@ -128,16 +125,14 @@ internal class SimSpaceSharedHypervisorTest { vm.close() machine.close() - assertEquals(duration, currentTime) { "Took enough time" } + assertEquals(duration, clock.millis()) { "Took enough time" } } /** * Test FLOPs workload on hypervisor. */ @Test - fun testFlopsWorkload() = runBlockingTest { - val clock = DelayControllerClockAdapter(this) - + fun testFlopsWorkload() = runBlockingSimulation { val duration = 5 * 60L * 1000 val workload = SimFlopsWorkload((duration * 3.2).toLong(), 1.0) val machine = SimBareMetalMachine( @@ -152,15 +147,14 @@ internal class SimSpaceSharedHypervisorTest { vm.run(workload) machine.close() - assertEquals(duration, currentTime) { "Took enough time" } + assertEquals(duration, clock.millis()) { "Took enough time" } } /** * Test two workloads running sequentially. */ @Test - fun testTwoWorkloads() = runBlockingTest { - val clock = DelayControllerClockAdapter(this) + fun testTwoWorkloads() = runBlockingSimulation { val duration = 5 * 60L * 1000 val machine = SimBareMetalMachine( coroutineContext, clock, machineModel, PerformanceScalingGovernor(), @@ -180,15 +174,14 @@ internal class SimSpaceSharedHypervisorTest { vm2.close() machine.close() - assertEquals(duration * 2, currentTime) { "Took enough time" } + assertEquals(duration * 2, clock.millis()) { "Took enough time" } } /** * Test concurrent workloads on the machine. */ @Test - fun testConcurrentWorkloadFails() = runBlockingTest { - val clock = DelayControllerClockAdapter(this) + fun testConcurrentWorkloadFails() = runBlockingSimulation { val machine = SimBareMetalMachine( coroutineContext, clock, machineModel, PerformanceScalingGovernor(), SimpleScalingDriver(ConstantPowerModel(0.0)) @@ -212,8 +205,7 @@ internal class SimSpaceSharedHypervisorTest { * Test concurrent workloads on the machine. */ @Test - fun testConcurrentWorkloadSucceeds() = runBlockingTest { - val clock = DelayControllerClockAdapter(this) + fun testConcurrentWorkloadSucceeds() = runBlockingSimulation { val machine = SimBareMetalMachine( coroutineContext, clock, machineModel, PerformanceScalingGovernor(), SimpleScalingDriver(ConstantPowerModel(0.0)) |
