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 9 and 10

Only display areas with differences | Details | Blame | View Log

Rev 9 Rev 10
###############################################################
###############################################################
#
#
#  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
  # test the id
    expect{ SOCMaker::Component.new( "4abc", "v1", "top" ) }.
  it "should raise an error, if the id is nil" do
      to raise_error( SOCMaker::ERR::ValueError )
 
  end
 
 
 
  it 'should raise an error, if the name conatins invalid symbols' do
 
    expect{ SOCMaker::Component.new( "abc$abc", "v1", "top" ) }.
 
      to raise_error( SOCMaker::ERR::ValueError )
 
  end
 
 
 
 
 
 
 
 
 
 
 
  # test the version
 
  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 id 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 id is not of type string " 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
 
    c = SOCMaker::Component.new( "acore", 3, "top" )
 
    c.class.should be == SOCMaker::Component
 
    c.version = "3"
 
  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:{dir:1}, p2:{dir:1}, p3:{dir:0} } )
    ifc_s1 = SOCMaker::IfcSpc.new( "Interface 1", "i1,v1", 'ports' => { p1:{dir:1}, p2:{dir:1}, p3:{dir:0} } )
    ifc_s2 = SOCMaker::IfcSpc.new( "i2", "v1", 'ports' => { x1:{dir:1}, x2:{dir:0} } )
    ifc_s2 = SOCMaker::IfcSpc.new( "Interface 2", "i2,v1", 'ports' => { x1:{dir:1}, x2:{dir: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", "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", "i2,v1", 0, { m_x1: x1, m_x2: x2           } )
 
 
 
 
    c = SOCMaker::Component.new( "acore", "v1", "top",
    c = SOCMaker::Component.new( "A core", "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_default,arg_is_last|
    c.ports do |arg_name,arg_dir,arg_len,arg_default,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     = []
 
 
    p c.interfaces
 
    c.ports( "i1" ) do |arg_name,arg_dir, arg_default, arg_is_last|
    c.ports( "i1" ) do |arg_name,arg_dir, arg_default, arg_is_last|
      #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[ m_p1 m_p2 m_p3 ]
    r_name.should be == %w[ m_p1 m_p2 m_p3 ]
    r_dir.should be  ==   [ 1, 1, 0, ]
    r_dir.should be  ==   [ 1, 1, 0, ]
  end
  end
end
end
describe SOCMaker::Component, "consistency_check" do
describe SOCMaker::Component, "consistency_check" do
  it "should throw an error if an incomplete interface is used" do
  it "should throw an error if an incomplete interface is used" do
    # three (auto) mandatory ports
    # three (auto) mandatory ports
    ifc_s1 = SOCMaker::IfcSpc.new( "i1", "v1", 'ports' => { p1: { dir: 1}, p2: {dir: 1}, p3: {dir:0} } )
    ifc_s1 = SOCMaker::IfcSpc.new( "i1", "v1", 'ports' => { p1: { dir: 1}, p2: {dir: 1}, p3: {dir:0} } )
    SOCMaker::lib.add_ifc( ifc_s1 )
    SOCMaker::lib.add_ifc( ifc_s1 )
    # interface implementaiton with only two of the three ports
    # interface implementaiton with only two of the three ports
    p1 = SOCMaker::IfcPort.new( "p1", 1 )
    p1 = SOCMaker::IfcPort.new( "p1", 1 )
    p2 = SOCMaker::IfcPort.new( "p2", 2 )
    p2 = SOCMaker::IfcPort.new( "p2", 2 )
    ifc_d1 = SOCMaker::IfcDef.new( "i1", "v1", 0, { m_p1: p1, m_p2: p2 } )
    ifc_d1 = SOCMaker::IfcDef.new( "i1", "v1", 0, { m_p1: p1, m_p2: p2 } )
    c = SOCMaker::Component.new( "acore", "v1", "top",
    c = SOCMaker::Component.new( "acore", "v1", "top",
      { 'interfaces' =>  { i1: ifc_d1 } } )
      { 'interfaces' =>  { i1: ifc_d1 } } )
   expect{ c.consistency_check }.
   expect{ c.consistency_check }.
     to raise_error( SOCMaker::ERR::ProcessingError )
     to raise_error( SOCMaker::ERR::ProcessingError )
  end
  end
end
end
# vim: noai:ts=2:sw=2
# vim: noai:ts=2:sw=2
 
 

powered by: WebSVN 2.1.0

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