Class: OrigenTesters::ATP::Processors::OneFlagPerTest

Inherits:
OrigenTesters::ATP::Processor show all
Defined in:
lib/origen_testers/atp/processors/one_flag_per_test.rb

Overview

Ensures that all test nodes only ever set a flag once

Instance Method Summary collapse

Methods inherited from OrigenTesters::ATP::Processor

#clean_flag, #extract_volatiles, #handler_missing, #process, #process_all, #volatile?, #volatile_flags

Instance Method Details

#on_test(node) ⇒ Object


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
# File 'lib/origen_testers/atp/processors/one_flag_per_test.rb', line 17

def on_test(node)
  on_pass = node.find(:on_pass)
  on_fail = node.find(:on_fail)
  if @build_table
    if on_fail
      on_fail.find_all(:set_flag).each do |n|
        @fail_table[n.to_a[0]] ||= 0
        @fail_table[n.to_a[0]] += 1
      end
    end
    if on_pass
      on_pass.find_all(:set_flag).each do |n|
        @pass_table[n.to_a[0]] ||= 0
        @pass_table[n.to_a[0]] += 1
      end
    end
  else
    to_be_set = {}
    if on_fail
      node = node.remove(on_fail)
      on_fail.find_all(:set_flag).each do |set_flag|
        old_flag = set_flag.to_a[0]
        if @fail_table[old_flag] > 1
          on_fail = on_fail.remove(set_flag)
          new_flag = "#{old_flag}_#{@counters[old_flag]}"
          @counters[old_flag] += 1
          to_be_set[old_flag] = new_flag
          c = set_flag.children.dup
          c[0] = new_flag
          set_flag = set_flag.updated(nil, c)
          on_fail = on_fail.updated(nil, on_fail.children + [set_flag])
        end
      end
      node = node.updated(nil, node.children + [on_fail])
    end
    if on_pass
      node = node.remove(on_pass)
      on_pass.find_all(:set_flag).each do |set_flag|
        old_flag = set_flag.to_a[0]
        if @pass_table[old_flag] > 1
          on_pass = on_pass.remove(set_flag)
          new_flag = "#{old_flag}_#{@counters[old_flag]}"
          @counters[old_flag] += 1
          to_be_set[old_flag] = new_flag
          c = set_flag.children.dup
          c[0] = new_flag
          set_flag = set_flag.updated(nil, c)
          on_pass = on_pass.updated(nil, on_pass.children + [set_flag])
        end
      end
      node = node.updated(nil, node.children + [on_pass])
    end
    if to_be_set.empty?
      node
    else
      nodes = to_be_set.map { |old, new| node.updated(:if_flag, [new, node.updated(:set_flag, [old, 'auto_generated'])]) }
      node.updated(:inline, [node] + nodes)
    end
  end
end

#run(node) ⇒ Object


5
6
7
8
9
10
11
12
13
14
15
# File 'lib/origen_testers/atp/processors/one_flag_per_test.rb', line 5

def run(node)
  @build_table = true
  @pass_table = {}
  @fail_table = {}
  process(node)
  @counters = {}
  @pass_table.each { |f, v| @counters[f] = 0 }
  @fail_table.each { |f, v| @counters[f] = 0 }
  @build_table = false
  process(node)
end