-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest_cp.py
171 lines (121 loc) · 4.93 KB
/
test_cp.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
from disk import *
from yggdrasil.util import *
from yggdrasil.diskspec import *
from yggdrasil import test
class CPSpec(object):
def __init__(self, ds):
self._ds = ds
def cp(self, sparent, sname, dparent, dname):
# sparent/sname exists
assertion(self._ds._direxists(sparent, sname))
# dparent/dname does not exist
assertion(Not(self._ds._direxists(dparent, dname)))
# source inode
sino = self._ds._dirfn(sparent, sname)
assertion(self._ds.is_regular(sino))
# destination inode
dino = self._ds.ialloc(True)
debug('sino', sino)
debug('sino valid?', self._ds.is_valid(sino))
debug('sino-mode', self._ds._attrs.mode(sino))
# Set attributes for new inode
self._ds._attrs.set_bsize(dino, 0)
self._ds._attrs.set_mtime(dino, 0) #self._ds._attrs.mtime(sino))
self._ds._attrs.set_mode(dino, 0) #self._ds._attrs.mode(sino))
#
# # associate parent x name -> ino
self._ds._dirfn = self._ds._dirfn.update((dparent, dname), dino)
self._ds._direxists = self._ds._direxists.update((dparent, dname), BoolVal(True))
# self.write(dino, 0, 0, self._datafn(sino, 0, 0))
return dino
class CPImpl(object):
def __init__(self, di):
self._di = di
def cp(self, sparent, sname, dparent, dname):
# sparent/sname exists
assertion(self._di._direxists(sparent, sname))
# dparent/dname does not exist
assertion(Not(self._di._direxists(dparent, dname)))
sino = self._di.lookup(sparent, sname)
if sino == 0:
return sino
assertion(self._di.is_regular(sino))
sattr = self._di.get_iattr(sino)
dino = self._di.mknod(dparent, dname, 0, 0) #, sattr.mode, sattr.mtime)
if dino < 0:
return dino
fsize = self._di.get_iattr(sino).bsize
if fsize == 0:
return dino
else:
assertion(False)
return dino
# dat = self.read(sino, 0, 0)
#
# b = ConstBlock(0)
# b[0] = dat
# self.write(dino, 0, 0, b)
class CPRefinement(test.RefinementTest):
def _create_dir(self, mach):
dirfn = FreshUFunction('dirfn', InoSort, NameSort, InoSort)
direxists = FreshUFunction('direxists', InoSort, NameSort, BoolSort())
datafn = FreshUFunction('datafn', InoSort, BitVecSort(32), BlockOffsetSort, SizeSort)
ifree = FreshUFunction('ifreefn', InoSort, BoolSort())
attrs = FreshAttributes()
return DirSpec(mach, dirfn, direxists, datafn, ifree, attrs)
def create_spec(self, mach):
dspec = self._create_dir(mach)
return dspec, CPSpec(dspec)
def create_impl(self, mach):
dspec = self._create_dir(mach)
return dspec, CPImpl(dspec)
def test_cp(self):
spec_mach = Machine()
spec, cp_spec = self.create_spec(spec_mach)
impl_mach = Machine()
impl, cp_impl = self.create_impl(impl_mach)
##
ino = FreshIno('ino-pre')
blocknum = FreshBitVec('blocknum-pre', 32)
off = FreshBitVec('off-pre', BlockOffsetSort.size())
pre = ForAll([ino], And(
spec.is_valid(ino) == impl.is_valid(ino),
# General inode properties
Implies(spec.is_valid(ino), And(
spec.get_iattr(ino) == impl.get_iattr(ino))),
# Non-directory properties
Implies(Not(spec.is_dir(ino)), And(
spec.read(ino, blocknum, off) == impl.read(ino, blocknum, off),
)),
# Directory properties
Implies(spec.is_dir(ino), And(
# spec.lookup(ino, name) == impl.lookup(ino, name))),
))
))
self.show(And(*assertion.assertions), pre)
########################
sparent0 = FreshIno('sparent0')
sname0 = FreshName('sname0')
dparent0 = FreshIno('dparent0')
dname0 = FreshName('dname0')
sino = cp_spec.cp(sparent0, sname0, dparent0, dname0)
iino = cp_impl.cp(sparent0, sname0, dparent0, dname0)
assertion(sino == iino)
#########################
ino = FreshIno('ino-post')
post = ForAll([ino], And(
spec.is_valid(ino) == impl.is_valid(ino),
# General inode properties
Implies(spec.is_valid(ino), And(
spec.get_iattr(ino) == impl.get_iattr(ino))),
Implies(Not(spec.is_dir(ino)), And(
spec.read(ino, blocknum, off) == impl.read(ino, blocknum, off),
)),
# Directory properties
Implies(spec.is_dir(ino), And(
# spec.lookup(ino, name) == impl.lookup(ino, name)
))
))
self.psolve(Not(Implies(pre, post)))
if __name__ == '__main__':
test.main()