Module: OrigenTesters::Flow

Includes:
ATP::FlowAPI, Generator
Included in:
IGXLBasedTester::Base::Flow, SmartestBasedTester::Base::Flow
Defined in:
lib/origen_testers/flow.rb

Overview

Provides a common API to add tests to a flow that is supported by all testers.

This builds up a flow model using the Abstract Test Program (ATP) gem, which now deals with implementing the flow control API.

Individual tester drivers in this plugin are then responsible at the end to render the abstract flow to their specific format and conventions.

Constant Summary collapse

PROGRAM_MODELS_DIR =
"#{Origen.root}/tmp/program_models"

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ATP::FlowAPI

#atp=, #hi_limit, #limit, #lo_limit

Methods included from Generator

#close, #collection, #collection=, #compiler, #current_dir, #dont_diff=, execute_source, #file_extension, #file_pipeline, #filename, #filename=, #finalize, #identity_map, #import, #inhibit_output, #name, #on_close, original_reference_file, original_reference_file=, #output_file, #output_inhibited?, #platform, #reference_file, #set_flow_description, #stats, #to_be_written?, #write_from_template, #write_to_file

Class Method Details

.callstackObject



23
24
25
# File 'lib/origen_testers/flow.rb', line 23

def self.callstack
  @callstack ||= []
end

.cc_commentsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



112
113
114
115
116
117
# File 'lib/origen_testers/flow.rb', line 112

def self.cc_comments
  unless @cc_comments.is_a? Hash
    @cc_comments = {}
  end
  @cc_comments
end

.cc_comments=(val) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



120
121
122
123
124
125
# File 'lib/origen_testers/flow.rb', line 120

def self.cc_comments=(val)
  unless @cc_comments.is_a? Hash
    @cc_comments = {}
  end
  @cc_comments = val
end

.comment_stackObject



27
28
29
# File 'lib/origen_testers/flow.rb', line 27

def self.comment_stack
  @comment_stack ||= []
end

.flow_commentsObject



35
36
37
# File 'lib/origen_testers/flow.rb', line 35

def self.flow_comments
  @flow_comments
end

.flow_comments=(val) ⇒ Object



39
40
41
# File 'lib/origen_testers/flow.rb', line 39

def self.flow_comments=(val)
  @flow_comments = val
end

.ht_commentsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



96
97
98
99
100
101
# File 'lib/origen_testers/flow.rb', line 96

def self.ht_comments
  unless @ht_comments.is_a? Hash
    @ht_comments = {}
  end
  @ht_comments
end

.ht_comments=(val) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



104
105
106
107
108
109
# File 'lib/origen_testers/flow.rb', line 104

def self.ht_comments=(val)
  unless @ht_comments.is_a? Hash
    @ht_comments = {}
  end
  @ht_comments = val
end

.name_stackObject



31
32
33
# File 'lib/origen_testers/flow.rb', line 31

def self.name_stack
  @name_stack ||= []
end

.unique_idsObject



43
44
45
# File 'lib/origen_testers/flow.rb', line 43

def self.unique_ids
  @unique_ids
end

.unique_ids=(val) ⇒ Object



47
48
49
# File 'lib/origen_testers/flow.rb', line 47

def self.unique_ids=(val)
  @unique_ids = val
end

Instance Method Details

#active_descriptionObject



205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/origen_testers/flow.rb', line 205

def active_description
  flow_file = OrigenTesters::Flow.callstack.last
  called_from = caller.find { |l| l =~ /^#{flow_file}:.*/ }
  # Windows fix - prevent the drive letter in the file name from changing the index of the line_no below
  called_from.gsub!(flow_file, '')
  desc = nil
  if called_from
    called_from = called_from.split(':')
    line_no = called_from[1].to_i
    ht_coms = OrigenTesters::Flow.ht_comments
    cc_coms = OrigenTesters::Flow.cc_comments
    if line_no
      if ht_coms[line_no]
        desc = ht_coms[line_no].join(' ')
      end
      if cc_coms[line_no] && cc_coms[line_no].first
        desc = [cc_coms[line_no].shift].join(' ')
      end
    end
  end
  desc
end

#at_flow_startObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This fires between flows (unless overridden by the ATE specific flow class)



173
174
175
# File 'lib/origen_testers/flow.rb', line 173

def at_flow_start
  @labels = {}
end

#at_run_startObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This fires between target loads (unless overridden by the ATE specific flow class)



167
168
169
# File 'lib/origen_testers/flow.rb', line 167

def at_run_start
  @@program = nil
end

#childrenObject

Returns a hash containing all child flows stored by their ID



67
68
69
# File 'lib/origen_testers/flow.rb', line 67

def children
  @children ||= {}.with_indifferent_access
end

#context_changed?(options) ⇒ Boolean

Returns true if the test context generated from the supplied options + existing condition wrappers is different from that which was applied to the previous test.

Returns:

  • (Boolean)


184
185
186
# File 'lib/origen_testers/flow.rb', line 184

def context_changed?(options)
  model.context_changed?(options)
end

#generate_unique_label(name = nil) ⇒ Object



188
189
190
191
192
193
194
195
196
# File 'lib/origen_testers/flow.rb', line 188

def generate_unique_label(name = nil)
  name = 'label' if !name || name == ''
  name.gsub!(' ', '_')
  name.upcase!
  @labels ||= {}
  @labels[name] ||= 0
  @labels[name] += 1
  "#{name}_#{@labels[name]}_#{sig}"
end

#is_the_flow?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


178
179
180
# File 'lib/origen_testers/flow.rb', line 178

def is_the_flow?
  true
end

#linesObject



85
86
87
# File 'lib/origen_testers/flow.rb', line 85

def lines
  @lines
end

#modelObject Also known as: atp



138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/origen_testers/flow.rb', line 138

def model
  if Origen.interface.resources_mode?
    @throwaway ||= ATP::Flow.new(self)
  else
    @model ||= begin
      f = program.flow(try(:path) || id, description: OrigenTesters::Flow.flow_comments)
      @sig = flow_sig(try(:path) || id)
      # f.id = @sig if OrigenTesters::Flow.unique_ids
      f
    end
  end
end

#nop(options = {}) ⇒ Object



162
163
# File 'lib/origen_testers/flow.rb', line 162

def nop(options = {})
end

#orig_renderObject

The ATP::FlowAPI provides a render method, but let’s grab a handle to the original render method from OrigenTesters, we will use this to extend the ATP render method with the ability to pass in a path to a file containing the content to be rendered into the flow



17
# File 'lib/origen_testers/flow.rb', line 17

alias_method :orig_render, :render

#parentObject

Returns the flow’s immediate parent flow object, or nil if this is a top-level flow



62
63
64
# File 'lib/origen_testers/flow.rb', line 62

def parent
  @parent
end

#pathObject

Returns the flow’s ID prefixed with the IDs of its parent flows, joined by ‘.’



72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/origen_testers/flow.rb', line 72

def path
  @path ||= begin
    ids = []
    p = parent
    while p
      ids.unshift(p.id)
      p = p.parent
    end
    ids << id
    ids.map(&:to_s).join('.')
  end
end

#programObject

Returns the abstract test program model, this is shared by all flow created together in a generation run



129
130
131
# File 'lib/origen_testers/flow.rb', line 129

def program
  @@program ||= ATP::Program.new
end

#render(file, options = {}) ⇒ Object



152
153
154
155
156
157
158
159
160
# File 'lib/origen_testers/flow.rb', line 152

def render(file, options = {})
  add_meta!(options)
  begin
    text = orig_render(file, options)
  rescue
    text = file
  end
  atp.render(text, options)
end

#save_programObject



133
134
135
136
# File 'lib/origen_testers/flow.rb', line 133

def save_program
  FileUtils.mkdir_p(PROGRAM_MODELS_DIR) unless File.exist?(PROGRAM_MODELS_DIR)
  program.save("#{PROGRAM_MODELS_DIR}/#{Origen.target.name}")
end

#sigObject Also known as: signature

Returns a unique signature that has been generated for the current flow, this can be appended to named references to avoid naming collisions with any other flow



200
201
202
# File 'lib/origen_testers/flow.rb', line 200

def sig
  @sig
end

#test(obj, options = {}) ⇒ Object



89
90
91
92
93
# File 'lib/origen_testers/flow.rb', line 89

def test(obj, options = {})
  @_last_parameters_ = options.dup # Save for the interface's if_parameter_changed method
  obj.extract_atp_attributes(options) if obj.respond_to?(:extract_atp_attributes)
  super(obj, options)
end

#top_levelObject

Returns the flow’s parent top-level flow object, or self if this is a top-level flow



57
58
59
# File 'lib/origen_testers/flow.rb', line 57

def top_level
  @top_level
end

#top_level?Boolean

Returns true if this is a top-level Origen test program flow

Returns:

  • (Boolean)


52
53
54
# File 'lib/origen_testers/flow.rb', line 52

def top_level?
  top_level == self
end