-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathtc_labeling.rb
295 lines (251 loc) · 5.16 KB
/
tc_labeling.rb
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
require './test_common'
require 'bud/labeling/labeling'
module TestState
state do
interface input, :i1
interface input, :i2
channel :c1
channel :c2
table :guard1
table :guard2
interface output, :response
end
end
module TestBasic
include TestState
bloom do
c1 <~ i1
c2 <~ i2
guard1 <= c1
guard2 <= c2
end
end
module TestNM
include TestBasic
bloom do
response <= guard1.notin(guard2, :val => :val)
end
end
module TestGroup
include TestBasic
bloom do
response <= guard1.group([:val], count)
end
end
module TestMono
include TestBasic
bloom do
response <= (guard1 * guard2).lefts(:val => :val)
end
end
module TestDeletion
include TestMono
state do
interface input, :dguard
channel :c3
end
bloom do
c3 <~ dguard
guard2 <- (guard2 * c3).lefts(:val => :val)
end
end
module TestNestMod
import TestNM => :tnm
state do
interface input, :inn1
interface input, :inn2
interface output, :outt
end
bloom do
tnm.i1 <= inn1
tnm.i2 <= inn2
outt <= tnm.response
end
end
# ``unguarded asynchrony'' is a hidden source of nondeterminism in otherwise
# monotonic bloom programs.
module JoinProto
state do
interface input, :ileft
interface input, :iright
interface output, :result
end
end
module Buffers
include JoinProto
state do
scratch :ls
scratch :rs
table :lt
table :rt
channel :lchan
channel :rchan
end
bloom do
ileft <= lchan
iright <= rchan
ls <= ileft
rs <= iright
lt <= ileft
rt <= iright
end
end
module BugButt
include Buffers
bloom do
result <= (ls * rs).lefts
end
end
module HalfGuard
include Buffers
bloom do
result <= (lt * rs).lefts
end
end
module FullGuard
include Buffers
bloom do
result <= (lt * rt).lefts
end
end
module BB
include Validate
include GuardedAsync
include Bud
end
class RolledUp
include BB
include TestNM
end
class RollupMono
include BB
include TestMono
end
class RollGroup
include BB
include TestGroup
end
class RollDels
include BB
include TestDeletion
end
class RollNest
include BB
include TestNestMod
end
module BBG
include BB
state do
interface input, :ul
interface input, :ur
end
bloom do
lchan <~ ul
rchan <~ ur
end
end
class RollHG
include BBG
include HalfGuard
end
class TestBlazes < Minitest::Test
def test_label1
r = RolledUp.new
r.tick
report = r.validate
assert(report.map{|r| r.to_a.last}.include?(["D"]), "flow not reported as divergent : #{report}")
end
def test_label2
r = RollGroup.new
r.tick
report = r.validate
assert(report.map{|r| r.to_a.last}.include?(["D"]), "flow not reported as divergent")
end
def test_mono
r = RollupMono.new
r.tick
report = r.validate
assert(!report.map{|r| r.to_a.last}.include?(["D"]), "flow not reported as confluent: #{report}")
end
def test_deletion
r = RollDels.new
r.tick
report = r.validate
reps = report.map{|r| [r[0], r[1], r.last]}
assert(reps.include?(["dguard", "response", ["D"]]), "deletion path not marked D")
assert(reps.include?(["i2", "response", ["D"]]), "main path not marked D #{reps}")
end
def test_nesting
r = RollNest.new
r.tick
report = r.validate
assert(report.map{|r| r.to_a.last}.include?(["D"]), "flow not reported as divergent : #{report}")
end
def test_unguarded
h = RollHG.new
h.tick
report = h.validate
assert(report.map{|r| r.to_a.last}.include?(["D"]), "flow not reported as divergent : #{report}")
end
def test_labeler1
l = Label.new("TestNM")
assert_equal({"response" => "D"}, l.output_report)
assert_equal({"response" => {"i1" => "A", "i2" => "D"}}, l.path_report)
end
def test_labeler2
l = Label.new("TestGroup")
assert_equal({"response" => "D"}, l.output_report)
assert_equal({"response" => {"i1" => "D"}}, l.path_report)
end
def test_labeler3
l = Label.new("TestMono")
assert_equal({"response" => "A"}, l.output_report)
assert_equal({"response" => {"i1" => "A", "i2" => "A"}}, l.path_report)
end
end
# Tests covering just the GA part
module Extry
include Bud
include GuardedAsync
state do
table :rem_race, channel_race.schema
end
bloom do
rem_race <= channel_race
end
end
class BugC
include Extry
include BugButt
end
class HalfGuardC
include Extry
include HalfGuard
end
class FullGuardC
include Extry
include FullGuard
end
class TestBlazes < Minitest::Test
def test_bug
c = BugC.new
c.tick
assert_equal([["rchan", "lchan", "result", false],
["lchan", "rchan", "result", false]].to_set,
c.rem_race.map{|r| r.to_a}.to_set)
end
def test_hg
c = HalfGuardC.new
c.tick
assert_equal([["rchan", "lchan", "result", false],
["lchan", "rchan", "result", false]].to_set,
c.rem_race.map{|r| r.to_a}.to_set)
end
def test_full
c = FullGuardC.new
c.tick
assert_equal([["rchan", "lchan", "result", true],
["lchan", "rchan", "result", true]].to_set,
c.rem_race.map{|r| r.to_a}.to_set)
end
end