Class: Origen::Tester::J750::Generator::TestInstances

Inherits:
Object
  • Object
show all
Includes:
Generator
Defined in:
lib/origen/tester/j750/generator/test_instances.rb

Defined Under Namespace

Classes: IndexedString

Constant Summary

TEMPLATE =
"#{Origen.top}/lib/origen/tester/j750/generator/templates/instances.txt.erb"
OUTPUT_POSTFIX =
'instances'

Instance Method Summary (collapse)

Methods included from Generator

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

Instance Method Details

- (Object) add(name, type, options = {})



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/origen/tester/j750/generator/test_instances.rb', line 19

def add(name, type, options = {})
  options = {
    test_instance_class: TestInstance
  }.merge(options)
  ins = options.delete(:test_instance_class).new(name, type, options)
  if @current_group
    @current_group << ins
  else
    collection << ins
  end
  c = Origen.interface.consume_comments
  Origen.interface.descriptions.add_for_test_definition(name, c)
  ins
end

- (Object) apmu_powersupply(name, options = {})



171
172
173
# File 'lib/origen/tester/j750/generator/test_instances.rb', line 171

def apmu_powersupply(name, options = {})
  add(name, :apmu_powersupply, options)
end

- (Object) bpmu(name, options = {}) Also known as: board_pmu



149
150
151
# File 'lib/origen/tester/j750/generator/test_instances.rb', line 149

def bpmu(name, options = {})
  add(name, :board_pmu, options)
end

- (Object) empty(name, options = {})



163
164
165
# File 'lib/origen/tester/j750/generator/test_instances.rb', line 163

def empty(name, options = {})
  add(name, :empty, options)
end

- (Object) finalize(_options = {})

:nodoc:



93
94
95
96
# File 'lib/origen/tester/j750/generator/test_instances.rb', line 93

def finalize(_options = {}) # :nodoc:
  uniq!
  sort!
end

- (Object) functional(name, options = {})



159
160
161
# File 'lib/origen/tester/j750/generator/test_instances.rb', line 159

def functional(name, options = {})
  add(name, :functional, options)
end

- (Object) group(name = nil, options = {}) {|@current_group| ... } Also known as: add_group

IG-XL doesn't have a formal instance group type and instead declares them anonymously whenever test instances of the same name appear consecutively in the test instance sheet. However when it comes to generating a test program life becomes much easier if we have a way to explicitly declare instances as part of a group - this makes duplicate tracking and sorting of the test instance sheet much easier.

Use this method to generate instance groups via a block. Within the the block you should generate instances as normal and they will automatically be assigned to the current group. Note that the name of the instances generated within the group is discarded and replaced with the name of the group. Origen automatically appends “grp” to this name to highlight instances that were generated as part of the group.

test_instances.group("erase_all_blocks") do |group|
  # Generate instances here as normal
  test_instances.functional("erase_blk0")
  test_instances.functional("erase_blk1")
end

The group object is passed into the block but usually you should not need to interact with this directly except maybe to set the name if it is not yet established at the point where the group is initiated:

test_instances.group do |group|
  # Generate instances here as normal
  group.name = "group_blah"
end

A common way to generate groups is to create a helper method in your application which is responsible for creating groups as required:

def group_wrapper(name, options)
  if options[:by_block]
    test_instances.group(name) do |group|
      yield group
    end
  else
    yield
  end
end

In that case the group argument becomes quite useful for branching based on whether you are generating a group or standalone instances:

group_wrapper(name, options) do |group|
  if group
    # Generate group instances
  else
    # Generate standalone instances
  end
end

Yields:

  • (@current_group)


84
85
86
87
88
89
90
# File 'lib/origen/tester/j750/generator/test_instances.rb', line 84

def group(name = nil, options = {})
  name, options = nil, name if name.is_a?(Hash)
  @current_group = TestInstanceGroup.new(name, options)
  collection << @current_group
  yield @current_group
  @current_group = nil
end

- (Object) mto_memory(name, options = {})



175
176
177
# File 'lib/origen/tester/j750/generator/test_instances.rb', line 175

def mto_memory(name, options = {})
  add(name, :mto_memory, options)
end

- (Object) other(name, options = {})



167
168
169
# File 'lib/origen/tester/j750/generator/test_instances.rb', line 167

def other(name, options = {})
  add(name, :other, options)
end

- (Object) ppmu(name, options = {}) Also known as: pin_pmu



154
155
156
# File 'lib/origen/tester/j750/generator/test_instances.rb', line 154

def ppmu(name, options = {})
  add(name, :pin_pmu, options)
end

- (Object) sort!

:nodoc:



138
139
140
141
142
143
144
145
146
147
# File 'lib/origen/tester/j750/generator/test_instances.rb', line 138

def sort! # :nodoc:
  # Present the instances in the final sheet in alphabetical order
  collection.map!.with_index do |ins, _i|
    if ins.is_a?(String)   # Can happen if content has been rendered in from a template
      ins = IndexedString.new(ins)
    end
    ins
  end
  collection.sort! { |a, b| [a.name.to_s] <=> [b.name.to_s] }
end

- (Object) uniq!

:nodoc:



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/origen/tester/j750/generator/test_instances.rb', line 98

def uniq! # :nodoc:
  uniques = []
  versions = {}
  multi_version_tests = {}
  collection.each do |instance|
    # If a uniquely named instance is found add it, otherwise update the version
    # of the current instance to match that of the existing instance that it duplicates
    unless uniques.any? do |i|
      if i == instance
        instance.version = i.version
        true
      else
        false
      end
    end
      if instance.respond_to?(:version=)
        versions[instance.unversioned_name] ||= 0
        versions[instance.unversioned_name] += 1
        if versions[instance.unversioned_name] > 1
          multi_version_tests[instance.unversioned_name] = true
        end
        instance.version = versions[instance.unversioned_name]
      end
      uniques << instance
    end
  end
  # This final loop disables the version identifier for tests that have only a single version,
  # this makes it clearer when multiple versions exist - whenever you see a v1 you know there
  # is at least a v2 also.
  collection.map! do |instance|
    if instance.respond_to?(:version=)
      unless multi_version_tests[instance.unversioned_name]
        instance.append_version = false
      end
    end
    instance
  end
  self.collection = uniques
end