diff options
| author | Hongyu <hongyuhe.cs@googlemail.com> | 2021-04-05 12:50:19 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2021-04-07 12:13:16 +0200 |
| commit | f3384ca33f84fc261aeb20ca7752ab052971dcf4 (patch) | |
| tree | f3c942f2ce6c8f38081ccf6200172815d539ab6a /simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin | |
| parent | e38e6b9341907e28d029054995cf43cbd5e8bb4d (diff) | |
simulator: Polish power models
This change updates the power models by fixing some of the documentation
and adding toString() methods.
Diffstat (limited to 'simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin')
| -rw-r--r-- | simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/power/PStatePowerModelTest.kt | 44 | ||||
| -rw-r--r-- | simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/power/PowerModelTest.kt (renamed from simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/power/MachinePowerModelTest.kt) | 17 |
2 files changed, 5 insertions, 56 deletions
diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/power/PStatePowerModelTest.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/power/PStatePowerModelTest.kt deleted file mode 100644 index 9116f928..00000000 --- a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/power/PStatePowerModelTest.kt +++ /dev/null @@ -1,44 +0,0 @@ -package org.opendc.simulator.compute.power - -import io.mockk.* -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Test -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() } - } -} diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/power/MachinePowerModelTest.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/power/PowerModelTest.kt index f42e2e73..8ec9910c 100644 --- a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/power/MachinePowerModelTest.kt +++ b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/power/PowerModelTest.kt @@ -1,6 +1,5 @@ package org.opendc.simulator.compute.power -import kotlinx.coroutines.ExperimentalCoroutinesApi import org.junit.jupiter.api.Assertions.assertAll import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test @@ -11,8 +10,7 @@ import org.junit.jupiter.params.provider.MethodSource import java.util.stream.Stream import kotlin.math.pow -@OptIn(ExperimentalCoroutinesApi::class) -internal class MachinePowerModelTest { +internal class PowerModelTest { private val epsilon = 10.0.pow(-3) private val cpuUtil = 0.9 @@ -42,11 +40,6 @@ internal class MachinePowerModelTest { val powerModel = InterpolationPowerModel("IBMx3550M3_XeonX5675") assertAll( - { assertThrows<IllegalArgumentException> { powerModel.computePower(-1.3) } }, - { assertThrows<IllegalArgumentException> { powerModel.computePower(1.3) } }, - ) - - assertAll( { assertEquals(58.4, powerModel.computePower(0.0)) }, { assertEquals(58.4 + (98 - 58.4) / 5, powerModel.computePower(0.02)) }, { assertEquals(98.0, powerModel.computePower(0.1)) }, @@ -63,10 +56,10 @@ internal class MachinePowerModelTest { @JvmStatic fun MachinePowerModelArgs(): 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), + Arguments.of(LinearPowerModel(350.0, 200.0), 335.0), + Arguments.of(SquarePowerModel(350.0, 200.0), 321.5), + Arguments.of(CubicPowerModel(350.0, 200.0), 309.35), + Arguments.of(SqrtPowerModel(350.0, 200.0), 342.302), ) } } |
