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 |
|
|
it 'should raise an error, if the name doesnt start with [a-zA-Z]' do
|
70 |
|
|
expect{ SOCMaker::Component.new( "4abc", "v1", "top" ) }.
|
71 |
|
|
to raise_error( SOCMaker::ERR::ValueError )
|
72 |
|
|
end
|
73 |
|
|
|
74 |
|
|
it 'should raise an error, if the name conatins invalid symbols' do
|
75 |
|
|
expect{ SOCMaker::Component.new( "abc$abc", "v1", "top" ) }.
|
76 |
|
|
to raise_error( SOCMaker::ERR::ValueError )
|
77 |
|
|
end
|
78 |
|
|
|
79 |
|
|
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
|
83 |
|
|
# test the version
|
84 |
|
|
it "should raise an error, if the version is nil" do
|
85 |
|
|
expect{ SOCMaker::Component.new( "acore", nil, "top" ) }.
|
86 |
|
|
to raise_error( SOCMaker::ERR::StructureError )
|
87 |
|
|
end
|
88 |
|
|
|
89 |
|
|
it "should raise an error, if the version has zero-length" do
|
90 |
|
|
expect{ SOCMaker::Component.new( "acore", "", "top" ) }.
|
91 |
|
|
to raise_error( SOCMaker::ERR::StructureError )
|
92 |
|
|
end
|
93 |
|
|
|
94 |
|
|
it "should raise an error, if the version is not of type string neither of type Numerical" do
|
95 |
|
|
expect{ SOCMaker::Component.new( "acore", [ 1, 2, 3 ], "top" ) }.
|
96 |
|
|
to raise_error( SOCMaker::ERR::ValueError )
|
97 |
|
|
end
|
98 |
|
|
|
99 |
|
|
it "should cast a numerical version to a string version" do
|
100 |
|
|
c = SOCMaker::Component.new( "acore", 3, "top" )
|
101 |
|
|
c.class.should be == SOCMaker::Component
|
102 |
|
|
c.version = "3"
|
103 |
|
|
end
|
104 |
|
|
|
105 |
|
|
|
106 |
|
|
%w[ description date license licensefile
|
107 |
|
|
author authormail vccmd ].each do |m|
|
108 |
|
|
it "should auto-set #{m} to an empty string" do
|
109 |
|
|
c = SOCMaker::Component.new( "acore", "v1", "top" )
|
110 |
|
|
c.instance_variable_get( '@'+m ).class.should be == String
|
111 |
|
|
c.instance_variable_get( '@'+m ).should be == ""
|
112 |
|
|
end
|
113 |
|
|
end
|
114 |
|
|
%w[ interfaces functions
|
115 |
|
|
inst_parameters
|
116 |
|
|
static_parameters ].each do |m|
|
117 |
|
|
it "should auto-set #{m} to an empty Hash" do
|
118 |
|
|
c = SOCMaker::Component.new( "acore", "v1", "top" )
|
119 |
|
|
c.instance_variable_get( '@'+m ).class.should be == Hash
|
120 |
|
|
c.instance_variable_get( '@'+m ).should be == {}
|
121 |
|
|
end
|
122 |
|
|
end
|
123 |
|
|
|
124 |
|
|
|
125 |
|
|
%w[ description date license licensefile
|
126 |
|
|
author authormail vccmd ].each do |m|
|
127 |
|
|
it "should raise an error if #{m} is not a string" do
|
128 |
|
|
# pass an numerical value
|
129 |
|
|
expect{ SOCMaker::Component.new( "acore", "v1", "top", { m => 4 } ) }.
|
130 |
|
|
to raise_error( SOCMaker::ERR::ValueError )
|
131 |
|
|
end
|
132 |
|
|
end
|
133 |
|
|
|
134 |
|
|
%w[ interfaces functions
|
135 |
|
|
inst_parameters
|
136 |
|
|
static_parameters ].each do |m|
|
137 |
|
|
it "should raise an error if #{m} is not a hash" do
|
138 |
|
|
# pass an numerical value
|
139 |
|
|
expect{ SOCMaker::Component.new( "acore", "v1", "top", { m => 4 } ) }.
|
140 |
|
|
to raise_error( SOCMaker::ERR::ValueError )
|
141 |
|
|
end
|
142 |
|
|
end
|
143 |
|
|
|
144 |
|
|
|
145 |
|
|
|
146 |
|
|
|
147 |
|
|
|
148 |
|
|
|
149 |
|
|
|
150 |
|
|
|
151 |
|
|
it 'should iterate over all generics (inst. parameters)' do
|
152 |
|
|
|
153 |
|
|
p1 = SOCMaker::Parameter.new( "integer" )
|
154 |
|
|
p2 = SOCMaker::Parameter.new( "string" )
|
155 |
|
|
p3 = SOCMaker::Parameter.new( "integer" )
|
156 |
|
|
p4 = SOCMaker::Parameter.new( "string" )
|
157 |
|
|
|
158 |
|
|
c = SOCMaker::Component.new( "acore", "v1", "top",
|
159 |
|
|
{ 'inst_parameters' => { p1: p1, p2: p2, p3: p3, p4: p4 } } )
|
160 |
|
|
|
161 |
|
|
a_name = [];
|
162 |
|
|
a_type = [];
|
163 |
|
|
a_default = [];
|
164 |
|
|
a_is_last = [];
|
165 |
|
|
c.generics do |name,type,default,is_last|
|
166 |
|
|
a_name << name
|
167 |
|
|
a_type << type
|
168 |
|
|
a_default << default
|
169 |
|
|
a_is_last << is_last
|
170 |
|
|
end
|
171 |
|
|
a_name.should be == %w[ p1 p2 p3 p4 ]
|
172 |
|
|
a_type.should be == %w[ integer string integer string ]
|
173 |
|
|
a_default.should be == [ 0, 0, 0, 0 ]
|
174 |
|
|
a_is_last.should be == [ false, false, false, true ]
|
175 |
|
|
end
|
176 |
|
|
|
177 |
|
|
|
178 |
|
|
it 'should iterate over all ports' do
|
179 |
|
|
|
180 |
|
|
SOCMaker::lib.clear
|
181 |
|
|
ifc_s1 = SOCMaker::IfcSpc.new( "i1", "v1", 'ports' => { p1: 1, p2: 1, p3: 0 } )
|
182 |
|
|
ifc_s2 = SOCMaker::IfcSpc.new( "i2", "v1", 'ports' => { x1: 1, x2: 0 } )
|
183 |
|
|
SOCMaker::lib.add_ifc( ifc_s1 )
|
184 |
|
|
SOCMaker::lib.add_ifc( ifc_s2 )
|
185 |
|
|
|
186 |
|
|
p1 = SOCMaker::IfcPort.new( "p1", 1 )
|
187 |
|
|
p2 = SOCMaker::IfcPort.new( "p2", 2 )
|
188 |
|
|
p3 = SOCMaker::IfcPort.new( "p3", 3 )
|
189 |
|
|
x1 = SOCMaker::IfcPort.new( "x1", 1 )
|
190 |
|
|
x2 = SOCMaker::IfcPort.new( "x2", 2 )
|
191 |
|
|
|
192 |
|
|
ifc_d1 = SOCMaker::IfcDef.new( "i1", "v1", 0, { m_p1: p1, m_p2: p2, m_p3: p3 } )
|
193 |
|
|
ifc_d2 = SOCMaker::IfcDef.new( "i2", "v1", 0, { m_x1: x1, m_x2: x2 } )
|
194 |
|
|
|
195 |
|
|
|
196 |
|
|
c = SOCMaker::Component.new( "acore", "v1", "top",
|
197 |
|
|
{ 'interfaces' => { i1: ifc_d1, i2: ifc_d2 } } )
|
198 |
|
|
|
199 |
|
|
r_name = []
|
200 |
|
|
r_dir = []
|
201 |
|
|
r_len = []
|
202 |
|
|
r_is_last = []
|
203 |
|
|
|
204 |
|
|
c.ports do |arg_name,arg_dir,arg_len,arg_is_last|
|
205 |
|
|
r_name << arg_name
|
206 |
|
|
r_dir << arg_dir
|
207 |
|
|
r_len << arg_len
|
208 |
|
|
r_is_last << arg_is_last
|
209 |
|
|
end
|
210 |
|
|
r_name.sort.should be == %w[ m_p1 m_p2 m_p3 m_x1 m_x2 ].sort
|
211 |
|
|
r_dir.sort.should be == [ 1, 1, 0, 1, 0 ].sort
|
212 |
|
|
r_len.sort.should be == [ 1, 2, 3, 1, 2 ].sort
|
213 |
|
|
r_is_last.should be == [ false, false, false, false, true ]
|
214 |
|
|
|
215 |
|
|
|
216 |
|
|
r_def = []
|
217 |
|
|
r_name = []
|
218 |
|
|
r_dir = []
|
219 |
|
|
|
220 |
|
|
c.ports( "i1" ) do |arg_name,arg_def,arg_dir|
|
221 |
|
|
r_def << arg_def
|
222 |
|
|
r_name << arg_name
|
223 |
|
|
r_dir << arg_dir
|
224 |
|
|
end
|
225 |
|
|
r_def.should be == %w[ m_p1 m_p2 m_p3 ]
|
226 |
|
|
r_name.should be == %w[ p1 p2 p3 ]
|
227 |
|
|
r_dir.should be == [ 1, 1, 0, ]
|
228 |
|
|
|
229 |
|
|
end
|
230 |
|
|
|
231 |
|
|
|
232 |
|
|
|
233 |
|
|
|
234 |
|
|
end
|