diff options
| author | Fabian Mastenbroek <fabianishere@outlook.com> | 2018-04-22 22:27:13 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-04-22 22:27:13 +0200 |
| commit | 07f245dcf4b01ade251d0f4bedc897d7145b04d1 (patch) | |
| tree | a7b4c49df918e812998074f3ff71b6ba1868d645 /opendc-kernel-omega/src/test | |
| parent | f691a72b12a43fa15c1617966450c55206664797 (diff) | |
| parent | 4ccf632ad4418114df0cd8460c7dd3a86c246f9d (diff) | |
feat(#12): Implement Instrumentation API
These changes contain the specification of the new Instrumentation API for the simulator, in addition to the implementation for the Omega kernel. As an example, the API allows users to measure data from processes in simulation and interpolate data points between the measurements.
Closes #11, #12
Diffstat (limited to 'opendc-kernel-omega/src/test')
| -rw-r--r-- | opendc-kernel-omega/src/test/kotlin/com/atlarge/opendc/omega/SmokeTest.kt | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/opendc-kernel-omega/src/test/kotlin/com/atlarge/opendc/omega/SmokeTest.kt b/opendc-kernel-omega/src/test/kotlin/com/atlarge/opendc/omega/SmokeTest.kt index c47f9a26..74d6e2de 100644 --- a/opendc-kernel-omega/src/test/kotlin/com/atlarge/opendc/omega/SmokeTest.kt +++ b/opendc-kernel-omega/src/test/kotlin/com/atlarge/opendc/omega/SmokeTest.kt @@ -27,8 +27,12 @@ package com.atlarge.opendc.omega import com.atlarge.opendc.simulator.Bootstrap import com.atlarge.opendc.simulator.Context import com.atlarge.opendc.simulator.Process +import com.atlarge.opendc.simulator.instrumentation.Instrument +import com.atlarge.opendc.simulator.kernel.Simulation +import kotlinx.coroutines.experimental.Unconfined +import kotlinx.coroutines.experimental.async +import kotlinx.coroutines.experimental.channels.consumeEach import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Test /** @@ -123,6 +127,7 @@ internal class SmokeTest { hold(10) } } + /** * Test if the kernel allows access to the simulation model object. */ @@ -135,9 +140,29 @@ internal class SmokeTest { value } - val simulation = OmegaKernel.create(bootstrap) - simulation.run(5) + val kernel = OmegaKernel.create(bootstrap) + kernel.run(5) + } + + + @Test + fun `instrumentation works`() { + val instrument: Instrument<Int, Unit> = { + var value = 0 - assertTrue(simulation.run { process.state }) + for (i in 1..10) { + send(value) + value += 10 + hold(20) + } + } + + val simulation: Simulation<Unit> = OmegaKernel.create(Bootstrap.create { Unit }) + val stream = simulation.openPort().install(instrument) + + val res = async(Unconfined) { + stream.consumeEach { println(it) } + } + simulation.run(100) } } |
