Skip to content

Commit

Permalink
Improve some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DLochmelis33 committed Sep 4, 2024
1 parent 388f2e9 commit 546d06c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
22 changes: 16 additions & 6 deletions core/src/nativeTest/kotlin/org/jetbrains/litmuskt/BarrierTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import platform.posix.sleep
import kotlin.concurrent.Volatile
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotEquals

class BarrierTest {

Expand All @@ -17,23 +16,34 @@ class BarrierTest {
class Context(
val barrier: Barrier,
var x: Int = 0,
var y: Int = 0,
@Volatile
var flush: Int = 0 // ensure that changes are visible
)

val ctx = Context(barrierProducer(2))

val f1 = t1.start(ctx) {
it.barrier.await()
it.barrier.await() // sync #1
it.x = 1
it.flush = it.x + 1
it.flush++

sleep(2u)
assertEquals(0, it.y) // thread 2 is waiting
it.barrier.await() // sync #2
sleep(1u)
assertEquals(1, it.y) // thread 2 has continued
}
val f2 = t2.start(ctx) {
sleep(1u)
assertNotEquals(1, it.x)
it.barrier.await()
assertEquals(0, it.x) // thread 1 is waiting
it.barrier.await() // sync #1
sleep(1u)
assertEquals(1, it.x)
assertEquals(1, it.x) // thread 1 has continued

it.barrier.await() // sync #2
it.y = 1
it.flush++
}

f1.await()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.jetbrains.litmuskt

import org.jetbrains.litmuskt.autooutcomes.LitmusIIOutcome
import org.jetbrains.litmuskt.autooutcomes.accept
import org.jetbrains.litmuskt.autooutcomes.interesting
import org.jetbrains.litmuskt.barriers.CinteropSpinBarrier
import kotlin.test.Test
import kotlin.test.assertNotEquals
Expand All @@ -26,11 +25,7 @@ class IntegrationTest {
spec {
accept(0, 2)
accept(1, 2)
interesting(0, 1)
interesting(1, 1)

interesting(0, 0)
interesting(1, 0)
accept(0, 1) // r1 = 0; x = 2; x = 1 (t1); r2 = 1
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jetbrains.litmuskt

import platform.posix.sleep
import kotlin.test.Test
import kotlin.test.assertEquals

Expand All @@ -8,12 +9,14 @@ class ThreadlikeTest {
private fun testThreadlike(t: Threadlike) {
class IntHolder(var x: Int)

val holder = IntHolder(5)
val holder = IntHolder(0)
val future = t.start(holder) {
it.x = 7
sleep(1u)
it.x = 1
}
assertEquals(0, holder.x) // checking parallelism
future.await()
assertEquals(7, holder.x)
assertEquals(1, holder.x)
}

@Test
Expand Down

0 comments on commit 546d06c

Please sign in to comment.