Class: OrigenTesters::Charz::Session

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

Overview

A charz session contains a collection of the final combinations of charz object (routines/profiles) and user options to determine how and what charz tests should be created the session should be checked in your interface to determine the current status and can be queried to make charz generation decisions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Session

Returns a new instance of Session.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/origen_testers/charz/session.rb', line 21

def initialize(options = {})
  @id = :empty_session
  @instances = []
  @current_instance = nil
  @stored_instance = nil
  @active = false
  @valid = false
  @defaults = {
    placement:         :inline,
    routines:          [],
    on_result:         nil,
    enables:           nil,
    flags:             nil,
    enables_and:       false,
    and_enables:       false,
    flags_and:         false,
    and_flags:         false,
    name:              'charz',
    charz_only:        false,
    force_keep_parent: false
  }.merge((options[:defaults] || {}))
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)



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

def method_missing(method, *args, &block)
  deprecated_methods = [
    :name,
    :placement,
    :on_result,
    :enables,
    :flags,
    :routines,
    :and_enables,
    :enables_and,
    :and_flags,
    :flags_and,
    :charz_only,
    :force_keep_parent
  ]
  if deprecated_methods.include?(method.to_sym) || deprecated_methods.include?(method.to_s[0..-2].to_sym)
    Origen.log.deprecate "charz_session.#{method} has been deprecated. Please query charz_instance.#{method} instead."
    if current_instance.nil? && !valid
      Origen.log.error "blocked call of 'charz_session.#{method}'!"
      Origen.log.warn 'The charz instance attributes are no longer accessible when the session is invalid!'
    else
      current_instance.send(method, *args, &block)
    end
  else
    super
  end
end

Instance Attribute Details

#current_instanceProfile

Returns Set when looping over instances via #loop_instances. The interface can query the charz_instance for more detailed info.

Returns:

  • (Profile)

    Set when looping over instances via #loop_instances. The interface can query the charz_instance for more detailed info



19
# File 'lib/origen_testers/charz/session.rb', line 19

attr_accessor :id, :instances, :current_instance, :valid, :defaults, :stored_instance

#defaultsHash

Returns list of values to instantiate the inherited attributes from Profile with if not altered by the session update.

Returns:

  • (Hash)

    list of values to instantiate the inherited attributes from Profile with if not altered by the session update



19
# File 'lib/origen_testers/charz/session.rb', line 19

attr_accessor :id, :instances, :current_instance, :valid, :defaults, :stored_instance

#idSymbol

Returns current session ID. Will be a concatenation of the instances' ids.

Returns:

  • (Symbol)

    current session ID. Will be a concatenation of the instances' ids



19
20
21
# File 'lib/origen_testers/charz/session.rb', line 19

def id
  @id
end

#instancesArray

Returns list of active instances (which are essentially Profiles).

Returns:

  • (Array)

    list of active instances (which are essentially Profiles)



19
# File 'lib/origen_testers/charz/session.rb', line 19

attr_accessor :id, :instances, :current_instance, :valid, :defaults, :stored_instance

#stored_instanceProfile

Returns This is to store the instance that the interface is storing. Its to support a legacy usecase of querying the session for instance level info during EOF.

Returns:

  • (Profile)

    This is to store the instance that the interface is storing. Its to support a legacy usecase of querying the session for instance level info during EOF



19
# File 'lib/origen_testers/charz/session.rb', line 19

attr_accessor :id, :instances, :current_instance, :valid, :defaults, :stored_instance

#validBoolean

Returns whether or not the current session setup is valid, if not then charz wont be created.

Returns:

  • (Boolean)

    whether or not the current session setup is valid, if not then charz wont be created



19
# File 'lib/origen_testers/charz/session.rb', line 19

attr_accessor :id, :instances, :current_instance, :valid, :defaults, :stored_instance

Instance Method Details

#active?Boolean Also known as: active

Returns:

  • (Boolean)


64
65
66
# File 'lib/origen_testers/charz/session.rb', line 64

def active?
  !!@active
end

#charz_onlyObject



54
55
56
57
# File 'lib/origen_testers/charz/session.rb', line 54

def charz_only
  Origen.log.deprecate '#charz_only has been deprecated in favor of #charz_only? It is no longer an attribute, instead a runtime calculation.'
  charz_only?
end

#charz_only?Boolean

Returns:

  • (Boolean)


48
49
50
51
52
# File 'lib/origen_testers/charz/session.rb', line 48

def charz_only?
  any_only = instances.any?(&:charz_only)
  any_force = instances.any?(&:force_keep_parent)
  !any_force && any_only && !on_result?
end

#loop_instancesObject



85
86
87
88
89
90
91
# File 'lib/origen_testers/charz/session.rb', line 85

def loop_instances
  instances.each do |charz_instance|
    @current_instance = charz_instance
    yield
    @current_instance = nil
  end
end

#on_result?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/origen_testers/charz/session.rb', line 44

def on_result?
  instances.any? { |charz_instance| !charz_instance.on_result.nil? }
end

#pauseObject

Pauses the current session's activity while maintaining everthing else about the sessions state



60
61
62
# File 'lib/origen_testers/charz/session.rb', line 60

def pause
  @active = false
end

#resumeObject

Resume activity, if the session is valid



70
71
72
73
74
# File 'lib/origen_testers/charz/session.rb', line 70

def resume
  if @valid
    @active = true
  end
end

#update(charz_tuples) ⇒ Object

Takes a CharzTuple and queries it to setup an instance's attributes the attributes values can be set from 3 different sources, in order of priority (first is most important):

- options
- charz object (Profile or Routine)
- defaults

If the resulting session is invalid, @valid will turn false. Otherwise, the session becomes active



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/origen_testers/charz/session.rb', line 100

def update(charz_tuples)
  @instances = []
  @valid = false
  if charz_tuples.nil? || charz_tuples.empty?
    @active = false
    @valid = false
    @current_instance = nil
    return @valid
  end
  @defined_routines = charz_tuples.map(&:defined_routines).flatten.uniq.compact

  charz_tuples.each do |charz_tuple|
    profile_options = assign_by_priority(charz_tuple)
    @instances << Profile.new(charz_tuple.obj.id, profile_options.merge(defined_routines: @defined_routines))
  end
  @id = instances.map(&:id).join('_').to_sym
  @active = true
  @valid = true
end