diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2018-02-14 12:12:57 +0100 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2018-02-23 12:20:30 +0100 |
| commit | 699338a4e7b226ae7acf0f4aef1b0b28d90eb5b3 (patch) | |
| tree | fbebd90aebd1863f6bcbe4ccbb790c6c7559c91e /opendc-kernel-omega/src/test | |
| parent | a64ae13a6c5aef435e048b13bb3d7bad449f783b (diff) | |
feat(#12): Implement Instrumentation API in Omega kernel
These changes implement the Instrumentation API described in issue #11
into the Omega simulation kernel.
Diffstat (limited to 'opendc-kernel-omega/src/test')
| -rw-r--r-- | opendc-kernel-omega/src/test/kotlin/com/atlarge/opendc/omega/SmokeTest.kt | 35 |
1 files changed, 31 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..42ca05ec 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,13 @@ 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.Kernel +import com.atlarge.opendc.simulator.kernel.Simulation +import kotlinx.coroutines.experimental.Unconfined +import kotlinx.coroutines.experimental.async +import kotlinx.coroutines.experimental.channels.* import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Test /** @@ -123,6 +128,7 @@ internal class SmokeTest { hold(10) } } + /** * Test if the kernel allows access to the simulation model object. */ @@ -135,9 +141,30 @@ 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 + + for (i in 1..10) { + send(value) + value += 10 + hold(20) + } + } + + val simulation: Simulation<Unit> = OmegaKernel.create(Bootstrap.create { Unit }) + val stream = simulation.install(instrument) + + val res = async(Unconfined) { + stream.consumeEach { println(it) } + } - assertTrue(simulation.run { process.state }) + simulation.run(100) } } |
