URL
https://opencores.org/ocsvn/soc_maker/soc_maker/trunk
Subversion Repositories soc_maker
[/] [soc_maker/] [trunk/] [spec/] [core_inst_spec.rb] - Rev 3
Go to most recent revision | Compare with Previous | Blame | View Log
###############################################################
#
# File: core_inst_spec.rb
#
# Author: Christian Hättich
#
# Project: System-On-Chip Maker
#
# Target: Linux / Windows / Mac
#
# Language: ruby
#
#
###############################################################
#
#
# Copyright (C) 2014 Christian Hättich - feddischson [ at ] opencores.org
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
###############################################################
#
# Description:
#
#
#
#
###############################################################
require_relative( 'spec_helper' )
describe SOCMaker::CoreInst, "structure and auto-completion functionallity" do
it "should raise an error, if parameters are not given as hash" do
file = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }
core = SOCMaker::CoreDef.new( "mycore", "rel1", file, "top" )
SOCMaker::lib.add_core( core )
expect{ SOCMaker::CoreInst.new( "mycorerel1", "not a hash" ) }.
to raise_error( SOCMaker::ERR::StructureError )
SOCMaker::lib.rm_core( core )
end
it "should raise an error, if parameters are given, which doesn't exist in the definition" do
file = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }
core = SOCMaker::CoreDef.new( "mycore", "rel1", file, "top" )
SOCMaker::lib.add_core( core )
expect{ SOCMaker::CoreInst.new( "mycorerel1", { "aparameter".to_sym => 4 } ) }.
to raise_error( SOCMaker::ERR::ValueError )
SOCMaker::lib.rm_core( core )
end
it "should auto-complete generics with default values" do
# create core with one file and one instance parameter
file = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }
parameters = { "param1".to_sym => SOCMaker::Parameter.new( "integer" ) }
core = SOCMaker::CoreDef.new( "mycore", "rel1", file, "top" )
core.inst_parameters = parameters
SOCMaker::lib.add_core( core )
inst = SOCMaker::CoreInst.new( "mycorerel1", {} )
inst.params[ :param1 ].should be == 0
SOCMaker::lib.rm_core( core )
end
end
describe SOCMaker::CoreDef, "object handling, en-decoding:" do
it "should be possible to encode and decode a core instance" do
file = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }
parameters = { "param1".to_sym => SOCMaker::Parameter.new( "integer" ) }
core = SOCMaker::CoreDef.new( "mycore", "rel1", file, "top" )
core.inst_parameters = parameters
SOCMaker::lib.add_core( core )
o1 = SOCMaker::CoreInst.new( "mycorerel1", {} )
yaml_str = o1.to_yaml
o2 = YAML::load( yaml_str )
o1.should be == o2
end
it "should return false for two non-equal objects" do
file = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }
parameters = { "param1".to_sym => SOCMaker::Parameter.new( "integer" ) }
core = SOCMaker::CoreDef.new( "mycore", "rel1", file, "top" )
core.inst_parameters = parameters
SOCMaker::lib.add_core( core )
o1 = SOCMaker::CoreInst.new( "mycorerel1" )
o2 = Marshal::load(Marshal.dump(o1))
o2.type << "X"
( o2 == o1 ).should be == false
o2 = Marshal::load(Marshal.dump(o1))
o2.params[ :param1 ] = 1
( o2 == o1 ).should be == false
end
end
Go to most recent revision | Compare with Previous | Blame | View Log