-
Notifications
You must be signed in to change notification settings - Fork 7
/
test_ufarray.py
75 lines (49 loc) · 1.88 KB
/
test_ufarray.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from z3 import *
import unittest
from yggdrasil.util import *
from yggdrasil.ufarray import *
from yggdrasil import test
def StoreIn(arr, bid, off, field):
i = arr[bid]
i = Store(i, off, field)
return Store(arr, bid, i)
def UpdateIn(arr, bid, off, field):
block = arr(bid)
block[off] = field
return arr.update(bid, block)
class ArrayTest(test.DiskTest):
def setUp(self):
pass
# Update a whole fresh block
def test_array_update(self):
spec = Array('spec', BitVecSort(64), ArraySort(BitVecSort(9), BitVecSort(64)))
impl = FreshDiskArray('impl')
bid = BitVec('bid', 64)
off = BitVec('off', 9)
bid0 = BitVec('bid0', 64)
dataimpl = FreshBlock('blockimpl')
dataspec = Array('dataspec', BitVecSort(9), BitVecSort(64))
dataoff = BitVec('off0', 9)
pre = And(
ForAll([dataoff], dataimpl[dataoff] == dataspec[dataoff]),
ForAll([bid, off], spec[bid][off] == impl(bid)[off]))
impl = impl.update(bid0, dataimpl)
spec = Store(spec, bid0, dataspec)
post = ForAll([bid, off], spec[bid][off] == impl(bid)[off])
self.prove(Implies(pre, post))
# Update a field within a block, write block back
def test_block_update(self):
spec = Array('spec', BitVecSort(64), ArraySort(BitVecSort(9), BitVecSort(64)))
impl = FreshDiskArray('impl')
bid = BitVec('bid', 64)
off = BitVec('off', 9)
bid0 = BitVec('bid0', 64)
off0 = BitVec('off0', 9)
field0 = BitVec('field', 64)
pre = ForAll([bid, off], spec[bid][off] == impl(bid)[off])
spec = StoreIn(spec, bid0, off0, field0)
impl = UpdateIn(impl, bid0, off0, field0)
post = ForAll([bid, off], spec[bid][off] == impl(bid)[off])
self.prove(Implies(pre, post))
if __name__ == '__main__':
test.main()