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

Subversion Repositories soc_maker

[/] [soc_maker/] [trunk/] [spec/] [soc_def_spec.rb] - Blame information for rev 8

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 feddischso
###############################################################
2
#
3
#  File:      soc_def_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 spec. for SOCMaker::SOCDef
37
#
38
#
39
#
40
###############################################################
41
require_relative( 'spec_helper' )
42
 
43
 
44
describe SOCMaker::SOCDef, "structure verification for loading a core-definition" do
45
 
46
  # not implemented at the moment
47
 
48
  # test for invalid path
49
  # it "should raise an error if a non-existing path is given" do
50
  #   expect { SOCMaker::from_f( 'blabla.txt' ) }.
51
  #       to raise_error( IOError )
52
  # end
53
 
54
 
55
 
56
 
57
  #
58
  # A yaml example, which contains
59
  #   - a full definition
60
  #   - an interface with one port
61
  #   - one hdl file
62
  #   - one instance parameter
63
  #   - one static parameter
64
  #
65
  FULL_SOC_YAML = '''SOCM_SOC
66
name: my_soc
67
description: A test SOC
68
version: rel2
69
date: 1.1.2014
70
license: LGPL
71
licensefile:
72
toplevel: soc_top
73
author: Christian Haettich
74
authormail: feddischson@opencores.org
75
repocmd: svn co http://some-address/
76
'''
77
 
78
 
79
SOC_YAML_WITH_CORE = '''SOCM_SOC
80
name: my_soc
81
description: A test SOC
82
version: rel2
83
date: 1.1.2014
84
license: LGPL
85
licensefile:
86
author: Christian Haettich
87
authormail: feddischson@opencores.org
88
repocmd: svn co http://some-address/
89
toplevel: soc_top
90
cores:
91
  :inst1: SOCM_INST
92
    type: mycorerel1
93
'''
94
 
95
 
96
 
97
 
98
 
99
 
100
  # process all valid YAMLs
101
  #  each should result in a CoreDef
102
  it 'should return a class of type SOCDef when loading a full soc-def' do
103
    SOCMaker::from_s( FULL_SOC_YAML ).class.should == SOCMaker::SOCDef
104
  end
105
 
106
  it "should rise an error if soc is loaded with a core, which is not in our library" do
107
    SOCMaker::lib.clear
108 7 feddischso
    expect { SOCMaker::from_s( SOC_YAML_WITH_CORE ).consistency_check }.
109 3 feddischso
      to raise_error( SOCMaker::ERR::LibError )
110
  end
111
 
112
 
113
  it "should return an SOC-object if soc is loaded with a core, which is in our library" do
114
    file = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }
115
    core = SOCMaker::CoreDef.new( "mycore", "rel1", file, "top" )
116
    SOCMaker::lib.add_core( core )
117
    soc = SOCMaker::from_s( SOC_YAML_WITH_CORE )
118
    soc.class.should be SOCMaker::SOCDef
119
  end
120
 
121
end
122
 
123
 
124
describe SOCMaker::SOCDef, "processing verification" do
125
 
126
    before( :each )do
127
      file = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }
128
      core = SOCMaker::CoreDef.new( "mycore", "rel1", file, "top" )
129
      SOCMaker::lib.add_core( core )
130
      @soc = SOCMaker::SOCDef.new( "test-soc", "v1", "my_soc_top" )
131
    end
132
 
133
    describe "adding/removing cores, connections etc." do
134
 
135
 
136
      it "inst_in_use should return true, if there is already an core instance with that name" do
137
        @soc.cores[ :core_inst ] = SOCMaker::CoreInst.new( "mycorerel1" )
138
        @soc.inst_in_use?( "core_inst" ).should be == true
139
      end
140
 
141
      it "inst_in_use should return false, if there is no core instance with that name" do
142
        @soc.inst_in_use?( "core_inst" ).should be == false
143
      end
144
 
145
      it "inst_in_use should return true, if there is already an connection instance with that name" do
146
        @soc.cons[ :a_con ] = { rule: "or", mapping: [ { :core_a => :ifc_a }, { :core_b => :ifc_b } ] }
147
        @soc.inst_in_use?( "a_con" ).should be == true
148
      end
149
 
150
 
151
 
152
      it "removing a core instance should be possible" do
153
        @soc.cores[ :core_inst ] = SOCMaker::CoreInst.new( "mycorerel1" )
154
        @soc.inst_in_use?( "core_inst" ).should be == true
155
        @soc.rm( "core_inst" ).should be == true
156
        @soc.inst_in_use?( "core_inst" ).should be == false
157
      end
158
 
159
 
160
      it "removing a connection instance should be possible" do
161
        @soc.cons[ :a_con ] = { rule: "or", mapping: [ { :core_a => :ifc_a }, { :core_b => :ifc_b } ] }
162
        @soc.inst_in_use?( "a_con" ).should be == true
163
        @soc.rm( "a_con" ).should be == true
164
        @soc.inst_in_use?( "a_con" ).should be == false
165
      end
166
 
167
      it "should return false, when removing a non-existance instance" do
168
        @soc.rm( "a_con" ).should be == false
169
      end
170
 
171
      it "should return nil if a instance is added twice" do
172
        @soc.cores[ :core_inst ] = SOCMaker::CoreInst.new( "mycorerel1" )
173
        @soc.add_core(  "mycore", "rel1", "core_inst" ).should be == false
174
      end
175
 
176
      it "should return non-nil value, if a instance is added once" do
177
        @soc.add_core(  "mycore", "rel1", "core_inst" ).should_not be == false
178
      end
179
 
180
      it "should return nil if a connection is added twice" do
181
        @soc.cons[ :a_con ] = { rule: "or", mapping: [ { :core_a => :ifc_a }, { :core_b => :ifc_b } ] }
182
        @soc.add_connection(  "core_a", "ifc_a", "core_c", "ifc_b", "a_con" ).should be == nil
183
      end
184
 
185
      it "should raise a library error when adding an unknown core" do
186
        expect{ @soc.add_core( "some_unknown_core", "v_xyz", "test" ) }.
187
          to raise_error( SOCMaker::ERR::LibError )
188
      end
189
 
190
      it "should create a dir and return the absolute path for a core inside the build/hdl dir" do
191
        SOCMaker::conf[ :build_dir ] = "./spec/tmp_build"
192
        SOCMaker::conf[ :hdl_dir   ] = "hdl"
193
        path = File.expand_path "./spec/tmp_build/hdl/a_core"
194
        FileUtils.rmdir( path ) if File.directory?( path )
195
        res = @soc.get_and_ensure_dst_dir!( "a_core" )
196
        File.directory?( path ).should be == true
197
        res.should be == path
198
      end
199
 
200
      it "should return false, when an interface is not used" do
201
        # setup interface ifc_b and ifc_c, test for ifc_a
202
        a_con = { rule: "or", mapping: [ { :core_a => :ifc_b }, { :core_b => :ifc_c } ] }
203
        @soc.cons[ :my_con ] = a_con
204
        @soc.ifc_in_use?( "core_a", "ifc_a" ).should be == false
205
      end
206
 
207
      it "should return true, if an interface is used" do
208
        a_con = { rule: "or", mapping: [ { :core_a => :ifc_a }, { :core_b => :ifc_b } ] }
209
        @soc.cons[ :my_con ] = a_con
210
        @soc.ifc_in_use?( "core_a", "ifc_a" ).should be == true
211
      end
212
 
213
 
214
      it "should raise an SOCMaker::ERR::ProcessingError add_connection tries to add a interface, wich is already used" do
215
        a_con = { rule: "or", mapping: [ { :core_a => :ifc_a }, { :core_b => :ifc_b } ] }
216
        @soc.cons[ :my_con ] = a_con
217
        expect{ @soc.add_connection(  "core_a", "ifc_a", "core_b", "ifc_c", "a_new_con" ) }.
218
          to raise_error( SOCMaker::ERR::ProcessingError )
219
        expect{ @soc.add_connection(  "core_a", "ifc_a", "core_c", "ifc_b", "a_new_con" ) }.
220
          to raise_error( SOCMaker::ERR::ProcessingError )
221
      end
222
 
223
      it "should raise an SOCMaker::ERR::ProcessingError if a connection is added from a non-existing core instance" do
224
        expect{ @soc.add_connection(  "core_a", "ifc_a", "core_c", "ifc_b", "a_new_con" ) }.
225
          to raise_error( SOCMaker::ERR::ProcessingError )
226
      end
227
 
228
      it "should raise an ProcessingError if a interface doesn't exist" do
229
        @soc.cores[ :core_a ] = SOCMaker::CoreInst.new( "mycorerel1" )
230
        @soc.cores[ :core_b ] = SOCMaker::CoreInst.new( "mycorerel1" )
231
        expect{ @soc.add_connection(  "core_a", "ifc_a", "core_b", "ifc_c", "a_new_con" ) }.
232
          to raise_error( SOCMaker::ERR::ProcessingError )
233
      end
234
 
235
 
236
      it "should raise an ProcessingError if the ifc.-version is wrong" do
237
 
238 8 feddischso
        ifc_spc1 = SOCMaker::IfcSpc.new( "myifc", "v1", 'ports' => { port_a: {dir:1}, port_b: {dir:0} } )
239
        ifc_spc2 = SOCMaker::IfcSpc.new( "myifc", "v2", 'ports' => { port_a: {dir:1}, port_b: {dir:0} } )
240 3 feddischso
        ifc_def_1 = SOCMaker::IfcDef.new( "myifc", "v1", 0, { a: SOCMaker::IfcPort.new( "port_a", 1 ) } )
241
        ifc_def_0 = SOCMaker::IfcDef.new( "myifc", "v2", 1, { b: SOCMaker::IfcPort.new( "port_b", 1 ) } )
242
        file = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }
243
        core_a = SOCMaker::CoreDef.new( "core_a", "v1", file, "top" )
244
        core_b = SOCMaker::CoreDef.new( "core_b", "v1", file, "top" )
245
        core_a.interfaces[ :ifc_a ] = ifc_def_0
246
        core_a.interfaces[ :ifc_b ] = ifc_def_1
247
        core_b.interfaces[ :ifc_a ] = ifc_def_0
248
        core_b.interfaces[ :ifc_b ] = ifc_def_1
249
 
250
        SOCMaker::lib.add_ifc( ifc_spc1 )
251
        SOCMaker::lib.add_ifc( ifc_spc2 )
252
        SOCMaker::lib.add_core( core_a )
253
        SOCMaker::lib.add_core( core_b )
254
        @soc.cores[ :core_a ] = SOCMaker::CoreInst.new( "core_av1" )
255
        @soc.cores[ :core_b ] = SOCMaker::CoreInst.new( "core_bv1" )
256
        expect { @soc.add_connection(  "inst_a", "ifc_a", "inst_b", "ifc_b", "a_new_con" ) }.
257
          to raise_error( SOCMaker::ERR::ProcessingError )
258
      end
259
 
260
 
261
 
262
 
263
      it "should add a connection entry" do
264
 
265 8 feddischso
        ifc_spc = SOCMaker::IfcSpc.new( "myifc", "v1", 'ports' => { port_a: {dir:1}, port_b: {dir:0} } )
266
 
267
        ifc_def_1 = SOCMaker::IfcDef.new( "myifc", "v1", 0, { a: SOCMaker::IfcPort.new( "port_a", 1 ),
268
                                                              b: SOCMaker::IfcPort.new( "port_b", 1 ) } )
269
 
270
        ifc_def_0 = SOCMaker::IfcDef.new( "myifc", "v1", 1, { a: SOCMaker::IfcPort.new( "port_a", 1 ),
271
                                                              b: SOCMaker::IfcPort.new( "port_b", 1 ) } )
272
 
273
 
274 3 feddischso
        file = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }
275
        core_a = SOCMaker::CoreDef.new( "core_a", "v1", file, "top" )
276
        core_b = SOCMaker::CoreDef.new( "core_b", "v1", file, "top" )
277
        core_a.interfaces[ :ifc_a ] = ifc_def_0
278
        core_a.interfaces[ :ifc_b ] = ifc_def_1
279
        core_b.interfaces[ :ifc_a ] = ifc_def_0
280
        core_b.interfaces[ :ifc_b ] = ifc_def_1
281
 
282
        SOCMaker::lib.add_ifc( ifc_spc )
283
        SOCMaker::lib.add_core( core_a )
284
        SOCMaker::lib.add_core( core_b )
285
 
286
 
287
 
288
        @soc.cores[ :inst_a ] = SOCMaker::CoreInst.new( "core_av1" )
289
        @soc.cores[ :inst_b ] = SOCMaker::CoreInst.new( "core_bv1" )
290 7 feddischso
        @soc.consistency_check
291 3 feddischso
        @soc.add_connection(  "inst_a", "ifc_a", "inst_b", "ifc_b", "a_new_con" )
292
        @soc.cons[ :a_new_con ].should be == { rule:'or', mapping: [ {inst_a: :ifc_a},{inst_b: :ifc_b} ] }
293
      end
294
 
295 5 feddischso
 
296
 
297
 
298
      it "should add a connection entry, which connects the toplevel's port" do
299
 
300 8 feddischso
        ifc_spc = SOCMaker::IfcSpc.new( "myifc", "v1", 'ports' => { port_a: {dir:1}, port_b: {dir:0} } )
301
 
302
        ifc_def_1 = SOCMaker::IfcDef.new( "myifc", "v1", 0, { a: SOCMaker::IfcPort.new( "port_a", 1 ),
303
                                                              b: SOCMaker::IfcPort.new( "port_b", 1 ) } )
304
 
305
        ifc_def_0 = SOCMaker::IfcDef.new( "myifc", "v1", 1, { a: SOCMaker::IfcPort.new( "port_a", 1 ),
306
                                                              b: SOCMaker::IfcPort.new( "port_b", 1 ) } )
307
 
308 5 feddischso
        file = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }
309
        core_a = SOCMaker::CoreDef.new( "core_a", "v1", file, "top" )
310
        core_a.interfaces[ :ifc_a ] = ifc_def_0
311
        core_a.interfaces[ :ifc_b ] = ifc_def_1
312
 
313
        SOCMaker::lib.add_ifc( ifc_spc )
314
        SOCMaker::lib.add_core( core_a )
315
 
316
 
317
       SOCMaker::lib.add_core( @soc )
318
       @soc.interfaces[ :t1 ] = ifc_def_1
319
       @soc.cores[ :inst_a ] = SOCMaker::CoreInst.new( "core_av1" )
320 7 feddischso
       @soc.consistency_check
321 5 feddischso
       @soc.add_connection(  "inst_a", "ifc_a", @soc.name, "t1", "a_new_con" )
322
       @soc.cons[ :a_new_con ].should be == { rule:'or', mapping: [ {inst_a: :ifc_a},{ @soc.name.to_sym => :t1} ] }
323
     end
324
 
325
 
326
 
327 3 feddischso
      it "should raise an error, if a parameter of unkonwn core is set" do
328
        expect{ @soc.set_param( "a_unknown_core", "p1", 1234 ) }.
329
          to raise_error( SOCMaker::ERR::ProcessingError )
330
      end
331
 
332
      it "should raise an error, if a parameter of unkonwn core is requested" do
333
        expect{ @soc.get_param( "a_unknown_core", "p1" ) }.
334
          to raise_error( SOCMaker::ERR::ProcessingError )
335
      end
336
 
337
      it "should raise an error, if a unknown parameter is set and requested" do
338
        file = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }
339
        core_a = SOCMaker::CoreDef.new( "core_a", "v1", file, "top" )
340
        parameter = SOCMaker::Parameter.new( "integer" )
341
        core_a.inst_parameters[ :p1 ] = parameter
342
        SOCMaker::lib.add_core( core_a )
343
        @soc.cores[ :inst_a ] = SOCMaker::CoreInst.new( "core_av1" )
344
        expect{ @soc.set_param( "inst_a", "px", 1234 ) }.
345
          to raise_error( SOCMaker::ERR::ProcessingError )
346
        expect{ @soc.get_param( "inst_a", "px" ) }.
347
          to raise_error( SOCMaker::ERR::ProcessingError )
348
      end
349
 
350
      it "should set a parameter and provide a parameter" do
351
        file = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }
352
        core_a = SOCMaker::CoreDef.new( "core_a", "v1", file, "top" )
353
        parameter = SOCMaker::Parameter.new( "integer" )
354
        core_a.inst_parameters[ :p1 ] = parameter
355
        SOCMaker::lib.add_core( core_a )
356
        @soc.cores[ :inst_a ] = SOCMaker::CoreInst.new( "core_av1" )
357
        @soc.set_param( "inst_a", "p1", 1234 )
358
        @soc.cores[ :inst_a ].params[ :p1 ].should be == 1234
359
        @soc.get_param( "inst_a", "p1" ).should be == 1234
360
      end
361
 
362
 
363
 
364
      it "should raise an error, if a static-parameter of unkonwn core is set" do
365
        expect{ @soc.set_sparam( "a_unknown_core", "p1", 1234 ) }.
366
          to raise_error( SOCMaker::ERR::ProcessingError )
367
      end
368
 
369
      it "should raise an error, if a statoc-parameter of unkonwn core is requested" do
370
        expect{ @soc.get_sparam( "a_unknown_core", "p1" ) }.
371
          to raise_error( SOCMaker::ERR::ProcessingError )
372
      end
373
 
374
      it "should an error, a static parameter doesn't exist" do
375
 
376
        file = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }
377
        core_a = SOCMaker::CoreDef.new( "core_a", "v1", file, "top" )
378
        SOCMaker::lib.add_core( core_a )
379
        @soc.cores[ :inst_a ] = SOCMaker::CoreInst.new( "core_av1" )
380
 
381
        expect{ @soc.set_sparam( "core_av1", "p1", 1234 ) }.
382
          to raise_error( SOCMaker::ERR::ProcessingError )
383
        expect{ @soc.get_sparam( "core_av1", "p1" ) }.
384
          to raise_error( SOCMaker::ERR::ProcessingError )
385
      end
386
 
387
      it "should set a static-parameter and provide this static parameter" do
388
 
389
        file = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }
390
        core_a = SOCMaker::CoreDef.new( "core_a", "v1", file, "top" )
391
        pentry = SOCMaker::SParameterEntry.new( "integer", "TOK" )
392
        parameter = SOCMaker::SParameter.new( "file/path.vhd.src",
393
                                              "file/path.vhd",
394
                                              'parameters' => { p1: pentry } )
395
        core_a.static_parameters[ :p1 ] = parameter
396
        SOCMaker::lib.add_core( core_a )
397
        @soc.cores[ :inst_a ] = SOCMaker::CoreInst.new( "core_av1" )
398
 
399
        @soc.set_sparam( "core_av1", "p1", 1234 )
400
        @soc.static[ :core_av1 ][ :p1 ].should be == 1234
401
        @soc.get_sparam( "core_av1", "p1" ).should be == 1234
402
      end
403
 
404
 
405
 
406
 
407
 
408
 
409
 
410
    end
411
 
412
  describe SOCMaker::SOCDef, "object handling, en-decoding:" do
413
 
414
    it "should be possible to encode and decode a core instance" do
415
      yaml_str = @soc.to_yaml
416
      o2 = YAML::load( yaml_str )
417
      @soc.should be == o2
418
    end
419
 
420
    it "should return false for two non-equal objects" do
421
      o2 = Marshal::load(Marshal.dump(@soc))
422
      o2.name << "X"
423
      ( o2 == @soc ).should be == false
424
    end
425
 
426
  end
427
 
428
 
429
end
430
 
431
 
432
 
433
 
434
# 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.