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 |
|
|
expect{ SOCMaker::CoreInst.new( "mycorerel1", { "aparameter".to_sym => 4 } ) }.
|
62 |
|
|
to raise_error( SOCMaker::ERR::ValueError )
|
63 |
|
|
SOCMaker::lib.rm_core( core )
|
64 |
|
|
|
65 |
|
|
end
|
66 |
|
|
|
67 |
|
|
it "should auto-complete generics with default values" do
|
68 |
|
|
|
69 |
|
|
# create core with one file and one instance parameter
|
70 |
|
|
file = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }
|
71 |
|
|
parameters = { "param1".to_sym => SOCMaker::Parameter.new( "integer" ) }
|
72 |
|
|
core = SOCMaker::CoreDef.new( "mycore", "rel1", file, "top" )
|
73 |
|
|
core.inst_parameters = parameters
|
74 |
|
|
SOCMaker::lib.add_core( core )
|
75 |
|
|
|
76 |
|
|
inst = SOCMaker::CoreInst.new( "mycorerel1", {} )
|
77 |
|
|
inst.params[ :param1 ].should be == 0
|
78 |
|
|
SOCMaker::lib.rm_core( core )
|
79 |
|
|
end
|
80 |
|
|
|
81 |
|
|
end
|
82 |
|
|
|
83 |
|
|
describe SOCMaker::CoreDef, "object handling, en-decoding:" do
|
84 |
|
|
|
85 |
|
|
it "should be possible to encode and decode a core instance" do
|
86 |
|
|
file = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }
|
87 |
|
|
parameters = { "param1".to_sym => SOCMaker::Parameter.new( "integer" ) }
|
88 |
|
|
core = SOCMaker::CoreDef.new( "mycore", "rel1", file, "top" )
|
89 |
|
|
core.inst_parameters = parameters
|
90 |
|
|
SOCMaker::lib.add_core( core )
|
91 |
|
|
|
92 |
|
|
o1 = SOCMaker::CoreInst.new( "mycorerel1", {} )
|
93 |
|
|
yaml_str = o1.to_yaml
|
94 |
|
|
o2 = YAML::load( yaml_str )
|
95 |
|
|
o1.should be == o2
|
96 |
|
|
end
|
97 |
|
|
|
98 |
|
|
it "should return false for two non-equal objects" do
|
99 |
|
|
file = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }
|
100 |
|
|
parameters = { "param1".to_sym => SOCMaker::Parameter.new( "integer" ) }
|
101 |
|
|
core = SOCMaker::CoreDef.new( "mycore", "rel1", file, "top" )
|
102 |
|
|
core.inst_parameters = parameters
|
103 |
|
|
SOCMaker::lib.add_core( core )
|
104 |
|
|
|
105 |
|
|
o1 = SOCMaker::CoreInst.new( "mycorerel1" )
|
106 |
|
|
o2 = Marshal::load(Marshal.dump(o1))
|
107 |
|
|
o2.type << "X"
|
108 |
|
|
( o2 == o1 ).should be == false
|
109 |
|
|
o2 = Marshal::load(Marshal.dump(o1))
|
110 |
|
|
o2.params[ :param1 ] = 1
|
111 |
|
|
( o2 == o1 ).should be == false
|
112 |
|
|
end
|
113 |
|
|
|
114 |
|
|
end
|