summaryrefslogtreecommitdiff
path: root/opendc/opendc-compute/src/test
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2020-02-26 12:25:01 +0100
committerGeorgios Andreadis <g.andreadis@student.tudelft.nl>2020-02-26 12:25:01 +0100
commitc66f5c4081b3d8b4fe79e46375dcab6000341dbc (patch)
treee86badfe17039646e20719afeb5278db6bf388f2 /opendc/opendc-compute/src/test
parent6f1162730d548baa12c9d594a94c4523d7e51889 (diff)
Improve design of workload modelling
Diffstat (limited to 'opendc/opendc-compute/src/test')
-rw-r--r--opendc/opendc-compute/src/test/kotlin/com/atlarge/opendc/compute/core/image/FlopsApplicationImageTest.kt78
-rw-r--r--opendc/opendc-compute/src/test/kotlin/com/atlarge/opendc/compute/virt/driver/hypervisor/HypervisorTest.kt92
2 files changed, 170 insertions, 0 deletions
diff --git a/opendc/opendc-compute/src/test/kotlin/com/atlarge/opendc/compute/core/image/FlopsApplicationImageTest.kt b/opendc/opendc-compute/src/test/kotlin/com/atlarge/opendc/compute/core/image/FlopsApplicationImageTest.kt
new file mode 100644
index 00000000..417db77d
--- /dev/null
+++ b/opendc/opendc-compute/src/test/kotlin/com/atlarge/opendc/compute/core/image/FlopsApplicationImageTest.kt
@@ -0,0 +1,78 @@
+/*
+ * MIT License
+ *
+ * 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 com.atlarge.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/opendc/opendc-compute/src/test/kotlin/com/atlarge/opendc/compute/virt/driver/hypervisor/HypervisorTest.kt b/opendc/opendc-compute/src/test/kotlin/com/atlarge/opendc/compute/virt/driver/hypervisor/HypervisorTest.kt
new file mode 100644
index 00000000..ce0ed10d
--- /dev/null
+++ b/opendc/opendc-compute/src/test/kotlin/com/atlarge/opendc/compute/virt/driver/hypervisor/HypervisorTest.kt
@@ -0,0 +1,92 @@
+/*
+ * MIT License
+ *
+ * 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 com.atlarge.opendc.compute.virt.driver.hypervisor
+
+import com.atlarge.odcsim.SimulationEngineProvider
+import com.atlarge.odcsim.processContext
+import com.atlarge.opendc.compute.core.ProcessingUnit
+import com.atlarge.opendc.compute.core.Server
+import com.atlarge.opendc.compute.core.ServerFlavor
+import com.atlarge.opendc.compute.core.ServerState
+import com.atlarge.opendc.compute.core.image.FlopsApplicationImage
+import com.atlarge.opendc.compute.core.monitor.ServerMonitor
+import com.atlarge.opendc.compute.metal.PowerState
+import com.atlarge.opendc.compute.metal.driver.SimpleBareMetalDriver
+import com.atlarge.opendc.compute.virt.driver.VirtDriver
+import com.atlarge.opendc.compute.virt.monitor.HypervisorMonitor
+import kotlinx.coroutines.delay
+import kotlinx.coroutines.runBlocking
+import org.junit.jupiter.api.Test
+import java.util.ServiceLoader
+import java.util.UUID
+
+/**
+ * Basic test-suite for the hypervisor.
+ */
+internal class HypervisorTest {
+ /**
+ * A smoke test for the bare-metal driver.
+ */
+ @Test
+ fun smoke() {
+ val provider = ServiceLoader.load(SimulationEngineProvider::class.java).first()
+ val system = provider({ _ ->
+ val metalFlavor = ServerFlavor(listOf(ProcessingUnit("Intel", "Xeon", "amd64", 2000.0, 1)))
+ val vmm = HypervisorImage(object : HypervisorMonitor {
+ override fun onSliceFinish(
+ time: Long,
+ totalRequestedBurst: Long,
+ totalGrantedBurst: Long,
+ numberOfDeployedImages: Int,
+ hostServer: Server
+ ) {
+ println("Hello World!")
+ }
+ })
+ val workloadA = FlopsApplicationImage(UUID.randomUUID(), "<unnamed>", emptyMap(), 1_000_000, 1)
+ val workloadB = FlopsApplicationImage(UUID.randomUUID(), "<unnamed>", emptyMap(), 2_000_000, 1)
+ val monitor = object : ServerMonitor {
+ override suspend fun onUpdate(server: Server, previousState: ServerState) {
+ println("[${processContext.clock.millis()}]: $server")
+ }
+ }
+ val metalDriver = SimpleBareMetalDriver(UUID.randomUUID(), "test", metalFlavor)
+
+ metalDriver.init(monitor)
+ metalDriver.setImage(vmm)
+ metalDriver.setPower(PowerState.POWER_ON)
+ delay(5)
+
+ val vmDriver = metalDriver.refresh().server!!.serviceRegistry[VirtDriver]
+ vmDriver.spawn(workloadA, monitor, metalFlavor)
+ vmDriver.spawn(workloadB, monitor, metalFlavor)
+ }, name = "sim")
+
+ runBlocking {
+ system.run()
+ system.terminate()
+ }
+ }
+}