diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2020-10-03 16:29:55 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2020-10-03 16:29:55 +0200 |
| commit | c8567a567348e13c341bf1a1ec64ed34ce25815a (patch) | |
| tree | e3818756de1c14846b57bef27adc3cef51a72279 /simulator/opendc-compute/src/test | |
| parent | ac7016c4c5f15bf20b21e7d34e93d8b963aab231 (diff) | |
Implement VirtDriver using opendc-simulator-compute module
This change adds an implementation of the VirtDriver interface that uses
the functionality provided by the opendc-simulator-compute module.
Diffstat (limited to 'simulator/opendc-compute/src/test')
| -rw-r--r-- | simulator/opendc-compute/src/test/kotlin/org/opendc/compute/virt/HypervisorTest.kt | 6 | ||||
| -rw-r--r-- | simulator/opendc-compute/src/test/kotlin/org/opendc/compute/virt/SimHypervisorTest.kt | 147 |
2 files changed, 149 insertions, 4 deletions
diff --git a/simulator/opendc-compute/src/test/kotlin/org/opendc/compute/virt/HypervisorTest.kt b/simulator/opendc-compute/src/test/kotlin/org/opendc/compute/virt/HypervisorTest.kt index 369b9538..82a82044 100644 --- a/simulator/opendc-compute/src/test/kotlin/org/opendc/compute/virt/HypervisorTest.kt +++ b/simulator/opendc-compute/src/test/kotlin/org/opendc/compute/virt/HypervisorTest.kt @@ -29,7 +29,6 @@ import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch import kotlinx.coroutines.test.TestCoroutineScope import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertAll import org.opendc.compute.core.Flavor @@ -53,7 +52,6 @@ internal class HypervisorTest { */ @OptIn(ExperimentalCoroutinesApi::class) @Test - @Disabled fun smoke() { val testScope = TestCoroutineScope() val clock = DelayControllerClockAdapter(testScope) @@ -75,7 +73,7 @@ internal class HypervisorTest { delay(5) - val flavor = org.opendc.compute.core.Flavor(1, 0) + val flavor = Flavor(1, 0) val vmDriver = metalDriver.refresh().server!!.services[VirtDriver] vmDriver.events.onEach { println(it) }.launchIn(this) val vmA = vmDriver.spawn("a", workloadA, flavor) @@ -140,7 +138,7 @@ internal class HypervisorTest { delay(5) - val flavor = org.opendc.compute.core.Flavor(2, 0) + val flavor = Flavor(2, 0) val vmDriver = metalDriver.refresh().server!!.services[VirtDriver] vmDriver.events .onEach { event -> diff --git a/simulator/opendc-compute/src/test/kotlin/org/opendc/compute/virt/SimHypervisorTest.kt b/simulator/opendc-compute/src/test/kotlin/org/opendc/compute/virt/SimHypervisorTest.kt new file mode 100644 index 00000000..9d33d395 --- /dev/null +++ b/simulator/opendc-compute/src/test/kotlin/org/opendc/compute/virt/SimHypervisorTest.kt @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2020 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.compute.virt + +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach +import kotlinx.coroutines.launch +import kotlinx.coroutines.test.TestCoroutineScope +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertAll +import org.opendc.compute.core.Flavor +import org.opendc.compute.core.image.SimWorkloadImage +import org.opendc.compute.metal.driver.SimBareMetalDriver +import org.opendc.compute.virt.driver.SimVirtDriverWorkload +import org.opendc.simulator.compute.SimMachineModel +import org.opendc.simulator.compute.model.MemoryUnit +import org.opendc.simulator.compute.model.ProcessingNode +import org.opendc.simulator.compute.model.ProcessingUnit +import org.opendc.simulator.compute.workload.SimTraceWorkload +import org.opendc.simulator.utils.DelayControllerClockAdapter +import java.time.Clock +import java.util.UUID + +/** + * Basic test-suite for the hypervisor. + */ +@OptIn(ExperimentalCoroutinesApi::class) +internal class SimHypervisorTest { + private lateinit var scope: TestCoroutineScope + private lateinit var clock: Clock + private lateinit var machineModel: SimMachineModel + + @BeforeEach + fun setUp() { + scope = TestCoroutineScope() + clock = DelayControllerClockAdapter(scope) + + val cpuNode = ProcessingNode("Intel", "Xeon", "amd64", 2) + + machineModel = SimMachineModel( + cpus = List(cpuNode.coreCount) { ProcessingUnit(cpuNode, it, 3200.0) }, + memory = List(4) { MemoryUnit("Crucial", "MTA18ASF4G72AZ-3G2B1", 3200.0, 32_000) } + ) + } + + /** + * Test overcommissioning of a hypervisor. + */ + @Test + fun overcommission() { + var requestedBurst = 0L + var grantedBurst = 0L + var overcommissionedBurst = 0L + + scope.launch { + val virtDriverWorkload = SimVirtDriverWorkload() + val vmm = SimWorkloadImage(UUID.randomUUID(), "vmm", emptyMap(), virtDriverWorkload) + val duration = 5 * 60L + val vmImageA = SimWorkloadImage( + UUID.randomUUID(), + "<unnamed>", + emptyMap(), + SimTraceWorkload( + sequenceOf( + SimTraceWorkload.Fragment(0, 28L * duration, duration * 1000, 28.0, 2), + SimTraceWorkload.Fragment(0, 3500L * duration, duration * 1000, 3500.0, 2), + SimTraceWorkload.Fragment(0, 0, duration * 1000, 0.0, 2), + SimTraceWorkload.Fragment(0, 183L * duration, duration * 1000, 183.0, 2) + ), + ) + ) + val vmImageB = SimWorkloadImage( + UUID.randomUUID(), + "<unnamed>", + emptyMap(), + SimTraceWorkload( + sequenceOf( + SimTraceWorkload.Fragment(0, 28L * duration, duration * 1000, 28.0, 2), + SimTraceWorkload.Fragment(0, 3100L * duration, duration * 1000, 3100.0, 2), + SimTraceWorkload.Fragment(0, 0, duration * 1000, 0.0, 2), + SimTraceWorkload.Fragment(0, 73L * duration, duration * 1000, 73.0, 2) + ) + ), + ) + + val metalDriver = + SimBareMetalDriver(this, clock, UUID.randomUUID(), "test", emptyMap(), machineModel) + + metalDriver.init() + metalDriver.setImage(vmm) + metalDriver.start() + + delay(5) + + val flavor = Flavor(2, 0) + val vmDriver = virtDriverWorkload.driver + vmDriver.events + .onEach { event -> + when (event) { + is HypervisorEvent.SliceFinished -> { + requestedBurst += event.requestedBurst + grantedBurst += event.grantedBurst + overcommissionedBurst += event.overcommissionedBurst + } + } + } + .launchIn(this) + + vmDriver.spawn("a", vmImageA, flavor) + vmDriver.spawn("b", vmImageB, flavor) + } + + scope.advanceUntilIdle() + + assertAll( + { assertEquals(emptyList<Throwable>(), scope.uncaughtExceptions, "No errors") }, + { assertEquals(2073600, requestedBurst, "Requested Burst does not match") }, + { assertEquals(2013600, grantedBurst, "Granted Burst does not match") }, + { assertEquals(60000, overcommissionedBurst, "Overcommissioned Burst does not match") }, + { assertEquals(1200007, scope.currentTime) } + ) + } +} |
