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

Subversion Repositories soc_maker

[/] [soc_maker/] [trunk/] [spec/] [core_inst_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_inst_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
#
37
#
38
#
39
#
40
###############################################################
41
require_relative( 'spec_helper' )
42
 
43
 
44
describe SOCMaker::CoreInst, "structure and auto-completion functionallity" do
45
 
46
 
47
  it "should raise an error, if parameters are not given as hash" do
48
     file = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }
49
     core = SOCMaker::CoreDef.new( "mycore", "rel1", file, "top" )
50
     SOCMaker::lib.add_core( core )
51
     expect{  SOCMaker::CoreInst.new( "mycorerel1", "not a hash"  ) }.
52
     to raise_error( SOCMaker::ERR::StructureError )
53
     SOCMaker::lib.rm_core( core )
54
  end
55
 
56
 
57
  it "should raise an error, if parameters are given, which doesn't exist in the definition" do
58
     file = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }
59 10 feddischso
     core = SOCMaker::CoreDef.new( "My Core", "mycore,rel1", file, "top" )
60 3 feddischso
     SOCMaker::lib.add_core( core )
61 7 feddischso
     expect{
62 10 feddischso
         inst = SOCMaker::CoreInst.new( "mycore,rel1", { "aparameter".to_sym => 4 } )
63 7 feddischso
         inst.consistency_check }.
64 3 feddischso
     to raise_error( SOCMaker::ERR::ValueError )
65
     SOCMaker::lib.rm_core( core )
66
 
67
  end
68
 
69
  it "should auto-complete generics with default values" do
70
 
71
     # create core with one file and one instance parameter
72
     file = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }
73
     parameters = { "param1".to_sym => SOCMaker::Parameter.new( "integer" )  }
74 10 feddischso
     core = SOCMaker::CoreDef.new( "My Core", "mycore,rel1", file, "top" )
75 3 feddischso
     core.inst_parameters = parameters
76
     SOCMaker::lib.add_core( core )
77
 
78 10 feddischso
     inst = SOCMaker::CoreInst.new( "mycore,rel1", {}  )
79 7 feddischso
     inst.consistency_check
80 3 feddischso
     inst.params[ :param1 ].should be == 0
81
     SOCMaker::lib.rm_core( core )
82
  end
83
 
84
end
85
 
86 7 feddischso
#describe SOCMaker::CoreDef, "HDL interaction" do
87 5 feddischso
 
88 7 feddischso
#   it 'should return true and false for implements_port?, when a port is implemented and
89
#       not implemented' do
90
#      file       = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }
91 10 feddischso
#      core       = SOCMaker::CoreDef.new( "My Core", "mycore,rel1", file, "top" )
92 7 feddischso
#      ifc_spc    = SOCMaker::IfcSpc.new( "a_ifc", "v1", "ports" => { p1: 1, p2: 0 } )
93
#      ifc        = SOCMaker::IfcDef.new( "a_ifc", "v1", 1, { p1: SOCMaker::IfcPort.new( "p1", 1 ) } )
94
#      core.interfaces[ :i1 ] = ifc
95
#      SOCMaker::lib.add_core( core )
96
#      SOCMaker::lib.add_ifc( ifc_spc )
97 5 feddischso
 
98 10 feddischso
#      o1 = SOCMaker::CoreInst.new( "mycore,rel1", {}  )
99 7 feddischso
#      o1.consistency_check
100
#      o1.implements_port?( 'i1', 'p1' ).should be == true
101
#      o1.implements_port?( 'i1', 'p2' ).should be == false
102
#    end
103
#end
104 5 feddischso
 
105 3 feddischso
describe SOCMaker::CoreDef, "object handling, en-decoding:" do
106
 
107
  it "should be possible to encode and decode a core instance" do
108
    file = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }
109
    parameters = { "param1".to_sym => SOCMaker::Parameter.new( "integer" )  }
110 10 feddischso
    core = SOCMaker::CoreDef.new( "My Core", "mycore,rel1", file, "top" )
111 3 feddischso
    core.inst_parameters = parameters
112
    SOCMaker::lib.add_core( core )
113
 
114 10 feddischso
    o1 = SOCMaker::CoreInst.new( "mycore,rel1", {}  )
115 3 feddischso
    yaml_str = o1.to_yaml
116
    o2 = YAML::load( yaml_str )
117
    o1.should be == o2
118
  end
119
 
120
  it "should return false for two non-equal objects" do
121
    file = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }
122
    parameters = { "param1".to_sym => SOCMaker::Parameter.new( "integer" )  }
123 10 feddischso
    core = SOCMaker::CoreDef.new( "My Core", "mycore,rel1", file, "top" )
124 3 feddischso
    core.inst_parameters = parameters
125
    SOCMaker::lib.add_core( core )
126
 
127 10 feddischso
    o1 = SOCMaker::CoreInst.new( "mycore,rel1" )
128 7 feddischso
    o1.consistency_check
129 3 feddischso
    o2 = Marshal::load(Marshal.dump(o1))
130
    o2.type << "X"
131
    ( o2 == o1 ).should be == false
132
    o2 = Marshal::load(Marshal.dump(o1))
133
    o2.params[ :param1 ] = 1
134
    ( o2 == o1 ).should be == false
135
  end
136
 
137 7 feddischso
   it "should call coder functions for each core-def. (stub-version)" do
138
 
139
     SOCMaker::lib.clear
140 10 feddischso
     soc = SOCMaker::SOCDef.new( "test_soc", "test_soc,v1", "my_soc_top" )
141 7 feddischso
 
142
 
143
     coder = double()
144
 
145
     added_cores = {}
146
     coder.stub( :add_core_component ) do |name_arg, def_arg|
147
       added_cores[ name_arg.to_sym ] = def_arg
148
     end
149
 
150
     added_instances = {}
151
     coder.stub( :add_core_instance ) do |name_arg, inst_arg|
152
       added_instances[ name_arg.to_sym ] = inst_arg
153
     end
154
 
155
     coder.stub( :get_hdl_code ){ |arg_coder| }
156
 
157
     coder.stub( :is_a? ){ SOCMaker::VHDLCoder }
158
 
159
     coder.stub( :filename ){ |x| x + ".vhd" }
160
 
161 8 feddischso
     coder.stub( :add_ifc_default_assignment )
162 7 feddischso
 
163
     coder.stub( :add_ifc_connection )
164
 
165
 
166
     added_cons = {}
167
 
168
     dir_path = ""
169
     FileUtils.stub( :mkdir_p ) { |arg| dir_path = arg }
170
     SOCMaker::conf[ :build_dir ] = 'a'
171
     SOCMaker::conf[ :hdl_dir   ] = 'b'
172
     dir_path_ref = "a/b"
173
 
174
 
175
 
176
 
177
     file = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }
178 10 feddischso
     core_a = SOCMaker::CoreDef.new( "core_a", "core_a,v1", file, "top" )
179
     core_b = SOCMaker::CoreDef.new( "core_b", "core_b,v1", file, "top" )
180 7 feddischso
     SOCMaker::lib.add_core( core_a )
181
     SOCMaker::lib.add_core( core_b )
182
 
183 10 feddischso
     ifc_spc = SOCMaker::IfcSpc.new( "myifc", "myifc,v1", 'ports' => { port_a: { dir: 1}, port_b: { dir: 0 } } )
184 7 feddischso
     SOCMaker::lib.add_ifc( ifc_spc )
185 10 feddischso
     ifc_def_1 = SOCMaker::IfcDef.new( "myifc", "myifc,v1", 0, { a: SOCMaker::IfcPort.new( "port_a", 1 ),
186
                                                                 b: SOCMaker::IfcPort.new( "port_b", 1 ) } )
187 8 feddischso
 
188 10 feddischso
     ifc_def_0 = SOCMaker::IfcDef.new( "myifc", "myifc,v1", 1, { a: SOCMaker::IfcPort.new( "port_a", 1 ),
189
                                                                 b: SOCMaker::IfcPort.new( "port_b", 1 ) } )
190 7 feddischso
 
191
 
192
     core_a.interfaces[ :ifc_a ] = ifc_def_0
193
     core_a.interfaces[ :ifc_b ] = ifc_def_1
194
     core_b.interfaces[ :ifc_a ] = ifc_def_0
195
     core_b.interfaces[ :ifc_b ] = ifc_def_1
196
 
197
 
198 10 feddischso
     i1 = SOCMaker::CoreInst.new( "core_a,v1" )
199
     i2 = SOCMaker::CoreInst.new( "core_a,v1" )
200
     i3 = SOCMaker::CoreInst.new( "core_b,v1" )
201
     i4 = SOCMaker::CoreInst.new( "core_b,v1" )
202 7 feddischso
 
203
     soc.cores[ :inst_a ] = i1
204
     soc.cores[ :inst_b ] = i2
205
     soc.cores[ :inst_c ] = i3
206
     soc.cores[ :inst_d ] = i4
207
     soc.consistency_check
208
     soc.add_connection(  "inst_a", "ifc_a", "inst_b", "ifc_b", "a_new_con" )
209
 
210
 
211
     SOCMaker::lib.add_core( soc )
212 10 feddischso
     soc_inst = SOCMaker::CoreInst.new( 'test_soc,v1' )
213 7 feddischso
     soc_inst.consistency_check
214
 
215
     soc_inst.stub( :gen_toplevel_con ) do |name_arg,
216
                                        rule_arg,
217
                                        m0_arg,
218
                                        m1_arg |
219
       added_cons[ name_arg.to_sym ] = { rule: rule_arg,
220
                                         m0: m0_arg, m1: m1_arg }
221
     end
222
 
223
 
224
 
225
     # file writing stub
226
     file_mock = double()
227
     file_mock.stub( :write )
228
     File.should_receive(:open).and_yield(file_mock)
229
 
230
     soc_inst.gen_toplevel( coder );
231 10 feddischso
     added_cores.should be == { "core_a,v1".to_sym => core_a, "core_b,v1".to_sym => core_b }
232 7 feddischso
     added_instances.should be == { inst_a: i1, inst_b: i2, inst_c: i3, inst_d: i4 }
233
     added_cons.should be == { a_new_con: { rule: "or", m0: {inst_a: :ifc_a}, m1: {inst_b: :ifc_b } } }
234
     dir_path.should be == dir_path_ref
235
   end
236
 
237
 
238 8 feddischso
 
239
 
240
   it "should create valid vhdl output with our test library" do
241
 
242
     SOCMaker::conf[ :build_dir ] = 'spec/tmp_build2'
243
     SOCMaker::conf[ :hdl_dir   ] = 'b'
244
     coder = SOCMaker::VHDLCoder.new
245
     SOCMaker::lib.refresh( './spec/test_soc_lib' )
246
     soc = SOCMaker::from_f( './spec/test_soc.yaml' );
247
     SOCMaker::lib.add_core( soc )
248 10 feddischso
     soc_inst = SOCMaker::CoreInst.new( 'test_soc,v1' )
249 8 feddischso
     soc_inst.consistency_check
250
     soc_inst.gen_toplevel( coder );
251
     soc.copy_files
252
    #p soc.cons
253
    #puts soc.to_yaml
254
   end
255
 
256 3 feddischso
end
257 7 feddischso
 
258
# 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.