1 |
3 |
feddischso |
###############################################################
|
2 |
|
|
#
|
3 |
|
|
# File: soc_lib_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::Lib do
|
45 |
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
it "should return a SOCMaker::Lib when creating with new" do
|
49 |
|
|
lib = SOCMaker::Lib.new()
|
50 |
|
|
lib.class.should be SOCMaker::Lib
|
51 |
|
|
end
|
52 |
|
|
|
53 |
|
|
describe "loading functionality" do
|
54 |
|
|
|
55 |
|
|
before( :each )do
|
56 |
|
|
@lib = SOCMaker::Lib.new
|
57 |
|
|
end
|
58 |
|
|
|
59 |
|
|
describe "path loading" do
|
60 |
|
|
it "should call process_include for each path given as argument" do
|
61 |
|
|
paths_res = []
|
62 |
|
|
@lib.stub( :process_include ) do |arg|
|
63 |
|
|
paths_res << arg
|
64 |
|
|
end
|
65 |
|
|
paths = [ "first_path", "second_path" ]
|
66 |
|
|
@lib.refresh( paths )
|
67 |
|
|
paths_res.should be == paths
|
68 |
|
|
end
|
69 |
|
|
|
70 |
|
|
it "should cal process_include for each path from config, if no argument is given" do
|
71 |
|
|
paths_res = []
|
72 |
|
|
@lib.stub( :process_include ) do |arg|
|
73 |
|
|
paths_res << arg
|
74 |
|
|
end
|
75 |
|
|
paths = [ "first_path", "second_path" ]
|
76 |
|
|
SOCMaker::conf[ :cores_search_path ] = paths
|
77 |
|
|
@lib.refresh( )
|
78 |
|
|
paths_res.should be == paths
|
79 |
|
|
end
|
80 |
|
|
|
81 |
|
|
end
|
82 |
|
|
|
83 |
|
|
describe "folder processing" do
|
84 |
|
|
it "should raise an LibError if a folder is included twice" do
|
85 |
|
|
expect do
|
86 |
|
|
@lib.process_include( "./empty_soc_lib_folder" )
|
87 |
|
|
@lib.process_include( "./empty_soc_lib_folder" )
|
88 |
|
|
end.
|
89 |
|
|
to raise_error( SOCMaker::ERR::LibError )
|
90 |
|
|
end
|
91 |
|
|
end
|
92 |
|
|
|
93 |
|
|
|
94 |
|
|
describe "yaml include loading" do
|
95 |
|
|
it "should return add two objects" do
|
96 |
|
|
|
97 |
|
|
obs = []
|
98 |
|
|
@lib.stub( :get_all_yaml_in_str ) do |arg|
|
99 |
|
|
"SOCM_INCLUDE\ndirs:\n- folder_a\n- folder_b\n- folder_c\nSOCM_INCLUDE\ndirs:\n- folder_d\n- folder_e\n- folder_f\n"
|
100 |
|
|
end
|
101 |
|
|
@lib.stub( :add_include ) do |arg|
|
102 |
|
|
obs << arg
|
103 |
|
|
end
|
104 |
|
|
@lib.refresh( [ "some_path" ] )
|
105 |
|
|
obs.should be == [ SOCMaker::LibInc.new( 'dirs' => ["folder_a", "folder_b", "folder_c"] ),
|
106 |
|
|
SOCMaker::LibInc.new( 'dirs' => ["folder_d", "folder_e", "folder_f"] ) ]
|
107 |
|
|
end
|
108 |
|
|
end
|
109 |
|
|
|
110 |
|
|
|
111 |
|
|
describe "library access" do
|
112 |
|
|
it "should be possible to add, get and remove a core" do
|
113 |
|
|
file = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }
|
114 |
|
|
c = SOCMaker::CoreDef.new( "acore", "v1", file, "top" )
|
115 |
|
|
@lib.add_core( c )
|
116 |
|
|
@lib.get_core( "acore", "v1" ).should be == c
|
117 |
|
|
@lib.rm_core( c )
|
118 |
|
|
expect { @lib.get_core( "acore", "v1" ) }.
|
119 |
|
|
to raise_error( SOCMaker::ERR::LibError )
|
120 |
|
|
end
|
121 |
|
|
|
122 |
|
|
it "should be possible to add, get and remove an interface" do
|
123 |
|
|
i = SOCMaker::IfcSpc.new( "myifc", "v2" )
|
124 |
|
|
@lib.add_ifc( i )
|
125 |
|
|
@lib.get_ifc( "myifc", "v2" ).should be == i
|
126 |
|
|
@lib.rm_ifc( i )
|
127 |
|
|
expect { @lib.get_ifc( "myifc", "v2" ) }.
|
128 |
|
|
to raise_error( SOCMaker::ERR::LibError )
|
129 |
|
|
end
|
130 |
|
|
|
131 |
|
|
it "should process all folders in add_include" do
|
132 |
|
|
all_folders = ["folder_a", "folder_b", "folder_c" ]
|
133 |
|
|
i = SOCMaker::LibInc.new( 'dirs' => all_folders )
|
134 |
|
|
all_folders_res = []
|
135 |
|
|
@lib.stub( :process_include ) do |arg|
|
136 |
|
|
all_folders_res << arg
|
137 |
|
|
end
|
138 |
|
|
@lib.add_include( i, "./" )
|
139 |
|
|
all_folders.each_with_index do |f,index|
|
140 |
|
|
File.expand_path( File.join( "./", f ) ).should be == all_folders_res[ index ]
|
141 |
|
|
end
|
142 |
|
|
end
|
143 |
|
|
|
144 |
|
|
it "should load all elements from our test library" do
|
145 |
|
|
@lib.refresh( './spec/test_soc_lib' )
|
146 |
|
|
core_A = @lib.get_core( "core_A", "rel1" )
|
147 |
|
|
core_B = @lib.get_core( "core_B", "rel1" )
|
148 |
|
|
core_AB_ifc = @lib.get_ifc( "core_AB_ifc", "1" )
|
149 |
|
|
core_A.class.should be SOCMaker::CoreDef
|
150 |
|
|
core_B.class.should be SOCMaker::CoreDef
|
151 |
|
|
core_AB_ifc.class.should be SOCMaker::IfcSpc
|
152 |
|
|
core_A.static_parameters.size.should be == 2
|
153 |
|
|
end
|
154 |
|
|
|
155 |
|
|
end
|
156 |
|
|
|
157 |
|
|
end
|
158 |
|
|
|
159 |
|
|
end
|
160 |
|
|
|
161 |
|
|
# vim: noai:ts=2:sw=2
|
162 |
|
|
|