@@ -13,12 +13,14 @@ import org.usvm.UComponents
1313import org.usvm.UContext
1414import org.usvm.UHeapRef
1515import org.usvm.collection.array.UAllocatedArrayId
16+ import org.usvm.collection.array.UInputArrayId
1617import org.usvm.regions.SetRegion
1718import org.usvm.regions.emptyRegionTree
19+ import kotlin.random.Random
1820import kotlin.test.assertNotNull
1921import kotlin.test.assertTrue
2022
21- class MemoryRegionTests {
23+ class MemoryRegionTest {
2224 private lateinit var ctx: UContext
2325
2426 @BeforeEach
@@ -107,4 +109,40 @@ class MemoryRegionTests {
107109 assertTrue(updatesAfter.last().includesConcretely(idx2, trueExpr))
108110 }
109111
112+ /* *
113+ * Tests random writes and reads with array region to ensure there are no REs.
114+ */
115+ @Test
116+ fun testSymbolicWrites (): Unit = with (ctx) {
117+ val random = Random (42 )
118+ val range = 3
119+
120+ val concreteRefs = List (range) { mkConcreteHeapRef(it) }
121+ val symbolicRefs = List (range) { mkRegisterReading(it, addressSort) }
122+ val refs = concreteRefs + symbolicRefs
123+
124+ val concreteIndices = List (range) { mkSizeExpr(it) }
125+ val symbolicIndices = List (range) { mkRegisterReading(it, sizeSort) }
126+ val indices = concreteIndices + symbolicIndices
127+
128+ val testsCount = 100
129+ repeat(testsCount) {
130+ var memoryRegion = UInputArrayId (mockk<Type >(), addressSort)
131+ .emptyRegion()
132+
133+ val writesCount = 20
134+ repeat(writesCount) {
135+ val ref = symbolicRefs.random(random)
136+ val idx = indices.random(random)
137+ val value = refs.random(random)
138+
139+ memoryRegion = memoryRegion.write(ref to idx, value, trueExpr)
140+ }
141+
142+ val readRef = symbolicRefs.random(random)
143+ val readIdx = indices.random(random)
144+
145+ memoryRegion.read(readRef to readIdx)
146+ }
147+ }
110148}
0 commit comments