Class: OrigenTesters::IGXLBasedTester::Base::CustomTestInstance

Inherits:
Object
  • Object
show all
Defined in:
lib/origen_testers/igxl_based_tester/base/custom_test_instance.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ CustomTestInstance

Returns a new instance of CustomTestInstance.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/origen_testers/igxl_based_tester/base/custom_test_instance.rb', line 52

def initialize(name, options = {})
  @append_version = true
  self.name = name
  # Add any methods
  if options[:methods][:methods]
    methods = options[:methods][:methods]
    @finalize = methods[:finalize]
    methods.each do |method_name, function|
      unless method_name == :finalize
        var_name = "@#{method_name}".gsub(/=|\?/, '_')
        instance_variable_set(var_name, function)
        define_singleton_method method_name do |*args|
          instance_variable_get(var_name).call(self, *args)
        end
      end
    end
  end
  # Create attributes corresponding to the test method type represented
  # by this method instance
  options[:methods].each do |attr, arg_default|
    arg_default = [arg_default] unless arg_default.is_a?(Array)
    unless attr == :aliases || attr == :methods
      clean_attr = clean_attr_name(attr)
      arg = arg_default[0]
      default = arg_default[1]
      allowed = arg_default[2]
      aliases = [clean_attr]
      aliases << clean_attr.underscore if clean_attr.underscore != clean_attr
      aliases.each do |alias_|
        define_singleton_method("#{alias_}=") do |v|
          if allowed
            unless allowed.include?(v)
              fail "Cannot set #{alias_} to #{v}, valid values are: #{allowed.join(', ')}"
            end
          end
          instance_variable_set("@#{arg}", v)
        end
        define_singleton_method(alias_) do
          instance_variable_get("@#{arg}")
        end
      end
      send("#{arg}=", default)
    end
  end
  if options[:methods][:aliases]
    options[:methods][:aliases].each do |alias_, attr|
      clean_attr = clean_attr_name(attr)
      define_singleton_method("#{alias_}=") do |v|
        send("#{clean_attr}=", v)
      end
      define_singleton_method(alias_) do
        send(clean_attr)
      end
    end
  end
  # Set the defaults
  self.class::TEST_INSTANCE_DEFAULTS.each do |k, v|
    send("#{k}=", v) if self.respond_to?("#{k}=", v)
  end
  # Finally set any initial values that have been supplied
  options[:attrs].each do |k, v|
    send("#{k}=", v) if respond_to?("#{k}=")
  end
end

Instance Attribute Details

#append_versionObject

Returns the value of attribute append_version.



5
6
7
# File 'lib/origen_testers/igxl_based_tester/base/custom_test_instance.rb', line 5

def append_version
  @append_version
end

#finalizeObject

Returns the value of attribute finalize.



5
6
7
# File 'lib/origen_testers/igxl_based_tester/base/custom_test_instance.rb', line 5

def finalize
  @finalize
end

#indexObject

Returns the value of attribute index.



5
6
7
# File 'lib/origen_testers/igxl_based_tester/base/custom_test_instance.rb', line 5

def index
  @index
end

#libraryObject (readonly)

Returns the object representing the test instance library that the given test instance is defined in



9
10
11
# File 'lib/origen_testers/igxl_based_tester/base/custom_test_instance.rb', line 9

def library
  @library
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/origen_testers/igxl_based_tester/base/custom_test_instance.rb', line 5

def type
  @type
end

#versionObject

Returns the value of attribute version.



5
6
7
# File 'lib/origen_testers/igxl_based_tester/base/custom_test_instance.rb', line 5

def version
  @version
end

Class Method Details

.attrsObject



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/origen_testers/igxl_based_tester/base/custom_test_instance.rb', line 40

def self.attrs
  @attrs ||= begin
    attrs = self::TEST_INSTANCE_ATTRS.dup

    self::TEST_INSTANCE_EXTRA_ARGS.times do |i|
      attrs << "arg#{i}"
    end
    attrs << 'comment'
    attrs
  end
end

.defineObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/origen_testers/igxl_based_tester/base/custom_test_instance.rb', line 11

def self.define
  # Generate accessors for all attributes and their aliases
  attrs.each do |attr|
    writer = "#{attr}=".to_sym
    reader = attr.to_sym
    attr_reader attr.to_sym unless method_defined? reader
    attr_writer attr.to_sym unless method_defined? writer
  end

  # Define the common aliases now, the instance type specific ones will
  # be created when the instance type is known
  self::TEST_INSTANCE_ALIASES.each do |_alias, val|
    writer = "#{_alias}=".to_sym
    reader = _alias.to_sym
    unless val.is_a? Hash
      unless method_defined? writer
        define_method("#{_alias}=") do |v|
          send("#{val}=", v)
        end
      end
      unless method_defined? reader
        define_method("#{_alias}") do
          send(val)
        end
      end
    end
  end
end

Instance Method Details

#==(other_instance) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/origen_testers/igxl_based_tester/base/custom_test_instance.rb', line 117

def ==(other_instance)
  self.class == other_instance.class &&
    unversioned_name.to_s == other_instance.unversioned_name.to_s &&
    self.class.attrs.all? do |attr|
      # Exclude test name, already examined above and don't want to include
      # the version in the comparison
      if attr == 'test_name'
        true
      else
        send(attr) == other_instance.send(attr)
      end
    end
end

#nameObject Also known as: test_name



144
145
146
147
148
149
150
# File 'lib/origen_testers/igxl_based_tester/base/custom_test_instance.rb', line 144

def name
  if version && @append_version
    "#{@test_name}_v#{version}"
  else
    @test_name.to_s
  end
end

#name=(val) ⇒ Object



153
154
155
# File 'lib/origen_testers/igxl_based_tester/base/custom_test_instance.rb', line 153

def name=(val)
  self.test_name = val
end

#to_s(override_name = nil) ⇒ Object

Returns the fully formatted test instance for insertion into an instance sheet



132
133
134
135
136
137
138
139
140
141
142
# File 'lib/origen_testers/igxl_based_tester/base/custom_test_instance.rb', line 132

def to_s(override_name = nil)
  l = "\t"
  self.class.attrs.each do |attr|
    if attr == 'test_name' && override_name
      l += "#{override_name}\t"
    else
      l += "#{send(attr)}\t"
    end
  end
  "#{l}"
end

#unversioned_nameObject



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

def unversioned_name
  @test_name.to_s
end