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

Subversion Repositories soc_maker

[/] [soc_maker/] [trunk/] [spec/] [component_spec.rb] - Blame information for rev 10

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 feddischso
###############################################################
2
#
3
#  File:      component.rb
4
#
5
#  Author:    Christian Hättich
6
#
7
#  Project:   System-On-Chip Maker
8
#
9
#  Target:    Linux / Windows / Mac
10
#
11
#  Language:  ruby
12
#
13
#
14
###############################################################
15
#
16
#
17
#   Copyright (C) 2014  Christian Hättich  - feddischson [ at ] opencores.org
18
#
19
#   This program is free software: you can redistribute it and/or modify
20
#   it under the terms of the GNU General Public License as published by
21
#   the Free Software Foundation, either version 3 of the License, or
22
#   (at your option) any later version.
23
#
24
#   This program is distributed in the hope that it will be useful,
25
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
26
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
#   GNU General Public License for more details.
28
#
29
#   You should have received a copy of the GNU General Public License
30
#   along with this program.  If not, see .
31
#
32
#
33
###############################################################
34
#
35
#   Description:
36
#     Test specification for SOCMaker::Component
37
#
38
#
39
#
40
#
41
###############################################################
42
require_relative( 'spec_helper' )
43
 
44
describe SOCMaker::Component, "initialization" do
45
 
46
 
47
  it "should return a Component object, if the object is created with new" do
48
    c = SOCMaker::Component.new( "acore", "v1", "top" )
49
    c.class.should be == SOCMaker::Component
50
  end
51
 
52
 
53
  # test the name
54
  it "should raise an error, if the name is nil" do
55
    expect{ SOCMaker::Component.new( nil, "v1", "top" ) }.
56
      to raise_error( SOCMaker::ERR::StructureError )
57
  end
58
 
59
  it "should raise an error, if the name has zero-length" do
60
    expect{ SOCMaker::Component.new( "", "v1", "top" ) }.
61
      to raise_error( SOCMaker::ERR::StructureError )
62
  end
63
 
64
  it "should raise an error, if the name is not of type string" do
65
    expect{ SOCMaker::Component.new( 3, "v1", "top" ) }.
66
      to raise_error( SOCMaker::ERR::ValueError )
67
  end
68
 
69 10 feddischso
  # test the id
70
  it "should raise an error, if the id is nil" do
71 3 feddischso
    expect{ SOCMaker::Component.new( "acore", nil, "top" ) }.
72
      to raise_error( SOCMaker::ERR::StructureError )
73
  end
74
 
75 10 feddischso
  it "should raise an error, if the id has zero-length" do
76 3 feddischso
    expect{ SOCMaker::Component.new( "acore", "", "top" ) }.
77
      to raise_error( SOCMaker::ERR::StructureError )
78
  end
79
 
80 10 feddischso
  it "should raise an error, if the id is not of type string " do
81 3 feddischso
    expect{ SOCMaker::Component.new( "acore", [ 1, 2, 3 ], "top" ) }.
82
      to raise_error( SOCMaker::ERR::ValueError )
83
  end
84
 
85
 
86
  %w[ description date license licensefile
87
      author authormail vccmd ].each do |m|
88
    it "should auto-set #{m} to an empty string" do
89
      c = SOCMaker::Component.new( "acore", "v1", "top" )
90
      c.instance_variable_get( '@'+m ).class.should be == String
91
      c.instance_variable_get( '@'+m ).should be       == ""
92
    end
93
  end
94
  %w[ interfaces functions
95
      inst_parameters
96
      static_parameters ].each do |m|
97
    it "should auto-set #{m} to an empty Hash" do
98
      c = SOCMaker::Component.new( "acore", "v1", "top" )
99
      c.instance_variable_get( '@'+m ).class.should be == Hash
100
      c.instance_variable_get( '@'+m ).should be       == {}
101
    end
102
  end
103
 
104
 
105
  %w[ description date license licensefile
106
      author authormail vccmd ].each do |m|
107
    it "should raise an error if #{m} is not a string" do
108
    # pass an numerical value
109
    expect{ SOCMaker::Component.new( "acore", "v1", "top", { m => 4 } ) }.
110
      to raise_error( SOCMaker::ERR::ValueError )
111
    end
112
  end
113
 
114
  %w[ interfaces functions
115
      inst_parameters
116
      static_parameters ].each do |m|
117
    it "should raise an error if #{m} is not a hash" do
118
      # pass an numerical value
119
      expect{ SOCMaker::Component.new( "acore", "v1", "top", { m => 4 } ) }.
120
        to raise_error( SOCMaker::ERR::ValueError )
121
    end
122
  end
123
 
124
 
125
 
126
 
127
 
128
 
129
 
130
 
131
  it 'should iterate over all generics (inst. parameters)' do
132
 
133 10 feddischso
 
134 3 feddischso
    p1 = SOCMaker::Parameter.new( "integer" )
135
    p2 = SOCMaker::Parameter.new( "string" )
136
    p3 = SOCMaker::Parameter.new( "integer" )
137
    p4 = SOCMaker::Parameter.new( "string" )
138
 
139
    c = SOCMaker::Component.new( "acore", "v1", "top",
140
      { 'inst_parameters' => { p1: p1, p2: p2, p3: p3, p4: p4 } } )
141
 
142
    a_name    = [];
143
    a_type    = [];
144
    a_default = [];
145
    a_is_last = [];
146
    c.generics do |name,type,default,is_last|
147
      a_name    << name
148
      a_type    << type
149
      a_default << default
150
      a_is_last << is_last
151
    end
152
    a_name.should be == %w[ p1 p2 p3 p4 ]
153
    a_type.should be == %w[ integer string integer string ]
154
    a_default.should be == [ 0, 0, 0, 0 ]
155
    a_is_last.should be == [ false, false, false, true ]
156
  end
157
 
158 5 feddischso
 
159 3 feddischso
 
160 5 feddischso
 
161 3 feddischso
  it 'should iterate over all ports' do
162
 
163
    SOCMaker::lib.clear
164 10 feddischso
    ifc_s1 = SOCMaker::IfcSpc.new( "Interface 1", "i1,v1", 'ports' => { p1:{dir:1}, p2:{dir:1}, p3:{dir:0} } )
165
    ifc_s2 = SOCMaker::IfcSpc.new( "Interface 2", "i2,v1", 'ports' => { x1:{dir:1}, x2:{dir:0} } )
166 3 feddischso
    SOCMaker::lib.add_ifc( ifc_s1 )
167
    SOCMaker::lib.add_ifc( ifc_s2 )
168
 
169
    p1 = SOCMaker::IfcPort.new( "p1", 1 )
170
    p2 = SOCMaker::IfcPort.new( "p2", 2 )
171
    p3 = SOCMaker::IfcPort.new( "p3", 3 )
172
    x1 = SOCMaker::IfcPort.new( "x1", 1 )
173
    x2 = SOCMaker::IfcPort.new( "x2", 2 )
174
 
175 10 feddischso
    ifc_d1 = SOCMaker::IfcDef.new( "i1", "i1,v1", 0, { m_p1: p1, m_p2: p2, m_p3: p3 } )
176
    ifc_d2 = SOCMaker::IfcDef.new( "i2", "i2,v1", 0, { m_x1: x1, m_x2: x2           } )
177 3 feddischso
 
178
 
179 10 feddischso
    c = SOCMaker::Component.new( "A core", "acore,v1", "top",
180 3 feddischso
      { 'interfaces' =>  { i1: ifc_d1, i2: ifc_d2 } } )
181
 
182
    r_name    = []
183
    r_dir     = []
184
    r_len     = []
185
    r_is_last = []
186
 
187 8 feddischso
    c.ports do |arg_name,arg_dir,arg_len,arg_default,arg_is_last|
188 3 feddischso
      r_name    << arg_name
189
      r_dir     << arg_dir
190
      r_len     << arg_len
191
      r_is_last << arg_is_last
192
    end
193
    r_name.sort.should be == %w[ m_p1 m_p2 m_p3 m_x1 m_x2 ].sort
194
    r_dir.sort.should be  ==   [ 1, 1, 0, 1, 0 ].sort
195
    r_len.sort.should be  ==   [ 1, 2, 3, 1, 2 ].sort
196
    r_is_last.should be   == [ false, false, false, false, true ]
197
 
198
 
199 8 feddischso
    #r_def     = []
200 3 feddischso
    r_name    = []
201
    r_dir     = []
202
 
203 8 feddischso
    c.ports( "i1" ) do |arg_name,arg_dir, arg_default, arg_is_last|
204
      #r_def     << arg_def
205 3 feddischso
      r_name    << arg_name
206
      r_dir     << arg_dir
207
    end
208 8 feddischso
    #r_def.should be == %w[ m_p1 m_p2 m_p3 ]
209
    r_name.should be == %w[ m_p1 m_p2 m_p3 ]
210 3 feddischso
    r_dir.should be  ==   [ 1, 1, 0, ]
211 8 feddischso
 
212 3 feddischso
  end
213
 
214 8 feddischso
end
215 3 feddischso
 
216
 
217 8 feddischso
describe SOCMaker::Component, "consistency_check" do
218 3 feddischso
 
219 8 feddischso
 
220
  it "should throw an error if an incomplete interface is used" do
221
 
222
    # three (auto) mandatory ports
223
    ifc_s1 = SOCMaker::IfcSpc.new( "i1", "v1", 'ports' => { p1: { dir: 1}, p2: {dir: 1}, p3: {dir:0} } )
224 9 feddischso
    SOCMaker::lib.add_ifc( ifc_s1 )
225 8 feddischso
 
226
    # interface implementaiton with only two of the three ports
227
    p1 = SOCMaker::IfcPort.new( "p1", 1 )
228
    p2 = SOCMaker::IfcPort.new( "p2", 2 )
229
    ifc_d1 = SOCMaker::IfcDef.new( "i1", "v1", 0, { m_p1: p1, m_p2: p2 } )
230
 
231
    c = SOCMaker::Component.new( "acore", "v1", "top",
232
      { 'interfaces' =>  { i1: ifc_d1 } } )
233
 
234
 
235
   expect{ c.consistency_check }.
236
     to raise_error( SOCMaker::ERR::ProcessingError )
237
 
238
  end
239
 
240 3 feddischso
end
241 8 feddischso
 
242
# 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.