I have a gem that supports two different libraries with a generic DUT model:
module MyGemLibrary
module RSpec
class DUT
include Origen::TopLevel
attr_accessor :force_import, :nick, :revision
def initialize(options = {})
options = {
force_import: false,
nick: :rspec,
revision: :a0
}.update(options)
@force_import = options[:force_import]
@nick = options[:nick]
@revision = options[:revision]
end
end
end
end
I have two rspec files:
myserver:ondie_devices $ ls spec
ringosc_spec.rb spec_helper.rb testtrans_spec.rb
What is the best known method for initializing the DUT and closing the DUT in each spec file? When I used a local variable to store the DUT I got this error:
myserver:ondie_devices $ origen specs
[INFO] 0.010[0.010] || OndieDevices: Loading ringosc model
Attempt to set an instance of OndieDevices::RSpec::DUT as the top level when there is already an instance of OndieDevices::RSpec::DUT defined as the top-level!
I have seen various ways of dong this but none seem to accomplish what I need done:
- prevent the error above
- Ensure Origen.top_level is initialized correctly such that theinstance attributes are readily available from within the gem code library. E.G.
An error occurred while loading ./spec/ringosc_spec.rb.
Failure/Error: Pathname.new("#{tmpdir}/#{Origen.top_level.nick}_#{Origen.top_level.revision}_ringosc_#{data_type}.bin")
NoMethodError:
undefined method `nick' for nil:NilClass
You can't manually instantiate multiple top-level objects, it needs to be done within the context of a target load/change.
The easiest way to do this for spec tests is by using anonymous targets - https://origen-sdk.org/origen/guides/runtime/programming/#Anonymous_Targets
That will also safely un-load any existing target (and its DUT) which will resolve your issue.
It is often common to do something like the above within a
before :eachblock to reload the target between tests, or in abefore :allblock to have the same target loaded for all tests in a spec file.