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

Subversion Repositories soc_maker

[/] [soc_maker/] [trunk/] [spec/] [hdl_file_spec.rb] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 feddischso
###############################################################
2
#
3
#  File:      hdl_file_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
#     Test specification for SOCMaker::HDLFile
37
#
38
#
39
#
40
###############################################################
41
require_relative( 'spec_helper' )
42
 
43
 
44
 
45
 
46
describe SOCMaker::HDLFile, "HDL file loading" do
47
 
48
  #
49
  # core definition with no info about the HDL file
50
  F_MIN_YAML_FIlE_NIL = '''SOCM_CORE
51
  name: core_A
52
  version: rel1
53
  toplevel: top_A
54
  hdlfiles:
55
     :a_file.v: SOCM_HDL_FILE
56
  '''
57
 
58
  F_YAML_FILE_TYPE = '''SOCM_CORE
59
  name: core_A
60
  version: rel1
61
  toplevel: top_A
62
  hdlfiles:
63
     :core_a.vhd: SOCM_HDL_FILE
64
        path: ./core_a.vhd
65
        type: xhdl
66
  '''
67
 
68
 
69
  it "should return a HDLFile object if new is called" do
70
     o = SOCMaker::HDLFile.new( "./path/to/file.vhd" )
71
     o.class.should be == SOCMaker::HDLFile
72
  end
73
 
74
 
75
  it "should raise an error, if an invalid file type is provided" do
76
     expect { SOCMaker::HDLFile.new( "./path/to/invalid_file.vhx" ) }.
77
     to raise_error( SOCMaker::ERR::ValueError )
78
  end
79
 
80
  it "should raise an error, if no path is given (empty string)" do
81
     expect { SOCMaker::HDLFile.new( "" ) }.
82
     to raise_error( SOCMaker::ERR::ValueError )
83
  end
84
 
85
  it "should raise an error, if no path is given (nil)" do
86
     expect { SOCMaker::HDLFile.new( nil ) }.
87
     to raise_error( SOCMaker::ERR::StructureError )
88
  end
89
 
90
  it "should raise an error, if path is not a string" do
91
     expect { SOCMaker::HDLFile.new( 3 ) }.
92
     to raise_error( SOCMaker::ERR::ValueError )
93
  end
94
 
95
  it "should raise an error, if the HDL file info is nil" do
96
     expect { SOCMaker::from_s( F_MIN_YAML_FIlE_NIL ) }.
97
     to raise_error( SOCMaker::ERR::StructureError )
98
  end
99
 
100
  it "should raise an error, if an invalid file type is given" do
101
     expect { SOCMaker::from_s( F_YAML_FILE_TYPE ) }.
102
     to raise_error( SOCMaker::ERR::ValueError )
103
  end
104
 
105
  it "should raise an error, if use_syn is not boolean" do
106
     expect { SOCMaker::HDLFile.new( "./path/to/file.vhd", "use_syn" => "not boolean" ) }.
107
     to raise_error( SOCMaker::ERR::ValueError )
108
  end
109
 
110
  it "should raise an error, if use_sys_sim is not boolean" do
111
     expect { SOCMaker::HDLFile.new( "./path/to/file.vhd", "use_sys_sim" => "not boolean" ) }.
112
     to raise_error( SOCMaker::ERR::ValueError )
113
  end
114
 
115
  it "should raise an error, if use_mod_sim is not boolean" do
116
     expect { SOCMaker::HDLFile.new( "./path/to/file.vhd", "use_mod_sim" => "not boolean" ) }.
117
     to raise_error( SOCMaker::ERR::ValueError )
118
  end
119
 
120
  it "should auto-detect verilog files" do
121
     o = SOCMaker::HDLFile.new( "./path/to/file.v" )
122
     o.type.should be == "verilog"
123
  end
124
 
125
  it "should auto-detect vhdl files" do
126
     o = SOCMaker::HDLFile.new( "./path/to/file.vhd" )
127
     o.type.should be == "vhdl"
128
  end
129
 
130
  it "should auto-complete the three flags use_syn use_sys_sim use_mod_sim" do
131
     o = SOCMaker::HDLFile.new( "./path/to/file.vhd" )
132
     o.use_syn.should be     == true
133
     o.use_mod_sim.should be == true
134
     o.use_sys_sim.should be == true
135
  end
136
 
137
  %w[ use_syn use_sys_sim use_mod_sim  ].each do |m|
138
    it "should raise an error if #{m} is not false or true" do
139
      expect { SOCMaker::HDLFile.new( "./path/to/file.vhd", { m => 4 } ) }.
140
      to raise_error( SOCMaker::ERR::ValueError )
141
    end
142
  end
143
 
144
  it "should return false for two non-equal objects" do
145
    o1 = SOCMaker::HDLFile.new( "./path/to/file.vhd" )
146
    o2 = Marshal::load(Marshal.dump(o1))
147
    o2.use_syn = !o2.use_syn
148
    ( o2 == o1 ).should be == false
149
  end
150
 
151
  it "should be possible to encode and decode a HDL file object" do
152
    o1 = SOCMaker::HDLFile.new( "./path/to/file.vhd",
153
        'use_syn' => false,
154
        'use_mod_sim' => false,
155
        'use_sys_sim' => false )
156
    yaml_str = o1.to_yaml
157
    o2 = YAML::load( yaml_str )
158
    o1.should be == o2
159
  end
160
 
161
 
162
 
163
end
164
 
165
 
166
# vim: noai:ts=2:sw=2
167
 

powered by: WebSVN 2.1.0

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