summaryrefslogtreecommitdiff
path: root/simulator/opendc-compute/opendc-compute-simulator/src/test
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-03-24 13:05:33 +0100
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-03-24 13:05:33 +0100
commit69598598be2c248acc49e40607b3dd0998ec1ca5 (patch)
tree62e154b6cc5b22f79f3aa67cf245c40c1332f7b4 /simulator/opendc-compute/opendc-compute-simulator/src/test
parent0ad600eb8e14c0ef3ba5529c59d300dc20c85ab2 (diff)
simulator: Move power models to simulator module
This change moves the power models from the `opendc-compute-simulator` to the `opendc-simulator-compute` module, since it better fits the scope of the models and allows them to be re-used for other purposes.
Diffstat (limited to 'simulator/opendc-compute/opendc-compute-simulator/src/test')
-rw-r--r--simulator/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/power/CpuPowerModelTest.kt77
-rw-r--r--simulator/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/power/PStatePowerModelTest.kt45
2 files changed, 0 insertions, 122 deletions
diff --git a/simulator/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/power/CpuPowerModelTest.kt b/simulator/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/power/CpuPowerModelTest.kt
deleted file mode 100644
index cd18b120..00000000
--- a/simulator/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/power/CpuPowerModelTest.kt
+++ /dev/null
@@ -1,77 +0,0 @@
-package org.opendc.compute.simulator.power
-
-import io.mockk.*
-import kotlinx.coroutines.ExperimentalCoroutinesApi
-import kotlinx.coroutines.flow.*
-import kotlinx.coroutines.test.runBlockingTest
-import org.junit.jupiter.api.Assertions.assertEquals
-import org.junit.jupiter.params.ParameterizedTest
-import org.junit.jupiter.params.provider.Arguments
-import org.junit.jupiter.params.provider.MethodSource
-import org.opendc.compute.simulator.power.api.CpuPowerModel
-import org.opendc.compute.simulator.power.models.*
-import org.opendc.simulator.compute.SimBareMetalMachine
-import java.util.stream.Stream
-import kotlin.math.pow
-
-@OptIn(ExperimentalCoroutinesApi::class)
-internal class CpuPowerModelTest {
- private val epsilon = 10.0.pow(-3)
- private val cpuUtil = 0.9
-
- @ParameterizedTest
- @MethodSource("cpuPowerModelArgs")
- fun `compute power consumption given CPU loads`(
- powerModel: CpuPowerModel,
- expectedPowerConsumption: Double
- ) {
- val computedPowerConsumption = powerModel.computeCpuPower(cpuUtil)
- assertEquals(expectedPowerConsumption, computedPowerConsumption, epsilon)
- }
-
- @ParameterizedTest
- @MethodSource("cpuPowerModelArgs")
- fun `ignore idle power when computing power consumptions`(
- powerModel: CpuPowerModel,
- expectedPowerConsumption: Double
- ) {
- val zeroPowerModel = ZeroIdlePowerDecorator(powerModel)
- val computedPowerConsumption = zeroPowerModel.computeCpuPower(0.0)
- assertEquals(0.0, computedPowerConsumption)
- }
-
- @ParameterizedTest
- @MethodSource("cpuPowerModelArgs")
- fun `emit power draw for hosts by different models`(
- powerModel: CpuPowerModel,
- expectedPowerConsumption: Double
- ) {
- runBlockingTest {
- val cpuLoads = flowOf(cpuUtil, cpuUtil, cpuUtil).stateIn(this)
- val machine = mockkClass(SimBareMetalMachine::class)
- every { machine.usage } returns cpuLoads
-
- val serverPowerDraw = powerModel.getPowerDraw(machine)
-
- assertEquals(
- serverPowerDraw.first().toDouble(),
- flowOf(expectedPowerConsumption).first().toDouble(),
- epsilon
- )
-
- verify(exactly = 1) { machine.usage }
- }
- }
-
- @Suppress("unused")
- private companion object {
- @JvmStatic
- fun cpuPowerModelArgs(): Stream<Arguments> = Stream.of(
- Arguments.of(ConstantPowerModel(0.0), 0.0),
- Arguments.of(LinearPowerModel(350.0, 200 / 350.0), 335.0),
- Arguments.of(SquarePowerModel(350.0, 200 / 350.0), 321.5),
- Arguments.of(CubicPowerModel(350.0, 200 / 350.0), 309.35),
- Arguments.of(SqrtPowerModel(350.0, 200 / 350.0), 342.302),
- )
- }
-}
diff --git a/simulator/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/power/PStatePowerModelTest.kt b/simulator/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/power/PStatePowerModelTest.kt
deleted file mode 100644
index e144e541..00000000
--- a/simulator/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/power/PStatePowerModelTest.kt
+++ /dev/null
@@ -1,45 +0,0 @@
-package org.opendc.compute.simulator.power
-
-import io.mockk.*
-import org.junit.jupiter.api.Assertions.assertEquals
-import org.junit.jupiter.api.Test
-import org.opendc.compute.simulator.power.models.PStatePowerModel
-import org.opendc.simulator.compute.SimBareMetalMachine
-import java.time.Clock
-
-internal class PStatePowerModelTest {
- @Test
- fun `update CPU power meter with P-states`() {
- val p0Power = 8.0
- val p3Power = 94.0
- val p4Power = 103.0
- val expectedP0Power = 8.0 * 10
- val expectedP0P4Power = expectedP0Power + 103.0 * 10
-
- val clock = mockkClass(Clock::class)
- val machine = mockkClass(SimBareMetalMachine::class)
- every { clock.millis() } returnsMany listOf(0L, 0L, 10_000L, 20_000L)
- every { machine.speed } returns
- listOf(2.8, 2.8, 2.8, 2.8).map { it * 1000 } andThen // Max. 2.8MHz covered by P0
- listOf(1.5, 3.1, 3.3, 3.6).map { it * 1000 } andThen // Max. 3.6MHz covered by P4
- listOf(1.5, 3.1, 3.1, 3.3).map { it * 1000 } // Max. 3.3MHz covered by P3
-
- // Power meter initialization.
- val pStatePowerModel = PStatePowerModel(machine, clock)
- verify(exactly = 2) { clock.millis() }
- verify(exactly = 1) { machine.speed }
- assertEquals(p0Power, pStatePowerModel.getInstantCpuPower())
-
- // The first measure.
- pStatePowerModel.updateCpuPowerMeter()
- assertEquals(p4Power, pStatePowerModel.getInstantCpuPower())
- assertEquals(expectedP0Power, pStatePowerModel.getAccumulatedCpuPower())
-
- // The second measure.
- pStatePowerModel.updateCpuPowerMeter()
- assertEquals(p3Power, pStatePowerModel.getInstantCpuPower())
- assertEquals(expectedP0P4Power, pStatePowerModel.getAccumulatedCpuPower())
-
- verify(exactly = 4) { clock.millis() }
- }
-}