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

Subversion Repositories soc_maker

[/] [soc_maker/] [trunk/] [spec/] [component_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:      component.rb
#  File:      component.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:
#     Test specification for SOCMaker::Component
#     Test specification for SOCMaker::Component
#
#
#
#
#
#
#
#
###############################################################
###############################################################
require_relative( 'spec_helper' )
require_relative( 'spec_helper' )
describe SOCMaker::Component, "initialization" do
describe SOCMaker::Component, "initialization" do
  it "should return a Component object, if the object is created with new" do
  it "should return a Component object, if the object is created with new" do
    c = SOCMaker::Component.new( "acore", "v1", "top" )
    c = SOCMaker::Component.new( "acore", "v1", "top" )
    c.class.should be == SOCMaker::Component
    c.class.should be == SOCMaker::Component
  end
  end
  # test the name
  # test the name
  it "should raise an error, if the name is nil" do
  it "should raise an error, if the name is nil" do
    expect{ SOCMaker::Component.new( nil, "v1", "top" ) }.
    expect{ SOCMaker::Component.new( nil, "v1", "top" ) }.
      to raise_error( SOCMaker::ERR::StructureError )
      to raise_error( SOCMaker::ERR::StructureError )
  end
  end
  it "should raise an error, if the name has zero-length" do
  it "should raise an error, if the name has zero-length" do
    expect{ SOCMaker::Component.new( "", "v1", "top" ) }.
    expect{ SOCMaker::Component.new( "", "v1", "top" ) }.
      to raise_error( SOCMaker::ERR::StructureError )
      to raise_error( SOCMaker::ERR::StructureError )
  end
  end
  it "should raise an error, if the name is not of type string" do
  it "should raise an error, if the name is not of type string" do
    expect{ SOCMaker::Component.new( 3, "v1", "top" ) }.
    expect{ SOCMaker::Component.new( 3, "v1", "top" ) }.
      to raise_error( SOCMaker::ERR::ValueError )
      to raise_error( SOCMaker::ERR::ValueError )
  end
  end
  it 'should raise an error, if the name doesnt start with [a-zA-Z]' do
  it 'should raise an error, if the name doesnt start with [a-zA-Z]' do
    expect{ SOCMaker::Component.new( "4abc", "v1", "top" ) }.
    expect{ SOCMaker::Component.new( "4abc", "v1", "top" ) }.
      to raise_error( SOCMaker::ERR::ValueError )
      to raise_error( SOCMaker::ERR::ValueError )
  end
  end
  it 'should raise an error, if the name conatins invalid symbols' do
  it 'should raise an error, if the name conatins invalid symbols' do
    expect{ SOCMaker::Component.new( "abc$abc", "v1", "top" ) }.
    expect{ SOCMaker::Component.new( "abc$abc", "v1", "top" ) }.
      to raise_error( SOCMaker::ERR::ValueError )
      to raise_error( SOCMaker::ERR::ValueError )
  end
  end
  # test the version
  # test the version
  it "should raise an error, if the version is nil" do
  it "should raise an error, if the version is nil" do
    expect{ SOCMaker::Component.new( "acore", nil, "top" ) }.
    expect{ SOCMaker::Component.new( "acore", nil, "top" ) }.
      to raise_error( SOCMaker::ERR::StructureError )
      to raise_error( SOCMaker::ERR::StructureError )
  end
  end
  it "should raise an error, if the version has zero-length" do
  it "should raise an error, if the version has zero-length" do
    expect{ SOCMaker::Component.new( "acore", "", "top" ) }.
    expect{ SOCMaker::Component.new( "acore", "", "top" ) }.
      to raise_error( SOCMaker::ERR::StructureError )
      to raise_error( SOCMaker::ERR::StructureError )
  end
  end
  it "should raise an error, if the version is not of type string neither of type Numerical" do
  it "should raise an error, if the version is not of type string neither of type Numerical" do
    expect{ SOCMaker::Component.new( "acore", [ 1, 2, 3 ], "top" ) }.
    expect{ SOCMaker::Component.new( "acore", [ 1, 2, 3 ], "top" ) }.
      to raise_error( SOCMaker::ERR::ValueError )
      to raise_error( SOCMaker::ERR::ValueError )
  end
  end
  it "should cast a numerical version to a string version" do
  it "should cast a numerical version to a string version" do
    c = SOCMaker::Component.new( "acore", 3, "top" )
    c = SOCMaker::Component.new( "acore", 3, "top" )
    c.class.should be == SOCMaker::Component
    c.class.should be == SOCMaker::Component
    c.version = "3"
    c.version = "3"
  end
  end
  %w[ description date license licensefile
  %w[ description date license licensefile
      author authormail vccmd ].each do |m|
      author authormail vccmd ].each do |m|
    it "should auto-set #{m} to an empty string" do
    it "should auto-set #{m} to an empty string" do
      c = SOCMaker::Component.new( "acore", "v1", "top" )
      c = SOCMaker::Component.new( "acore", "v1", "top" )
      c.instance_variable_get( '@'+m ).class.should be == String
      c.instance_variable_get( '@'+m ).class.should be == String
      c.instance_variable_get( '@'+m ).should be       == ""
      c.instance_variable_get( '@'+m ).should be       == ""
    end
    end
  end
  end
  %w[ interfaces functions
  %w[ interfaces functions
      inst_parameters
      inst_parameters
      static_parameters ].each do |m|
      static_parameters ].each do |m|
    it "should auto-set #{m} to an empty Hash" do
    it "should auto-set #{m} to an empty Hash" do
      c = SOCMaker::Component.new( "acore", "v1", "top" )
      c = SOCMaker::Component.new( "acore", "v1", "top" )
      c.instance_variable_get( '@'+m ).class.should be == Hash
      c.instance_variable_get( '@'+m ).class.should be == Hash
      c.instance_variable_get( '@'+m ).should be       == {}
      c.instance_variable_get( '@'+m ).should be       == {}
    end
    end
  end
  end
  %w[ description date license licensefile
  %w[ description date license licensefile
      author authormail vccmd ].each do |m|
      author authormail vccmd ].each do |m|
    it "should raise an error if #{m} is not a string" do
    it "should raise an error if #{m} is not a string" do
    # pass an numerical value
    # pass an numerical value
    expect{ SOCMaker::Component.new( "acore", "v1", "top", { m => 4 } ) }.
    expect{ SOCMaker::Component.new( "acore", "v1", "top", { m => 4 } ) }.
      to raise_error( SOCMaker::ERR::ValueError )
      to raise_error( SOCMaker::ERR::ValueError )
    end
    end
  end
  end
  %w[ interfaces functions
  %w[ interfaces functions
      inst_parameters
      inst_parameters
      static_parameters ].each do |m|
      static_parameters ].each do |m|
    it "should raise an error if #{m} is not a hash" do
    it "should raise an error if #{m} is not a hash" do
      # pass an numerical value
      # pass an numerical value
      expect{ SOCMaker::Component.new( "acore", "v1", "top", { m => 4 } ) }.
      expect{ SOCMaker::Component.new( "acore", "v1", "top", { m => 4 } ) }.
        to raise_error( SOCMaker::ERR::ValueError )
        to raise_error( SOCMaker::ERR::ValueError )
    end
    end
  end
  end
  it 'should iterate over all generics (inst. parameters)' do
  it 'should iterate over all generics (inst. parameters)' do
    p1 = SOCMaker::Parameter.new( "integer" )
    p1 = SOCMaker::Parameter.new( "integer" )
    p2 = SOCMaker::Parameter.new( "string" )
    p2 = SOCMaker::Parameter.new( "string" )
    p3 = SOCMaker::Parameter.new( "integer" )
    p3 = SOCMaker::Parameter.new( "integer" )
    p4 = SOCMaker::Parameter.new( "string" )
    p4 = SOCMaker::Parameter.new( "string" )
    c = SOCMaker::Component.new( "acore", "v1", "top",
    c = SOCMaker::Component.new( "acore", "v1", "top",
      { 'inst_parameters' => { p1: p1, p2: p2, p3: p3, p4: p4 } } )
      { 'inst_parameters' => { p1: p1, p2: p2, p3: p3, p4: p4 } } )
    a_name    = [];
    a_name    = [];
    a_type    = [];
    a_type    = [];
    a_default = [];
    a_default = [];
    a_is_last = [];
    a_is_last = [];
    c.generics do |name,type,default,is_last|
    c.generics do |name,type,default,is_last|
      a_name    << name
      a_name    << name
      a_type    << type
      a_type    << type
      a_default << default
      a_default << default
      a_is_last << is_last
      a_is_last << is_last
    end
    end
    a_name.should be == %w[ p1 p2 p3 p4 ]
    a_name.should be == %w[ p1 p2 p3 p4 ]
    a_type.should be == %w[ integer string integer string ]
    a_type.should be == %w[ integer string integer string ]
    a_default.should be == [ 0, 0, 0, 0 ]
    a_default.should be == [ 0, 0, 0, 0 ]
    a_is_last.should be == [ false, false, false, true ]
    a_is_last.should be == [ false, false, false, true ]
  end
  end
 
 
 
 
 
 
 
 
  it 'should iterate over all ports' do
  it 'should iterate over all ports' do
    SOCMaker::lib.clear
    SOCMaker::lib.clear
    ifc_s1 = SOCMaker::IfcSpc.new( "i1", "v1", 'ports' => { p1: 1, p2: 1, p3: 0 } )
    ifc_s1 = SOCMaker::IfcSpc.new( "i1", "v1", 'ports' => { p1: 1, p2: 1, p3: 0 } )
    ifc_s2 = SOCMaker::IfcSpc.new( "i2", "v1", 'ports' => { x1: 1, x2: 0 } )
    ifc_s2 = SOCMaker::IfcSpc.new( "i2", "v1", 'ports' => { x1: 1, x2: 0 } )
    SOCMaker::lib.add_ifc( ifc_s1 )
    SOCMaker::lib.add_ifc( ifc_s1 )
    SOCMaker::lib.add_ifc( ifc_s2 )
    SOCMaker::lib.add_ifc( ifc_s2 )
    p1 = SOCMaker::IfcPort.new( "p1", 1 )
    p1 = SOCMaker::IfcPort.new( "p1", 1 )
    p2 = SOCMaker::IfcPort.new( "p2", 2 )
    p2 = SOCMaker::IfcPort.new( "p2", 2 )
    p3 = SOCMaker::IfcPort.new( "p3", 3 )
    p3 = SOCMaker::IfcPort.new( "p3", 3 )
    x1 = SOCMaker::IfcPort.new( "x1", 1 )
    x1 = SOCMaker::IfcPort.new( "x1", 1 )
    x2 = SOCMaker::IfcPort.new( "x2", 2 )
    x2 = SOCMaker::IfcPort.new( "x2", 2 )
    ifc_d1 = SOCMaker::IfcDef.new( "i1", "v1", 0, { m_p1: p1, m_p2: p2, m_p3: p3 } )
    ifc_d1 = SOCMaker::IfcDef.new( "i1", "v1", 0, { m_p1: p1, m_p2: p2, m_p3: p3 } )
    ifc_d2 = SOCMaker::IfcDef.new( "i2", "v1", 0, { m_x1: x1, m_x2: x2           } )
    ifc_d2 = SOCMaker::IfcDef.new( "i2", "v1", 0, { m_x1: x1, m_x2: x2           } )
    c = SOCMaker::Component.new( "acore", "v1", "top",
    c = SOCMaker::Component.new( "acore", "v1", "top",
      { 'interfaces' =>  { i1: ifc_d1, i2: ifc_d2 } } )
      { 'interfaces' =>  { i1: ifc_d1, i2: ifc_d2 } } )
    r_name    = []
    r_name    = []
    r_dir     = []
    r_dir     = []
    r_len     = []
    r_len     = []
    r_is_last = []
    r_is_last = []
    c.ports do |arg_name,arg_dir,arg_len,arg_is_last|
    c.ports do |arg_name,arg_dir,arg_len,arg_is_last|
      r_name    << arg_name
      r_name    << arg_name
      r_dir     << arg_dir
      r_dir     << arg_dir
      r_len     << arg_len
      r_len     << arg_len
      r_is_last << arg_is_last
      r_is_last << arg_is_last
    end
    end
    r_name.sort.should be == %w[ m_p1 m_p2 m_p3 m_x1 m_x2 ].sort
    r_name.sort.should be == %w[ m_p1 m_p2 m_p3 m_x1 m_x2 ].sort
    r_dir.sort.should be  ==   [ 1, 1, 0, 1, 0 ].sort
    r_dir.sort.should be  ==   [ 1, 1, 0, 1, 0 ].sort
    r_len.sort.should be  ==   [ 1, 2, 3, 1, 2 ].sort
    r_len.sort.should be  ==   [ 1, 2, 3, 1, 2 ].sort
    r_is_last.should be   == [ false, false, false, false, true ]
    r_is_last.should be   == [ false, false, false, false, true ]
    r_def     = []
    r_def     = []
    r_name    = []
    r_name    = []
    r_dir     = []
    r_dir     = []
    c.ports( "i1" ) do |arg_name,arg_def,arg_dir|
    c.ports( "i1" ) do |arg_name,arg_def,arg_dir|
      r_def     << arg_def
      r_def     << arg_def
      r_name    << arg_name
      r_name    << arg_name
      r_dir     << arg_dir
      r_dir     << arg_dir
    end
    end
    r_def.should be == %w[ m_p1 m_p2 m_p3 ]
    r_def.should be == %w[ m_p1 m_p2 m_p3 ]
    r_name.should be == %w[ p1 p2 p3 ]
    r_name.should be == %w[ p1 p2 p3 ]
    r_dir.should be  ==   [ 1, 1, 0, ]
    r_dir.should be  ==   [ 1, 1, 0, ]
  end
  end
end
end
 
 

powered by: WebSVN 2.1.0

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