URL
https://opencores.org/ocsvn/soc_maker/soc_maker/trunk
Subversion Repositories soc_maker
[/] [soc_maker/] [trunk/] [spec/] [soc_def_spec.rb] - Rev 8
Go to most recent revision | Compare with Previous | Blame | View Log
################################################################# File: soc_def_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:# Test spec. for SOCMaker::SOCDef##################################################################require_relative( 'spec_helper' )describe SOCMaker::SOCDef, "structure verification for loading a core-definition" do# not implemented at the moment# test for invalid path# it "should raise an error if a non-existing path is given" do# expect { SOCMaker::from_f( 'blabla.txt' ) }.# to raise_error( IOError )# end## A yaml example, which contains# - a full definition# - an interface with one port# - one hdl file# - one instance parameter# - one static parameter#FULL_SOC_YAML = '''SOCM_SOCname: my_socdescription: A test SOCversion: rel2date: 1.1.2014license: LGPLlicensefile:toplevel: soc_topauthor: Christian Haettichauthormail: feddischson@opencores.orgrepocmd: svn co http://some-address/'''SOC_YAML_WITH_CORE = '''SOCM_SOCname: my_socdescription: A test SOCversion: rel2date: 1.1.2014license: LGPLlicensefile:author: Christian Haettichauthormail: feddischson@opencores.orgrepocmd: svn co http://some-address/toplevel: soc_topcores::inst1: SOCM_INSTtype: mycorerel1'''# process all valid YAMLs# each should result in a CoreDefit 'should return a class of type SOCDef when loading a full soc-def' doSOCMaker::from_s( FULL_SOC_YAML ).class.should == SOCMaker::SOCDefendit "should rise an error if soc is loaded with a core, which is not in our library" doSOCMaker::lib.clearexpect { SOCMaker::from_s( SOC_YAML_WITH_CORE ).consistency_check }.to raise_error( SOCMaker::ERR::LibError )endit "should return an SOC-object if soc is loaded with a core, which is in our library" dofile = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }core = SOCMaker::CoreDef.new( "mycore", "rel1", file, "top" )SOCMaker::lib.add_core( core )soc = SOCMaker::from_s( SOC_YAML_WITH_CORE )soc.class.should be SOCMaker::SOCDefendenddescribe SOCMaker::SOCDef, "processing verification" dobefore( :each )dofile = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }core = SOCMaker::CoreDef.new( "mycore", "rel1", file, "top" )SOCMaker::lib.add_core( core )@soc = SOCMaker::SOCDef.new( "test-soc", "v1", "my_soc_top" )enddescribe "adding/removing cores, connections etc." doit "inst_in_use should return true, if there is already an core instance with that name" do@soc.cores[ :core_inst ] = SOCMaker::CoreInst.new( "mycorerel1" )@soc.inst_in_use?( "core_inst" ).should be == trueendit "inst_in_use should return false, if there is no core instance with that name" do@soc.inst_in_use?( "core_inst" ).should be == falseendit "inst_in_use should return true, if there is already an connection instance with that name" do@soc.cons[ :a_con ] = { rule: "or", mapping: [ { :core_a => :ifc_a }, { :core_b => :ifc_b } ] }@soc.inst_in_use?( "a_con" ).should be == trueendit "removing a core instance should be possible" do@soc.cores[ :core_inst ] = SOCMaker::CoreInst.new( "mycorerel1" )@soc.inst_in_use?( "core_inst" ).should be == true@soc.rm( "core_inst" ).should be == true@soc.inst_in_use?( "core_inst" ).should be == falseendit "removing a connection instance should be possible" do@soc.cons[ :a_con ] = { rule: "or", mapping: [ { :core_a => :ifc_a }, { :core_b => :ifc_b } ] }@soc.inst_in_use?( "a_con" ).should be == true@soc.rm( "a_con" ).should be == true@soc.inst_in_use?( "a_con" ).should be == falseendit "should return false, when removing a non-existance instance" do@soc.rm( "a_con" ).should be == falseendit "should return nil if a instance is added twice" do@soc.cores[ :core_inst ] = SOCMaker::CoreInst.new( "mycorerel1" )@soc.add_core( "mycore", "rel1", "core_inst" ).should be == falseendit "should return non-nil value, if a instance is added once" do@soc.add_core( "mycore", "rel1", "core_inst" ).should_not be == falseendit "should return nil if a connection is added twice" do@soc.cons[ :a_con ] = { rule: "or", mapping: [ { :core_a => :ifc_a }, { :core_b => :ifc_b } ] }@soc.add_connection( "core_a", "ifc_a", "core_c", "ifc_b", "a_con" ).should be == nilendit "should raise a library error when adding an unknown core" doexpect{ @soc.add_core( "some_unknown_core", "v_xyz", "test" ) }.to raise_error( SOCMaker::ERR::LibError )endit "should create a dir and return the absolute path for a core inside the build/hdl dir" doSOCMaker::conf[ :build_dir ] = "./spec/tmp_build"SOCMaker::conf[ :hdl_dir ] = "hdl"path = File.expand_path "./spec/tmp_build/hdl/a_core"FileUtils.rmdir( path ) if File.directory?( path )res = @soc.get_and_ensure_dst_dir!( "a_core" )File.directory?( path ).should be == trueres.should be == pathendit "should return false, when an interface is not used" do# setup interface ifc_b and ifc_c, test for ifc_aa_con = { rule: "or", mapping: [ { :core_a => :ifc_b }, { :core_b => :ifc_c } ] }@soc.cons[ :my_con ] = a_con@soc.ifc_in_use?( "core_a", "ifc_a" ).should be == falseendit "should return true, if an interface is used" doa_con = { rule: "or", mapping: [ { :core_a => :ifc_a }, { :core_b => :ifc_b } ] }@soc.cons[ :my_con ] = a_con@soc.ifc_in_use?( "core_a", "ifc_a" ).should be == trueendit "should raise an SOCMaker::ERR::ProcessingError add_connection tries to add a interface, wich is already used" doa_con = { rule: "or", mapping: [ { :core_a => :ifc_a }, { :core_b => :ifc_b } ] }@soc.cons[ :my_con ] = a_conexpect{ @soc.add_connection( "core_a", "ifc_a", "core_b", "ifc_c", "a_new_con" ) }.to raise_error( SOCMaker::ERR::ProcessingError )expect{ @soc.add_connection( "core_a", "ifc_a", "core_c", "ifc_b", "a_new_con" ) }.to raise_error( SOCMaker::ERR::ProcessingError )endit "should raise an SOCMaker::ERR::ProcessingError if a connection is added from a non-existing core instance" doexpect{ @soc.add_connection( "core_a", "ifc_a", "core_c", "ifc_b", "a_new_con" ) }.to raise_error( SOCMaker::ERR::ProcessingError )endit "should raise an ProcessingError if a interface doesn't exist" do@soc.cores[ :core_a ] = SOCMaker::CoreInst.new( "mycorerel1" )@soc.cores[ :core_b ] = SOCMaker::CoreInst.new( "mycorerel1" )expect{ @soc.add_connection( "core_a", "ifc_a", "core_b", "ifc_c", "a_new_con" ) }.to raise_error( SOCMaker::ERR::ProcessingError )endit "should raise an ProcessingError if the ifc.-version is wrong" doifc_spc1 = SOCMaker::IfcSpc.new( "myifc", "v1", 'ports' => { port_a: {dir:1}, port_b: {dir:0} } )ifc_spc2 = SOCMaker::IfcSpc.new( "myifc", "v2", 'ports' => { port_a: {dir:1}, port_b: {dir:0} } )ifc_def_1 = SOCMaker::IfcDef.new( "myifc", "v1", 0, { a: SOCMaker::IfcPort.new( "port_a", 1 ) } )ifc_def_0 = SOCMaker::IfcDef.new( "myifc", "v2", 1, { b: SOCMaker::IfcPort.new( "port_b", 1 ) } )file = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }core_a = SOCMaker::CoreDef.new( "core_a", "v1", file, "top" )core_b = SOCMaker::CoreDef.new( "core_b", "v1", file, "top" )core_a.interfaces[ :ifc_a ] = ifc_def_0core_a.interfaces[ :ifc_b ] = ifc_def_1core_b.interfaces[ :ifc_a ] = ifc_def_0core_b.interfaces[ :ifc_b ] = ifc_def_1SOCMaker::lib.add_ifc( ifc_spc1 )SOCMaker::lib.add_ifc( ifc_spc2 )SOCMaker::lib.add_core( core_a )SOCMaker::lib.add_core( core_b )@soc.cores[ :core_a ] = SOCMaker::CoreInst.new( "core_av1" )@soc.cores[ :core_b ] = SOCMaker::CoreInst.new( "core_bv1" )expect { @soc.add_connection( "inst_a", "ifc_a", "inst_b", "ifc_b", "a_new_con" ) }.to raise_error( SOCMaker::ERR::ProcessingError )endit "should add a connection entry" doifc_spc = SOCMaker::IfcSpc.new( "myifc", "v1", 'ports' => { port_a: {dir:1}, port_b: {dir:0} } )ifc_def_1 = SOCMaker::IfcDef.new( "myifc", "v1", 0, { a: SOCMaker::IfcPort.new( "port_a", 1 ),b: SOCMaker::IfcPort.new( "port_b", 1 ) } )ifc_def_0 = SOCMaker::IfcDef.new( "myifc", "v1", 1, { a: SOCMaker::IfcPort.new( "port_a", 1 ),b: SOCMaker::IfcPort.new( "port_b", 1 ) } )file = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }core_a = SOCMaker::CoreDef.new( "core_a", "v1", file, "top" )core_b = SOCMaker::CoreDef.new( "core_b", "v1", file, "top" )core_a.interfaces[ :ifc_a ] = ifc_def_0core_a.interfaces[ :ifc_b ] = ifc_def_1core_b.interfaces[ :ifc_a ] = ifc_def_0core_b.interfaces[ :ifc_b ] = ifc_def_1SOCMaker::lib.add_ifc( ifc_spc )SOCMaker::lib.add_core( core_a )SOCMaker::lib.add_core( core_b )@soc.cores[ :inst_a ] = SOCMaker::CoreInst.new( "core_av1" )@soc.cores[ :inst_b ] = SOCMaker::CoreInst.new( "core_bv1" )@soc.consistency_check@soc.add_connection( "inst_a", "ifc_a", "inst_b", "ifc_b", "a_new_con" )@soc.cons[ :a_new_con ].should be == { rule:'or', mapping: [ {inst_a: :ifc_a},{inst_b: :ifc_b} ] }endit "should add a connection entry, which connects the toplevel's port" doifc_spc = SOCMaker::IfcSpc.new( "myifc", "v1", 'ports' => { port_a: {dir:1}, port_b: {dir:0} } )ifc_def_1 = SOCMaker::IfcDef.new( "myifc", "v1", 0, { a: SOCMaker::IfcPort.new( "port_a", 1 ),b: SOCMaker::IfcPort.new( "port_b", 1 ) } )ifc_def_0 = SOCMaker::IfcDef.new( "myifc", "v1", 1, { a: SOCMaker::IfcPort.new( "port_a", 1 ),b: SOCMaker::IfcPort.new( "port_b", 1 ) } )file = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }core_a = SOCMaker::CoreDef.new( "core_a", "v1", file, "top" )core_a.interfaces[ :ifc_a ] = ifc_def_0core_a.interfaces[ :ifc_b ] = ifc_def_1SOCMaker::lib.add_ifc( ifc_spc )SOCMaker::lib.add_core( core_a )SOCMaker::lib.add_core( @soc )@soc.interfaces[ :t1 ] = ifc_def_1@soc.cores[ :inst_a ] = SOCMaker::CoreInst.new( "core_av1" )@soc.consistency_check@soc.add_connection( "inst_a", "ifc_a", @soc.name, "t1", "a_new_con" )@soc.cons[ :a_new_con ].should be == { rule:'or', mapping: [ {inst_a: :ifc_a},{ @soc.name.to_sym => :t1} ] }endit "should raise an error, if a parameter of unkonwn core is set" doexpect{ @soc.set_param( "a_unknown_core", "p1", 1234 ) }.to raise_error( SOCMaker::ERR::ProcessingError )endit "should raise an error, if a parameter of unkonwn core is requested" doexpect{ @soc.get_param( "a_unknown_core", "p1" ) }.to raise_error( SOCMaker::ERR::ProcessingError )endit "should raise an error, if a unknown parameter is set and requested" dofile = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }core_a = SOCMaker::CoreDef.new( "core_a", "v1", file, "top" )parameter = SOCMaker::Parameter.new( "integer" )core_a.inst_parameters[ :p1 ] = parameterSOCMaker::lib.add_core( core_a )@soc.cores[ :inst_a ] = SOCMaker::CoreInst.new( "core_av1" )expect{ @soc.set_param( "inst_a", "px", 1234 ) }.to raise_error( SOCMaker::ERR::ProcessingError )expect{ @soc.get_param( "inst_a", "px" ) }.to raise_error( SOCMaker::ERR::ProcessingError )endit "should set a parameter and provide a parameter" dofile = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }core_a = SOCMaker::CoreDef.new( "core_a", "v1", file, "top" )parameter = SOCMaker::Parameter.new( "integer" )core_a.inst_parameters[ :p1 ] = parameterSOCMaker::lib.add_core( core_a )@soc.cores[ :inst_a ] = SOCMaker::CoreInst.new( "core_av1" )@soc.set_param( "inst_a", "p1", 1234 )@soc.cores[ :inst_a ].params[ :p1 ].should be == 1234@soc.get_param( "inst_a", "p1" ).should be == 1234endit "should raise an error, if a static-parameter of unkonwn core is set" doexpect{ @soc.set_sparam( "a_unknown_core", "p1", 1234 ) }.to raise_error( SOCMaker::ERR::ProcessingError )endit "should raise an error, if a statoc-parameter of unkonwn core is requested" doexpect{ @soc.get_sparam( "a_unknown_core", "p1" ) }.to raise_error( SOCMaker::ERR::ProcessingError )endit "should an error, a static parameter doesn't exist" dofile = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }core_a = SOCMaker::CoreDef.new( "core_a", "v1", file, "top" )SOCMaker::lib.add_core( core_a )@soc.cores[ :inst_a ] = SOCMaker::CoreInst.new( "core_av1" )expect{ @soc.set_sparam( "core_av1", "p1", 1234 ) }.to raise_error( SOCMaker::ERR::ProcessingError )expect{ @soc.get_sparam( "core_av1", "p1" ) }.to raise_error( SOCMaker::ERR::ProcessingError )endit "should set a static-parameter and provide this static parameter" dofile = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }core_a = SOCMaker::CoreDef.new( "core_a", "v1", file, "top" )pentry = SOCMaker::SParameterEntry.new( "integer", "TOK" )parameter = SOCMaker::SParameter.new( "file/path.vhd.src","file/path.vhd",'parameters' => { p1: pentry } )core_a.static_parameters[ :p1 ] = parameterSOCMaker::lib.add_core( core_a )@soc.cores[ :inst_a ] = SOCMaker::CoreInst.new( "core_av1" )@soc.set_sparam( "core_av1", "p1", 1234 )@soc.static[ :core_av1 ][ :p1 ].should be == 1234@soc.get_sparam( "core_av1", "p1" ).should be == 1234endenddescribe SOCMaker::SOCDef, "object handling, en-decoding:" doit "should be possible to encode and decode a core instance" doyaml_str = @soc.to_yamlo2 = YAML::load( yaml_str )@soc.should be == o2endit "should return false for two non-equal objects" doo2 = Marshal::load(Marshal.dump(@soc))o2.name << "X"( o2 == @soc ).should be == falseendendend# vim: noai:ts=2:sw=2
Go to most recent revision | Compare with Previous | Blame | View Log
