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 5

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
     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 5 feddischso
describe SOCMaker::CoreDef, "HDL interaction" do
84
 
85
   it 'should return true and false for implements_port?, when a port is implemented and
86
       not implemented' do
87
      file       = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }
88
      core       = SOCMaker::CoreDef.new( "mycore", "rel1", file, "top" )
89
      ifc_spc    = SOCMaker::IfcSpc.new( "a_ifc", "v1", "ports" => { p1: 1, p2: 0 } )
90
      ifc        = SOCMaker::IfcDef.new( "a_ifc", "v1", 1, { p1: SOCMaker::IfcPort.new( "p1", 1 ) } )
91
      core.interfaces[ :i1 ] = ifc
92
      SOCMaker::lib.add_core( core )
93
      SOCMaker::lib.add_ifc( ifc_spc )
94
 
95
      o1 = SOCMaker::CoreInst.new( "mycorerel1", {}  )
96
      o1.implements_port?( 'i1', 'p1' ).should be == true
97
      o1.implements_port?( 'i1', 'p2' ).should be == false
98
    end
99
end
100
 
101 3 feddischso
describe SOCMaker::CoreDef, "object handling, en-decoding:" do
102
 
103
  it "should be possible to encode and decode a core instance" do
104
    file = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }
105
    parameters = { "param1".to_sym => SOCMaker::Parameter.new( "integer" )  }
106
    core = SOCMaker::CoreDef.new( "mycore", "rel1", file, "top" )
107
    core.inst_parameters = parameters
108
    SOCMaker::lib.add_core( core )
109
 
110
    o1 = SOCMaker::CoreInst.new( "mycorerel1", {}  )
111
    yaml_str = o1.to_yaml
112
    o2 = YAML::load( yaml_str )
113
    o1.should be == o2
114
  end
115
 
116
  it "should return false for two non-equal objects" do
117
    file = { "file.vhd".to_sym => SOCMaker::HDLFile.new( "./file.vhd" ) }
118
    parameters = { "param1".to_sym => SOCMaker::Parameter.new( "integer" )  }
119
    core = SOCMaker::CoreDef.new( "mycore", "rel1", file, "top" )
120
    core.inst_parameters = parameters
121
    SOCMaker::lib.add_core( core )
122
 
123
    o1 = SOCMaker::CoreInst.new( "mycorerel1" )
124
    o2 = Marshal::load(Marshal.dump(o1))
125
    o2.type << "X"
126
    ( o2 == o1 ).should be == false
127
    o2 = Marshal::load(Marshal.dump(o1))
128
    o2.params[ :param1 ] = 1
129
    ( o2 == o1 ).should be == false
130
  end
131
 
132
end

powered by: WebSVN 2.1.0

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