atp 0.8.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,21 +11,21 @@ module ATP
11
11
  failed = false
12
12
  @referenced_ids.each do |id, nodes|
13
13
  unless @present_ids[id]
14
- Origen.log.error "Test ID #{id} is referenced in flow #{flow.name} in the following lines, but it is never defined:"
14
+ error "Test ID #{id} is referenced in flow #{flow.name} in the following lines, but it is never defined:"
15
15
  nodes.each do |node|
16
- Origen.log.error " #{node.source}"
16
+ error " #{node.source}"
17
17
  end
18
18
  failed = true
19
19
  @referenced_early.delete(id)
20
20
  end
21
21
  end
22
22
  @referenced_early.each do |id, nodes|
23
- Origen.log.error "Test ID #{id} is referenced in flow #{flow.name} in the following line(s):"
23
+ error "Test ID #{id} is referenced in flow #{flow.name} in the following line(s):"
24
24
  nodes.each do |node|
25
- Origen.log.error " #{node.source}"
25
+ error " #{node.source}"
26
26
  end
27
- Origen.log.error 'but it was not defined until later:'
28
- Origen.log.error " #{@present_ids[id].first.source}"
27
+ error 'but it was not defined until later:'
28
+ error " #{@present_ids[id].first.source}"
29
29
  failed = true
30
30
  end
31
31
  failed
@@ -37,7 +37,7 @@ module ATP
37
37
  @present_ids[id] << node
38
38
  end
39
39
 
40
- def on_test_executed(node)
40
+ def on_if_failed(node)
41
41
  ids = node.to_a[0]
42
42
  [ids].flatten.each do |id|
43
43
  unless id =~ /^extern/
@@ -51,7 +51,13 @@ module ATP
51
51
  end
52
52
  process_all(node)
53
53
  end
54
- alias_method :on_test_result, :on_test_executed
54
+ alias_method :on_if_any_failed, :on_if_failed
55
+ alias_method :on_if_all_failed, :on_if_failed
56
+ alias_method :on_if_passed, :on_if_failed
57
+ alias_method :on_if_any_passed, :on_if_failed
58
+ alias_method :on_if_all_passed, :on_if_failed
59
+ alias_method :on_if_ran, :on_if_failed
60
+ alias_method :on_unless_ran, :on_if_failed
55
61
  end
56
62
  end
57
63
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen McGinty
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-02 00:00:00.000000000 Z
11
+ date: 2017-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: origen
@@ -64,11 +64,10 @@ files:
64
64
  - config/commands.rb
65
65
  - config/version.rb
66
66
  - lib/atp.rb
67
- - lib/atp/ast/builder.rb
68
67
  - lib/atp/ast/extractor.rb
69
- - lib/atp/ast/factories.rb
70
68
  - lib/atp/ast/node.rb
71
69
  - lib/atp/flow.rb
70
+ - lib/atp/flow_api.rb
72
71
  - lib/atp/formatter.rb
73
72
  - lib/atp/formatters/basic.rb
74
73
  - lib/atp/formatters/datalog.rb
@@ -76,11 +75,22 @@ files:
76
75
  - lib/atp/processor.rb
77
76
  - lib/atp/processors/add_ids.rb
78
77
  - lib/atp/processors/add_set_result.rb
78
+ - lib/atp/processors/adjacent_if_combiner.rb
79
+ - lib/atp/processors/append_to.rb
80
+ - lib/atp/processors/apply_post_group_actions.rb
79
81
  - lib/atp/processors/condition.rb
82
+ - lib/atp/processors/continue_implementer.rb
83
+ - lib/atp/processors/else_remover.rb
84
+ - lib/atp/processors/empty_branch_remover.rb
85
+ - lib/atp/processors/extract_set_flags.rb
86
+ - lib/atp/processors/flag_optimizer.rb
87
+ - lib/atp/processors/flattener.rb
80
88
  - lib/atp/processors/flow_id.rb
81
89
  - lib/atp/processors/marshal.rb
82
- - lib/atp/processors/post_cleaner.rb
90
+ - lib/atp/processors/on_pass_fail_remover.rb
91
+ - lib/atp/processors/one_flag_per_test.rb
83
92
  - lib/atp/processors/pre_cleaner.rb
93
+ - lib/atp/processors/redundant_condition_remover.rb
84
94
  - lib/atp/processors/relationship.rb
85
95
  - lib/atp/program.rb
86
96
  - lib/atp/runner.rb
@@ -1,397 +0,0 @@
1
- module ATP
2
- module AST
3
- class Builder
4
- include Factories
5
-
6
- attr_reader :context
7
- attr_accessor :source_file, :source_line_number, :description
8
-
9
- def initialize
10
- @context = { conditions: [] }
11
- end
12
-
13
- def flow(str)
14
- n(:flow, name(str))
15
- end
16
-
17
- # Ensures the given flow ast has a volatile node, then adds the
18
- # given flags to it
19
- def add_volatile_flags(flow, flags)
20
- name, *nodes = *flow
21
- if nodes[0] && nodes[0].type == :volatile
22
- v = nodes.shift
23
- else
24
- v = n0(:volatile)
25
- end
26
- existing = v.children.map { |f| f.type == :flag ? f.value : nil }.compact
27
- new = []
28
- flags.each do |flag|
29
- new << n(:flag, flag) unless existing.include?(flag)
30
- end
31
- v = v.updated(nil, v.children + new)
32
- flow.updated(nil, [name, v] + nodes)
33
- end
34
-
35
- def name(str)
36
- n(:name, str.to_s)
37
- end
38
-
39
- def log(str, options = {})
40
- test = n(:log, str.to_s)
41
- if options[:conditions]
42
- apply_conditions(test, options[:conditions])
43
- else
44
- test
45
- end
46
- end
47
-
48
- def render(str, options = {})
49
- test = n(:render, str)
50
- if options[:conditions]
51
- apply_conditions(test, options[:conditions])
52
- else
53
- test
54
- end
55
- end
56
-
57
- def id(symbol)
58
- n(:id, symbol.to_sym)
59
- end
60
-
61
- def flow_flag(name, enabled, node)
62
- n(:flow_flag, name, enabled, node)
63
- end
64
-
65
- def test_result(id, passed, node)
66
- n(:test_result, id, passed, node)
67
- end
68
-
69
- def test_executed(id, executed, node)
70
- n(:test_executed, id, executed, node)
71
- end
72
-
73
- def job(id, enabled, node)
74
- n(:job, id, enabled, node)
75
- end
76
-
77
- def run_flag(id, enabled, node)
78
- n(:run_flag, id, enabled, node)
79
- end
80
-
81
- def set_run_flag(flag)
82
- n(:set_run_flag, flag)
83
- end
84
-
85
- def enable_flow_flag(var, options = {})
86
- test = n(:enable_flow_flag, var)
87
- if options[:conditions]
88
- apply_conditions(test, options[:conditions])
89
- else
90
- test
91
- end
92
- end
93
-
94
- def disable_flow_flag(var, options = {})
95
- test = n(:disable_flow_flag, var)
96
- if options[:conditions]
97
- apply_conditions(test, options[:conditions])
98
- else
99
- test
100
- end
101
- end
102
-
103
- def group(group_name, nodes, options = {})
104
- children = [name(group_name)]
105
-
106
- children << id(options[:id].to_s.downcase.to_sym) if options[:id]
107
-
108
- children << on_fail(options[:on_fail]) if options[:on_fail]
109
- children << on_pass(options[:on_pass]) if options[:on_pass]
110
-
111
- children += nodes
112
- group = n(:group, *children)
113
-
114
- if options[:conditions]
115
- apply_conditions(group, options[:conditions])
116
- else
117
- group
118
- end
119
- end
120
-
121
- def cz(setup, node, options = {})
122
- test = n(:cz, setup, node)
123
- if options[:conditions]
124
- apply_conditions(test, options[:conditions])
125
- else
126
- test
127
- end
128
- end
129
-
130
- def new_context
131
- @context = { conditions: [] }
132
- yield if block_given?
133
- @context
134
- end
135
-
136
- CONDITION_KEYS = [
137
- :if_enabled, :enabled, :enable_flag, :enable, :if_enable,
138
- :unless_enabled, :not_enabled, :disabled, :disable, :unless_enable,
139
- :if_failed, :unless_passed, :failed,
140
- :if_passed, :unless_failed, :passed,
141
- :if_ran, :if_executed,
142
- :unless_ran, :unless_executed,
143
- :job, :jobs, :if_job, :if_jobs,
144
- :unless_job, :unless_jobs,
145
- :if_any_failed, :unless_all_passed,
146
- :if_all_failed, :unless_any_passed,
147
- :if_any_passed, :unless_all_failed,
148
- :if_all_passed, :unless_any_failed,
149
- :if_flag, :unless_flag
150
- ]
151
-
152
- def apply_conditions(node, conditions)
153
- conditions.each do |key, value|
154
- # Sometimes conditions can be an array (in the case of the current context
155
- # being re-used), so rectify that now
156
- if key.is_a?(Hash)
157
- fail 'Something has gone wrong applying the test conditions' if key.size > 1
158
- key, value = key.first[0], key.first[1]
159
- end
160
- key = key.to_s.downcase.to_sym
161
- # Represent all condition values as lower cased strings internally
162
- if value.is_a?(Array)
163
- value = value.map { |v| (v[0] == '$') ? v.to_s : v.to_s.downcase }
164
- else
165
- value = (value[0] == '$') ? value.to_s : value.to_s.downcase
166
- end
167
- context[:conditions] << { key => value }
168
- case key
169
- when :if_enabled, :enabled, :enable_flag, :enable, :if_enable
170
- node = flow_flag(value, true, node)
171
- when :unless_enabled, :not_enabled, :disabled, :disable, :unless_enable
172
- node = flow_flag(value, false, node)
173
- when :if_failed, :unless_passed, :failed
174
- if value.is_a?(Array)
175
- fail 'if_failed only accepts one ID, use if_any_failed or if_all_failed for multiple IDs'
176
- end
177
- node = test_result(value, false, node)
178
- when :if_passed, :unless_failed, :passed
179
- if value.is_a?(Array)
180
- fail 'if_passed only accepts one ID, use if_any_passed or if_all_passed for multiple IDs'
181
- end
182
- node = test_result(value, true, node)
183
- when :if_any_failed, :unless_all_passed
184
- node = test_result(value, false, node)
185
- when :if_all_failed, :unless_any_passed
186
- node = value.reduce(nil) do |nodes, val|
187
- test_result(val, false, nodes ? nodes : node)
188
- end
189
- when :if_any_passed, :unless_all_failed
190
- node = test_result(value, true, node)
191
- when :if_all_passed, :unless_any_failed
192
- node = value.reduce(nil) do |nodes, val|
193
- test_result(val, true, nodes ? nodes : node)
194
- end
195
- when :if_ran, :if_executed
196
- node = test_executed(value, true, node)
197
- when :unless_ran, :unless_executed
198
- node = test_executed(value, false, node)
199
- when :job, :jobs, :if_job, :if_jobs
200
- node = job(value, true, node)
201
- when :unless_job, :unless_jobs
202
- node = job(value, false, node)
203
- when :if_flag
204
- if value.is_a?(Array)
205
- fail 'if_flag only accepts one flag'
206
- end
207
- node = run_flag(value, true, node)
208
- when :unless_flag
209
- if value.is_a?(Array)
210
- fail 'unless_flag only accepts one flag'
211
- end
212
- node = run_flag(value, false, node)
213
- else
214
- fail "Unknown test condition attribute - #{key} (#{value})"
215
- end
216
- end
217
- node
218
- end
219
-
220
- def test(object, options = {})
221
- children = [n(:object, object)]
222
-
223
- n = (options[:name] || options[:tname] || options[:test_name])
224
- unless n
225
- [:name, :tname, :test_name].each do |m|
226
- n ||= object.respond_to?(m) ? object.send(m) : nil
227
- end
228
- end
229
- children << name(n) if n
230
-
231
- n = (options[:number] || options[:num] || options[:tnum] || options[:test_number])
232
- unless n
233
- [:number, :num, :tnum, :test_number].each do |m|
234
- n ||= object.respond_to?(m) ? object.send(m) : nil
235
- end
236
- end
237
- children << number(n) if n
238
-
239
- children << id(options[:id].to_s.downcase.to_sym) if options[:id]
240
-
241
- if levels = options[:level] || options[:levels]
242
- levels = [levels] unless levels.is_a?(Array)
243
- levels.each do |l|
244
- children << level(l[:name], l[:value], l[:unit] || l[:units])
245
- end
246
- end
247
-
248
- if lims = options[:limit] || options[:limits]
249
- lims = [lims] unless lims.is_a?(Array)
250
- lims.each do |l|
251
- children << limit(l[:value], l[:rule], l[:unit] || l[:units])
252
- end
253
- end
254
-
255
- if pins = options[:pin] || options[:pins]
256
- pins = [pins] unless pins.is_a?(Array)
257
- pins.each do |p|
258
- if p.is_a?(Hash)
259
- children << pin(p[:name])
260
- else
261
- children << pin(p)
262
- end
263
- end
264
- end
265
-
266
- if pats = options[:pattern] || options[:patterns]
267
- pats = [pats] unless pats.is_a?(Array)
268
- pats.each do |p|
269
- if p.is_a?(Hash)
270
- children << pattern(p[:name], p[:path])
271
- else
272
- children << pattern(p)
273
- end
274
- end
275
- end
276
-
277
- if options[:meta]
278
- attrs = []
279
- options[:meta].each { |k, v| attrs << attribute(k, v) }
280
- children << n(:meta, *attrs)
281
- end
282
-
283
- if subs = options[:sub_test] || options[:sub_tests]
284
- subs = [subs] unless subs.is_a?(Array)
285
- subs.each do |s|
286
- children << s.updated(:sub_test, nil)
287
- end
288
- end
289
-
290
- children << on_fail(options[:on_fail]) if options[:on_fail]
291
- children << on_pass(options[:on_pass]) if options[:on_pass]
292
-
293
- test = n(:test, *children)
294
-
295
- if options[:conditions]
296
- apply_conditions(test, options[:conditions])
297
- else
298
- test
299
- end
300
- end
301
-
302
- def pattern(name, path = nil)
303
- if path
304
- n(:pattern, name, path)
305
- else
306
- n(:pattern, name)
307
- end
308
- end
309
-
310
- def attribute(name, value)
311
- n(:attribute, name, value)
312
- end
313
-
314
- def level(name, value, units = nil)
315
- if units
316
- n(:level, name, value, units)
317
- else
318
- n(:level, name, value)
319
- end
320
- end
321
-
322
- def limit(value, rule, units = nil)
323
- if units
324
- n(:limit, value, rule, units)
325
- else
326
- n(:limit, value, rule)
327
- end
328
- end
329
-
330
- def pin(name)
331
- n(:pin, name)
332
- end
333
-
334
- def on_fail(options = {})
335
- children = []
336
- if options[:bin] || options[:softbin]
337
- fail_opts = { bin: options[:bin], softbin: options[:softbin] }
338
- fail_opts[:bin_description] = options[:bin_description] if options[:bin_description]
339
- fail_opts[:softbin_description] = options[:softbin_description] if options[:softbin_description]
340
- children << set_result(:fail, fail_opts)
341
- end
342
- if options[:set_run_flag] || options[:set_flag]
343
- children << set_run_flag(options[:set_run_flag] || options[:set_flag])
344
- end
345
- children << continue if options[:continue]
346
- children << render(options[:render]) if options[:render]
347
- n(:on_fail, *children)
348
- end
349
-
350
- def on_pass(options = {})
351
- children = []
352
- if options[:bin] || options[:softbin]
353
- pass_opts = { bin: options[:bin], softbin: options[:softbin] }
354
- pass_opts[:bin_description] = options[:bin_description] if options[:bin_description]
355
- pass_opts[:softbin_description] = options[:softbin_description] if options[:softbin_description]
356
- children << set_result(:pass, pass_opts)
357
- end
358
- if options[:set_run_flag] || options[:set_flag]
359
- children << set_run_flag(options[:set_run_flag] || options[:set_flag])
360
- end
361
- children << continue if options[:continue]
362
- children << render(options[:render]) if options[:render]
363
- n(:on_pass, *children)
364
- end
365
-
366
- def set_result(type, options = {})
367
- children = []
368
- children << type
369
- if options[:bin] && options[:bin_description]
370
- children << n(:bin, options[:bin], options[:bin_description])
371
- else
372
- children << n(:bin, options[:bin]) if options[:bin]
373
- end
374
- if options[:softbin] && options[:softbin_description]
375
- children << n(:softbin, options[:softbin], options[:softbin_description])
376
- else
377
- children << n(:softbin, options[:softbin]) if options[:softbin]
378
- end
379
- result = n(:set_result, *children)
380
-
381
- if options[:conditions]
382
- apply_conditions(result, options[:conditions])
383
- else
384
- result
385
- end
386
- end
387
-
388
- def number(val)
389
- n(:number, val.to_i)
390
- end
391
-
392
- def continue
393
- n0(:continue)
394
- end
395
- end
396
- end
397
- end