1 |
3 |
feddischso |
###############################################################
|
2 |
|
|
#
|
3 |
|
|
# File: sparameter_spec.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::SParameter and
|
37 |
|
|
# SOCMaker::SParameterEntry
|
38 |
|
|
#
|
39 |
|
|
#
|
40 |
|
|
#
|
41 |
|
|
#
|
42 |
|
|
###############################################################
|
43 |
|
|
require_relative( 'spec_helper' )
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
describe SOCMaker::Parameter, "verification" do
|
49 |
|
|
|
50 |
|
|
F_YAML_STATIC_NO_TOKEN = '''SOCM_CORE
|
51 |
|
|
name: core_A
|
52 |
|
|
version: rel1
|
53 |
|
|
toplevel: top_A
|
54 |
|
|
hdlfiles:
|
55 |
|
|
:core_a.vhd: SOCM_HDL_FILE
|
56 |
|
|
:path: ./core_a.vhd
|
57 |
|
|
static_parameters:
|
58 |
|
|
:a_file.vhd.src: SOCM_SPARAM
|
59 |
|
|
path: ./core_a.vhd
|
60 |
|
|
file_dst: a_file.vhd
|
61 |
|
|
parameters:
|
62 |
|
|
:p1: SOCM_SENTRY
|
63 |
|
|
min: 4
|
64 |
|
|
type: integer
|
65 |
|
|
'''
|
66 |
|
|
|
67 |
|
|
F_YAML_STATIC_NO_PATH = '''SOCM_CORE
|
68 |
|
|
name: core_A
|
69 |
|
|
version: rel1
|
70 |
|
|
toplevel: top_A
|
71 |
|
|
hdlfiles:
|
72 |
|
|
:core_a.vhd: SOCM_HDL_FILE
|
73 |
|
|
:path: ./core_a.vhd
|
74 |
|
|
static_parameters:
|
75 |
|
|
:a_file.vhd.src: SOCM_SPARAM
|
76 |
|
|
file_dst: a_file.vhd
|
77 |
|
|
parameters:
|
78 |
|
|
:p1: SOCM_SENTRY
|
79 |
|
|
min: 4
|
80 |
|
|
token: ABC
|
81 |
|
|
type: integer
|
82 |
|
|
'''
|
83 |
|
|
|
84 |
|
|
F_YAML_STATIC_NO_TYPE = '''SOCM_CORE
|
85 |
|
|
name: core_A
|
86 |
|
|
version: rel1
|
87 |
|
|
toplevel: top_A
|
88 |
|
|
hdlfiles:
|
89 |
|
|
:core_a.vhd: SOCM_HDL_FILE
|
90 |
|
|
:path: ./core_a.vhd
|
91 |
|
|
static_parameters:
|
92 |
|
|
:a_file.vhd.src: SOCM_SPARAM
|
93 |
|
|
file_dst: a_file.vhd
|
94 |
|
|
path: ./core_a.vhd
|
95 |
|
|
parameters:
|
96 |
|
|
:p1: SOCM_SENTRY
|
97 |
|
|
min: 4
|
98 |
|
|
token: ABC
|
99 |
|
|
'''
|
100 |
|
|
|
101 |
|
|
# missing file_dst in static parameter
|
102 |
|
|
F_YAML_STATIC_NO_DST1 = '''SOCM_CORE
|
103 |
|
|
name: core_A
|
104 |
|
|
version: rel1
|
105 |
|
|
toplevel: top_A
|
106 |
|
|
hdlfiles:
|
107 |
|
|
:core_a.vhd: SOCM_HDL_FILE
|
108 |
|
|
:path: ./core_a.vhd
|
109 |
|
|
static_parameters:
|
110 |
|
|
:a_file.vhd: SOCM_SPARAM
|
111 |
|
|
parameters:
|
112 |
|
|
:p1: SOCM_SENTRY
|
113 |
|
|
type: integer
|
114 |
|
|
token: T1
|
115 |
|
|
'''
|
116 |
|
|
# no parameter entry
|
117 |
|
|
F_YAML_STATIC_NO_SENTRY = '''SOCM_CORE
|
118 |
|
|
name: core_A
|
119 |
|
|
version: rel1
|
120 |
|
|
toplevel: top_A
|
121 |
|
|
hdlfiles:
|
122 |
|
|
:core_a.vhd: SOCM_HDL_FILE
|
123 |
|
|
path: ./core_a.vhd
|
124 |
|
|
static_parameters:
|
125 |
|
|
:a_file.vhd.src: SOCM_SPARAM
|
126 |
|
|
file_dst: a_file_xyz.vhd
|
127 |
|
|
path: ./core_a.vhd
|
128 |
|
|
parameters:
|
129 |
|
|
:p1: SOCM_SENTRY
|
130 |
|
|
'''
|
131 |
|
|
|
132 |
|
|
|
133 |
|
|
|
134 |
|
|
|
135 |
|
|
it "should return an object of type SOCMaker::SParameter when creating it with new" do
|
136 |
|
|
o = SOCMaker::SParameter.new( "./path/to/file.src", "./path/to/file.dst" )
|
137 |
|
|
o.class.should be SOCMaker::SParameter
|
138 |
|
|
o.parameters.class.should be Hash
|
139 |
|
|
end
|
140 |
|
|
|
141 |
|
|
it "should raise an error if the destination path has zero length" do
|
142 |
|
|
expect{ SOCMaker::SParameter.new( "./path/to/file.src", "" ) }.
|
143 |
|
|
to raise_error( SOCMaker::ERR::ValueError )
|
144 |
|
|
end
|
145 |
|
|
|
146 |
|
|
it "should raise an error if the destination path is nil" do
|
147 |
|
|
expect{ SOCMaker::SParameter.new( "./path/to/file.src", nil ) }.
|
148 |
|
|
to raise_error( SOCMaker::ERR::StructureError )
|
149 |
|
|
end
|
150 |
|
|
|
151 |
|
|
it "should raise an error if the destination path is not a string" do
|
152 |
|
|
expect{ SOCMaker::SParameter.new( "./path/to/file.src", 4 ) }.
|
153 |
|
|
to raise_error( SOCMaker::ERR::ValueError )
|
154 |
|
|
end
|
155 |
|
|
|
156 |
|
|
|
157 |
|
|
it "should raise an error if the src path has zero length" do
|
158 |
|
|
expect{ SOCMaker::SParameter.new( "", "./path/to/file.dst" ) }.
|
159 |
|
|
to raise_error( SOCMaker::ERR::ValueError )
|
160 |
|
|
end
|
161 |
|
|
|
162 |
|
|
it "should raise an error if the src path is nil" do
|
163 |
|
|
expect{ SOCMaker::SParameter.new( nil, "./path/to/file.dst" ) }.
|
164 |
|
|
to raise_error( SOCMaker::ERR::StructureError )
|
165 |
|
|
end
|
166 |
|
|
|
167 |
|
|
it "should raise an error if the src path is not a string" do
|
168 |
|
|
expect{ SOCMaker::SParameter.new( 4,"./path/to/file.dst" ) }.
|
169 |
|
|
to raise_error( SOCMaker::ERR::ValueError )
|
170 |
|
|
end
|
171 |
|
|
|
172 |
|
|
|
173 |
|
|
it "should raise an error if the path is not defined" do
|
174 |
|
|
expect{ SOCMaker::from_s( F_YAML_STATIC_NO_PATH ) }.
|
175 |
|
|
to raise_error( SOCMaker::ERR::StructureError )
|
176 |
|
|
end
|
177 |
|
|
|
178 |
|
|
it "should raise an error if the token is not defined" do
|
179 |
|
|
expect{ SOCMaker::from_s( F_YAML_STATIC_NO_TOKEN ) }.
|
180 |
|
|
to raise_error( SOCMaker::ERR::StructureError )
|
181 |
|
|
end
|
182 |
|
|
|
183 |
|
|
it "should raise an error if the type is not defined" do
|
184 |
|
|
expect{ SOCMaker::from_s( F_YAML_STATIC_NO_TYPE ) }.
|
185 |
|
|
to raise_error( SOCMaker::ERR::StructureError )
|
186 |
|
|
end
|
187 |
|
|
|
188 |
|
|
|
189 |
|
|
it "should raise an error if the destination is not defined" do
|
190 |
|
|
expect{ SOCMaker::from_s( F_YAML_STATIC_NO_DST1 ) }.
|
191 |
|
|
to raise_error( SOCMaker::ERR::StructureError )
|
192 |
|
|
end
|
193 |
|
|
|
194 |
|
|
it "should return an object of type SOCMaker::SParameterentry when creating it with new" do
|
195 |
|
|
o = SOCMaker::SParameterEntry.new( "type", "mytoken" )
|
196 |
|
|
o.class.should be SOCMaker::SParameterEntry
|
197 |
|
|
end
|
198 |
|
|
|
199 |
|
|
it "should raise an error if token is nil" do
|
200 |
|
|
expect{ SOCMaker::SParameterEntry.new( "type", nil ) }.
|
201 |
|
|
to raise_error( SOCMaker::ERR::StructureError )
|
202 |
|
|
end
|
203 |
|
|
|
204 |
|
|
it "should raise an error if token is an empty string" do
|
205 |
|
|
expect{ SOCMaker::SParameterEntry.new( "type", "" ) }.
|
206 |
|
|
to raise_error( SOCMaker::ERR::ValueError )
|
207 |
|
|
end
|
208 |
|
|
|
209 |
|
|
it "should raise an error if token is not a string" do
|
210 |
|
|
expect{ SOCMaker::SParameterEntry.new( "type", 4 ) }.
|
211 |
|
|
to raise_error( SOCMaker::ERR::ValueError )
|
212 |
|
|
end
|
213 |
|
|
|
214 |
|
|
it "should raise an error if an entry is not provided" do
|
215 |
|
|
expect{ SOCMaker::from_s( F_YAML_STATIC_NO_SENTRY ) }.
|
216 |
|
|
to raise_error( SOCMaker::ERR::StructureError )
|
217 |
|
|
end
|
218 |
|
|
|
219 |
|
|
|
220 |
|
|
end
|
221 |
|
|
|
222 |
|
|
describe SOCMaker::SParameter, "object handling, en-decoding:" do
|
223 |
|
|
|
224 |
|
|
|
225 |
|
|
it "should be possible to encode and decode a static parameter" do
|
226 |
|
|
o1 = SOCMaker::SParameter.new(
|
227 |
|
|
"./path/to/file.src",
|
228 |
|
|
"./path/to/file.dst",
|
229 |
|
|
'parameters' => { p1: SOCMaker::SParameterEntry.new( "file.src", "file.dst" ) } )
|
230 |
|
|
|
231 |
|
|
yaml_str = o1.to_yaml
|
232 |
|
|
o2 = YAML::load( yaml_str )
|
233 |
|
|
o1.should be == o2
|
234 |
|
|
end
|
235 |
|
|
|
236 |
|
|
it "should return false for two non-equal objects" do
|
237 |
|
|
o1 = SOCMaker::SParameterEntry.new(
|
238 |
|
|
"./path/to/file.src",
|
239 |
|
|
"./path/to/file.dst" )
|
240 |
|
|
o2 = Marshal::load(Marshal.dump(o1))
|
241 |
|
|
o2.min = 4
|
242 |
|
|
( o2 == o1 ).should be == false
|
243 |
|
|
end
|
244 |
|
|
|
245 |
|
|
it "should be possible to encode and decode a static parameter entry" do
|
246 |
|
|
o1 = SOCMaker::SParameterEntry.new(
|
247 |
|
|
"./path/to/file.src",
|
248 |
|
|
"./path/to/file.dst",
|
249 |
|
|
'default' => 0,
|
250 |
|
|
'min' => 0,
|
251 |
|
|
'max' => 3,
|
252 |
|
|
'visible' => true,
|
253 |
|
|
'editable' => false,
|
254 |
|
|
'description' => "test description" )
|
255 |
|
|
yaml_str = o1.to_yaml
|
256 |
|
|
o2 = YAML::load( yaml_str )
|
257 |
|
|
o1.should be == o2
|
258 |
|
|
end
|
259 |
|
|
|
260 |
|
|
|
261 |
|
|
end
|
262 |
|
|
|
263 |
|
|
|
264 |
|
|
# vim: noai:ts=2:sw=2
|
265 |
|
|
|