module Origen module Tester class V93K module Generator class TestFunction attr_accessor :name, :type, :description # When defining attributes of a given test function here they must be defined # in the correct order ATTRS = { functional: [], general_pmu: %w(pins force_units force clamp_units clamp precharge_units precharge pass_min_units pass_min pass_max_units pass_max settling_time_units settling_time test_system_state term output_string mode ) } ALIASES = { desc: :description, general_pmu: { state: :test_system_state } } DEFAULTS = { description: 'A test function generated by Origen' } # Define the common aliases now, the instance type specific ones will # be created when the instance type is known ALIASES.each do |_alias, val| if val.is_a? Hash else define_method("#{_alias}=") do |v| send("#{val}=", v) end define_method("#{_alias}") do send(val) end end end def initialize(name, type, attrs = {}) @type = type self.name = name # Build the type specific attribute accessors ATTRS[@type.to_sym].each do |method| define_singleton_method("#{method}=") do |v| instance_variable_set("@#{method}".to_sym, v) end define_singleton_method("#{method}") do instance_variable_get("@#{method}".to_sym) end end # Build the type specific accessors (aliases) if ALIASES[@type.to_sym] ALIASES[@type.to_sym].each do |_alias, val| define_singleton_method("#{_alias}=") do |v| send("#{val}=", v) end define_singleton_method("#{_alias}") do send(val) end end end # Set the defaults DEFAULTS.each do |key, val| send("#{key}=", val) unless val.is_a?(Hash) end if DEFAULTS[@type.to_sym] DEFAULTS[@type.to_sym].each do |k, v| send("#{k}=", v) end end # Then the values that have been supplied attrs.each do |k, v| m = "#{k}=" send(m, v) if self.respond_to?(m) end end # Returns the fully formatted lines (an array) that should be inserted into a flow # sheet to include this test function def lines [ "#{name}:", "testfunction_description = \"#{description}\";", "testfunction_parameters = \"#{type};#{parameter_string}\";" ] end def parameter_string ATTRS[@type.to_sym].map { |attr| send(attr) }.compact.join(';') end end end end end end