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 5

Go to most recent revision | 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
  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 5 feddischso
 
178 3 feddischso
 
179 5 feddischso
 
180 3 feddischso
  it 'should iterate over all ports' do
181
 
182
    SOCMaker::lib.clear
183
    ifc_s1 = SOCMaker::IfcSpc.new( "i1", "v1", 'ports' => { p1: 1, p2: 1, p3: 0 } )
184
    ifc_s2 = SOCMaker::IfcSpc.new( "i2", "v1", 'ports' => { x1: 1, x2: 0 } )
185
    SOCMaker::lib.add_ifc( ifc_s1 )
186
    SOCMaker::lib.add_ifc( ifc_s2 )
187
 
188
    p1 = SOCMaker::IfcPort.new( "p1", 1 )
189
    p2 = SOCMaker::IfcPort.new( "p2", 2 )
190
    p3 = SOCMaker::IfcPort.new( "p3", 3 )
191
    x1 = SOCMaker::IfcPort.new( "x1", 1 )
192
    x2 = SOCMaker::IfcPort.new( "x2", 2 )
193
 
194
    ifc_d1 = SOCMaker::IfcDef.new( "i1", "v1", 0, { m_p1: p1, m_p2: p2, m_p3: p3 } )
195
    ifc_d2 = SOCMaker::IfcDef.new( "i2", "v1", 0, { m_x1: x1, m_x2: x2           } )
196
 
197
 
198
    c = SOCMaker::Component.new( "acore", "v1", "top",
199
      { 'interfaces' =>  { i1: ifc_d1, i2: ifc_d2 } } )
200
 
201
    r_name    = []
202
    r_dir     = []
203
    r_len     = []
204
    r_is_last = []
205
 
206
    c.ports do |arg_name,arg_dir,arg_len,arg_is_last|
207
      r_name    << arg_name
208
      r_dir     << arg_dir
209
      r_len     << arg_len
210
      r_is_last << arg_is_last
211
    end
212
    r_name.sort.should be == %w[ m_p1 m_p2 m_p3 m_x1 m_x2 ].sort
213
    r_dir.sort.should be  ==   [ 1, 1, 0, 1, 0 ].sort
214
    r_len.sort.should be  ==   [ 1, 2, 3, 1, 2 ].sort
215
    r_is_last.should be   == [ false, false, false, false, true ]
216
 
217
 
218
    r_def     = []
219
    r_name    = []
220
    r_dir     = []
221
 
222
    c.ports( "i1" ) do |arg_name,arg_def,arg_dir|
223
      r_def     << arg_def
224
      r_name    << arg_name
225
      r_dir     << arg_dir
226
    end
227
    r_def.should be == %w[ m_p1 m_p2 m_p3 ]
228
    r_name.should be == %w[ p1 p2 p3 ]
229
    r_dir.should be  ==   [ 1, 1, 0, ]
230
 
231
  end
232
 
233
 
234
 
235
 
236
end

powered by: WebSVN 2.1.0

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