Class: OrigenTesters::Charz::Profile

Inherits:
Object
  • Object
show all
Defined in:
lib/origen_testers/charz/profile.rb

Overview

A Charz Profile Used to store characterization routines as well as flow control, conditional execution, and test placement meta data

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, options, &block) ⇒ Profile

Returns a new instance of Profile.



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/origen_testers/charz/profile.rb', line 24

def initialize(id, options, &block)
  @id = id
  @id = @id.symbolize unless id.is_a? Symbol
  options.each { |k, v| instance_variable_set("@#{k}", v) }
  (block.arity < 1 ? (instance_eval(&block)) : block.call(self)) if block_given?
  @name ||= id
  @placement ||= :inline
  @defined_routines = options.delete(:defined_routines)
  attrs_ok?
  massage_gates
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/origen_testers/charz/profile.rb', line 182

def method_missing(m, *args, &block)
  ivar = "@#{m.to_s.gsub('=', '')}"
  ivar_sym = ":#{ivar}"
  if m.to_s =~ /=$/
    define_singleton_method(m) do |val|
      instance_variable_set(ivar, val)
    end
  elsif instance_variables.include? ivar_sym
    instance_variable_get(ivar)
  else
    define_singleton_method(m) do
      instance_variable_get(ivar)
    end
  end
  send(m, *args, &block)
end

Instance Attribute Details

#and_enablesObject

Returns the value of attribute and_enables.



22
23
24
# File 'lib/origen_testers/charz/profile.rb', line 22

def and_enables
  @and_enables
end

#and_flagsObject

Returns the value of attribute and_flags.



22
23
24
# File 'lib/origen_testers/charz/profile.rb', line 22

def and_flags
  @and_flags
end

#charz_onlyBoolean

Returns indicates if the point tests should or shouldn't be added to the flow.

Returns:

  • (Boolean)

    indicates if the point tests should or shouldn't be added to the flow



22
# File 'lib/origen_testers/charz/profile.rb', line 22

attr_accessor :id, :name, :placement, :on_result, :enables, :flags, :routines, :charz_only, :force_keep_parent, :and_enables, :and_flags

#enablesSymbol, ...

Returns enable gates to be wrapped around the resulting charz tests.

Returns:

  • (Symbol, String, Array, Hash)

    enable gates to be wrapped around the resulting charz tests



22
# File 'lib/origen_testers/charz/profile.rb', line 22

attr_accessor :id, :name, :placement, :on_result, :enables, :flags, :routines, :charz_only, :force_keep_parent, :and_enables, :and_flags

#flagsSymbol, ...

Returns flag gates to be wrapped around the resulting charz tests.

Returns:

  • (Symbol, String, Array, Hash)

    flag gates to be wrapped around the resulting charz tests



22
# File 'lib/origen_testers/charz/profile.rb', line 22

attr_accessor :id, :name, :placement, :on_result, :enables, :flags, :routines, :charz_only, :force_keep_parent, :and_enables, :and_flags

#force_keep_parentObject

Returns the value of attribute force_keep_parent.



22
23
24
# File 'lib/origen_testers/charz/profile.rb', line 22

def force_keep_parent
  @force_keep_parent
end

#idSymbol

Returns the id of the current profile, used as a key in OrigenTesters::Charz#charz_profiles hash.

Returns:

  • (Symbol)

    the id of the current profile, used as a key in OrigenTesters::Charz#charz_profiles hash



22
23
24
# File 'lib/origen_testers/charz/profile.rb', line 22

def id
  @id
end

#nameSymbol

Returns the value used (if the user decides) to generate the name of the created charz test. defaults to the value of @id.

Returns:

  • (Symbol)

    the value used (if the user decides) to generate the name of the created charz test. defaults to the value of @id



22
# File 'lib/origen_testers/charz/profile.rb', line 22

attr_accessor :id, :name, :placement, :on_result, :enables, :flags, :routines, :charz_only, :force_keep_parent, :and_enables, :and_flags

#on_resultSymbol

Returns indicates if the resulting charz tests are depending on the point tests result, valid values include :on_fail, and :on_pass.

Returns:

  • (Symbol)

    indicates if the resulting charz tests are depending on the point tests result, valid values include :on_fail, and :on_pass



22
# File 'lib/origen_testers/charz/profile.rb', line 22

attr_accessor :id, :name, :placement, :on_result, :enables, :flags, :routines, :charz_only, :force_keep_parent, :and_enables, :and_flags

#placementSymbol

Returns placement of the to be created charz tests, defaults to inline, accepts :eof as well. Other placements can be used as well if @valid_placements is altered.

Returns:

  • (Symbol)

    placement of the to be created charz tests, defaults to inline, accepts :eof as well. Other placements can be used as well if @valid_placements is altered



22
# File 'lib/origen_testers/charz/profile.rb', line 22

attr_accessor :id, :name, :placement, :on_result, :enables, :flags, :routines, :charz_only, :force_keep_parent, :and_enables, :and_flags

#routinesArray

Returns list of charz routines to be called under this profile.

Returns:

  • (Array)

    list of charz routines to be called under this profile



22
# File 'lib/origen_testers/charz/profile.rb', line 22

attr_accessor :id, :name, :placement, :on_result, :enables, :flags, :routines, :charz_only, :force_keep_parent, :and_enables, :and_flags

Instance Method Details

#attrs_ok?Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
# File 'lib/origen_testers/charz/profile.rb', line 36

def attrs_ok?
  return if @quality_check == false

  unless @routines.is_a?(Array)
    Origen.log.error "Profile #{id}: routines is expected to be of type <Array>, but is instead of type <#{@routines.class}>!"
    fail
  end

  # allowing a config for empty routines for usecase of
  # determining routines on the fly dynamically
  if @routines.empty? && !@allow_empty_routines
    Origen.log.error "Profile #{id}: routines array is empty!"
    Origen.log.warn "If you'd like to enable profile creation without routines, set the profile's @allow_empty_routines attribute to true"
    fail
  end

  unknown_routines = @routines - @defined_routines
  unless unknown_routines.empty?
    Origen.log.error "Profile #{id}: unknown routines: #{unknown_routines}"
    fail
  end

  @valid_placements ||= [:inline, :eof]
  unless @valid_placements.include? @placement
    Origen.log.error "Profile #{id}: invalid placement value, must be one of: #{@valid_placements}"
    fail
  end

  if @on_result
    @valid_on_results ||= [:on_fail, :fail, :failed, :on_pass, :pass, :passed]
    unless @valid_on_results.include?(@on_result)
      Origen.log.error "Profile #{id}: invalid on_result value, must be one of: #{@valid_on_results}"
      fail
    end
  end

  if @charz_only && @on_result
    Origen.log.error "Profile #{id}: @charz_only is set, but @on_result (#{@on_result}) requires the parent test to exist in the flow"
    fail
  end

  unless @gate_checks == false
    if @and_enables && @and_flags
      Origen.log.error "@and_enables and @and_flags are both set to true. Please only 'and' one gate type"
      fail
    end
    if @and_enables
      gate_check(@flags, :flags) if @flags
      gate_check_and(@enables, :enables, @flags) if @enables
    elsif @and_flags
      gate_check(@enables, :enables) if @enables
      gate_check_and(@flags, :flags, @enables) if @flags
    else
      gate_check(@enables, :enable) if @enables
      gate_check(@flags, :flags) if @flags
    end
  end
end

#gate_check(gates, gate_type) ⇒ Object



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
137
138
139
140
# File 'lib/origen_testers/charz/profile.rb', line 109

def gate_check(gates, gate_type)
  case gates
  when Symbol, String
    return
  when Array
    unknown_gates = gates.reject { |gate| [String, Symbol].include? gate.class }
    if unknown_gates.empty?
      return
    else
      Origen.log.error "Profile #{id}: Unknown #{gate_type} type(s) in #{gate_type} array."
      Origen.log.error "Arrays must contain Strings and/or Symbols, but #{unknown_gates.map(&:class).uniq } were found in #{gates}"
      fail
    end
  when Hash
    gates.each do |gate, gated_routines|
      if gate.is_a? Hash
        Origen.log.error "Profile #{id}: #{gate_type} Hash keys cannot be of type Hash, but only Symbol, String, or Array"
        fail
      end
      gate_check(gate, gate_type)
      gated_routines = [gated_routines] unless gated_routines.is_a? Array
      unknown_routines = gated_routines - @defined_routines
      unless unknown_routines.empty?
        Origen.log.error "Profile #{id}: unknown routines found in @#{gate_type}[#{gate.is_a?(Symbol) ? ':' : ''}#{gate}]: #{unknown_routines}"
        fail
      end
    end
  else
    Origen.log.error "Profile #{id}: Unknown #{gate_type} type: #{gates.class}. #{gate_type} must be of type Symbol, String, Array, or Hash"
    fail
  end
end

#gate_check_and(gates, gate_type, other_gate) ⇒ Object



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
# File 'lib/origen_testers/charz/profile.rb', line 142

def gate_check_and(gates, gate_type, other_gate)
  if other_gate.is_a? Hash
    Origen.log.error "Profile #{id}: #{other_gate} When using &&-ing feature, the non-anded gate can not be of type hash."
    fail
  end
  case gates
  when Symbol, String
    return
  when Array
    unknown_gates = gates.reject { |gate| [String, Symbol].include? gate.class }
    if unknown_gates.empty?
      return
    else
      Origen.log.error "Profile #{id}: Unknown #{gate_type} type(s) in #{gate_type} array."
      Origen.log.error "Arrays must contain Strings and/or Symbols, but #{unknown_gates.map(&:class).uniq } were found in #{gates}"
      fail
    end
  when Hash
    gates.each do |gated_routine, gates|
      if gated_routine.is_a? Hash
        Origen.log.error "Profile #{id}: #{gate_type} Hash keys cannot be of type Hash, but only Symbol, String, or Array"
        fail
      end
      unless @defined_routines.include?(gated_routine)
        Origen.log.error "Profile #{id}: #{gated_routine} Hash keys for &&-ed gates must be defined routines."
        fail
      end
      gates = [gates] unless gates.is_a? Array
      unknown_gates = gates.reject { |gate| [String, Symbol].include? gate.class }
      unless unknown_gates.empty?
        Origen.log.error "Gate array must contain Strings and/or Symbols, but #{unknown_gates.map(&:class).uniq } were found in #{gates}"
        fail
      end
    end
  else
    Origen.log.error "Profile #{id}: Unknown #{gate_type} type: #{gates.class}. #{gate_type} must be of type Symbol, String, Array, or Hash"
    fail
  end
end

#massage_gatesObject

convert hash gates to set convert their routines to type array if not already



96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/origen_testers/charz/profile.rb', line 96

def massage_gates
  if @enables.is_a?(Hash)
    @enables = {}.tap do |new_h|
      @enables.each { |gates, routines| new_h[gates] = [routines].flatten }
    end
  end
  if @flags.is_a?(Hash)
    @flags = {}.tap do |new_h|
      @flags.each { |gates, routines| new_h[gates] = [routines].flatten }
    end
  end
end