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

Subversion Repositories soc_maker

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
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 10 feddischso
        c = SOCMaker::CoreDef.new( "A core", "acore,v1", file, "top" )
115 3 feddischso
        @lib.add_core( c )
116 10 feddischso
        @lib.get_core( "acore,v1" ).should be == c
117 3 feddischso
        @lib.rm_core( c )
118 10 feddischso
        expect { @lib.get_core( "acore,v1" ) }.
119 3 feddischso
          to raise_error( SOCMaker::ERR::LibError )
120
      end
121
 
122
      it "should be possible to add, get and remove an interface" do
123 10 feddischso
        i = SOCMaker::IfcSpc.new( "My Interface", "myifc,v2" )
124
 
125
        # removing with instance
126 3 feddischso
        @lib.add_ifc( i )
127 10 feddischso
        @lib.get_ifc( "myifc,v2" ).should be == i
128 3 feddischso
        @lib.rm_ifc( i )
129 10 feddischso
 
130
        expect { @lib.get_ifc( "myifc,v2" ) }.
131 3 feddischso
          to raise_error( SOCMaker::ERR::LibError )
132 10 feddischso
 
133
        # removing with id
134
        @lib.add_ifc( i )
135
        @lib.get_ifc( "myifc,v2" ).should be == i
136
        @lib.rm_ifc( i.id )
137
 
138
        expect { @lib.get_ifc( "myifc,v2" ) }.
139
          to raise_error( SOCMaker::ERR::LibError )
140
 
141 3 feddischso
      end
142
 
143
      it "should process all folders in add_include" do
144
        all_folders = ["folder_a", "folder_b", "folder_c" ]
145
        i = SOCMaker::LibInc.new( 'dirs' => all_folders  )
146
        all_folders_res = []
147
        @lib.stub( :process_include ) do |arg|
148
          all_folders_res << arg
149
        end
150
        @lib.add_include( i, "./" )
151
        all_folders.each_with_index do |f,index|
152
          File.expand_path( File.join( "./", f ) ).should be == all_folders_res[ index ]
153
        end
154
      end
155
 
156
      it "should load all elements from our test library" do
157
        @lib.refresh( './spec/test_soc_lib' )
158 10 feddischso
        core_A      = @lib.get_core( "core_A,rel1"  )
159
        core_B      = @lib.get_core( "core_B,rel1"  )
160
        core_AB_ifc = @lib.get_ifc( "core_AB_ifc,1" )
161 3 feddischso
        core_A.class.should       be SOCMaker::CoreDef
162
        core_B.class.should       be SOCMaker::CoreDef
163
        core_AB_ifc.class.should  be SOCMaker::IfcSpc
164 9 feddischso
        core_A.static_parameters.size.should be == 3
165 3 feddischso
      end
166
 
167
    end
168
 
169
  end
170
 
171
end
172
 
173
# vim: noai:ts=2:sw=2
174
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.