Class: OrigenTesters::IGXLBasedTester::Base::TestInstances

Inherits:
Object
  • Object
show all
Includes:
Generator
Defined in:
lib/origen_testers/igxl_based_tester/base/test_instances.rb

Defined Under Namespace

Classes: IndexedString

Constant Summary collapse

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?, #platform, #reference_file, #render, #set_flow_description, #stats, #to_be_written?, #write_from_template, #write_to_file

Instance Method Details

#add(name, type, options = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/origen_testers/igxl_based_tester/base/test_instances.rb', line 17

def add(name, type, options = {})
  options = {
    test_instance_class: platform::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

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



169
170
171
# File 'lib/origen_testers/igxl_based_tester/base/test_instances.rb', line 169

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

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



147
148
149
# File 'lib/origen_testers/igxl_based_tester/base/test_instances.rb', line 147

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

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



161
162
163
# File 'lib/origen_testers/igxl_based_tester/base/test_instances.rb', line 161

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

#finalize(options = {}) ⇒ Object

:nodoc:



91
92
93
94
# File 'lib/origen_testers/igxl_based_tester/base/test_instances.rb', line 91

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

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



157
158
159
# File 'lib/origen_testers/igxl_based_tester/base/test_instances.rb', line 157

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

#group(name = nil, options = {}) {|@current_group| ... } ⇒ Object 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 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)


82
83
84
85
86
87
88
# File 'lib/origen_testers/igxl_based_tester/base/test_instances.rb', line 82

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

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



173
174
175
# File 'lib/origen_testers/igxl_based_tester/base/test_instances.rb', line 173

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

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



165
166
167
# File 'lib/origen_testers/igxl_based_tester/base/test_instances.rb', line 165

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

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



152
153
154
# File 'lib/origen_testers/igxl_based_tester/base/test_instances.rb', line 152

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

#sort!Object

:nodoc:



136
137
138
139
140
141
142
143
144
145
# File 'lib/origen_testers/igxl_based_tester/base/test_instances.rb', line 136

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

#uniq!Object

:nodoc:



96
97
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
# File 'lib/origen_testers/igxl_based_tester/base/test_instances.rb', line 96

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