Module: OrigenTesters::Flow

Includes:
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 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, #output_file, #output_inhibited?, #platform, #reference_file, #set_flow_description, #stats, #to_be_written?, #write_from_template, #write_to_file

Class Method Details

.callstackObject



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

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

.comment_stackObject



19
20
21
# File 'lib/origen_testers/flow.rb', line 19

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

.flow_commentsObject



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

def self.flow_comments
  @flow_comments
end

.flow_comments=(val) ⇒ Object



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

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

.unique_idsObject



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

def self.unique_ids
  @unique_ids
end

.unique_ids=(val) ⇒ Object



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

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

Instance Method Details

#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



140
141
142
# File 'lib/origen_testers/flow.rb', line 140

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



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

def at_run_start
  @@program = nil
end

#bin(number, options = {}) ⇒ Object



77
78
79
80
81
82
83
84
85
# File 'lib/origen_testers/flow.rb', line 77

def bin(number, options = {})
  options[:bin_description] ||= options.delete(:description)
  if number.is_a?(Hash)
    fail 'The bin number must be passed as the first argument'
  end
  add_meta!(options)
  options[:type] ||= :fail
  model.bin(number, clean_options(options))
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)


289
290
291
292
# File 'lib/origen_testers/flow.rb', line 289

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

#cz(instance, cz_setup, options = {}) ⇒ Object Also known as: characterize



110
111
112
113
# File 'lib/origen_testers/flow.rb', line 110

def cz(instance, cz_setup, options = {})
  add_meta_and_description!(options)
  model.cz(instance, cz_setup, clean_options(options))
end

#disable(var, options = {}) ⇒ Object



72
73
74
75
# File 'lib/origen_testers/flow.rb', line 72

def disable(var, options = {})
  add_meta!(options)
  model.disable(var, clean_options(options))
end

#enable(var, options = {}) ⇒ Object



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

def enable(var, options = {})
  add_meta!(options)
  model.enable(var, clean_options(options))
end

#generate_unique_label(name = nil) ⇒ Object



294
295
296
297
298
299
300
301
302
# File 'lib/origen_testers/flow.rb', line 294

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

#group(name, options = {}) ⇒ Object



122
123
124
125
126
127
# File 'lib/origen_testers/flow.rb', line 122

def group(name, options = {})
  add_meta!(options)
  model.group(name, clean_options(options)) do
    yield
  end
end

#if_all_failed(*ids) ⇒ Object



239
240
241
242
243
244
245
246
# File 'lib/origen_testers/flow.rb', line 239

def if_all_failed(*ids)
  options = ids.last.is_a?(Hash) ? ids.pop : {}
  options[:if_all_failed] = ids.flatten
  add_meta!(options)
  model.with_conditions(options) do
    yield
  end
end

#if_all_passed(*ids) ⇒ Object



257
258
259
260
261
262
263
264
# File 'lib/origen_testers/flow.rb', line 257

def if_all_passed(*ids)
  options = ids.last.is_a?(Hash) ? ids.pop : {}
  options[:if_all_passed] = ids.flatten
  add_meta!(options)
  model.with_conditions(options) do
    yield
  end
end

#if_any_failed(*ids) ⇒ Object



230
231
232
233
234
235
236
237
# File 'lib/origen_testers/flow.rb', line 230

def if_any_failed(*ids)
  options = ids.last.is_a?(Hash) ? ids.pop : {}
  options[:if_any_failed] = ids.flatten
  add_meta!(options)
  model.with_conditions(options) do
    yield
  end
end

#if_any_passed(*ids) ⇒ Object



248
249
250
251
252
253
254
255
# File 'lib/origen_testers/flow.rb', line 248

def if_any_passed(*ids)
  options = ids.last.is_a?(Hash) ? ids.pop : {}
  options[:if_any_passed] = ids.flatten
  add_meta!(options)
  model.with_conditions(options) do
    yield
  end
end

#if_enable(word, options = {}) ⇒ Object Also known as: if_enabled



164
165
166
167
168
169
170
171
172
173
174
# File 'lib/origen_testers/flow.rb', line 164

def if_enable(word, options = {})
  if options[:or]
    yield
  else
    options = { enable: word }
    add_meta!(options)
    model.with_conditions(options) do
      yield
    end
  end
end

#if_failed(test_id, options = {}) ⇒ Object Also known as: unless_passed



202
203
204
205
206
207
208
209
210
211
# File 'lib/origen_testers/flow.rb', line 202

def if_failed(test_id, options = {})
  if test_id.is_a?(Array)
    fail 'if_failed only accepts one ID, use if_any_failed or if_all_failed for multiple IDs'
  end
  options = { if_failed: test_id }
  add_meta!(options)
  model.with_conditions(options) do
    yield
  end
end

#if_flag(flag, options = {}) ⇒ Object



266
267
268
269
270
271
272
# File 'lib/origen_testers/flow.rb', line 266

def if_flag(flag, options = {})
  options = { if_flag: flag }
  add_meta!(options)
  model.with_conditions(options) do
    yield
  end
end

#if_job(*jobs) ⇒ Object Also known as: if_jobs



144
145
146
147
148
149
150
151
# File 'lib/origen_testers/flow.rb', line 144

def if_job(*jobs)
  options = jobs.last.is_a?(Hash) ? jobs.pop : {}
  options[:if_job] = jobs.flatten
  add_meta!(options)
  model.with_conditions(options) do
    yield
  end
end

#if_passed(test_id, options = {}) ⇒ Object Also known as: unless_failed



190
191
192
193
194
195
196
197
198
199
# File 'lib/origen_testers/flow.rb', line 190

def if_passed(test_id, options = {})
  if test_id.is_a?(Array)
    fail 'if_passed only accepts one ID, use if_any_passed or if_all_passed for multiple IDs'
  end
  options = { if_passed: test_id }
  add_meta!(options)
  model.with_conditions(options) do
    yield
  end
end

#if_ran(test_id, options = {}) ⇒ Object



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

def if_ran(test_id, options = {})
  options = { if_ran: test_id }
  add_meta!(options)
  model.with_conditions(options) do
    yield
  end
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)


283
284
285
# File 'lib/origen_testers/flow.rb', line 283

def is_the_flow?
  true
end

#linesObject



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

def lines
  @lines
end

#log(message, options = {}) ⇒ Object Also known as: logprint



116
117
118
119
# File 'lib/origen_testers/flow.rb', line 116

def log(message, options = {})
  add_meta!(options)
  model.log(message, clean_options(options))
end

#modelObject



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/origen_testers/flow.rb', line 54

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

#nop(options = {}) ⇒ Object



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

def nop(options = {})
end

#pass(number, options = {}) ⇒ Object



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

def pass(number, options = {})
  if number.is_a?(Hash)
    fail 'The bin number must be passed as the first argument'
  end
  options[:type] = :pass
  bin(number, clean_options(options))
end

#programObject

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



45
46
47
# File 'lib/origen_testers/flow.rb', line 45

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

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



100
101
102
103
104
105
106
107
108
# File 'lib/origen_testers/flow.rb', line 100

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

#save_programObject



49
50
51
52
# File 'lib/origen_testers/flow.rb', line 49

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



306
307
308
# File 'lib/origen_testers/flow.rb', line 306

def sig
  @sig
end

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



95
96
97
98
# File 'lib/origen_testers/flow.rb', line 95

def test(instance, options = {})
  add_meta_and_description!(options)
  model.test(instance, clean_options(options))
end

#unless_enable(word, options = {}) ⇒ Object Also known as: unless_enabled



177
178
179
180
181
182
183
184
185
186
187
# File 'lib/origen_testers/flow.rb', line 177

def unless_enable(word, options = {})
  if options[:or]
    yield
  else
    options = { unless_enable: word }
    add_meta!(options)
    model.with_conditions(options) do
      yield
    end
  end
end

#unless_flag(flag, options = {}) ⇒ Object



274
275
276
277
278
279
280
# File 'lib/origen_testers/flow.rb', line 274

def unless_flag(flag, options = {})
  options = { unless_flag: flag }
  add_meta!(options)
  model.with_conditions(options) do
    yield
  end
end

#unless_job(*jobs) ⇒ Object Also known as: unless_jobs



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

def unless_job(*jobs)
  options = jobs.last.is_a?(Hash) ? jobs.pop : {}
  options[:unless_job] = jobs.flatten
  add_meta!(options)
  model.with_conditions(options) do
    yield
  end
end

#unless_ran(test_id, options = {}) ⇒ Object



222
223
224
225
226
227
228
# File 'lib/origen_testers/flow.rb', line 222

def unless_ran(test_id, options = {})
  options = { unless_ran: test_id }
  add_meta!(options)
  model.with_conditions(options) do
    yield
  end
end