Class: OrigenTesters::ATP::Flow

Inherits:
Object
  • Object
show all
Defined in:
lib/origen_testers/atp/flow.rb

Overview

Implements the main user API for building and interacting with an abstract test program

Constant Summary collapse

CONDITION_KEYS =
{
  if_enabled:              :if_enabled,
  if_enable:               :if_enabled,
  enabled:                 :if_enabled,
  enable_flag:             :if_enabled,
  enable:                  :if_enabled,

  unless_enabled:          :unless_enabled,
  not_enabled:             :unless_enabled,
  disabled:                :unless_enabled,
  disable:                 :unless_enabled,
  unless_enable:           :unless_enabled,

  if_failed:               :if_failed,
  unless_passed:           :if_failed,
  failed:                  :if_failed,

  if_passed:               :if_passed,
  unless_failed:           :if_passed,
  passed:                  :if_passed,

  if_any_failed:           :if_any_failed,
  unless_all_passed:       :if_any_failed,

  if_all_failed:           :if_all_failed,
  unless_any_passed:       :if_all_failed,

  if_any_passed:           :if_any_passed,
  unless_all_failed:       :if_any_passed,

  if_all_passed:           :if_all_passed,
  unless_any_failed:       :if_all_passed,

  if_ran:                  :if_ran,
  if_executed:             :if_ran,

  unless_ran:              :unless_ran,
  unless_executed:         :unless_ran,

  job:                     :if_job,
  jobs:                    :if_job,
  if_job:                  :if_job,
  if_jobs:                 :if_job,

  unless_job:              :unless_job,
  unless_jobs:             :unless_job,

  if_flag:                 :if_flag,

  unless_flag:             :unless_flag,

  whenever:                :whenever,
  whenever_all:            :whenever_all,
  whenever_any:            :whenever_any,

  group:                   :group,

  if_any_site_failed:      :if_any_sites_failed,
  if_any_sites_failed:     :if_any_sites_failed,
  unless_all_sites_passed: :if_any_sites_failed,

  if_all_sites_failed:     :if_all_sites_failed,
  unless_any_sites_passed: :if_all_sites_failed,
  unless_any_site_passed:  :if_all_sites_failed,

  if_any_site_passed:      :if_any_sites_passed,
  if_any_sites_passed:     :if_any_sites_passed,
  unless_all_sites_failed: :if_any_sites_passed,

  if_all_sites_passed:     :if_all_sites_passed,
  unless_any_sites_failed: :if_all_sites_passed,
  unless_any_site_failed:  :if_all_sites_passed
}
CONDITION_NODE_TYPES =
CONDITION_KEYS.values.uniq
RELATIONAL_OPERATORS =
[:eq, :ne, :lt, :le, :gt, :ge]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(program, name = nil, options = {}) ⇒ Flow

Returns a new instance of Flow.



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/origen_testers/atp/flow.rb', line 85

def initialize(program, name = nil, options = {})
  name, options = nil, name if name.is_a?(Hash)
  @source_file = []
  @source_line_number = []
  @description = []
  @program = program
  @name = name
  extract_meta!(options) do
    @pipeline = [n1(:flow, n1(:name, name))]
  end
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/origen_testers/atp/flow.rb', line 5

def name
  @name
end

#programObject (readonly)

Returns the value of attribute program.



5
6
7
# File 'lib/origen_testers/atp/flow.rb', line 5

def program
  @program
end

Instance Method Details

#ast(options = {}) ⇒ Object

Returns a processed/optimized AST, this is the one that should be used to build and represent the given test flow



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/origen_testers/atp/flow.rb', line 123

def ast(options = {})
  options = {
    apply_relationships:          true,
    # Supply a unique ID to append to all IDs
    unique_id:                    nil,
    # Set to :smt, or :igxl
    optimization:                 :runner,
    # When true, will remove set_result nodes in an on_fail branch which contains a continue
    implement_continue:           true,
    # When false, this will not optimize the use of a flag by nesting a dependent test within
    # the parent test's on_fail branch if the on_fail contains a continue
    optimize_flags_when_continue: true,
    # These options are not intended for application use, but provide the ability to
    # turn off certain processors during test cases
    add_ids:                      true,
    optimize_flags:               true,
    one_flag_per_test:            true,
    include_sub_flows:            true
  }.merge(options)
  ###############################################################################
  ## Common pre-processing and validation
  ###############################################################################
  ast = Processors::PreCleaner.new.run(raw)
  Validators::DuplicateIDs.new(self).run(ast)
  Validators::MissingIDs.new(self).run(ast)
  Validators::Jobs.new(self).run(ast)
  Validators::Flags.new(self).run(ast)
  # Ensure everything has an ID, this helps later if condition nodes need to be generated
  ast = Processors::AddIDs.new.run(ast) if options[:add_ids]
  ast = Processors::FlowID.new.run(ast, options[:unique_id]) if options[:unique_id]
  ast = Processors::SubFlowRemover.new.run(ast) unless options[:include_sub_flows]

  ###############################################################################
  ## Optimization for a C-like flow target, e.g. V93K
  ###############################################################################
  if options[:optimization] == :smt || options[:optimization] == :runner
    # This applies all the relationships by setting flags in the referenced test and
    # changing all if_passed/failed type nodes to if_flag type nodes
    ast = Processors::Relationship.new.run(ast) if options[:apply_relationships]
    ast = Processors::Condition.new.run(ast)
    unless options[:optimization] == :runner
      ast = Processors::ContinueImplementer.new.run(ast) if options[:implement_continue]
    end
    if options[:optimize_flags]
      ast = Processors::FlagOptimizer.new.run(ast, optimize_when_continue: options[:optimize_flags_when_continue])
    end
    ast = Processors::AdjacentIfCombiner.new.run(ast)

  ###############################################################################
  ## Optimization for a row-based target, e.g. UltraFLEX
  ###############################################################################
  elsif options[:optimization] == :igxl
    # Un-nest everything embedded in else nodes
    ast = Processors::ElseRemover.new.run(ast)
    # Un-nest everything embedded in on_pass/fail nodes except for binning and
    # flag setting
    ast = Processors::OnPassFailRemover.new.run(ast)
    # This applies all the relationships by setting flags in the referenced test and
    # changing all if_passed/failed type nodes to if_flag type nodes
    ast = Processors::Relationship.new.run(ast) if options[:apply_relationships]
    ast = Processors::Condition.new.run(ast)
    ast = Processors::ApplyPostGroupActions.new.run(ast)
    ast = Processors::OneFlagPerTest.new.run(ast) if options[:one_flag_per_test]
    ast = Processors::RedundantConditionRemover.new.run(ast)

  ###############################################################################
  ## Not currently used, more of a test case
  ###############################################################################
  elsif options[:optimization] == :flat
    # Un-nest everything embedded in else nodes
    ast = Processors::ElseRemover.new.run(ast)
    # Un-nest everything embedded in on_pass/fail nodes except for binning and
    # flag setting
    ast = Processors::OnPassFailRemover.new.run(ast)
    ast = Processors::Condition.new.run(ast)
    ast = Processors::Flattener.new.run(ast)

  ###############################################################################
  ## Default Optimization
  ###############################################################################
  else
    ast = Processors::Condition.new.run(ast)
  end

  ###############################################################################
  ## Common cleanup
  ###############################################################################
  # Removes any empty on_pass and on_fail branches
  ast = Processors::EmptyBranchRemover.new.run(ast)
  ast
end

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



470
471
472
473
474
475
476
477
478
479
480
481
482
483
# File 'lib/origen_testers/atp/flow.rb', line 470

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


571
572
573
574
# File 'lib/origen_testers/atp/flow.rb', line 571

def context_changed?(options)
  options[:_dont_delete_conditions_] = true
  last_conditions != clean_conditions(open_conditions + [extract_conditions(options)])
end

#continue(options = {}) ⇒ Object



555
556
557
558
559
560
561
# File 'lib/origen_testers/atp/flow.rb', line 555

def continue(options = {})
  extract_meta!(options) do
    apply_conditions(options) do
      n0(:continue)
    end
  end
end

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



493
494
495
496
497
498
499
500
# File 'lib/origen_testers/atp/flow.rb', line 493

def cz(instance, cz_setup, options = {})
  extract_meta!(options) do
    apply_conditions(options) do
      node = n1(:cz, cz_setup)
      append_to(node) { test(instance, options) }
    end
  end
end

#describe_bin(number, description, options = {}) ⇒ Object

Record a description for a bin number



224
225
226
# File 'lib/origen_testers/atp/flow.rb', line 224

def describe_bin(number, description, options = {})
  @pipeline[0] = add_bin_description(@pipeline[0], number, description, type: :hard)
end

#describe_soft_bin(number, description, options = {}) ⇒ Object Also known as: describe_softbin

Record a description for a softbin number



229
230
231
# File 'lib/origen_testers/atp/flow.rb', line 229

def describe_soft_bin(number, description, options = {})
  @pipeline[0] = add_bin_description(@pipeline[0], number, description, type: :soft)
end

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

Disable a flow control variable



522
523
524
525
526
527
528
# File 'lib/origen_testers/atp/flow.rb', line 522

def disable(var, options = {})
  extract_meta!(options) do
    apply_conditions(options) do
      n1(:disable, var)
    end
  end
end

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

Enable a flow control variable



513
514
515
516
517
518
519
# File 'lib/origen_testers/atp/flow.rb', line 513

def enable(var, options = {})
  extract_meta!(options) do
    apply_conditions(options) do
      n1(:enable, var)
    end
  end
end

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

Group all tests generated within the given block

Examples:

flow.group "RAM Tests" do
  flow.test ...
  flow.test ...
end


241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/origen_testers/atp/flow.rb', line 241

def group(name, options = {}, &block)
  # The idiomatic way of creating a group in SMT8 is a sub-flow
  if tester.try(:smt8?)
    extract_meta!(options) do
      apply_conditions(options) do
        parent, sub_flow = *::Flow._sub_flow(name, options, &block)
        path = sub_flow.output_file.relative_path_from(Origen.file_handler.output_directory)
        ast = sub_flow.atp.raw
        name, *children = *ast
        nodes = [name]
        nodes << id(options[:id]) if options[:id]
        nodes << n1(:path, path.to_s)
        nodes += children
        ast = ast.updated :sub_flow, nodes,
                          file:        options.delete(:source_file) || source_file,
                          line_number: options.delete(:source_line_number) || source_line_number,
                          description: options.delete(:description) || description
        ast
      end
    end
  else
    extract_meta!(options) do
      apply_conditions(options) do
        children = [n1(:name, name)]
        children << n1(:bypass, options[:bypass]) if options[:bypass]
        if options[:comment] || options[:description] || options[:desc]
          children << n1(:comment, options[:comment] || options[:description] || options[:desc])
        end
        children << id(options[:id]) if options[:id]
        children << on_fail(options[:on_fail]) if options[:on_fail]
        children << on_pass(options[:on_pass]) if options[:on_pass]
        g = n(:group, children)
        append_to(g) { yield }
      end
    end
  end
end

#ids(options = {}) ⇒ Object



652
653
654
# File 'lib/origen_testers/atp/flow.rb', line 652

def ids(options = {})
  OrigenTesters::ATP::AST::Extractor.new.process(raw, [:id]).map { |node| node.to_a[0] }
end

#inspectObject



648
649
650
# File 'lib/origen_testers/atp/flow.rb', line 648

def inspect
  "<OrigenTesters::ATP::Flow:#{object_id} #{name}>"
end

#log(message, options = {}) ⇒ Object

Append a log message line to the flow



504
505
506
507
508
509
510
# File 'lib/origen_testers/atp/flow.rb', line 504

def log(message, options = {})
  extract_meta!(options) do
    apply_conditions(options) do
      n1(:log, message.to_s)
    end
  end
end

#loop(*args, &block) ⇒ Object



585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
# File 'lib/origen_testers/atp/flow.rb', line 585

def loop(*args, &block)
  unless args[0].keys.include?(:from) && args[0].keys.include?(:to)
    fail 'Loop must specify :from, :to'
  end
  # assume 1 if :step not provided
  unless args[0].keys.include?(:step)
    args[0][:step] = 1
  end
  # assume 1 if :test_num_inc not provided
  unless args[0].keys.include?(:test_num_inc)
    args[0][:test_num_inc] = 1
  end
  # Add node for set of flag to be used for loop
  unless args[0][:var].nil?
    set(args[0][:var], 0)
  end
  extract_meta!(options) do
    apply_conditions(options) do
      # always pass 5-element array to loop node to simplify downstream parser
      #   element, 'var', will be nil if not specified by loop call
      params = [args[0][:from], args[0][:to], args[0][:step], args[0][:var], args[0][:test_num_inc]]

      node = n(:loop, params)
      node = append_to(node) { block.call }
      node
    end
  end
end

#marshal_dumpObject

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.



98
99
100
# File 'lib/origen_testers/atp/flow.rb', line 98

def marshal_dump
  [@name, @program, Processors::Marshal.new.process(raw)]
end

#marshal_load(array) ⇒ 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.



103
104
105
106
# File 'lib/origen_testers/atp/flow.rb', line 103

def marshal_load(array)
  @name, @program, raw = array
  @pipeline = [raw]
end

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



485
486
487
488
489
490
491
# File 'lib/origen_testers/atp/flow.rb', line 485

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, options)
end

#rawObject

Returns the raw AST



109
110
111
112
113
114
115
116
117
118
119
# File 'lib/origen_testers/atp/flow.rb', line 109

def raw
  n = nil
  @pipeline.reverse_each do |node|
    if n
      n = node.updated(nil, node.children + [n])
    else
      n = node
    end
  end
  n
end

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

Insert explicitly rendered content in to the flow



547
548
549
550
551
552
553
# File 'lib/origen_testers/atp/flow.rb', line 547

def render(str, options = {})
  extract_meta!(options) do
    apply_conditions(options) do
      n1(:render, str)
    end
  end
end

#run(options = {}) ⇒ Object

Execute the given flow in the console



564
565
566
567
# File 'lib/origen_testers/atp/flow.rb', line 564

def run(options = {})
  Formatters::Datalog.run_and_format(ast, options)
  nil
end

#set(var, val, options = {}) ⇒ Object



538
539
540
541
542
543
544
# File 'lib/origen_testers/atp/flow.rb', line 538

def set(var, val, options = {})
  extract_meta!(options) do
    apply_conditions(options) do
      n2(:set, var, val)
    end
  end
end

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



530
531
532
533
534
535
536
# File 'lib/origen_testers/atp/flow.rb', line 530

def set_flag(flag, options = {})
  extract_meta!(options) do
    apply_conditions(options) do
      set_flag_node(flag)
    end
  end
end

#sub_flow(flow_node, options = {}) ⇒ Object



458
459
460
461
462
463
464
465
466
467
468
# File 'lib/origen_testers/atp/flow.rb', line 458

def sub_flow(flow_node, options = {})
  name, *children = *flow_node
  if options[:path]
    children = [name] + [n1(:path, options[:path])] + children
  else
    children = [name] + children
  end
  apply_conditions(options) do
    flow_node.updated(:sub_flow, children)
  end
end

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

Equivalent to calling test, but returns a sub_test node instead of adding it to the flow.

This is a helper to create sub_tests for inclusion in a top-level test node.



453
454
455
456
# File 'lib/origen_testers/atp/flow.rb', line 453

def sub_test(instance, options = {})
  temp = append_to(n0(:temp)) { test(instance, options) }
  temp.children.first.updated(:sub_test, nil)
end

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

Add a test line to the flow

Parameters:

  • the (String, Symbol)

    name of the test

  • options (Hash) (defaults to: {})

    a hash to describe the test’s attributes

Options Hash (options):

  • :id (Symbol)

    A unique test ID

  • :description (String)

    A description of what the test does, usually formatted in markdown

  • :on_fail (Hash)

    What action to take if the test fails, e.g. assign a bin

  • :on_pass (Hash)

    What action to take if the test passes

  • :conditions (Hash)

    What conditions must be met to execute the test



288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
# File 'lib/origen_testers/atp/flow.rb', line 288

def test(instance, options = {})
  extract_meta!(options) do
    apply_conditions(options) do
      if options[:on_fail].is_a?(Proc)
        before_on_fail = options.delete(:on_fail)
      end
      if options[:on_pass].is_a?(Proc)
        before_on_pass = options.delete(:on_pass)
      end
      # Allows any continue, bin, or soft bin argument passed in at the options top-level to be assumed
      # to be the action to take if the test fails
      if b = options.delete(:bin)
        options[:on_fail] ||= {}
        options[:on_fail][:bin] = b
      end
      if b = options.delete(:bin_description)
        options[:on_fail] ||= {}
        options[:on_fail][:bin_description] = b
      end
      if b = options.delete(:bin_attrs)
        options[:on_fail] ||= {}
        options[:on_fail][:bin_attrs] = b
      end
      if b = options.delete(:softbin) || b = options.delete(:sbin) || b = options.delete(:soft_bin)
        options[:on_fail] ||= {}
        options[:on_fail][:softbin] = b
      end
      if b = options.delete(:softbin_description) || options.delete(:sbin_description) || options.delete(:soft_bin_description)
        options[:on_fail] ||= {}
        options[:on_fail][:softbin_description] = b
      end
      if options.delete(:continue)
        options[:on_fail] ||= {}
        options[:on_fail][:continue] = true
      end
      if options.key?(:delayed)
        options[:on_fail] ||= {}
        options[:on_fail][:delayed] = options.delete(:delayed)
      end
      if f = options.delete(:flag_pass)
        options[:on_pass] ||= {}
        options[:on_pass][:set_flag] = f
      end
      if f = options.delete(:flag_fail)
        options[:on_fail] ||= {}
        options[:on_fail][:set_flag] = f
      end

      children = [n1(:object, instance)]

      name = (options[:name] || options[:tname] || options[:test_name])
      unless name
        [:name, :tname, :test_name].each do |m|
          name ||= instance.respond_to?(m) ? instance.send(m) : nil
        end
      end
      children << n1(:name, name) if name

      num = (options[:number] || options[:num] || options[:tnum] || options[:test_number])
      unless num
        [:number, :num, :tnum, :test_number].each do |m|
          num ||= instance.respond_to?(m) ? instance.send(m) : nil
        end
      end
      children << number(num) if num

      children << id(options[:id]) if options[:id]

      if levels = options[:level] || options[:levels]
        levels = [levels] unless levels.is_a?(Array)
        levels.each do |l|
          children << level(l[:name], l[:value], l[:unit] || l[:units])
        end
      end

      lims = options[:limit] || options[:limits]
      if lims || options[:lo] || options[:low] || options[:hi] || options[:high]
        if lims == :none || lims == 'none'
          children << n0(:nolimits)
        else
          lims = Array(lims) unless lims.is_a?(Array)
          if lo = options[:lo] || options[:low]
            lims << { value: lo, rule: :gte }
          end
          if hi = options[:hi] || options[:high]
            lims << { value: hi, rule: :lte }
          end
          lims.each do |l|
            if l.is_a?(Hash)
              children << n(:limit, [l[:value], l[:rule], l[:unit] || l[:units], l[:selector]])
            end
          end
        end
      end

      if pins = options[:pin] || options[:pins]
        pins = [pins] unless pins.is_a?(Array)
        pins.each do |p|
          if p.is_a?(Hash)
            children << pin(p[:name])
          else
            children << pin(p)
          end
        end
      end

      if pats = options[:pattern] || options[:patterns]
        pats = [pats] unless pats.is_a?(Array)
        pats.each do |p|
          if p.is_a?(Hash)
            children << pattern(p[:name], p[:path])
          else
            children << pattern(p)
          end
        end
      end

      if options[:meta]
        attrs = []
        options[:meta].each { |k, v| attrs << attribute(k, v) }
        children << n(:meta, attrs)
      end

      if options[:test_text]
        children << n(:test_text, [options[:test_text]])
      end

      if subs = options[:sub_test] || options[:sub_tests]
        subs = [subs] unless subs.is_a?(Array)
        subs.each do |s|
          children << s.updated(:sub_test, nil)
        end
      end

      if before_on_fail
        on_fail_node = on_fail(before_on_fail)
        if options[:on_fail]
          on_fail_node = on_fail_node.updated(nil, on_fail_node.children + on_fail(options[:on_fail]).children)
        end
        children << on_fail_node
      else
        children << on_fail(options[:on_fail]) if options[:on_fail]
      end

      if before_on_pass
        on_pass_node = on_pass(before_on_pass)
        if options[:on_pass]
          on_pass_node = on_pass_node.updated(nil, on_pass_node.children + on_pass(options[:on_pass]).children)
        end
        children << on_pass_node
      else
        children << on_pass(options[:on_pass]) if options[:on_pass]
      end

      children << priority(options[:priority]) if options[:priority]

      save_conditions
      n(:test, children)
    end
  end
end

#volatile(*flags) ⇒ Object

Indicate the that given flags should be considered volatile (can change at any time), which will prevent them from been touched by the optimization algorithms



217
218
219
220
221
# File 'lib/origen_testers/atp/flow.rb', line 217

def volatile(*flags)
  options = flags.pop if flags.last.is_a?(Hash)
  flags = flags.flatten
  @pipeline[0] = add_volatile_flags(@pipeline[0], flags)
end

#whenever(*expressions, &block) ⇒ Object



576
577
578
579
580
581
582
583
# File 'lib/origen_testers/atp/flow.rb', line 576

def whenever(*expressions, &block)
  if expressions.last.is_a?(Hash)
    options = expressions.pop
  else
    options = {}
  end
  flow_control_method(:whenever, expressions, options, &block)
end