1
1
package org.usvm.memory
2
2
3
+ import io.ksmt.expr.KBitVecValue
4
+ import io.ksmt.sort.KBv32Sort
3
5
import io.mockk.every
4
6
import io.mockk.mockk
5
7
import org.junit.jupiter.api.BeforeEach
6
8
import org.usvm.Type
9
+ import org.usvm.UBoolExpr
7
10
import org.usvm.UBv32SizeExprProvider
11
+ import org.usvm.UBv32Sort
8
12
import org.usvm.UComponents
9
13
import org.usvm.UContext
10
14
import org.usvm.UExpr
11
15
import org.usvm.UHeapRef
12
16
import org.usvm.USizeSort
17
+ import org.usvm.UTransformer
13
18
import org.usvm.api.refSetAddElement
14
19
import org.usvm.api.refSetRemoveElement
15
20
import org.usvm.api.setAddElement
16
21
import org.usvm.api.setRemoveElement
22
+ import org.usvm.apply
23
+ import org.usvm.collection.set.primitive.USetEntryLValue
17
24
import org.usvm.collection.set.primitive.setEntries
18
25
import org.usvm.collection.set.primitive.setUnion
19
26
import org.usvm.collection.set.ref.refSetEntries
@@ -23,6 +30,7 @@ import org.usvm.constraints.UEqualityConstraints
23
30
import org.usvm.constraints.UTypeConstraints
24
31
import org.usvm.isTrue
25
32
import org.usvm.memory.key.USizeExprKeyInfo
33
+ import org.usvm.regions.SetRegion
26
34
import kotlin.test.Test
27
35
import kotlin.test.assertEquals
28
36
import kotlin.test.assertTrue
@@ -104,4 +112,58 @@ class SetEntriesTest {
104
112
val definitelyInSet = setEntries.entries.filter { heap.read(it).isTrue }.mapTo(hashSetOf()) { it.setElement }
105
113
assertEquals(expectedDefInSet, definitelyInSet)
106
114
}
115
+
116
+ private object SetBv32ElementInfo :
117
+ USymbolicCollectionKeyInfo <UExpr <UBv32Sort >, SetRegion <KBitVecValue <KBv32Sort >>> {
118
+ override fun mapKey (key : UExpr <UBv32Sort >, transformer : UTransformer <* , * >? ): UExpr <UBv32Sort > =
119
+ transformer.apply (key)
120
+
121
+ override fun eqSymbolic (ctx : UContext <* >, key1 : UExpr <UBv32Sort >, key2 : UExpr <UBv32Sort >): UBoolExpr =
122
+ ctx.mkEq(key1, key2)
123
+
124
+ override fun eqConcrete (key1 : UExpr <UBv32Sort >, key2 : UExpr <UBv32Sort >): Boolean =
125
+ key1 == key2
126
+
127
+ override fun keyToRegion (key : UExpr <UBv32Sort >): SetRegion <KBitVecValue <KBv32Sort >> =
128
+ if (key is KBitVecValue <UBv32Sort >) {
129
+ SetRegion .singleton(key)
130
+ } else {
131
+ SetRegion .universe()
132
+ }
133
+
134
+ override fun topRegion (): SetRegion <KBitVecValue <KBv32Sort >> = SetRegion .universe()
135
+ override fun bottomRegion (): SetRegion <KBitVecValue <KBv32Sort >> = SetRegion .empty()
136
+
137
+ override fun cmpSymbolicLe (ctx : UContext <* >, key1 : UExpr <UBv32Sort >, key2 : UExpr <UBv32Sort >) = error(" unused" )
138
+ override fun cmpConcreteLe (key1 : UExpr <UBv32Sort >, key2 : UExpr <UBv32Sort >) = error(" unused" )
139
+ override fun keyRangeRegion (from : UExpr <UBv32Sort >, to : UExpr <UBv32Sort >) = error(" unused" )
140
+ }
141
+
142
+ @Test
143
+ fun testSetUnion (): Unit = with (ctx) {
144
+ val maxElement = 100
145
+ val sets = List (maxElement + 1 ) { idx ->
146
+ val setRef = mkConcreteHeapRef(addressCounter.freshAllocatedAddress())
147
+ val setElement = mkBv(idx)
148
+ heap.setAddElement(setRef, setElement, setType, SetBv32ElementInfo , trueExpr)
149
+ setRef
150
+ }
151
+
152
+ sets.reduce { left, right ->
153
+ heap.setUnion(left, right, setType, bv32Sort, SetBv32ElementInfo , trueExpr)
154
+ right
155
+ }
156
+
157
+ val resultSet = sets.last()
158
+
159
+ for (i in 0 .. maxElement) {
160
+ val lvalue = USetEntryLValue (bv32Sort, resultSet, mkBv(i), setType, SetBv32ElementInfo )
161
+ val elementContains = heap.read(lvalue)
162
+ assertEquals(trueExpr, elementContains)
163
+ }
164
+
165
+ val lvalue = USetEntryLValue (bv32Sort, resultSet, mkBv(maxElement + 1 ), setType, SetBv32ElementInfo )
166
+ val elementContains = heap.read(lvalue)
167
+ assertEquals(falseExpr, elementContains)
168
+ }
107
169
}
0 commit comments