Class: OrigenTesters::ATP::Processors::Relationship

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

Overview

This processor will apply the relationships between tests, e.g. if testB should only execute if testA passes, then this processor will update the AST to make testA set a flag on pass, and then update testB to only run if that flag is set.

Defined Under Namespace

Classes: ExtractTestResults

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from OrigenTesters::ATP::Processor

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

Instance Attribute Details

#test_resultsObject (readonly)

Returns a hash containing the IDs of all tests that have dependents



8
9
10
# File 'lib/origen_testers/atp/processors/relationship.rb', line 8

def test_results
  @test_results
end

Instance Method Details

#add_fail_flag(id, node) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/origen_testers/atp/processors/relationship.rb', line 85

def add_fail_flag(id, node)
  node = node.ensure_node_present(:on_fail)
  node.updated(nil, node.children.map do |n|
    if n.type == :on_fail
      n = n.add node.updated(:set_flag, ["#{id}_FAILED", :auto_generated])
      delayed = n.find(:delayed)
      if delayed && delayed.to_a[0]
        n
      else
        n.ensure_node_present(:continue)
      end
    else
      n
    end
  end)
end

#add_pass_flag(id, node) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/origen_testers/atp/processors/relationship.rb', line 66

def add_pass_flag(id, node)
  node = node.ensure_node_present(:on_pass)
  node = node.ensure_node_present(:on_fail)
  node.updated(nil, node.children.map do |n|
    if n.type == :on_pass
      n = n.add node.updated(:set_flag, ["#{id}_PASSED", :auto_generated])
    elsif n.type == :on_fail
      delayed = n.find(:delayed)
      if delayed && delayed.to_a[0]
        n
      else
        n.ensure_node_present(:continue)
      end
    else
      n
    end
  end)
end

#add_ran_flags(id, node) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/origen_testers/atp/processors/relationship.rb', line 102

def add_ran_flags(id, node)
  set_flag = node.updated(:set_flag, ["#{id}_RAN", :auto_generated])
  # For a group, set a flag immediately upon entry to the group to signal that
  # it ran to later tests, this is better than doing it immediately after the group
  # in case it was bypassed
  if node.type == :group || node.type == :sub_flow
    nodes = node.to_a.dup
    pre_nodes = []
    while [:name, :id, :path].include?(nodes.first.try(:type))
      pre_nodes << nodes.shift
    end
    node.updated(nil, pre_nodes + [set_flag] + nodes)

  # For a test, set a flag immediately after the referenced test has executed
  # but don't change its pass/fail handling
  elsif node.type == :test
    node.updated(:inline, [node, set_flag])
  else
    fail "Don't know how to add ran flag to #{node.type}"
  end
end

#id(node) ⇒ Object

Returns the ID of the give test node (if any), caller is responsible for only passing test nodes



208
209
210
211
212
# File 'lib/origen_testers/atp/processors/relationship.rb', line 208

def id(node)
  if n = node.children.find { |c| c.type == :id }
    n.children.first
  end
end

#id_to_flag(id, type) ⇒ Object



214
215
216
217
218
219
220
# File 'lib/origen_testers/atp/processors/relationship.rb', line 214

def id_to_flag(id, type)
  if id.is_a?(Array)
    id.map { |i| "#{i}_#{type}" }
  else
    "#{id}_#{type}"
  end
end

#on_if_all_failed(node) ⇒ Object



156
157
158
159
160
161
162
163
164
165
166
# File 'lib/origen_testers/atp/processors/relationship.rb', line 156

def on_if_all_failed(node)
  ids, *children = *node
  ids.reverse_each.with_index do |id, i|
    if i == 0
      node = node.updated(:if_flag, [id_to_flag(id, 'FAILED')] + process_all(children))
    else
      node = node.updated(:if_flag, [id_to_flag(id, 'FAILED'), node])
    end
  end
  node
end

#on_if_all_passed(node) ⇒ Object



184
185
186
187
188
189
190
191
192
193
194
# File 'lib/origen_testers/atp/processors/relationship.rb', line 184

def on_if_all_passed(node)
  ids, *children = *node
  ids.reverse_each.with_index do |id, i|
    if i == 0
      node = node.updated(:if_flag, [id_to_flag(id, 'PASSED')] + process_all(children))
    else
      node = node.updated(:if_flag, [id_to_flag(id, 'PASSED'), node])
    end
  end
  node
end

#on_if_all_sites_failed(node) ⇒ Object



151
152
153
154
# File 'lib/origen_testers/atp/processors/relationship.rb', line 151

def on_if_all_sites_failed(node)
  id, *children = *node
  node.updated(:if_all_sites_flag, [id_to_flag(id, 'FAILED')] + process_all(children))
end

#on_if_all_sites_passed(node) ⇒ Object



179
180
181
182
# File 'lib/origen_testers/atp/processors/relationship.rb', line 179

def on_if_all_sites_passed(node)
  id, *children = *node
  node.updated(:if_all_sites_flag, [id_to_flag(id, 'PASSED')] + process_all(children))
end

#on_if_any_sites_failed(node) ⇒ Object



146
147
148
149
# File 'lib/origen_testers/atp/processors/relationship.rb', line 146

def on_if_any_sites_failed(node)
  id, *children = *node
  node.updated(:if_any_sites_flag, [id_to_flag(id, 'FAILED')] + process_all(children))
end

#on_if_any_sites_passed(node) ⇒ Object



174
175
176
177
# File 'lib/origen_testers/atp/processors/relationship.rb', line 174

def on_if_any_sites_passed(node)
  id, *children = *node
  node.updated(:if_any_sites_flag, [id_to_flag(id, 'PASSED')] + process_all(children))
end

#on_if_failed(node) ⇒ Object Also known as: on_if_any_failed



140
141
142
143
# File 'lib/origen_testers/atp/processors/relationship.rb', line 140

def on_if_failed(node)
  id, *children = *node
  node.updated(:if_flag, [id_to_flag(id, 'FAILED')] + process_all(children))
end

#on_if_passed(node) ⇒ Object Also known as: on_if_any_passed



168
169
170
171
# File 'lib/origen_testers/atp/processors/relationship.rb', line 168

def on_if_passed(node)
  id, *children = *node
  node.updated(:if_flag, [id_to_flag(id, 'PASSED')] + process_all(children))
end

#on_if_ran(node) ⇒ Object



196
197
198
199
# File 'lib/origen_testers/atp/processors/relationship.rb', line 196

def on_if_ran(node)
  id, *children = *node
  node.updated(:if_flag, [id_to_flag(id, 'RAN')] + process_all(children))
end

#on_test(node) ⇒ Object Also known as: on_group, on_sub_flow

Set flags depending on the result on tests which have dependents later in the flow



126
127
128
129
130
131
132
133
134
135
136
# File 'lib/origen_testers/atp/processors/relationship.rb', line 126

def on_test(node)
  node = node.updated(nil, process_all(node.children))
  nid = id(node)
  # If this test has a dependent
  if test_results[nid]
    node = add_pass_flag(nid, node) if test_results[nid][:passed]
    node = add_fail_flag(nid, node) if test_results[nid][:failed]
    node = add_ran_flags(nid, node) if test_results[nid][:ran]
  end
  node
end

#on_unless_ran(node) ⇒ Object



201
202
203
204
# File 'lib/origen_testers/atp/processors/relationship.rb', line 201

def on_unless_ran(node)
  id, *children = *node
  node.updated(:unless_flag, [id_to_flag(id, 'RAN')] + process_all(children))
end

#run(node) ⇒ Object



59
60
61
62
63
64
# File 'lib/origen_testers/atp/processors/relationship.rb', line 59

def run(node)
  t = ExtractTestResults.new
  t.process(node)
  @test_results = t.results || {}
  process(node)
end