31: def RubyVpi.init_bench aDesignId, aSpecFormat, &aSimulationCycle
32: raise ArgumentError, "block must be given" unless block_given?
33:
34: if caller.find {|s| s =~ /^(.*?)_bench.rb:/}
35: testName = $1
36: else
37: raise 'Unable to determine name of test.'
38: end
39:
40: useDebugger = !(ENV['DEBUG'] || '').empty?
41: useCoverage = !(ENV['COVERAGE'] || '').empty?
42: usePrototype = !(ENV['PROTOTYPE'] || '').empty?
43:
44:
45:
46: require 'ruby-vpi/vpi'
47:
48: if useCoverage
49: require 'ruby-vpi/rcov'
50:
51: RubyVpi.with_coverage_analysis do |a|
52: a.dump_coverage_info [
53: Rcov::TextReport.new,
54: Rcov::HTMLCoverage.new(:destdir => "#{testName}_coverage")
55: ]
56: end
57:
58: Vpi::vpi_printf "#{Config::PROJECT_NAME}: coverage analysis is enabled for test #{testName.inspect}\n"
59: end
60:
61:
62: case aSpecFormat
63: when :xUnit
64: require 'test/unit'
65:
66: when :rSpec
67: ARGV.concat %w[-f s]
68: require 'spec'
69:
70: when :tSpec
71: ARGV << '-rs'
72: require 'test/spec'
73: end
74:
75:
76: if useDebugger
77: require 'ruby-debug'
78:
79: Debugger.start
80: Debugger.post_mortem
81:
82: Vpi::vpi_printf "#{Config::PROJECT_NAME}: debugger is enabled for test #{testName.inspect}\n"
83: end
84:
85:
86: unless Kernel.respond_to? :debugger
87: Kernel.class_eval do
88: define_method :debugger do
89:
90: end
91: end
92: end
93:
94:
95: Object.class_eval do
96: include Vpi
97: end
98:
99:
100: unless design = vpi_handle_by_name("#{testName}_bench", nil)
101: raise "Verilog bench for test #{testName.inspect} is inaccessible."
102: end
103:
104: Kernel.const_set(aDesignId, design)
105: require "#{testName}_design.rb"
106:
107:
108: if usePrototype
109: require "#{testName}_proto.rb"
110:
111: Vpi.module_eval do
112: define_method :simulate do
113: design.simulate!
114: end
115:
116: define_method :vpi_register_cb do
117: warn "vpi_register_cb: callbacks not allowed when prototyping"
118: end
119: end
120:
121: Vpi::vpi_printf "#{Config::PROJECT_NAME}: prototype is enabled for test #{testName.inspect}\n"
122:
123: else
124: Vpi.module_eval do
125: define_method :simulate, &aSimulationCycle
126: end
127:
128:
129: advance_time
130: end
131:
132:
133: require "#{testName}_spec.rb"
134: end