OpenCores
URL https://opencores.org/ocsvn/soc_maker/soc_maker/trunk

Subversion Repositories soc_maker

[/] [soc_maker/] [trunk/] [spec/] [core_inst_spec.rb] - Diff between revs 3 and 5

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.