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 7

Go to most recent revision | 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
     core = SOCMaker::CoreDef.new( "mycore", "rel1", file, "top" )
60
     SOCMaker::lib.add_core( core )
61 7 feddischso
     expect{
62
         inst = SOCMaker::CoreInst.new( "mycorerel1", { "aparameter".to_sym => 4 } )
63
         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
     core = SOCMaker::CoreDef.new( "mycore", "rel1", file, "top" )
75
     core.inst_parameters = parameters
76
     SOCMaker::lib.add_core( core )
77
 
78
     inst = SOCMaker::CoreInst.new( "mycorerel1", {}  )
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
#      core       = SOCMaker::CoreDef.new( "mycore", "rel1", file, "top" )
92
#      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 7 feddischso
#      o1 = SOCMaker::CoreInst.new( "mycorerel1", {}  )
99
#      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
    core = SOCMaker::CoreDef.new( "mycore", "rel1", file, "top" )
111
    core.inst_parameters = parameters
112
    SOCMaker::lib.add_core( core )
113
 
114
    o1 = SOCMaker::CoreInst.new( "mycorerel1", {}  )
115
    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
    core = SOCMaker::CoreDef.new( "mycore", "rel1", file, "top" )
124
    core.inst_parameters = parameters
125
    SOCMaker::lib.add_core( core )
126
 
127
    o1 = SOCMaker::CoreInst.new( "mycorerel1" )
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
 
138
 
139
   it "should create valid vhdl output with our test library" do
140
 
141
     SOCMaker::conf[ :build_dir ] = 'spec/tmp_build2'
142
     SOCMaker::conf[ :hdl_dir   ] = 'b'
143
     coder = SOCMaker::VHDLCoder.new
144
     SOCMaker::lib.refresh( './spec/test_soc_lib' )
145
     soc = SOCMaker::from_f( './spec/test_soc.yaml' );
146
     SOCMaker::lib.add_core( soc )
147
     soc_inst = SOCMaker::CoreInst.new( 'test_socv1' )
148
     soc_inst.consistency_check
149
     soc_inst.gen_toplevel( coder );
150
    #soc.copy_files
151
    #p soc.cons
152
    #puts soc.to_yaml
153
   end
154
 
155
   it "should call coder functions for each core-def. (stub-version)" do
156
 
157
     SOCMaker::lib.clear
158
     soc = SOCMaker::SOCDef.new( "test_soc", "v1", "my_soc_top" )
159
 
160
 
161
     coder = double()
162
 
163
     added_cores = {}
164
     coder.stub( :add_core_component ) do |name_arg, def_arg|
165
       added_cores[ name_arg.to_sym ] = def_arg
166
     end
167
 
168
     added_instances = {}
169
     coder.stub( :add_core_instance ) do |name_arg, inst_arg|
170
       added_instances[ name_arg.to_sym ] = inst_arg
171
     end
172
 
173
     coder.stub( :get_hdl_code ){ |arg_coder| }
174
 
175
     coder.stub( :is_a? ){ SOCMaker::VHDLCoder }
176
 
177
     coder.stub( :filename ){ |x| x + ".vhd" }
178
 
179
 
180
     coder.stub( :add_ifc_connection )
181
 
182
 
183
     added_cons = {}
184
 
185
     dir_path = ""
186
     FileUtils.stub( :mkdir_p ) { |arg| dir_path = arg }
187
     SOCMaker::conf[ :build_dir ] = 'a'
188
     SOCMaker::conf[ :hdl_dir   ] = 'b'
189
     dir_path_ref = "a/b"
190
 
191
 
192
 
193
 
194
     file = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }
195
     core_a = SOCMaker::CoreDef.new( "core_a", "v1", file, "top" )
196
     core_b = SOCMaker::CoreDef.new( "core_b", "v1", file, "top" )
197
     SOCMaker::lib.add_core( core_a )
198
     SOCMaker::lib.add_core( core_b )
199
 
200
     ifc_spc = SOCMaker::IfcSpc.new( "myifc", "v1", 'ports' => { port_a: 1, port_b: 0 } )
201
     SOCMaker::lib.add_ifc( ifc_spc )
202
     ifc_def_1 = SOCMaker::IfcDef.new( "myifc", "v1", 0, { a: SOCMaker::IfcPort.new( "port_a", 1 ) } )
203
     ifc_def_0 = SOCMaker::IfcDef.new( "myifc", "v1", 1, { b: SOCMaker::IfcPort.new( "port_b", 1 ) } )
204
 
205
 
206
     core_a.interfaces[ :ifc_a ] = ifc_def_0
207
     core_a.interfaces[ :ifc_b ] = ifc_def_1
208
     core_b.interfaces[ :ifc_a ] = ifc_def_0
209
     core_b.interfaces[ :ifc_b ] = ifc_def_1
210
 
211
 
212
     i1 = SOCMaker::CoreInst.new( "core_av1" )
213
     i2 = SOCMaker::CoreInst.new( "core_av1" )
214
     i3 = SOCMaker::CoreInst.new( "core_bv1" )
215
     i4 = SOCMaker::CoreInst.new( "core_bv1" )
216
 
217
     soc.cores[ :inst_a ] = i1
218
     soc.cores[ :inst_b ] = i2
219
     soc.cores[ :inst_c ] = i3
220
     soc.cores[ :inst_d ] = i4
221
     soc.consistency_check
222
     soc.add_connection(  "inst_a", "ifc_a", "inst_b", "ifc_b", "a_new_con" )
223
 
224
 
225
     SOCMaker::lib.add_core( soc )
226
     soc_inst = SOCMaker::CoreInst.new( 'test_socv1' )
227
     soc_inst.consistency_check
228
 
229
     soc_inst.stub( :gen_toplevel_con ) do |name_arg,
230
                                        rule_arg,
231
                                        m0_arg,
232
                                        m1_arg |
233
       added_cons[ name_arg.to_sym ] = { rule: rule_arg,
234
                                         m0: m0_arg, m1: m1_arg }
235
     end
236
 
237
 
238
 
239
     # file writing stub
240
     file_mock = double()
241
     file_mock.stub( :write )
242
     File.should_receive(:open).and_yield(file_mock)
243
 
244
     soc_inst.gen_toplevel( coder );
245
     added_cores.should be == { :core_av1 => core_a, :core_bv1 => core_b }
246
     added_instances.should be == { inst_a: i1, inst_b: i2, inst_c: i3, inst_d: i4 }
247
     added_cons.should be == { a_new_con: { rule: "or", m0: {inst_a: :ifc_a}, m1: {inst_b: :ifc_b } } }
248
     dir_path.should be == dir_path_ref
249
   end
250
 
251
 
252 3 feddischso
end
253 7 feddischso
 
254
# 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.