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

Subversion Repositories soc_maker

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 feddischso
###############################################################
2
#
3
#  File:      core_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 specification for SOCMaker::CoreDef
37
#
38
#
39
#
40
#
41
###############################################################
42
require_relative( 'spec_helper' )
43
 
44
 
45
 
46
 
47
 
48
 
49
 
50
describe SOCMaker::CoreDef, "structure verification for loading a core-definition" do
51
 
52
  valid_yamls = []
53
  invalid_v_yamls = []
54
  invalid_s_yamls = []
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_YAML = '''SOCM_CORE
66
name: core_A
67
description: A test IP-core
68 10 feddischso
id: core_A,rel1
69 3 feddischso
date: 1.1.2014
70
license: LGPL
71
licensefile:
72
author: Christian Haettich
73
authormail: feddischson@opencores.org
74
vccmd: svn co http://some-address/
75
toplevel: core_a
76
interfaces:
77
  :ifc01: SOCM_IFC
78
    name: core_AB_ifc
79
    dir: 0
80 10 feddischso
    id: core_AB_ifc,1
81 3 feddischso
    ports:
82
      :sig_con1a: SOCM_PORT
83
         defn: sig_a
84
         len:  param1
85
hdlfiles:
86
   :core_a.vhd: SOCM_HDL_FILE
87
      use_syn: true
88
      use_sys_sim: true
89
      use_mod_sim: true
90
      type: vhdl
91
      path: ./core_a.vhd
92
inst_parameters:
93
  :param1: SOCM_PARAM
94
    type: integer
95
    default: 8
96
    min: 0
97
    max: 10
98
    visible: true
99
    editable: true
100
    description: More setup
101
static_parameters:
102
  :core_a_pkg.vhd.src: SOCM_SPARAM
103
    path: ./core_a.pkg.src
104
    file_dst: core_a_pkg.vhd
105
    parameters:
106
      :p1: SOCM_SENTRY
107
        token: TOK1
108
        type: integer
109
        min:  0
110
        max:  100
111
        visible: true
112
        editable: true
113
        default: 3
114
        description: Some setup
115
'''
116
  valid_yamls << {  desc: 'should return a class of type CoreDef when loading a full core-def',
117
                    yaml: FULL_YAML }
118
 
119
 
120
 
121
  # minimalistic def with one vhdl file
122
  MIN_YAML1 = '''SOCM_CORE
123
name: core_A
124 10 feddischso
id: core_A,rel1
125 3 feddischso
toplevel: top_A
126
hdlfiles:
127
   :core_a.vhd: SOCM_HDL_FILE
128
      path: ./core_a.vhd
129
'''
130
  valid_yamls << {  desc: 'should return a class of type CoreDef when loading a minimal core-def',
131
                    yaml: MIN_YAML1 }
132
 
133
 
134
  # minimalistic def with one
135
  # vhdl and one verilog file
136
  MIN_YAML2 = '''SOCM_CORE
137
name: core_A
138 10 feddischso
id: core_A,rel1
139 3 feddischso
toplevel: top_A
140
hdlfiles:
141
   :core_a.vhd: SOCM_HDL_FILE
142
      path: ./core_a.vhd
143
   :core_b.v: SOCM_HDL_FILE
144
      path: ./core_b.v
145
'''
146
  valid_yamls << {  desc: 'should return a class of type CoreDef when loading a core-def with two files',
147
                    yaml: MIN_YAML2 }
148
 
149
 
150
 
151
 
152
 
153
 
154
#    # def with version.size == 0
155
#    F_YAML_VERSION = '''SOCM_CORE
156
#  name: core_A
157
#  version: ''
158
#  toplevel: top_A
159
#  hdlfiles:
160
#     :core_a.vhd: SOCM_HDL_FILE
161
#        path: ./core_a.vhd
162
#  '''
163
#    invalid_s_yamls << {  desc: 'should raise an error if version is a string with length 0',
164
#                          yaml: F_YAML_VERSION }
165
 
166
 
167
#    # def with name.size == 0
168
#    F_YAML_NAME = '''SOCM_CORE
169
#  name: ''
170
#  version: rel1
171
#  toplevel: top_A
172
#  hdlfiles:
173
#     :core_a.vhd: SOCM_HDL_FILE
174
#        path: ./core_a.vhd
175
#  '''
176
#    invalid_s_yamls << {  desc: 'should raise an error if name is a string with length 0',
177
#                          yaml: F_YAML_NAME }
178
 
179
 
180
 
181
 
182
 
183
 
184
 
185
  # def with toplevel.size == 0
186
  F_YAML_TOPLEVEL = '''SOCM_CORE
187
name: core_A
188 10 feddischso
id: core_A,rel1
189 3 feddischso
toplevel: ''
190
hdlfiles:
191
   :core_a.vhd: SOCM_HDL_FILE
192
      path: ./core_a.vhd
193
'''
194
  invalid_s_yamls << {  desc: 'should raise an error if toplevel is a string with length 0',
195
                        yaml: F_YAML_TOPLEVEL }
196
 
197
 
198
 
199
  # def with hdlfiles.class != Hash
200
  F_YAML_FILE_HASH = '''SOCM_CORE
201
name: core_A
202 10 feddischso
id: core_A,rel1
203 3 feddischso
toplevel: top_A
204
hdlfiles:
205
   - test1.vhd
206
   - test2.vhd
207
'''
208
  invalid_s_yamls << {  desc: 'should raise an error if hdlfiles is not a hash',
209
                        yaml: F_YAML_FILE_HASH }
210
 
211
 
212
 
213
 
214
  # minimal setup with one interface
215
  MIN_YAML_IFC = '''SOCM_CORE
216
name: core_A
217 10 feddischso
id: core_A,rel1
218 3 feddischso
toplevel: top_A
219
hdlfiles:
220
   :core_a.vhd: SOCM_HDL_FILE
221
      path: ./core_a.vhd
222
interfaces:
223
  :ifc01: SOCM_IFC
224
    name: a_ifc_def
225
    dir: 0
226 10 feddischso
    id: a_ifc_def,1
227 3 feddischso
    ports:
228
      :sig_con1a: SOCM_PORT
229
         defn: sig_a
230
'''
231
  valid_yamls << { desc: 'should return a class of type CoreDef when loading a minimal core-def with a minimal interface',
232
                   yaml: MIN_YAML_IFC }
233
 
234
 
235
 
236
 
237
 
238
  # minimal setup with one instance parameter
239
  MIN_YAML_INSTP = '''SOCM_CORE
240
name: core_A
241 10 feddischso
id: core_A,rel1
242 3 feddischso
toplevel: top_A
243
hdlfiles:
244
   :core_a.vhd: SOCM_HDL_FILE
245
      path: ./core_a.vhd
246
inst_parameters:
247
  :param1: SOCM_PARAM
248
    type: integer
249
'''
250
  valid_yamls << {  desc: 'should return a class of type CoreDef when loading a minimal core-def (with instance param.)',
251
                    yaml: MIN_YAML_INSTP }
252
 
253
 
254
  # empty hash for param1
255
  F_YAML_INSTP_EMPTY = '''SOCM_CORE
256
name: core_A
257 10 feddischso
id: core_A,rel1
258 3 feddischso
toplevel: top_A
259
hdlfiles:
260
   :core_a.vhd: SOCM_HDL_FILE
261
      path: ./core_a.vhd
262
inst_parameters:
263
  :param1: SOCM_PARAM
264
'''
265
  invalid_s_yamls << {  desc: 'should raise an error if an instance param. is empty',
266
                        yaml: F_YAML_INSTP_EMPTY }
267
 
268
  # minimal def with one static parameter
269
  MIN_YAML_STATIC = '''SOCM_CORE
270
name: core_A
271 10 feddischso
id: core_A,rel1
272 3 feddischso
toplevel: top_A
273
hdlfiles:
274
   :core_a.vhd: SOCM_HDL_FILE
275
      path: ./core_a.vhd
276
static_parameters:
277
  :a_file.vhd.src: SOCM_SPARAM
278
    file_dst: a_file.vhd
279
    path: ./core_a.vhd
280
    parameters:
281
      :p1:  SOCM_SENTRY
282
        type: integer
283
        token: T1
284
'''
285
  valid_yamls << {  desc: 'should return a class of type CoreDef when loading a minimal core-def (with static param.)',
286
                    yaml: MIN_YAML_STATIC }
287
 
288
 
289
 
290
  # empty static parameter
291
  F_YAML_STATIC_EMPTY = '''SOCM_CORE
292
name: core_A
293 10 feddischso
id: core_A,rel1
294 3 feddischso
toplevel: top_A
295
hdlfiles:
296
   :core_a.vhd: SOCM_HDL_FILE
297
      path: ./core_a.vhd
298
static_parameters:
299
  :a_file.vhd: SOCM_SPARAM
300
'''
301
  invalid_s_yamls << {  desc: 'should raise an error if a static parameters is empty',
302
                        yaml: F_YAML_STATIC_EMPTY }
303
 
304
 
305
 
306
  # removed: not implemented at the moment
307
 
308
# #
309
# # test for invalid path
310
# it "should raise an error if a non-existing path is given" do
311
#   expect { SOCMaker::from_f( 'blabla.txt' ) }.
312
#       to raise_error( IOError )
313
# end
314
 
315
 
316
  it "should return a CoreDef object, if the object is created via new" do
317
    file = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }
318 10 feddischso
    c = SOCMaker::CoreDef.new( "acore", "acore,v1", file, "top" )
319 3 feddischso
    c.class.should be == SOCMaker::CoreDef
320
  end
321
 
322
 
323
 
324
  # process all valid YAMLs
325
  #  each should result in a CoreDef
326
  valid_yamls.each do |setup|
327
    it setup[:desc] do
328
      SOCMaker::from_s( setup[:yaml] ).class.should == SOCMaker::CoreDef
329
    end
330
  end
331
 
332
  # process all invalid YAMLs
333
  #  each should result in a StructureError
334
  invalid_s_yamls.each do |setup|
335
    it setup[:desc] do
336
      expect { SOCMaker::from_s( setup[ :yaml ] ) }.
337
        to raise_error( SOCMaker::ERR::StructureError )
338
    end
339
  end
340
 
341
 
342
  # process all invalid YAMLs
343
  #  each should result in a ValueError
344
  invalid_v_yamls.each do |setup|
345
    it setup[:desc] do
346
      expect { SOCMaker::from_s( setup[ :yaml ] ) }.
347
        to raise_error( SOCMaker::ERR::ValueError )
348
    end
349
  end
350
 
351
  #
352
  # remove some entries in the basic definition
353
  #   It is ok, when the first line is not available:
354
  #   In this case, we assume, that something unrelated
355
  #   to SOCMaker is loaded
356
  #
357
  min_yaml_lines = MIN_YAML1.lines
358
  (1..min_yaml_lines.size-1).each do |i|
359
    min_yaml_lines.delete_at( i )
360
    inval_yaml = min_yaml_lines.join
361
    it 'should raise an error if loading of an invalid yaml is done (A)' do
362
      expect { SOCMaker::from_s( inval_yaml ) }.
363
        to raise_error
364
    end
365
    min_yaml_lines = MIN_YAML1.lines
366
  end
367
 
368
  # remove entries in the interface definition
369
  #
370
  min_yaml_lines = MIN_YAML_IFC.lines
371
  (9..min_yaml_lines.size-1).each do |i|
372
    min_yaml_lines.delete_at( i )
373
    inval_yaml = min_yaml_lines.join
374
    it 'should raise an error if loading of an invalid yaml is done (B)' do
375
      expect { SOCMaker::from_s( inval_yaml ) }.
376
        to raise_error
377
    end
378
    min_yaml_lines = MIN_YAML_IFC.lines
379
  end
380
 
381
 
382
 
383
  # auto-completion of basic info
384
  #
385
  it 'should return an CoreDef object with non-nil parameters, even if parameters are not specified' do
386
    tmp = SOCMaker::from_s( MIN_YAML2 )
387
    tmp.class.should be                 == SOCMaker::CoreDef
388
    tmp.vccmd.should_not be             == nil
389
    tmp.description.should_not be       == nil
390
    tmp.date.should_not be              == nil
391
    tmp.license.should_not be           == nil
392
    tmp.licensefile.should_not be       == nil
393
    tmp.author.should_not be            == nil
394
    tmp.authormail.should_not be        == nil
395
    tmp.vccmd.should_not be             == nil
396
    tmp.interfaces.should_not be        == nil
397
    tmp.functions.should_not be         == nil
398
    tmp.inst_parameters.should_not be   == nil
399
    tmp.static_parameters.should_not be == nil
400
 
401
    tmp.hdlfiles[ 'core_a.vhd'.to_sym ].type        .should be == 'vhdl'
402
    tmp.hdlfiles[ 'core_b.v'.to_sym   ].type        .should be == 'verilog'
403
    tmp.hdlfiles[ 'core_a.vhd'.to_sym ].use_syn     .should be == true
404
    tmp.hdlfiles[ 'core_a.vhd'.to_sym ].use_sys_sim .should be == true
405
    tmp.hdlfiles[ 'core_a.vhd'.to_sym ].use_mod_sim .should be == true
406
  end
407
 
408
  # auto-completion of interface setups
409
  #
410
  it 'should auto-complete the field length to 1 when loading a minimal core-def with a minimal interface' do
411
    tmp = SOCMaker::from_s( MIN_YAML_IFC )
412
    tmp.interfaces[ :ifc01 ].ports[ :sig_con1a ].len.should == 1
413
  end
414
 
415
  # auto-completion of static-parameters
416
  #
417
  it 'should auto-complete static parameter setup to non-nil values when loading a minimal core-def' do
418
    tmp = SOCMaker::from_s( MIN_YAML_STATIC )
419
    tmp.static_parameters[ :'a_file.vhd.src'].parameters[ :p1 ].default.should be     == 0
420
    tmp.static_parameters[ :'a_file.vhd.src'].parameters[ :p1 ].min.should be         == 0
421
    tmp.static_parameters[ :'a_file.vhd.src'].parameters[ :p1 ].max.should be         == 0
422
    tmp.static_parameters[ :'a_file.vhd.src'].parameters[ :p1 ].visible.should be     == true
423
    tmp.static_parameters[ :'a_file.vhd.src'].parameters[ :p1 ].editable.should be    == false
424
    tmp.static_parameters[ :'a_file.vhd.src'].parameters[ :p1 ].description.should be == ''
425
  end
426
 
427
  # auto-completion of instance-parameters
428
  #
429
  it 'should auto-complete inst. parameter setup to non-nil values when a minimal core-def' do
430
    tmp = SOCMaker::from_s( MIN_YAML_INSTP )
431
    tmp.inst_parameters[ :param1 ].min          .should be  == 0
432
    tmp.inst_parameters[ :param1 ].max          .should be  == 0
433
    tmp.inst_parameters[ :param1 ].default      .should be  == 0
434
    tmp.inst_parameters[ :param1 ].visible      .should be  == true
435
    tmp.inst_parameters[ :param1 ].editable     .should be  == false
436
    tmp.inst_parameters[ :param1 ].description  .should be  == ''
437
  end
438
 
439
 
440
 
441
  # This is a valid version which we manipulate and
442
  # test, if the manipulation is detected/corrected
443
# tmp = SOCMaker::from_s( FULL_YAML )
444
#
445
#
446
#
447
#
448
# it 'should raise an error if ifc-name is not a string' do
449
#   tmp.interfaces[ :ifc01 ].name  = 4
450
#   expect { SOCMaker::from_s( SOCMaker::YPP.from_yaml( tmp.to_yaml ) ) }.
451
#     to raise_error( SOCMaker::ERR::ValueError )
452
#   tmp.interfaces[ :ifc01 ].name = 'name'
453
# end
454
#
455
# it 'should raise an error if ifc-dir is not 0 or 1' do
456
#   tmp.interfaces[ :ifc01 ].dir  = 4
457
#   expect { SOCMaker::from_s( SOCMaker::YPP.from_yaml( tmp.to_yaml ) ) }.
458
#     to raise_error( SOCMaker::ERR::ValueError )
459
#
460
#   tmp.interfaces[ :ifc01 ].dir  = "test"
461
#   expect { SOCMaker::from_s( SOCMaker::YPP.from_yaml( tmp.to_yaml )  ) }.
462
#     to raise_error( SOCMaker::ERR::ValueError )
463
#   tmp.interfaces[ :ifc01 ].dir = 0
464
# end
465
#
466
# it 'should convert an interface version from numerical to string' do
467
#   tmp.interfaces[ :ifc01 ].version = 4
468
#   tmp2 = SOCMaker::from_s( SOCMaker::YPP.from_yaml( tmp.to_yaml ) )
469
#   tmp2.interfaces[ :ifc01 ].version.class.should be == String
470
# end
471
 
472
end
473
 
474
describe SOCMaker::CoreDef, "object handling, en-decoding:" do
475
 
476
  it "should be possible to encode and decode a core definition" do
477
    file = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }
478 10 feddischso
    o1 = SOCMaker::CoreDef.new( "acore", "acore,v1", file, "top" )
479 3 feddischso
    yaml_str = o1.to_yaml
480
    o2 = YAML::load( yaml_str )
481
    o1.should be == o2
482
  end
483
 
484
  it "should return false for two non-equal objects" do
485
    file = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }
486 10 feddischso
    o1 = SOCMaker::CoreDef.new( "acore", "acore,v1", file, "top" )
487 3 feddischso
    o2 = Marshal::load(Marshal.dump(o1))
488 10 feddischso
    o2.id = "acore,v2"
489 3 feddischso
    ( o2 == o1 ).should be == false
490
    o2 = Marshal::load(Marshal.dump(o1))
491
    o2.hdlfiles[ "file.vhd".to_sym ].use_syn = false
492
    ( o2 == o1 ).should be == false
493
  end
494
 
495
 
496
 
497
# tmp = SOCMaker::from_s( FULL_YAML )
498
# tmp.save_def( "./test.yaml" )
499
 
500
 
501
 
502
end
503
 
504
 
505 8 feddischso
 
506 3 feddischso
# 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.