summaryrefslogtreecommitdiff
path: root/simulator/opendc-compute/src/test
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2020-10-03 17:41:59 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2020-10-04 16:35:21 +0200
commit136c1b9ddc7bd9331d3552d681e9190fc6198271 (patch)
tree19a04e730d93969542f726084444b9e7f13a7b8d /simulator/opendc-compute/src/test
parentc8567a567348e13c341bf1a1ec64ed34ce25815a (diff)
Migrate codebase to opendc-simulator-compute
This change updates the remainder of the codebase to use the opendc-simulator-compute module for the simulation of workloads.
Diffstat (limited to 'simulator/opendc-compute/src/test')
-rw-r--r--simulator/opendc-compute/src/test/kotlin/org/opendc/compute/core/image/FlopsApplicationImageTest.kt76
-rw-r--r--simulator/opendc-compute/src/test/kotlin/org/opendc/compute/metal/driver/SimpleBareMetalDriverTest.kt81
-rw-r--r--simulator/opendc-compute/src/test/kotlin/org/opendc/compute/virt/HypervisorTest.kt167
3 files changed, 0 insertions, 324 deletions
diff --git a/simulator/opendc-compute/src/test/kotlin/org/opendc/compute/core/image/FlopsApplicationImageTest.kt b/simulator/opendc-compute/src/test/kotlin/org/opendc/compute/core/image/FlopsApplicationImageTest.kt
deleted file mode 100644
index 8870f138..00000000
--- a/simulator/opendc-compute/src/test/kotlin/org/opendc/compute/core/image/FlopsApplicationImageTest.kt
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * 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.core.image
-
-import org.junit.jupiter.api.DisplayName
-import org.junit.jupiter.api.Test
-import org.junit.jupiter.api.assertThrows
-import java.util.UUID
-
-/**
- * Test suite for [FlopsApplicationImage]
- */
-@DisplayName("FlopsApplicationImage")
-internal class FlopsApplicationImageTest {
- @Test
- fun `flops must be non-negative`() {
- assertThrows<IllegalArgumentException>("FLOPs must be non-negative") {
- FlopsApplicationImage(UUID.randomUUID(), "<unnamed>", emptyMap(), -1, 1)
- }
- }
-
- @Test
- fun `cores cannot be zero`() {
- assertThrows<IllegalArgumentException>("Cores cannot be zero") {
- FlopsApplicationImage(UUID.randomUUID(), "<unnamed>", emptyMap(), 1, 0)
- }
- }
-
- @Test
- fun `cores cannot be negative`() {
- assertThrows<IllegalArgumentException>("Cores cannot be negative") {
- FlopsApplicationImage(UUID.randomUUID(), "<unnamed>", emptyMap(), 1, -1)
- }
- }
-
- @Test
- fun `utilization cannot be zero`() {
- assertThrows<IllegalArgumentException>("Utilization cannot be zero") {
- FlopsApplicationImage(UUID.randomUUID(), "<unnamed>", emptyMap(), 1, 1, 0.0)
- }
- }
-
- @Test
- fun `utilization cannot be negative`() {
- assertThrows<IllegalArgumentException>("Utilization cannot be negative") {
- FlopsApplicationImage(UUID.randomUUID(), "<unnamed>", emptyMap(), 1, 1, -1.0)
- }
- }
-
- @Test
- fun `utilization cannot be larger than one`() {
- assertThrows<IllegalArgumentException>("Utilization cannot be larger than one") {
- FlopsApplicationImage(UUID.randomUUID(), "<unnamed>", emptyMap(), 1, 1, 2.0)
- }
- }
-}
diff --git a/simulator/opendc-compute/src/test/kotlin/org/opendc/compute/metal/driver/SimpleBareMetalDriverTest.kt b/simulator/opendc-compute/src/test/kotlin/org/opendc/compute/metal/driver/SimpleBareMetalDriverTest.kt
deleted file mode 100644
index 23c9408d..00000000
--- a/simulator/opendc-compute/src/test/kotlin/org/opendc/compute/metal/driver/SimpleBareMetalDriverTest.kt
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * 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.metal.driver
-
-import kotlinx.coroutines.ExperimentalCoroutinesApi
-import kotlinx.coroutines.flow.collect
-import kotlinx.coroutines.flow.launchIn
-import kotlinx.coroutines.flow.onEach
-import kotlinx.coroutines.launch
-import kotlinx.coroutines.test.TestCoroutineScope
-import kotlinx.coroutines.withContext
-import org.junit.jupiter.api.Assertions.assertEquals
-import org.junit.jupiter.api.Test
-import org.opendc.compute.core.ProcessingNode
-import org.opendc.compute.core.ProcessingUnit
-import org.opendc.compute.core.ServerEvent
-import org.opendc.compute.core.ServerState
-import org.opendc.compute.core.image.FlopsApplicationImage
-import org.opendc.simulator.utils.DelayControllerClockAdapter
-import java.util.UUID
-
-@OptIn(ExperimentalCoroutinesApi::class)
-internal class SimpleBareMetalDriverTest {
- /**
- * A smoke test for the bare-metal driver.
- */
- @Test
- fun smoke() {
- val testScope = TestCoroutineScope()
- val clock = DelayControllerClockAdapter(testScope)
-
- var finalState: ServerState = ServerState.BUILD
- testScope.launch {
- val cpuNode = ProcessingNode("Intel", "Xeon", "amd64", 4)
- val cpus = List(4) { ProcessingUnit(cpuNode, it, 2000.0) }
- val driver = SimpleBareMetalDriver(this, clock, UUID.randomUUID(), "test", emptyMap(), cpus, emptyList())
- val image = FlopsApplicationImage(UUID.randomUUID(), "<unnamed>", emptyMap(), 4_000, 2, utilization = 1.0)
-
- // Batch driver commands
- withContext(coroutineContext) {
- driver.init()
- driver.setImage(image)
- val server = driver.start().server!!
- driver.usage
- .onEach { println("${clock.millis()} $it") }
- .launchIn(this)
- server.events.collect { event ->
- when (event) {
- is ServerEvent.StateChanged -> {
- println("${clock.millis()} $event")
- finalState = event.server.state
- }
- }
- }
- }
- }
-
- testScope.advanceUntilIdle()
- assertEquals(ServerState.SHUTOFF, finalState)
- }
-}
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
deleted file mode 100644
index 82a82044..00000000
--- a/simulator/opendc-compute/src/test/kotlin/org/opendc/compute/virt/HypervisorTest.kt
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * 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.Test
-import org.junit.jupiter.api.assertAll
-import org.opendc.compute.core.Flavor
-import org.opendc.compute.core.ProcessingNode
-import org.opendc.compute.core.ProcessingUnit
-import org.opendc.compute.core.image.FlopsApplicationImage
-import org.opendc.compute.core.image.FlopsHistoryFragment
-import org.opendc.compute.core.image.VmImage
-import org.opendc.compute.metal.driver.SimpleBareMetalDriver
-import org.opendc.compute.virt.driver.VirtDriver
-import org.opendc.simulator.utils.DelayControllerClockAdapter
-import java.util.UUID
-
-/**
- * Basic test-suite for the hypervisor.
- */
-@OptIn(ExperimentalCoroutinesApi::class)
-internal class HypervisorTest {
- /**
- * A smoke test for the bare-metal driver.
- */
- @OptIn(ExperimentalCoroutinesApi::class)
- @Test
- fun smoke() {
- val testScope = TestCoroutineScope()
- val clock = DelayControllerClockAdapter(testScope)
-
- testScope.launch {
- val vmm = HypervisorImage
- val workloadA = FlopsApplicationImage(UUID.randomUUID(), "<unnamed>", emptyMap(), 1_000, 1)
- val workloadB = FlopsApplicationImage(UUID.randomUUID(), "<unnamed>", emptyMap(), 2_000, 1)
-
- val cpuNode = ProcessingNode("Intel", "Xeon", "amd64", 1)
- val cpus = List(1) { ProcessingUnit(cpuNode, it, 2000.0) }
- val metalDriver =
- SimpleBareMetalDriver(this, clock, UUID.randomUUID(), "test", emptyMap(), cpus, emptyList())
-
- metalDriver.init()
- metalDriver.setImage(vmm)
- val node = metalDriver.start()
- node.server?.events?.onEach { println(it) }?.launchIn(this)
-
- delay(5)
-
- 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)
- vmA.events.onEach { println(it) }.launchIn(this)
- val vmB = vmDriver.spawn("b", workloadB, flavor)
- vmB.events.onEach { println(it) }.launchIn(this)
- }
-
- testScope.advanceUntilIdle()
- }
-
- /**
- * Test overcommissioning of a hypervisor.
- */
- @Test
- fun overcommission() {
- val testScope = TestCoroutineScope()
- val clock = DelayControllerClockAdapter(testScope)
-
- var requestedBurst = 0L
- var grantedBurst = 0L
- var overcommissionedBurst = 0L
-
- testScope.launch {
- val vmm = HypervisorImage
- val duration = 5 * 60L
- val vmImageA = VmImage(
- UUID.randomUUID(),
- "<unnamed>",
- emptyMap(),
- sequenceOf(
- FlopsHistoryFragment(0, 28L * duration, duration * 1000, 28.0, 2),
- FlopsHistoryFragment(0, 3500L * duration, duration * 1000, 3500.0, 2),
- FlopsHistoryFragment(0, 0, duration * 1000, 0.0, 2),
- FlopsHistoryFragment(0, 183L * duration, duration * 1000, 183.0, 2)
- ),
- 2,
- 0
- )
- val vmImageB = VmImage(
- UUID.randomUUID(),
- "<unnamed>",
- emptyMap(),
- sequenceOf(
- FlopsHistoryFragment(0, 28L * duration, duration * 1000, 28.0, 2),
- FlopsHistoryFragment(0, 3100L * duration, duration * 1000, 3100.0, 2),
- FlopsHistoryFragment(0, 0, duration * 1000, 0.0, 2),
- FlopsHistoryFragment(0, 73L * duration, duration * 1000, 73.0, 2)
- ),
- 2,
- 0
- )
-
- val cpuNode = ProcessingNode("Intel", "Xeon", "amd64", 2)
- val cpus = List(2) { ProcessingUnit(cpuNode, it, 3200.0) }
- val metalDriver =
- SimpleBareMetalDriver(this, clock, UUID.randomUUID(), "test", emptyMap(), cpus, emptyList())
-
- metalDriver.init()
- metalDriver.setImage(vmm)
- metalDriver.start()
-
- delay(5)
-
- val flavor = Flavor(2, 0)
- val vmDriver = metalDriver.refresh().server!!.services[VirtDriver]
- 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)
- }
-
- testScope.advanceUntilIdle()
-
- assertAll(
- { assertEquals(2073600, requestedBurst, "Requested Burst does not match") },
- { assertEquals(2013600, grantedBurst, "Granted Burst does not match") },
- { assertEquals(60000, overcommissionedBurst, "Overcommissioned Burst does not match") }
- )
- }
-}