ruby-vpi 16.0.1 → 17.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +19 -19
- data/README +1 -1
- data/Rakefile +35 -32
- data/bin/convert.rb +28 -0
- data/bin/generate/design.rb +16 -0
- data/bin/generate/proto.rb +13 -0
- data/bin/generate/runner.rake +33 -0
- data/bin/generate/spec.rb +45 -0
- data/bin/generate.rb +177 -0
- data/bin/ruby-vpi +56 -0
- data/doc/Rakefile +20 -4
- data/doc/common.css +92 -33
- data/doc/common.inc +13 -0
- data/doc/common.tpl +42 -28
- data/doc/history.doc +11 -11
- data/doc/history.html +769 -248
- data/doc/history.inc +909 -0
- data/doc/history.rb +9 -0
- data/doc/history.yaml +69 -0
- data/doc/intro.inc +170 -178
- data/doc/lib/doc_format.rb +57 -144
- data/doc/lib/doc_proxy.rb +504 -88
- data/doc/lib/erb_content.rb +8 -8
- data/doc/lib/erb_proxy.rb +17 -17
- data/doc/manual.doc +626 -777
- data/doc/manual.html +1541 -1031
- data/doc/memo.doc +38 -36
- data/doc/memo.html +64 -28
- data/doc/readme.doc +4 -31
- data/doc/readme.html +221 -163
- data/doc/rss.erb +1 -1
- data/doc/rss.xml +73 -1761
- data/ext/Rakefile +6 -5
- data/ext/main.c +17 -15
- data/ext/relay.c +4 -7
- data/ext/relay.h +2 -2
- data/ext/swig_vpi.h +2 -2
- data/ext/swig_vpi.i +1 -2
- data/ext/swig_wrap.cin +12 -16
- data/ext/vlog.c +5 -5
- data/ext/vlog.h +2 -2
- data/lib/ruby-vpi/erb.rb +3 -3
- data/lib/ruby-vpi/float.rb +2 -2
- data/lib/ruby-vpi/rcov.rb +5 -7
- data/lib/ruby-vpi/runner.rb +43 -41
- data/lib/ruby-vpi/runner_boot_loader.rb +117 -0
- data/lib/ruby-vpi/runner_proxy.rb +6 -8
- data/lib/ruby-vpi/util.rb +10 -0
- data/lib/ruby-vpi/verilog_parser.rb +28 -56
- data/lib/ruby-vpi/vpi.rb +168 -123
- data/lib/ruby-vpi.rb +22 -143
- data/ref/c/annotated.html +1 -1
- data/ref/c/common_8h.html +1 -1
- data/ref/c/files.html +1 -1
- data/ref/c/functions.html +1 -1
- data/ref/c/functions_vars.html +1 -1
- data/ref/c/globals.html +1 -1
- data/ref/c/globals_0x63.html +1 -1
- data/ref/c/globals_0x65.html +1 -1
- data/ref/c/globals_0x66.html +1 -1
- data/ref/c/globals_0x6d.html +1 -1
- data/ref/c/globals_0x70.html +1 -1
- data/ref/c/globals_0x72.html +1 -1
- data/ref/c/globals_0x73.html +1 -1
- data/ref/c/globals_0x74.html +1 -1
- data/ref/c/globals_0x76.html +1 -1
- data/ref/c/globals_0x78.html +1 -1
- data/ref/c/globals_defs.html +1 -1
- data/ref/c/globals_defs_0x65.html +1 -1
- data/ref/c/globals_defs_0x70.html +1 -1
- data/ref/c/globals_defs_0x76.html +1 -1
- data/ref/c/globals_defs_0x78.html +1 -1
- data/ref/c/globals_enum.html +1 -1
- data/ref/c/globals_eval.html +1 -1
- data/ref/c/globals_func.html +1 -1
- data/ref/c/globals_type.html +1 -1
- data/ref/c/globals_vars.html +1 -1
- data/ref/c/index.html +1 -1
- data/ref/c/main_8c.html +1 -1
- data/ref/c/main_8h.html +1 -1
- data/ref/c/relay_8c.html +1 -1
- data/ref/c/relay_8h.html +1 -1
- data/ref/c/structt__cb__data.html +1 -1
- data/ref/c/structt__vpi__delay.html +1 -1
- data/ref/c/structt__vpi__error__info.html +1 -1
- data/ref/c/structt__vpi__strengthval.html +1 -1
- data/ref/c/structt__vpi__systf__data.html +1 -1
- data/ref/c/structt__vpi__time.html +1 -1
- data/ref/c/structt__vpi__value.html +1 -1
- data/ref/c/structt__vpi__vecval.html +1 -1
- data/ref/c/structt__vpi__vlog__info.html +1 -1
- data/ref/c/verilog_8h.html +1 -1
- data/ref/c/vlog_8c.html +1 -1
- data/ref/c/vlog_8h.html +1 -1
- data/ref/c/vpi__user_8h.html +1 -1
- data/ref/ruby/classes/ERB.html +5 -5
- data/ref/ruby/classes/ERB.src/{M000024.html → M000026.html} +0 -0
- data/ref/ruby/classes/FileUtils.html +11 -11
- data/ref/ruby/classes/FileUtils.src/{M000025.html → M000027.html} +0 -0
- data/ref/ruby/classes/FileUtils.src/{M000026.html → M000028.html} +0 -0
- data/ref/ruby/classes/Float.html +6 -6
- data/ref/ruby/classes/Float.src/{M000020.html → M000021.html} +0 -0
- data/ref/ruby/classes/Integer.html +65 -65
- data/ref/ruby/classes/Integer.src/M000009.html +12 -5
- data/ref/ruby/classes/Integer.src/M000010.html +5 -5
- data/ref/ruby/classes/Integer.src/M000011.html +5 -5
- data/ref/ruby/classes/Integer.src/M000012.html +5 -5
- data/ref/ruby/classes/Integer.src/M000013.html +5 -5
- data/ref/ruby/classes/Integer.src/M000014.html +18 -0
- data/ref/ruby/classes/Integer.src/M000017.html +12 -18
- data/ref/ruby/classes/Integer.src/M000018.html +18 -12
- data/ref/ruby/classes/Integer.src/M000019.html +12 -17
- data/ref/ruby/classes/Integer.src/M000020.html +30 -0
- data/ref/ruby/classes/RDoc.html +5 -5
- data/ref/ruby/classes/RDoc.src/{M000053.html → M000058.html} +0 -0
- data/ref/ruby/classes/{RubyVpi/Config.html → RubyVPI.html} +20 -6
- data/ref/ruby/classes/String.html +34 -15
- data/ref/ruby/classes/String.src/M000022.html +5 -28
- data/ref/ruby/classes/String.src/M000023.html +5 -5
- data/ref/ruby/classes/String.src/{M000021.html → M000024.html} +0 -0
- data/ref/ruby/classes/String.src/M000025.html +41 -0
- data/ref/ruby/classes/VerilogParser/Module/Port.html +16 -36
- data/ref/ruby/classes/VerilogParser/Module/Port.src/M000006.html +10 -5
- data/ref/ruby/classes/VerilogParser/Module/Port.src/{M000004.html → M000007.html} +4 -4
- data/ref/ruby/classes/VerilogParser/Module/Port.src/{M000005.html → M000008.html} +4 -4
- data/ref/ruby/classes/VerilogParser/Module.html +28 -9
- data/ref/ruby/classes/VerilogParser/Module.src/M000005.html +29 -0
- data/ref/ruby/classes/VerilogParser.html +5 -39
- data/ref/ruby/classes/VerilogParser.src/M000004.html +26 -0
- data/ref/ruby/classes/Vpi/Handle.html +179 -77
- data/ref/ruby/classes/Vpi/Handle.src/M000035.html +18 -0
- data/ref/ruby/classes/Vpi/Handle.src/M000036.html +5 -5
- data/ref/ruby/classes/Vpi/Handle.src/M000037.html +5 -5
- data/ref/ruby/classes/Vpi/Handle.src/M000038.html +5 -5
- data/ref/ruby/classes/Vpi/Handle.src/M000039.html +5 -5
- data/ref/ruby/classes/Vpi/Handle.src/M000040.html +5 -8
- data/ref/ruby/classes/Vpi/Handle.src/M000041.html +5 -8
- data/ref/ruby/classes/Vpi/Handle.src/M000042.html +5 -9
- data/ref/ruby/classes/Vpi/Handle.src/M000043.html +8 -31
- data/ref/ruby/classes/Vpi/Handle.src/M000044.html +8 -74
- data/ref/ruby/classes/Vpi/Handle.src/M000045.html +9 -17
- data/ref/ruby/classes/Vpi/Handle.src/M000046.html +31 -11
- data/ref/ruby/classes/Vpi/Handle.src/M000047.html +86 -0
- data/ref/ruby/classes/Vpi/Handle.src/M000048.html +17 -18
- data/ref/ruby/classes/Vpi/Handle.src/M000050.html +18 -0
- data/ref/ruby/classes/Vpi/Handle.src/M000051.html +24 -0
- data/ref/ruby/classes/Vpi/Handle.src/M000053.html +31 -0
- data/ref/ruby/classes/Vpi/Handle.src/M000054.html +89 -0
- data/ref/ruby/classes/Vpi/S_vpi_time.html +16 -16
- data/ref/ruby/classes/Vpi/S_vpi_time.src/{M000050.html → M000055.html} +4 -4
- data/ref/ruby/classes/Vpi/S_vpi_time.src/{M000051.html → M000056.html} +5 -5
- data/ref/ruby/classes/Vpi/S_vpi_value.html +15 -15
- data/ref/ruby/classes/Vpi/S_vpi_value.src/{M000035.html → M000032.html} +5 -5
- data/ref/ruby/classes/Vpi/S_vpi_value.src/M000033.html +5 -5
- data/ref/ruby/classes/Vpi/S_vpi_value.src/M000034.html +5 -5
- data/ref/ruby/classes/Vpi.html +6 -42
- data/ref/ruby/classes/Vpi.src/M000029.html +15 -5
- data/ref/ruby/classes/Vpi.src/M000030.html +24 -24
- data/ref/ruby/classes/Vpi.src/M000031.html +6 -8
- data/ref/ruby/created.rid +1 -1
- data/ref/ruby/files/bin/{header_to_ruby_rb.html → convert_rb.html} +5 -5
- data/ref/ruby/files/bin/{generate_test_rb.html → generate_rb.html} +8 -21
- data/ref/ruby/files/lib/ruby-vpi/erb_rb.html +1 -1
- data/ref/ruby/files/lib/ruby-vpi/float_rb.html +1 -1
- data/ref/ruby/files/lib/ruby-vpi/integer_rb.html +1 -1
- data/ref/ruby/files/lib/ruby-vpi/rake_rb.html +1 -1
- data/ref/ruby/files/lib/ruby-vpi/rcov_rb.html +1 -1
- data/ref/ruby/files/lib/ruby-vpi/rdoc_rb.html +1 -1
- data/ref/ruby/files/lib/ruby-vpi/runner_boot_loader_rb.html +197 -0
- data/ref/ruby/files/lib/ruby-vpi/runner_boot_loader_rb.src/M000001.html +17 -0
- data/ref/ruby/files/lib/ruby-vpi/runner_boot_loader_rb.src/M000002.html +18 -0
- data/ref/ruby/files/lib/ruby-vpi/runner_proxy_rb.html +1 -1
- data/ref/ruby/files/lib/ruby-vpi/runner_rb.html +6 -19
- data/ref/ruby/files/lib/ruby-vpi/util_rb.html +101 -0
- data/ref/ruby/files/lib/ruby-vpi/verilog_parser_rb.html +8 -1
- data/ref/ruby/files/lib/ruby-vpi/vpi_rb.html +1 -1
- data/ref/ruby/files/lib/ruby-vpi_rb.html +2 -14
- data/ref/ruby/fr_class_index.html +1 -3
- data/ref/ruby/fr_file_index.html +4 -2
- data/ref/ruby/fr_method_index.html +56 -51
- data/ref/ruby/index.html +1 -1
- data/samp/counter/RSpec/Rakefile +1 -0
- data/samp/counter/RSpec/counter_design.rb +15 -0
- data/samp/counter/RSpec/counter_proto.rb +10 -0
- data/samp/counter/RSpec/counter_runner.rake +44 -0
- data/samp/counter/RSpec/counter_spec.rb +39 -0
- data/samp/counter/Rakefile +1 -1
- data/samp/counter/counter.v +7 -7
- data/samp/counter/xUnit/Rakefile +1 -0
- data/samp/counter/xUnit/counter_bench.rb +95 -0
- data/samp/counter/{counter_xunit_bench.v → xUnit/counter_bench.v} +0 -0
- data/samp/counter/xUnit/counter_design.rb +15 -0
- data/samp/counter/xUnit/counter_proto.rb +10 -0
- data/samp/counter/xUnit/counter_runner.rake +44 -0
- data/samp/counter/{counter_xunit_spec.rb → xUnit/counter_spec.rb} +9 -9
- data/samp/pipelined_alu/Rakefile +1 -1
- data/samp/pipelined_alu/TestHw5UnitModel.rb +4 -5
- data/samp/pipelined_alu/hw5_unit.v +55 -85
- data/samp/pipelined_alu/hw5_unit_design.rb +51 -0
- data/samp/pipelined_alu/hw5_unit_proto.rb +4 -0
- data/samp/pipelined_alu/hw5_unit_runner.rake +43 -0
- data/samp/pipelined_alu/hw5_unit_spec.rb +64 -0
- data/samp/register_file/LICENSE +20 -0
- data/samp/register_file/README +4 -0
- data/samp/register_file/Rakefile +1 -0
- data/samp/register_file/register_file.v +18 -0
- data/samp/register_file/register_file_design.rb +11 -0
- data/samp/register_file/register_file_proto.rb +11 -0
- data/samp/register_file/register_file_runner.rake +43 -0
- data/samp/register_file/register_file_spec.rb +58 -0
- metadata +78 -66
- data/bin/generate_test.rb +0 -200
- data/bin/generate_test_tpl/bench.rb +0 -89
- data/bin/generate_test_tpl/bench.v +0 -26
- data/bin/generate_test_tpl/design.rb +0 -11
- data/bin/generate_test_tpl/proto.rb +0 -16
- data/bin/generate_test_tpl/runner.rake +0 -42
- data/bin/generate_test_tpl/spec.rb +0 -37
- data/bin/header_to_ruby.rb +0 -27
- data/ref/ruby/classes/Integer.src/M000008.html +0 -25
- data/ref/ruby/classes/Integer.src/M000016.html +0 -25
- data/ref/ruby/classes/RubyVpi.html +0 -199
- data/ref/ruby/classes/RubyVpi.src/M000027.html +0 -121
- data/ref/ruby/classes/VerilogParser/Module/Parameter.html +0 -160
- data/ref/ruby/classes/VerilogParser/Module/Parameter.src/M000007.html +0 -19
- data/ref/ruby/classes/VerilogParser/Module/Port.src/M000003.html +0 -21
- data/ref/ruby/classes/VerilogParser/Module.src/M000002.html +0 -34
- data/ref/ruby/classes/VerilogParser.src/M000001.html +0 -34
- data/ref/ruby/classes/Vpi/Handle.src/M000049.html +0 -69
- data/ref/ruby/classes/Vpi.src/M000028.html +0 -28
- data/ref/ruby/classes/Vpi.src/M000032.html +0 -22
- data/samp/counter/counter_rspec_bench.rb +0 -86
- data/samp/counter/counter_rspec_bench.v +0 -9
- data/samp/counter/counter_rspec_design.rb +0 -8
- data/samp/counter/counter_rspec_proto.rb +0 -13
- data/samp/counter/counter_rspec_runner.rake +0 -52
- data/samp/counter/counter_rspec_spec.rb +0 -39
- data/samp/counter/counter_xunit_bench.rb +0 -86
- data/samp/counter/counter_xunit_design.rb +0 -8
- data/samp/counter/counter_xunit_proto.rb +0 -13
- data/samp/counter/counter_xunit_runner.rake +0 -52
- data/samp/pipelined_alu/hw5_unit_test_bench.rb +0 -86
- data/samp/pipelined_alu/hw5_unit_test_bench.v +0 -14
- data/samp/pipelined_alu/hw5_unit_test_design.rb +0 -61
- data/samp/pipelined_alu/hw5_unit_test_proto.rb +0 -7
- data/samp/pipelined_alu/hw5_unit_test_runner.rake +0 -52
- data/samp/pipelined_alu/hw5_unit_test_spec.rb +0 -68
data/doc/manual.doc
CHANGED
@@ -1,960 +1,809 @@
|
|
1
|
-
|
1
|
+
<doc_proxy_include common.inc>
|
2
2
|
|
3
|
-
|
3
|
+
<% front_cover "Ruby-VPI #{version} user manual" do %>
|
4
|
+
h2(author). Suraj N. Kurapati
|
4
5
|
|
5
|
-
|
6
|
+
h3(date). <%= Time.now.strftime("%d %B %Y") %>
|
6
7
|
|
7
|
-
You can give feedback about this manual and, in general, any aspect of the Ruby-VPI project on the "project forums":http://rubyforge.org/forum/?group_id=1339.
|
8
8
|
|
9
|
-
|
9
|
+
<% paragraph "About this manual" do %>
|
10
|
+
This manual is meant to be read in conjunction with the "reference documentation for Ruby-VPI":../ref/ruby/index.html. In addition, if you are new to "the Ruby language":http://www.ruby-lang.org, you are encouraged to "explore its documentation":http://www.ruby-lang.org/en/documentation/ as necessary.
|
10
11
|
|
12
|
+
In this manual, you will notice that the numbers of chapters, sections, figures, admonitions, etc. are hyperlinks that take you back to the corresponding place in the table of contents. These links make it easy to navigate this manual, especially for users of text-only web browsers.
|
11
13
|
|
12
|
-
|
14
|
+
In addition, this manual is distributed as one big HTML file so that you can easily search for a particular topic using nothing more than your web browser's built-in text search mechanism. This facilitates offline reading, where an Internet search engine is not available.
|
13
15
|
|
14
|
-
|
16
|
+
You can give feedback about this manual and, in general, any aspect of the Ruby-VPI project on the "project forums":<%= forumURL %>. Furthermore, you can <%= xref "hacking.manual", "edit this manual" %> and contribute your improvements to the "project patches":<%= trackerURL %>. Finally, you can find the newest version of this manual at the "Ruby-VPI project website":<%= projectURL %>.
|
17
|
+
<% end %>
|
15
18
|
|
16
|
-
|
19
|
+
<% paragraph "Legal notice" do %>
|
20
|
+
This manual is distributed under <%= xref "intro.license", "the same license as Ruby-VPI" %>.
|
17
21
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
<%= import 'intro.inc' %>
|
22
|
-
|
23
|
-
|
24
|
-
h1(#background). Background
|
25
|
-
|
26
|
-
|
27
|
-
h2(#background.methodology). Methodology
|
28
|
-
|
29
|
-
Ruby-VPI presents an open-ended interface to VPI. Thus, you can use any methodology you wish when writing tests. However, being an agile language, Ruby makes it _very_ easy to use agile development practies such as "TDD":#glossary.TDD and "BDD":#glossary.BDD.
|
30
|
-
|
31
|
-
|
32
|
-
h2(#background.vocab). Terminology
|
33
|
-
|
34
|
-
<% note "Glossary has definitions" do %>
|
35
|
-
Have a look at the "glossary":#glossary for definitions of terms used in this manual.
|
36
|
-
<% end %>
|
37
|
-
|
38
|
-
As a newcomer into the world of Verilog, I often heard the term *test bench*: "I ran the test bench, but it didn't work!" or "Are you crazy?!! You _still_ haven't written the test bench?", for example. I poured through my textbook for a definition of the term, but it was to no avail. Instead, it nonchalantly employed the term _throughout_ its being, as if mocking my ignorance of what seems to be universal knowledge.
|
39
|
-
|
40
|
-
Defeated, I turned to my inner faculties to determine the answer. Let's see, the term _test bench_ has the word _test_—so it has something to do with testing—and it has the word _bench_—so maybe it's referring to a table where the testing should occur. This reasoning grew increasingly familiar as my mind rummaged through towering stores of obsolescence and ultimately revealed dreaded memories of sleepless anguish: debugging electronics in the robotics laboratory.
|
41
|
-
|
42
|
-
Aha! I exclaimed, hesitantly, rushing to dismiss the past. The term has its roots in the testing of electronic devices, where an engineer would sit at a bench in an electronics laboratory and verify that an electronic component satisfies some criteria. The bench would be furnished with tools of measurement and manipulation—such as oscilloscopes, voltmeters, soldering irons, and so on—which help the engineer to verify the electronic component or locate the sources of defects in the component.
|
43
|
-
|
44
|
-
Alright, now I remember what a laboratory bench is, but how does that compare with the term test bench? Surely they cannot have the same meaning, because it doesn't make sense to _run_ a laboratory bench or to _write_ one. Thus, to avoid propagating such confusion into this manual, I have attempted to clarify the terminology by "simplifying and reintroducing it in a new light":#glossary.
|
45
|
-
|
46
|
-
|
47
|
-
h2(#background.org). Organization
|
48
|
-
|
49
|
-
<% figure "Overall organization of a test", "#fig..organization" do %>
|
50
|
-
!figures/organization.png!
|
51
|
-
<% end %>
|
52
|
-
|
53
|
-
As <xref #fig..organization> shows, a "test":#glossary.test is composed of a "bench":#glossary.bench, a "design":#glossary.design, and a "specification":#glossary.specification.
|
54
|
-
|
55
|
-
To extend the "analogy of an electronics laboratory":#background.vocab, the _bench_ acts as the laboratory bench which provides measurement and manipulation tools. The _design_ acts as the electronic component being verified by the engineer. And the _specification_ acts as the engineer who measures, manipulates, and verifies the electronic component.
|
56
|
-
|
57
|
-
<% figure "Detailed organization of a test", "#fig..organization.detail" do %>
|
58
|
-
!figures/organization_detailed.png!
|
22
|
+
The admonition graphics used in this manual are Copyright 2005, 2006 "Tango Desktop Project":http://tango.freedesktop.org and are distributed under "these terms":./images/tango/LICENSE.
|
23
|
+
<% end %>
|
59
24
|
<% end %>
|
60
25
|
|
61
|
-
|
62
|
-
|
63
|
-
Notice that Ruby-VPI encapsulates all communication between the Ruby interpreter and VPI. This allows the specification, or any Ruby program in general, to access VPI using nothing more than the Ruby language! Thus, Ruby-VPI removes the burden of having to write C programs in order to use VPI.
|
64
|
-
|
65
|
-
|
66
|
-
h2(#background.relay). Ruby/Verilog interaction
|
67
|
-
|
68
|
-
In a typical VPI application written in C, the _Verilog simulator_ is in charge. Verilog code temporarily transfers control to C by invoking C functions, which return control to Verilog when they finish.
|
69
|
-
|
70
|
-
In contrast, Ruby-VPI puts the _specification_ in charge. The specification temporarily transfers control to the Verilog simulator by invoking the @Vpi::advance_time@ method, which returns control to the specification when it finishes. This process is illustrated in <xref#fig..ruby_relay>.
|
71
|
-
|
72
|
-
Ruby-VPI's approach is the same as any software testing framework, where the _specification_ drives the design under test. Whereas, the typical VPI & C approach is literally _backwards_ because the design under test drives the specification.
|
73
|
-
|
74
|
-
<% figure "Interaction between Ruby and Verilog", "#fig..ruby_relay" do %>
|
75
|
-
!figures/ruby_relay.png!
|
76
|
-
|
77
|
-
# The current simulation time is _X_.
|
78
|
-
# The specification invokes the @Vpi::advance_time@ method with parameter _Y_, which specifies the number of simulation time steps to be simulated.
|
79
|
-
# The Verilog simulator is now in control (temporarily).
|
80
|
-
# The current simulation time has _not_ changed; it is still _X_.
|
81
|
-
# The Verilog simulator simulates _Y_ simulation time steps.
|
82
|
-
# The current simulation time is now _X + Y_.
|
83
|
-
# The Verilog simulator returns control back to the specification.
|
84
|
-
<% end %>
|
85
|
-
|
86
|
-
|
87
|
-
h1(#setup). Setup
|
88
|
-
|
89
|
-
|
90
|
-
h2(#setup.manifest). Manifest
|
91
|
-
|
92
|
-
When you extract a release package, the following is what you would expect to find.
|
93
|
-
|
94
|
-
* <tt>doc</tt> contains user documentation in various formats.
|
95
|
-
* <tt>ref</tt> contains reference API documentation in HTML format.
|
96
|
-
* <tt>ext</tt> contains source code, written in the C language, for the "core of Ruby-VPI":#background.org.
|
97
|
-
* <tt>lib</tt> contains Ruby libraries provided by Ruby-VPI.
|
98
|
-
* <tt>bin</tt> contains various tools. See <xref #usage.tools> for more information.
|
99
|
-
* <tt>samp</tt> contains example tests. See <xref #usage.examples> for more information.
|
100
|
-
|
101
|
-
|
102
|
-
h2(#setup.reqs). Requirements
|
103
|
-
|
104
|
-
See <xref#intro.reqs> above.
|
105
|
-
|
106
|
-
<% tip "Add support for your Verilog simulator" do %>
|
107
|
-
Write a "support request":http://rubyforge.org/tracker/?group_id=1339 for your simulator, while providing a sample transcript of the commands you use to run a test with your simulator, and we will add support for your simulator in the next release!
|
26
|
+
<% chapter "Welcome", 'intro' do %>
|
27
|
+
<doc_proxy_include intro.inc>
|
108
28
|
<% end %>
|
109
29
|
|
30
|
+
<% chapter "Setup", "setup" do %>
|
31
|
+
<% section "Manifest", "setup.manifest" do %>
|
32
|
+
When you extract a release package, the following is what you would expect to find.
|
110
33
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
An _interactive_ text merging tool can greatly simplify the process of transferring wanted changes from one file to another. In particular, such tools are especially beneficial when using the "automated test generator":#usage.tools.generate-test. A handful of the currently available open-source text merging tools are listed below.
|
119
|
-
** "*kdiff3*":http://kdiff3.sourceforge.net/ is a graphical, three-way merging tool for KDE.
|
120
|
-
** "*meld*":http://meld.sourceforge.net/ is a graphical, three-way merging tool for GNOME.
|
121
|
-
** "*tkdiff*":http://tkdiff.sourceforge.net/ is a graphical, two-way merging tool that uses the cross-platform Tk windowing toolkit.
|
122
|
-
** "*xxdiff*":http://furius.ca/xxdiff/ is a graphical, three-way merging tool.
|
123
|
-
** "*imediff2*":http://elonen.iki.fi/code/imediff/ is a textual, fullscreen two-way merging tool. It is very useful when you are working remotely via SSH.
|
124
|
-
|
125
|
-
|
126
|
-
h2(#setup.installation). Installation
|
127
|
-
|
128
|
-
Once you have satisfied the "necessary requirements":#setup.reqs, you can install Ruby-VPI by running the <pre>gem install -y ruby-vpi</pre> command. RubyGems will install Ruby-VPI into the system gem directory, whose path can be determined by running the <pre>gem env gemdir</pre> command. Within this directory, there is a <tt>gems/</tt> subdirectory which contains the Ruby-VPI installation, as illustrated below.
|
129
|
-
|
130
|
-
<pre>
|
131
|
-
$ gem env gemdir
|
132
|
-
/usr/lib/ruby/gems/1.8
|
133
|
-
|
134
|
-
$ ls -d /usr/lib/ruby/gems/1.8/gems/ruby-vpi*
|
135
|
-
/usr/lib/ruby/gems/1.8/gems/ruby-vpi-7.0.0/
|
136
|
-
</pre>
|
137
|
-
|
138
|
-
|
139
|
-
h3(#setup.installation.windows). Installing on Windows
|
140
|
-
|
141
|
-
* Install "Cygwin":http://www.cygwin.com, the Linux-like environment for Windows.
|
142
|
-
|
143
|
-
<% note "Undefined symbols in Windows" do %>
|
144
|
-
After Ruby-VPI is compiled, it is linked to symbols whose names begin with <tt>_vpi</tt>. In GNU/Linux and similar operating systems, these symbols are allowed to be undefined. However, one "cannot compile a shared object file with references to undefined symbols in Windows":http://sourceware.org/ml/cygwin/2001-12/msg01293.html.
|
145
|
-
|
146
|
-
One solution is to supply the Verilog simulator's VPI object file, which contains definitions of all VPI symbols, to the linker. The following steps illustrate this process.
|
147
|
-
<% end %>
|
148
|
-
|
149
|
-
* Search for object files whose names end with <tt>.so</tt>, <tt>.o</tt>, or <tt>.dll</tt> in your Verilog simulator's installation directory.
|
150
|
-
|
151
|
-
* Determine which object files, among those found in the previous step, contain symbols whose names begin with "_vpi" by running the <pre>for x in *.{o,so,dll}; do nm $x | grep -q '[Tt] _vpi' && echo $x; done</pre> command in Cygwin.
|
152
|
-
** If you are using Mentor Modelsim, the desired object file can be found at a path similar to <tt>C:\Modeltech\win32\libvsim.dll</tt>.
|
153
|
-
** If you are using GPL Cver, the desired object file can be found at a path similar to <tt>C:\gplcver\objs\v_vpi.o</tt>.
|
154
|
-
|
155
|
-
* Assign the path of the object file (determined in the previous step) to the @LDFLAGS@ environment variable. For example, if the object file's path is <tt>/foo/bar/vpi.so</tt>, then you would run the <pre>export LDFLAGS=/foo/bar/vpi.so</pre> command in Cygwin.
|
156
|
-
|
157
|
-
* You may now install Ruby-VPI by running the <pre>gem install ruby-vpi</pre> command in Cygwin.
|
158
|
-
|
159
|
-
|
160
|
-
h2(#setup.maintenance). Maintenance
|
161
|
-
|
162
|
-
* You can uninstall Ruby-VPI by running the <pre>gem uninstall ruby-vpi</pre> command.
|
163
|
-
* You can upgrade to the latest release of Ruby-VPI by running the <pre>gem update ruby-vpi</pre> command.
|
164
|
-
|
165
|
-
Learn more about using and manipulating RubyGems in "the RubyGems user manual":http://www.rubygems.org.
|
166
|
-
|
167
|
-
|
168
|
-
h1(#usage). Usage
|
169
|
-
|
170
|
-
|
171
|
-
h2(#usage.vpi). VPI in Ruby
|
172
|
-
|
173
|
-
The _entire_ IEEE Std 1364-2005 VPI interface is available in Ruby, but with a few minor differences.
|
174
|
-
|
175
|
-
p(title). Capitalize those names!
|
176
|
-
|
177
|
-
The names of all VPI types, structures, and constants become _capitalized_ because Ruby requires that the names of constants begin with a capital letter.
|
178
|
-
|
179
|
-
For example, the @s_vpi_value@ structure becomes the @S_vpi_value@ class in Ruby. Likewise, the @vpiIntVal@ constant becomes the @VpiIntVal@ constant in Ruby.
|
180
|
-
|
181
|
-
<% note "No capitalization for VPI functions" do %>
|
182
|
-
Ruby's capitalization rule does _not_ apply to VPI functions--their names remain unchanged in Ruby.
|
183
|
-
<% end %>
|
184
|
-
|
185
|
-
p(title). Use Ruby's @printf@
|
186
|
-
|
187
|
-
The VPI functions @vpi_vprintf@ and @vpi_mcd_vprintf@ are not made accessible to Ruby. However, this isn't a big problem because you can use Ruby's @printf@ method instead.
|
188
|
-
|
189
|
-
The reason for this limitation is that some C compilers have trouble with pointers to the @va_list@ type. For these compilers, the third line of source code shown below causes a "type mismatch" error.
|
190
|
-
|
191
|
-
<code lang="c">
|
192
|
-
#include <stdarg.h>
|
193
|
-
void foo(va_list ap) {
|
194
|
-
va_list *p = ≈
|
195
|
-
}
|
196
|
-
</code>
|
197
|
-
|
198
|
-
|
199
|
-
h3(#usage.vpi.handles). Handles
|
200
|
-
|
201
|
-
A _handle_ is a reference to an object, such as a module, register, wire, and so on, inside the Verilog simulation. In short, handles allow you to inspect and manipulate the design under test and its components.
|
202
|
-
|
203
|
-
<% note "@Vpi::Handle@ heritage" do %>
|
204
|
-
Handles are instances of the @Vpi::Handle@ class (see "reference documentation":../ref/ruby/classes/Vpi/Handle.html for details) in Ruby-VPI.
|
205
|
-
<% end %>
|
206
|
-
|
207
|
-
Handles have various _properties_, which provide different kinds of information (see the "Kind of value accessed" column in <xref #tbl..accessors>) about the underlying Verilog object represented by a handle. These properties are accessed through various functions, which are listed in the "VPI functions used to access the value" column in <xref #tbl..accessors>.
|
208
|
-
|
209
|
-
Handles are typically obtained through the @vpi_handle_by_name@ and @vpi_handle@ functions. These functions are hierarchical in nature, because they allow you to obtain new handles that are related to existing handles. For example, to obtain a handle to a register inside a module, you would typically write: @some_reg = vpi_handle(VpiReg, some_handle)@.
|
210
|
-
|
211
|
-
|
212
|
-
p(title). Shortcuts for productivity
|
34
|
+
* <tt>doc</tt> contains user documentation in various formats.
|
35
|
+
* <tt>ref</tt> contains reference API documentation in HTML format.
|
36
|
+
* <tt>ext</tt> contains source code, written in the C language, for the <%= xref "organization", "core of Ruby-VPI" %>
|
37
|
+
* <tt>lib</tt> contains Ruby libraries provided by Ruby-VPI.
|
38
|
+
* <tt>bin</tt> contains various tools. See <%= xref "usage.tools" %> for more information.
|
39
|
+
* <tt>samp</tt> contains example tests. See <%= xref "usage.examples" %> for more information.
|
40
|
+
<% end %>
|
213
41
|
|
214
|
-
|
42
|
+
<% section "Requirements", "setup.reqs" do %>
|
43
|
+
See <%= xref "intro.reqs" %> above.
|
215
44
|
|
216
|
-
|
45
|
+
<% tip "Add support for your Verilog simulator" do %>
|
46
|
+
Write a "support request":http://rubyforge.org/tracker/?group_id=1339 for your simulator, while providing a sample transcript of the commands you use to run a test with your simulator, and I will add support for your simulator in the next release!
|
47
|
+
<% end %>
|
48
|
+
<% end %>
|
217
49
|
|
50
|
+
<% section "Recommendations", "setup.recom" do %>
|
51
|
+
The following software may make your interactions with Ruby-VPI more pleasant.
|
218
52
|
|
219
|
-
|
53
|
+
<% section "Text merging tool", "setup.recom.merger" do %>
|
54
|
+
An _interactive_ text merging tool can greatly simplify the process of transferring wanted changes from one file to another. In particular, such tools are especially beneficial when using the <%= xref "usage.tools.generate", "automated test generator" %>. A handful of the currently available open-source text merging tools are listed below.
|
220
55
|
|
221
|
-
|
56
|
+
* "*kdiff3*":http://kdiff3.sourceforge.net/ is a graphical, three-way merging tool for KDE.
|
222
57
|
|
223
|
-
|
58
|
+
* "*meld*":http://meld.sourceforge.net/ is a graphical, three-way merging tool for GNOME.
|
224
59
|
|
225
|
-
|
226
|
-
counter_module = vpi_handle_by_name("counter", nil)
|
60
|
+
* "*tkdiff*":http://tkdiff.sourceforge.net/ is a graphical, two-way merging tool that uses the cross-platform Tk windowing toolkit.
|
227
61
|
|
228
|
-
|
229
|
-
</code>
|
62
|
+
* "*xxdiff*":http://furius.ca/xxdiff/ is a graphical, three-way merging tool.
|
230
63
|
|
231
|
-
|
64
|
+
* "*imediff2*":http://elonen.iki.fi/code/imediff/ is a textual, fullscreen two-way merging tool. It is very useful when you are working remotely via SSH.
|
65
|
+
<% end %>
|
66
|
+
<% end %>
|
232
67
|
|
68
|
+
<% section "Installation", "setup.inst" do %>
|
69
|
+
Once you have satisfied the <%= xref "setup.reqs", "necessary requirements" %>, you can install Ruby-VPI by running the <pre>gem install -y ruby-vpi</pre> command. RubyGems will install Ruby-VPI into the system gem directory, whose path can be determined by running the <pre>gem env gemdir</pre> command. Within this directory, there is a <tt>gems/</tt> subdirectory which contains the Ruby-VPI installation, as illustrated below.
|
233
70
|
|
234
|
-
|
71
|
+
<pre>
|
72
|
+
$ gem env gemdir
|
73
|
+
/usr/lib/ruby/gems/1.8
|
235
74
|
|
236
|
-
|
75
|
+
$ ls -d /usr/lib/ruby/gems/1.8/gems/ruby-vpi*
|
76
|
+
/usr/lib/ruby/gems/1.8/gems/ruby-vpi-7.0.0/
|
77
|
+
</pre>
|
237
78
|
|
238
|
-
<%
|
239
|
-
|
240
|
-
|
79
|
+
<% note "Tuning for maximum performance" do %>
|
80
|
+
You can tune your installation of Ruby-VPI for maximum performance by adding your C compiler's optimization flag to the @CFLAGS@ environment variable _before_ you run the <pre>gem install -y ruby-vpi</pre> command. For example, if your C compiler is GCC, then you can set @CFLAGS@ to <tt>-O9</tt> for maximum optimization.
|
81
|
+
<% end %>
|
241
82
|
|
242
|
-
|
83
|
+
<% section "Installing on Windows", "setup.inst.windows" do %>
|
84
|
+
After Ruby-VPI is compiled, it is linked to symbols whose names begin with <tt>_vpi</tt>. In GNU/Linux and similar operating systems, these symbols are allowed to be undefined. However, one "cannot compile a shared object file with references to undefined symbols in Windows":http://sourceware.org/ml/cygwin/2001-12/msg01293.html.
|
243
85
|
|
244
|
-
|
86
|
+
One solution to this problem is to supply the Verilog simulator's VPI object file, which contains definitions of all VPI symbols, to the linker. The following steps illustrate this process.
|
245
87
|
|
246
|
-
*
|
88
|
+
* Install "Cygwin":http://www.cygwin.com, the Linux-like environment for Windows.
|
247
89
|
|
248
|
-
|
90
|
+
* Search for object files whose names end with <tt>.so</tt>, <tt>.o</tt>, or <tt>.dll</tt> in your Verilog simulator's installation directory.
|
249
91
|
|
250
|
-
*
|
92
|
+
* Determine which object files, among those found in the previous step, contain symbols whose names begin with "_vpi" by running the <pre>for x in *.{o,so,dll}; do nm $x | grep -q '[Tt] _vpi' && echo $x; done</pre> command in Cygwin.
|
93
|
+
** If you are using Mentor Modelsim, the desired object file can be found at a path similar to <tt>C:\Modeltech\win32\libvsim.dll</tt>.
|
94
|
+
** If you are using GPL Cver, the desired object file can be found at a path similar to <tt>C:\gplcver\objs\v_vpi.o</tt>.
|
251
95
|
|
252
|
-
|
253
|
-
<% end %>
|
254
|
-
|
255
|
-
<% table "Possible accessors and their implications", "tbl..accessors" do %>
|
256
|
-
|_. Accessor |_. Kind of value accessed |_. VPI functions used to access the value |
|
257
|
-
| d | delay | @vpi_get_delays@, @vpi_put_delays@ |
|
258
|
-
| l | logic | @vpi_get_value@, @vpi_put_value@ |
|
259
|
-
| i | integer | @vpi_get@ |
|
260
|
-
| b | boolean | @vpi_get@ |
|
261
|
-
| s | string | @vpi_get_str@ |
|
262
|
-
| h | handle | @vpi_handle@ |
|
263
|
-
<% end %>
|
96
|
+
* Assign the path of the object file (determined in the previous step) to the @LDFLAGS@ environment variable. For example, if the object file's path is <tt>/foo/bar/vpi.so</tt>, then you would run the <pre>export LDFLAGS=/foo/bar/vpi.so</pre> command in Cygwin.
|
264
97
|
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
| @handle.vpiIntVal@ | | | vpiIntVal | | | |/4. These expressions access the *logic value* of the handle's @VpiIntVal@ property. |
|
269
|
-
| @handle.vpiIntVal_l@ | | | vpiIntVal | _ | l | |
|
270
|
-
| @handle.intVal@ | | | intVal | | | |
|
271
|
-
| @handle.intVal_l@ | | | intVal | _ | l | |
|
272
|
-
| @handle.vpiIntVal = 15@ | | | vpiIntVal | | | = |/4. These expressions assign the number 15 to the *logic value* of the handle's @VpiIntVal@ property. |
|
273
|
-
| @handle.vpiIntVal_l = 15@ | | | vpiIntVal | _ | l | = |
|
274
|
-
| @handle.intVal = 15@ | | | intVal | | | = |
|
275
|
-
| @handle.intVal_l = 15@ | | | intVal | _ | l | = |
|
276
|
-
| @handle.vpiType@ | | | vpiType | | | |/4. These expressions access the *integer value* of the handle's @VpiType@ property. |
|
277
|
-
| @handle.vpiType_i@ | | | vpiType | _ | i | |
|
278
|
-
| @handle.type@ | | | type | | | |
|
279
|
-
| @handle.type_i@ | | | type | _ | i | |
|
280
|
-
| @handle.vpiProtected@ | | | vpiProtected | | | |/6. These expressions access the *boolean value* of the handle's @VpiProtected@ property. |
|
281
|
-
| @handle.vpiProtected_b@ | | | vpiProtected | _ | b | |
|
282
|
-
| @handle.vpiProtected?@ | | | vpiProtected | | | ? |
|
283
|
-
| @handle.protected@ | | | protected | | | |
|
284
|
-
| @handle.protected_b@ | | | protected | _ | b | |
|
285
|
-
| @handle.protected?@ | | | protected | | | ? |
|
286
|
-
| @handle.vpiFullName@ | | | vpiFullName | | | |/4. These expressions access the *string value* of the handle's @VpiFullName@ property. |
|
287
|
-
| @handle.vpiFullName_s@ | | | vpiFullName | _ | s | |
|
288
|
-
| @handle.fullName@ | | | fullName | | | |
|
289
|
-
| @handle.fullName_s@ | | | fullName | _ | s | |
|
290
|
-
| @handle.vpiParent@ | | | vpiParent | | | |/4. These expressions access the *handle value* of the handle's @VpiParent@ property. |
|
291
|
-
| @handle.vpiParent_h@ | | | vpiParent | _ | h | |
|
292
|
-
| @handle.parent@ | | | parent | | | |
|
293
|
-
| @handle.parent_h@ | | | parent | _ | h | |
|
294
|
-
| <code>handle.each_vpiNet {|net| puts net.fullName}</code> | each | _ | vpiNet | | | |/2. These expressions print the full name of each @VpiNet@ object associated with the handle. |
|
295
|
-
| <code>handle.each_net {|net| puts net.fullName}</code> | each | _ | net | | | |
|
296
|
-
| <code>handle.all_vpiReg? {|reg| reg.size == 1}</code> | all? | _ | vpiReg | | | |/2. These expressions check if all registers associated with the handle are capable of storing only one bit. |
|
297
|
-
| <code>handle.all_reg? {|reg| reg.size == 1}</code> | all? | _ | reg | | | |
|
298
|
-
| <code>handle.select_vpiNet {|net| net.x?}</code> | select | _ | VpiNet | | | |/2. These expressions return a list of nets whose *logic value* is unknown or "don't care" (x).|
|
299
|
-
| <code>handle.select_net {|net| net.x?}</code> | select | _ | net | | | |
|
300
|
-
<% end %>
|
98
|
+
* You may now install Ruby-VPI by running the <pre>gem install ruby-vpi</pre> command in Cygwin.
|
99
|
+
<% end %>
|
100
|
+
<% end %>
|
301
101
|
|
102
|
+
<% section "Maintenance", "setup.maintenance" do %>
|
103
|
+
* You can upgrade to the latest release of Ruby-VPI by running the <pre>gem update ruby-vpi</pre> command.
|
104
|
+
* You can uninstall Ruby-VPI by running the <pre>gem uninstall ruby-vpi</pre> command.
|
302
105
|
|
303
|
-
|
304
|
-
|
305
|
-
A _callback_ is a mechanism that makes the Verilog simuluator execute a block of code, which is known as a "callback handler", when some prescribed event occurs in the simulation. They are set up using the @vpi_register_cb@ function and torn down using the @vpi_remove_cb@ function.
|
306
|
-
|
307
|
-
<% example "Using a callback for value change notification", "ex..callback" do %>
|
308
|
-
This example shows how to use a callback for notification of changes in a handle's @VpiIntVal@ property. When you no longer need this callback, you can tear it down using @vpi_remove_cb(cb_handle)@.
|
309
|
-
|
310
|
-
In this example, the handle being monitored is the @Counter.count@ signal from <xref#fig..counter.v_decl>.
|
311
|
-
|
312
|
-
<code>
|
313
|
-
cbTime = S_vpi_time.new
|
314
|
-
cbTime.type = VpiSimTime
|
315
|
-
cbTime.low = 0
|
316
|
-
cbTime.high = 0
|
317
|
-
|
318
|
-
cbValue = S_vpi_value.new
|
319
|
-
cbValue.format = VpiIntVal
|
320
|
-
|
321
|
-
cbData = S_cb_data.new
|
322
|
-
cbData.reason = CbValueChange
|
323
|
-
cbData.obj = Counter.count
|
324
|
-
cbData.time = cbTime
|
325
|
-
cbData.value = cbValue
|
326
|
-
cbData.index = 0
|
327
|
-
|
328
|
-
cbHandle = vpi_register_cb(cbData) do |data|
|
329
|
-
|
330
|
-
time = (data.time.high << 32) | data.time.low
|
331
|
-
count = data.value.value.integer
|
332
|
-
|
333
|
-
puts "hello from callback! time=#{time} count=#{count}"
|
334
|
-
|
335
|
-
end
|
336
|
-
</code>
|
337
|
-
|
338
|
-
Shown below is the result of appending this code to the <tt>counter_rspec_spec.rb</tt> file (provided in <xref#usage.examples> and discussed in <xref#usage.tutorial.specification>) and running the "counter_rspec test":#usage.tutorial.
|
339
|
-
|
340
|
-
<pre>
|
341
|
-
$ rake -f counter_rspec_runner.rake cver
|
342
|
-
|
343
|
-
(in /home/sun/src/ruby-vpi/samp/counter)
|
344
|
-
cver +loadvpi=/home/sun/src/ruby-vpi/lib/ruby-vpi/../../obj/ruby-vpi.cver.so:vlog_startup_routines_bootstrap counter.v counter_rspec_bench.v
|
345
|
-
GPLCVER_2.11a of 07/05/05 (Linux-elf).
|
346
|
-
Copyright (c) 1991-2005 Pragmatic C Software Corp.
|
347
|
-
All Rights reserved. Licensed under the GNU General Public License (GPL).
|
348
|
-
See the 'COPYING' file for details. NO WARRANTY provided.
|
349
|
-
Today is Sat Dec 30 09:24:09 2006.
|
350
|
-
Compiling source file "counter.v"
|
351
|
-
Compiling source file "counter_rspec_bench.v"
|
352
|
-
Highest level modules:
|
353
|
-
counter_rspec_bench
|
354
|
-
|
355
|
-
|
356
|
-
A resetted counter's value
|
357
|
-
hello from callback! time=1 count=0
|
358
|
-
- should be zero
|
359
|
-
hello from callback! time=5 count=1
|
360
|
-
hello from callback! time=7 count=2
|
361
|
-
hello from callback! time=9 count=3
|
362
|
-
hello from callback! time=11 count=4
|
363
|
-
hello from callback! time=13 count=5
|
364
|
-
hello from callback! time=15 count=6
|
365
|
-
hello from callback! time=17 count=7
|
366
|
-
hello from callback! time=19 count=8
|
367
|
-
hello from callback! time=21 count=9
|
368
|
-
hello from callback! time=23 count=10
|
369
|
-
hello from callback! time=25 count=11
|
370
|
-
hello from callback! time=27 count=12
|
371
|
-
hello from callback! time=29 count=13
|
372
|
-
hello from callback! time=31 count=14
|
373
|
-
hello from callback! time=33 count=15
|
374
|
-
hello from callback! time=35 count=16
|
375
|
-
hello from callback! time=37 count=17
|
376
|
-
hello from callback! time=39 count=18
|
377
|
-
hello from callback! time=41 count=19
|
378
|
-
hello from callback! time=43 count=20
|
379
|
-
hello from callback! time=45 count=21
|
380
|
-
hello from callback! time=47 count=22
|
381
|
-
hello from callback! time=49 count=23
|
382
|
-
hello from callback! time=51 count=24
|
383
|
-
hello from callback! time=53 count=25
|
384
|
-
hello from callback! time=55 count=26
|
385
|
-
hello from callback! time=57 count=27
|
386
|
-
hello from callback! time=59 count=28
|
387
|
-
hello from callback! time=61 count=29
|
388
|
-
hello from callback! time=63 count=30
|
389
|
-
hello from callback! time=65 count=31
|
390
|
-
hello from callback! time=67 count=0
|
391
|
-
- should increment by one count upon each rising clock edge
|
392
|
-
|
393
|
-
A counter with the maximum value
|
394
|
-
hello from callback! time=71 count=1
|
395
|
-
hello from callback! time=73 count=2
|
396
|
-
hello from callback! time=75 count=3
|
397
|
-
hello from callback! time=77 count=4
|
398
|
-
hello from callback! time=79 count=5
|
399
|
-
hello from callback! time=81 count=6
|
400
|
-
hello from callback! time=83 count=7
|
401
|
-
hello from callback! time=85 count=8
|
402
|
-
hello from callback! time=87 count=9
|
403
|
-
hello from callback! time=89 count=10
|
404
|
-
hello from callback! time=91 count=11
|
405
|
-
hello from callback! time=93 count=12
|
406
|
-
hello from callback! time=95 count=13
|
407
|
-
hello from callback! time=97 count=14
|
408
|
-
hello from callback! time=99 count=15
|
409
|
-
hello from callback! time=101 count=16
|
410
|
-
hello from callback! time=103 count=17
|
411
|
-
hello from callback! time=105 count=18
|
412
|
-
hello from callback! time=107 count=19
|
413
|
-
hello from callback! time=109 count=20
|
414
|
-
hello from callback! time=111 count=21
|
415
|
-
hello from callback! time=113 count=22
|
416
|
-
hello from callback! time=115 count=23
|
417
|
-
hello from callback! time=117 count=24
|
418
|
-
hello from callback! time=119 count=25
|
419
|
-
hello from callback! time=121 count=26
|
420
|
-
hello from callback! time=123 count=27
|
421
|
-
hello from callback! time=125 count=28
|
422
|
-
hello from callback! time=127 count=29
|
423
|
-
hello from callback! time=129 count=30
|
424
|
-
hello from callback! time=131 count=31
|
425
|
-
hello from callback! time=133 count=0
|
426
|
-
- should overflow upon increment
|
427
|
-
|
428
|
-
Finished in 0.042328 seconds
|
429
|
-
|
430
|
-
3 specifications, 0 failures
|
431
|
-
</pre>
|
106
|
+
Learn more about using and manipulating RubyGems in "the RubyGems user manual":http://www.rubygems.org.
|
107
|
+
<% end %>
|
432
108
|
<% end %>
|
433
109
|
|
110
|
+
<% chapter "Organization", "organization" do %>
|
111
|
+
Ruby-VPI is a bridge between IEEE 1364-2005 Verilog VPI and the Ruby language. It enables Ruby programs to use VPI either (1) in the same, verbose way that C programs do, or (2) in a simpler, higher level way. In addition, it serves as a vehicle for the application of agile software development practices, such as <%= xref "glossary.TDD", "TDD" %> and <%= xref "glossary.BDD", "BDD" %> to the realm of hardware development with Verilog.
|
434
112
|
|
435
|
-
|
113
|
+
Ruby-VPI can be used with any Verilog simulator that supports VPI. In particular, it is known to operate with (1) Synopsys VCS and Mentor Modelsim, the two "most prominent Verilog simulators":http://www.eetimes.com/news/design/showArticle.jhtml?articleID=47204415 in the Electronic Design Automation (EDA) industry; as well as (2) GPL Cver and Icarus Verilog, the two most prevalent open source Verilog simulators today.
|
436
114
|
|
437
|
-
|
115
|
+
<% figure "Where does Ruby-VPI fit in?", "fig:organization.detail" do %>
|
116
|
+
!figures/organization_detailed.png!
|
117
|
+
<% end %>
|
438
118
|
|
439
|
-
|
440
|
-
# "Determine the *interface*":#usage.tutorial.declare-design (Verilog module declaration) of your design.
|
441
|
-
# "Generate a test":#usage.tutorial.generate-test for that interface.
|
442
|
-
# "Implement the prototype":#usage.tutorial.implement-proto in the generated <tt>proto.rb</tt> file.
|
443
|
-
# "Verify the prototype":#usage.tutorial.test-proto against its specification.
|
119
|
+
As <%= xref "fig:organization.detail" %> shows, Ruby-VPI is composed of two complementary parts: one interacts with VPI through the C language, while the other interacts with an executable specification written in the Ruby language. The former is complied during installation to produce dynamically loadable C libraries---each tailored to accommodate the quirks of its respective Verilog simulator. The latter is not compiled because Ruby programs are interpreted dynamically.
|
444
120
|
|
445
|
-
|
121
|
+
<% section "Ruby/Verilog interaction", "overview.relay" do %>
|
122
|
+
In a typical VPI application written in C, the _Verilog simulator_ is in charge. Verilog code temporarily transfers control to C by invoking C functions, which return control to Verilog when they finish.
|
446
123
|
|
447
|
-
|
124
|
+
In contrast, Ruby-VPI puts the _specification_ in charge. The specification temporarily transfers control to the Verilog simulator by invoking the @advance_time@ method, which returns control to the specification when it finishes. This process is illustrated in <%= xref "fig:ruby_relay" %>.
|
448
125
|
|
126
|
+
Ruby-VPI's approach is the same as any software testing framework, where the _specification_ drives the design under test. Whereas, the typical VPI & C approach is literally _backwards_ because the design under test drives the specification.
|
449
127
|
|
450
|
-
|
128
|
+
<% figure "Interaction between Ruby and Verilog", "fig:ruby_relay" do %>
|
129
|
+
!figures/ruby_relay.png!
|
451
130
|
|
452
|
-
The
|
131
|
+
# The current simulation time is _X_.
|
132
|
+
# The specification invokes the @Vpi::advance_time@ method with parameter _Y_, which specifies the number of simulation time steps to be simulated.
|
133
|
+
# The Verilog simulator is now in control (temporarily).
|
134
|
+
# The current simulation time has _not_ changed; it is still _X_.
|
135
|
+
# The Verilog simulator simulates _Y_ simulation time steps.
|
136
|
+
# The current simulation time is now _X + Y_.
|
137
|
+
# The Verilog simulator returns control back to the specification.
|
138
|
+
<% end %>
|
453
139
|
|
454
|
-
|
455
|
-
|
140
|
+
Another means of transferring control from the specification to the Verilog simulator is the <%= xref "vpi.callbacks", "VPI callback" %>.
|
141
|
+
<% end %>
|
456
142
|
|
143
|
+
<% section "Tests", "organization.tests" do %>
|
144
|
+
In Ruby-VPI, the process of functional verification is neatly packaged into self-contained, executable tests. As <%= xref "fig:organization" %> illustrates, a test is composed of a *bench*, a *design*, and a *specification*.
|
457
145
|
|
458
|
-
|
146
|
+
<% figure "Organization of a test in Ruby-VPI", "fig:organization" do %>
|
147
|
+
!figures/organization.png!
|
148
|
+
<% end %>
|
459
149
|
|
460
|
-
|
150
|
+
*The bench* is Ruby-VPI. It defines the environment in which functional verification takes place. This is analogous to a workbench in an electronics laboratory that is furnished with tools of measurement and manipulation such as oscilloscopes, voltmeters, soldering irons, and so on which enable engineers to verify electronic components and locate the source of defects within those components.
|
461
151
|
|
462
|
-
|
463
|
-
# Put your own code, which initializes the debugger, above the @RubyVpi.init_bench@ line in your generated <tt>spec.rb</tt> file.
|
152
|
+
*The design* is an instantiated Verilog module. To extend the analogy of the electronics laboratory, it corresponds to the electronic component that is verified by an engineer.
|
464
153
|
|
154
|
+
*The specification* is a Ruby program. In the electronics laboratory analogy, it corresponds to the engineer who inspects, manipulates, and verifies the electronic component. In terms of specification-driven functional verification, it corresponds to the executable specification.
|
155
|
+
<% end %>
|
465
156
|
|
466
|
-
h2(#usage.test-runner). Test runner
|
467
157
|
|
468
|
-
|
158
|
+
<% section "VPI in Ruby" do %>
|
159
|
+
<% section "Deviations from the VPI standard" do %>
|
160
|
+
Ruby-VPI makes the entire IEEE Std 1364-2005 VPI interface available to Ruby, but with the following minor differences.
|
469
161
|
|
470
|
-
<% example "Seeing what a test runner can do" do %>
|
471
|
-
When you invoke a test runner without any arguments, it will show you a list of available tasks:
|
472
|
-
<pre>$ rake -f some_test_runner.rake
|
473
162
|
|
474
|
-
|
475
|
-
|
163
|
+
<% section "Names are capitalized" do %>
|
164
|
+
The names of all VPI types, structures, and constants become _capitalized_ because Ruby requires that the names of constants begin with a capital letter. However, note that Ruby's capitalization rule does _not_ apply to VPI functions.
|
476
165
|
|
477
|
-
|
478
|
-
|
166
|
+
For example, the @s_vpi_value@ structure becomes the @S_vpi_value@ class in Ruby. Likewise, the @vpiIntVal@ constant becomes the @VpiIntVal@ constant in Ruby. However, the @vpi_handle@ function remains as @vpi_handle@ in Ruby.
|
167
|
+
<% end %>
|
479
168
|
|
480
|
-
@require 'ruby-vpi/runner_proxy'@
|
481
169
|
|
482
|
-
|
483
|
-
|
170
|
+
<% section "@vprintf@ is @printf@" do %>
|
171
|
+
The @vpi_vprintf@ and @vpi_mcd_vprintf@ VPI functions are aliased to @vpi_printf@ and @vpi_mcd_printf@ respectively because:
|
484
172
|
|
173
|
+
* Ruby represents "variable argument lists as arrays":http://www.rubycentral.com/book/tut_methods.html#UA instead of defining a special datatype, such as @va_list@, for them.
|
485
174
|
|
486
|
-
|
175
|
+
* Some C compilers have trouble with pointers to the @va_list@ type. For these compilers, the third line of source code shown below causes a "type mismatch" error.
|
487
176
|
|
488
|
-
|
177
|
+
<code lang="c">
|
178
|
+
#include <stdarg.h>
|
179
|
+
void foo(va_list ap) {
|
180
|
+
va_list *p = ≈
|
181
|
+
}
|
182
|
+
</code>
|
183
|
+
<% end %>
|
184
|
+
<% end %>
|
489
185
|
|
490
|
-
|
491
|
-
*
|
492
|
-
* @PROTOTYPE@ enables the Ruby prototype for the design under test.
|
186
|
+
<% section "Handles", "vpi.handles" do %>
|
187
|
+
A *handle* is a reference to an object (such as a module, register, wire, and so on) inside the Verilog simulation. Handles allows you to inspect and manipulate the design under test and its internal components. They are instances of the @Vpi::Handle@ class (see "reference documentation":../ref/ruby/classes/Vpi/Handle.html for details) in Ruby-VPI.
|
493
188
|
|
494
|
-
|
189
|
+
Handles have various *properties*, listed in the second column of <%= xref "tbl:accessors" %>, which provide different kinds of information about the underlying Verilog objects they represent. These properties are accessed through the VPI functions listed in the last column of <%= xref "tbl:accessors" %>.
|
495
190
|
|
496
|
-
|
497
|
-
|
498
|
-
In addition, you can specify variable assignments as arguments to the *rake* command. For example, <pre>rake DEBUG=1</pre> is equivalent to <pre>
|
499
|
-
$ DEBUG=1
|
500
|
-
$ export DEBUG
|
501
|
-
$ rake
|
502
|
-
</pre> in Bourne shell or <pre>
|
503
|
-
% setenv DEBUG 1
|
504
|
-
% rake
|
505
|
-
</pre> in C shell.
|
506
|
-
|
507
|
-
<% example "Running a test with environment variables" do %>
|
508
|
-
|
509
|
-
Here we enable the prototype and code coverage analysis:
|
510
|
-
<pre>rake -f some_test_runner.rake PROTOTYPE=1 COVERAGE=1</pre>
|
511
|
-
|
512
|
-
Here we _disable_ the prototype and enable the code coverage analysis. Note that both of these invocations are equivalent:
|
513
|
-
<pre>rake -f some_test_runner.rake PROTOTYPE= COVERAGE=1</pre>
|
514
|
-
<pre>rake -f some_test_runner.rake COVERAGE=1</pre>
|
515
|
-
<% end %>
|
191
|
+
Handles are typically obtained through the @vpi_handle_by_name@ and @vpi_handle@ functions. These functions are hierarchical in nature, as they allow you to obtain new handles that are related to existing ones. For example, to obtain a handle to a register contained within a module, one would typically write: @your_reg = vpi_handle( VpiReg, your_handle )@
|
516
192
|
|
517
193
|
|
518
|
-
|
194
|
+
<% paragraph "Shortcuts for productivity" do %>
|
195
|
+
Given a handle, Ruby-VPI allows you to access (1) its relatives and (2) its properties simply by invoking methods on the handle. If a handle's relative happens to have the same name as one its properties, then the relative is given priority because a handle's properties can always be accessed explicitly through the @handle.get_value@ and @handle.put_value@ methods.
|
196
|
+
<% end %>
|
519
197
|
|
520
|
-
The <tt>samp</tt> directory contains several sample tests which illustrate how Ruby-VPI can be used. Each sample has an associated <tt>Rakefile</tt> which simplifies the process of running it. Therefore, simply navigate into an example directory and run the <pre>rake</pre> command to get started.
|
521
198
|
|
199
|
+
<% section "Accessing a handle's relatives" do %>
|
200
|
+
Imagine that the design under test, say _foo_, instantiated a Verilog module named _bar_, which in turn contained a register named _baz_. To access baz from Ruby, one could employ VPI idioms by writing:
|
522
201
|
|
523
|
-
|
202
|
+
<code>
|
203
|
+
foo = vpi_handle_by_name( "foo", nil )
|
204
|
+
bar = vpi_handle_by_name( "bar", foo )
|
205
|
+
baz = vpi_handle_by_name( "baz", bar )
|
206
|
+
</code>
|
524
207
|
|
525
|
-
|
208
|
+
or by writing:
|
526
209
|
|
210
|
+
<code>baz = vpi_handle_by_name( "foo.bar.bar", nil )</code>
|
527
211
|
|
528
|
-
|
212
|
+
These idioms seem excessively verbose in a higher level language such as Ruby, so Ruby-VPI allows you to access a handle's relative by simply invoking the relative's name as a method on the handle:
|
529
213
|
|
530
|
-
|
214
|
+
<code>foo.bar.baz</code>
|
215
|
+
<% end %>
|
531
216
|
|
532
|
-
* Runner
|
533
|
-
- written in "Rake":#glossary.rake, this file builds and runs the test.
|
534
|
-
* Bench
|
535
|
-
- written in Verilog and Ruby, these files define the testing environment.
|
536
|
-
* Design
|
537
|
-
- written in Ruby, this file provides an interface to the design being verified.
|
538
|
-
* Prototype
|
539
|
-
- written in Ruby, this file defines a prototype of the design being verified.
|
540
|
-
* Specification
|
541
|
-
- written in Ruby, this file describes the expected behavior of the design.
|
542
217
|
|
543
|
-
|
218
|
+
<% section "Accessing a handle's properties" do %>
|
219
|
+
Imagine that the design under test, say _foo_, contained a register named _bar_. To access the integer value of _bar_ in Ruby-VPI, one could employ VPI idioms by writing:
|
544
220
|
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
</code>
|
551
|
-
# Make the file executable by running the <pre>chmod +x merge2</pre> command.
|
552
|
-
# Place the file somewhere accessible by your @PATH@ environment variable.
|
553
|
-
# Assign the value "merge2" to the @MERGER@ environment variable using your shell's *export* or *setenv* command.
|
221
|
+
<code>
|
222
|
+
wrapper = S_vpi_value.new
|
223
|
+
wrapper.format = VpiIntVal
|
224
|
+
vpi_get_value( foo.bar, wrapper )
|
225
|
+
result = wrapper.value.integer
|
226
|
+
</code>
|
554
227
|
|
555
|
-
|
556
|
-
<% end %>
|
228
|
+
or, if _bar_ is capable of storing more than 32 bits, one would convert a string representation of bar's integer value into a limitless Ruby integer by writing:
|
557
229
|
|
230
|
+
<code>
|
231
|
+
wrapper = S_vpi_value.new
|
232
|
+
wrapper.format = VpiHexStrVal
|
233
|
+
vpi_get_value( foo.bar, wrapper )
|
234
|
+
result = wrapper.value.str.to_i( 16 )
|
235
|
+
</code>
|
558
236
|
|
559
|
-
|
237
|
+
These idioms seem excessively verbose in a higher level language such as Ruby, so Ruby-VPI allows you to access a handle's properties by simply invoking property names, using the special naming format shown in <%= xref "fig:method naming format" %>, as methods on the handle:
|
560
238
|
|
561
|
-
|
239
|
+
<code>result = foo.bar.intVal</code>
|
240
|
+
<% end %>
|
562
241
|
|
563
|
-
|
242
|
+
<% figure "Method naming format for accessing a handle's properties", "fig:method naming format" do %>
|
243
|
+
|_. Operation |_. _ |_. Property |_. _ |_. Accessor |_. Addendum |
|
244
|
+
|\2. optional | required |\3. optional |
|
564
245
|
|
246
|
+
* *Operation* suggests a method that should be invoked in the context of the *Property* parameter. All methods in "Ruby's @Enumerable@ module":http://www.ruby-doc.org/core/classes/Enumerable.html are valid operations.
|
565
247
|
|
566
|
-
|
248
|
+
* *Property* suggests a VPI property that should be accessed. The "vpi" prefix, which is common to all VPI properties, can be omitted if you wish. For example, the VPI property "vpiFullName" is considered equivalent to "fullName" and "FullName", but not equivalent to "full_name".
|
567
249
|
|
568
|
-
|
569
|
-
# "Generate a test":#usage.tutorial.generate-test for the design using the "automated test generator":#usage.tools.generate-test tool.
|
570
|
-
# "Identify your expectations":#usage.tutorial.specification for the design and implement them in the specification.
|
571
|
-
# (Optional) "Implement the prototype":#usage.tutorial.implement-proto of the design in Ruby.
|
572
|
-
# (Optional) "Verify the prototype":#usage.tutorial.test-proto against the specification.
|
573
|
-
# "Implement the design":#usage.tutorial.implement-design in Verilog once the prototype has been verified.
|
574
|
-
# "Verify the design":#usage.tutorial.test-design against the specification.
|
250
|
+
* *Accessor* suggests a VPI function that should be used in order to access the VPI property. When this parameter is not specified, Ruby-VPI will attempt to _guess_ the value of this parameter.
|
575
251
|
|
252
|
+
<%= xref "tbl:accessors" %> shows a list of valid accessors and how they influence the means by which a property is accessed.
|
576
253
|
|
577
|
-
|
254
|
+
* When *Addendum* is an equal sign (=), it suggests that the specified VPI property should be written to.
|
578
255
|
|
579
|
-
|
256
|
+
When it is a question mark (?), it suggests that the specified VPI property should be accessed as a boolean value. This suggestion is the same as specifying "b" as the *Accessor*.
|
257
|
+
<% end %>
|
580
258
|
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
259
|
+
<% table "Possible accessors and their implications", "tbl:accessors" do %>
|
260
|
+
|_. Accessor |_. Kind of value accessed |_. VPI functions used to access the value |
|
261
|
+
| d | delay | @vpi_get_delays@, @vpi_put_delays@ |
|
262
|
+
| l | logic | @vpi_get_value@, @vpi_put_value@ |
|
263
|
+
| i | integer | @vpi_get@ |
|
264
|
+
| b | boolean | @vpi_get@ |
|
265
|
+
| s | string | @vpi_get_str@ |
|
266
|
+
| h | handle | @vpi_handle@ |
|
267
|
+
| a | array | @vpi_iterate@ |
|
268
|
+
<% end %>
|
585
269
|
|
586
|
-
<%
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
270
|
+
<% table "Examples of accessing a handle's properties", "ex:properties" do %>
|
271
|
+
|_/2. Ruby expression |_\6. Method naming format |_/2. Description |
|
272
|
+
||_. Operation |_. _ |_. Property |_. _ |_. Accessor |_. Addendum ||
|
273
|
+
| @handle.vpiIntVal@ | | | vpiIntVal | | | |/4. Obtain the _logic value_ of the handle's @VpiIntVal@ property. |
|
274
|
+
| @handle.vpiIntVal_l@ | | | vpiIntVal | _ | l | |
|
275
|
+
| @handle.intVal@ | | | intVal | | | |
|
276
|
+
| @handle.intVal_l@ | | | intVal | _ | l | |
|
277
|
+
| @handle.vpiIntVal = 15@ | | | vpiIntVal | | | = |/4. Assign the integer 15 to the _logic value_ of the handle's @VpiIntVal@ property. |
|
278
|
+
| @handle.vpiIntVal_l = 15@ | | | vpiIntVal | _ | l | = |
|
279
|
+
| @handle.intVal = 15@ | | | intVal | | | = |
|
280
|
+
| @handle.intVal_l = 15@ | | | intVal | _ | l | = |
|
281
|
+
| @handle.vpiType@ | | | vpiType | | | |/4. Obtain the _integer value_ of the handle's @VpiType@ property. |
|
282
|
+
| @handle.vpiType_i@ | | | vpiType | _ | i | |
|
283
|
+
| @handle.type@ | | | type | | | |
|
284
|
+
| @handle.type_i@ | | | type | _ | i | |
|
285
|
+
| @handle.vpiProtected@ | | | vpiProtected | | | |/6. Obtain the _boolean value_ of the handle's @VpiProtected@ property. |
|
286
|
+
| @handle.vpiProtected_b@ | | | vpiProtected | _ | b | |
|
287
|
+
| @handle.vpiProtected?@ | | | vpiProtected | | | ? |
|
288
|
+
| @handle.protected@ | | | protected | | | |
|
289
|
+
| @handle.protected_b@ | | | protected | _ | b | |
|
290
|
+
| @handle.protected?@ | | | protected | | | ? |
|
291
|
+
| @handle.vpiFullName@ | | | vpiFullName | | | |/4. Obtain the _string value_ of the handle's @VpiFullName@ property. |
|
292
|
+
| @handle.vpiFullName_s@ | | | vpiFullName | _ | s | |
|
293
|
+
| @handle.fullName@ | | | fullName | | | |
|
294
|
+
| @handle.fullName_s@ | | | fullName | _ | s | |
|
295
|
+
| @handle.vpiParent@ | | | vpiParent | | | |/4. Obtain the _handle value_ of the handle's @VpiParent@ property. |
|
296
|
+
| @handle.vpiParent_h@ | | | vpiParent | _ | h | |
|
297
|
+
| @handle.parent@ | | | parent | | | |
|
298
|
+
| @handle.parent_h@ | | | parent | _ | h | |
|
299
|
+
| <code>handle.each_vpiNet {|net| puts net.fullName}</code> | each | _ | vpiNet | | | |/2. Use the @each@ operation to print the full name of each @VpiNet@ object associated with the handle. |
|
300
|
+
| <code>handle.each_net {|net| puts net.fullName}</code> | each | _ | net | | | |
|
301
|
+
| <code>handle.all_vpiReg? {|reg| reg.size == 1}</code> | all? | _ | vpiReg | | | |/2. Use the @all?@ operation to check whether all @VpiReg@ objects associated with the handle are capable of storing only one bit of information. |
|
302
|
+
| <code>handle.all_reg? {|reg| reg.size == 1}</code> | all? | _ | reg | | | |
|
303
|
+
| <code>handle.select_vpiNet {|net| net.x?}</code> | select | _ | VpiNet | | | |/2. Use the @select@ operation to obtain a list of @VpiNet@ objects whose _logic value_ is unknown (x).|
|
304
|
+
| <code>handle.select_net {|net| net.x?}</code> | select | _ | net | | | |
|
305
|
+
<% end %>
|
306
|
+
<% end %>
|
596
307
|
|
597
|
-
<%
|
598
|
-
|
599
|
-
|
308
|
+
<% section "Callbacks", "vpi.callbacks" do %>
|
309
|
+
A _callback_ is a mechanism that makes the Verilog simuluator execute a block of code, which is known as a "callback handler", when some prescribed event occurs in the simulation.
|
310
|
+
|
311
|
+
Callbacks are added using the @vpi_register_cb@ function and removed using the @vpi_remove_cb@ function. However, instead of storing the address of a C function in the @cb_rtn@ field of the @s_cb_data@ structure (as you would do in C) you pass a block of code to the @vpi_register_cb@ method in Ruby. This block will be executed whenever the callback occurs.
|
312
|
+
|
313
|
+
<% example "Using a callback for value change notification", "ex:callback" do %>
|
314
|
+
This example shows how to use a callback for notification of changes in a handle's @VpiIntVal@ property. When you no longer need this callback, you can tear it down using @vpi_remove_cb(cb_handle)@.
|
315
|
+
|
316
|
+
In this example, the handle being monitored is the @Counter.count@ signal from <%= xref "fig:counter.v_decl" %>.
|
317
|
+
|
318
|
+
<code>
|
319
|
+
cbTime = S_vpi_time.new
|
320
|
+
cbTime.type = VpiSimTime
|
321
|
+
cbTime.low = 0
|
322
|
+
cbTime.high = 0
|
323
|
+
|
324
|
+
cbValue = S_vpi_value.new
|
325
|
+
cbValue.format = VpiIntVal
|
326
|
+
|
327
|
+
cbData = S_cb_data.new
|
328
|
+
cbData.reason = CbValueChange
|
329
|
+
cbData.obj = Counter.count
|
330
|
+
cbData.time = cbTime
|
331
|
+
cbData.value = cbValue
|
332
|
+
cbData.index = 0
|
333
|
+
|
334
|
+
cbHandle = vpi_register_cb(cbData) do |data|
|
335
|
+
time = (data.time.high << 32) | data.time.low
|
336
|
+
count = data.value.value.integer
|
337
|
+
puts "hello from callback! time=#{time} count=#{count}"
|
338
|
+
end
|
339
|
+
</code>
|
340
|
+
|
341
|
+
Append this code to the <tt>RSpec/counter_spec.rb</tt> file (provided in <%= xref "usage.examples" %> and discussed in <%= xref "usage.tutorial.specification" %>) and run the <%= xref "usage.tutorial", "counter_RSpec test" %>
|
342
|
+
<% end %>
|
343
|
+
<% end %>
|
344
|
+
<% end %>
|
345
|
+
<% end %>
|
346
|
+
|
347
|
+
<% chapter "Usage", "usage" do %>
|
348
|
+
<% section "Prototyping", "usage.prototyping" do %>
|
349
|
+
Ruby-VPI enables you to rapidly prototype your designs in Ruby without having to do full-scale implementations in Verilog. This lets you explore and evaluate different design choices quickly.
|
350
|
+
|
351
|
+
The prototyping process is completely transparent: there is absolutely no difference, in the eyes of your executable specification, between a real Verilog design or its Ruby prototype.
|
352
|
+
|
353
|
+
In addition, the prototyping process is completely standard-based: Ruby prototypes emulate the behavior of real Verilog designs using _nothing more_ than the VPI itself.
|
354
|
+
|
355
|
+
For example, compare the Verilog design shown in <%= xref "fig:counter.v_impl" %> with its Ruby prototype shown in figure <%= xref "fig:counter_proto.rb" %>. The prototype uses only VPI to (1) detect changes in its inputs and (2) manipulate its outputs accordingly. In addition, notice how well the prototype's syntax reflects the intended behavior of the Verilog design. This similarity facilitates rapid translation of a prototype from Ruby into Verilog later in the design process.
|
356
|
+
|
357
|
+
<% paragraph "Getting started" do %>
|
358
|
+
To create a prototype,
|
359
|
+
# Start with a <%= xref "usage.tutorial.declare-design", "Verilog module declaration" %> for your design.
|
360
|
+
# <%= xref "usage.tutorial.generate-test", "Generate a test" %> using that module declaration.
|
361
|
+
# <%= xref "usage.tutorial.implement-proto", "Implement the prototype" %> in the generated <tt>proto.rb</tt> file.
|
362
|
+
# <%= xref "usage.tutorial.test-proto", "Verify the prototype" %> against its specification.
|
363
|
+
|
364
|
+
Once you are satisfied with your prototype, you can proceed to <%= xref "usage.tutorial.implement-design", "implement your design in Verilog" %>. This process is often a simple translation your Ruby prototype into your Verilog. At the very least, your prototype serves as a reference while you are implementing your Verilog design.
|
365
|
+
|
366
|
+
Once your design has been implemented in Verilog, you can use the _same_ specification, which was originally used to verify your prototype, to verify your Verilog design (see <%= xref "usage.test-runner" %> for details).
|
367
|
+
<% end %>
|
368
|
+
|
369
|
+
<% section "How does prototyping work?" do %>
|
370
|
+
The @advance_time@ method normally transfers control from the executable specification to the Verilog simulator. However, when prototyping is enabled, Ruby-VPI redefines it so that the @feign!@ method (which is defined in a test's <tt>proto.rb</tt> file) is invoked on the design under test. The @feign!@ method artificially simulates the behavior of the real Verilog design.
|
371
|
+
|
372
|
+
In this manner, control is kept within the Ruby interpreter when prototyping is enabled. An advantage of this approach is that it reduces the total execution time of a Ruby-VPI test by allowing Ruby's POSIX thread to commandeer the Verilog simulator's process. A disadvantage of this approach is that callbacks, which require the transfer of control to the Verilog simulator, must be ignored.
|
373
|
+
<% end %>
|
374
|
+
<% end %>
|
375
|
+
|
376
|
+
<% section "Debugging", "usage.debugger" do %>
|
377
|
+
The "ruby-debug project":http://www.datanoise.com/articles/category/ruby-debug serves as the interactive debugger for Ruby-VPI.
|
378
|
+
|
379
|
+
# Enable the debugger by activating the @DEBUGGER@ environment variable (see <%= xref "usage.test-runner" %> for details).
|
380
|
+
# Put the @debugger@ command in your code -- anywhere you wish to activate an interactive debugging session. These commands are automatically ignored when the debugger is disabled; so you can safely leave them in your code, if you wish.
|
381
|
+
|
382
|
+
<% section "Advanced initialization", "usage.debugger.init" do %>
|
383
|
+
By default, Ruby-VPI enables the debugger by invoking the @Debugger.start@ method. If you wish to perform more advanced initialization, such as having the debugger accept remote network connections for interfacing with a remote debugging session or perhaps with an IDE (see "the ruby-debug documentation":http://www.datanoise.com/articles/category/ruby-debug for details), then:
|
384
|
+
|
385
|
+
# Deactivate the @DEBUG@ environment variable.
|
386
|
+
# Put your own code, which initializes the debugger, at the top of your test's <tt>spec.rb</tt> file.
|
387
|
+
<% end %>
|
388
|
+
<% end %>
|
389
|
+
|
390
|
+
<% section "Test runner", "usage.test-runner" do %>
|
391
|
+
A test runner is a file, generated by the <%= xref "usage.tools.generate", "automated test generator" %> whose name ends with <tt>.rake</tt>. It helps you run generated tests -- you can think of it as a _makefile_ if you are familiar with C programming in a UNIX environment.
|
392
|
+
|
393
|
+
When you invoke a test runner without any arguments, it will show you a list of available tasks:
|
394
|
+
<pre>$ rake -f your_test_runner.rake
|
600
395
|
|
396
|
+
<%= `rake -f ../samp/counter/RSpec/counter_runner.rake` %></pre>
|
601
397
|
|
602
|
-
|
398
|
+
<% section "Environment variables", "usage.test-runner.env-vars" do %>
|
399
|
+
Test runners support the following _environment_ variables, which allow you to easily change the behavior of the test runner.
|
603
400
|
|
604
|
-
|
401
|
+
* @COVERAGE@ enables code coverage analysis and generation of code coverage reports.
|
402
|
+
* @DEBUGGER@ enables the <%= xref "usage.debugger", "interactive debugger" %> in its "post-mortem debugging mode":http://www.datanoise.com/articles/2006/12/20/post-mortem-debugging.
|
403
|
+
* @PROTOTYPE@ enables the Ruby prototype for the design under test so that the prototype, rather than the real Verilog design, is verified by the specification.
|
605
404
|
|
606
|
-
|
607
|
-
* rSpec represents "BDD":#glossary.BDD
|
608
|
-
* xUnit represents "TDD":#glossary.TDD
|
609
|
-
* our own format can represent another methodology
|
405
|
+
To activate these variables, simply assign the number 1 to them. For example, @DEBUG=1@ activates the @DEBUG@ variable.
|
610
406
|
|
611
|
-
|
612
|
-
Both rSpec and xUnit formats are presented in this tutorial.
|
613
|
-
<% end %>
|
407
|
+
To deactivate these variables, simply assign a different value to them or *unset* them in your shell. For example, both @DEBUG=0@ and @DEBUG=@ dectivate the @DEBUG@ variable.
|
614
408
|
|
615
|
-
|
409
|
+
<% paragraph "Variables as command-line arguments" do %>
|
410
|
+
You can specify variable assignments as arguments to the *rake* command. For example, <pre>rake DEBUG=1</pre> is equivalent to
|
411
|
+
<pre>
|
412
|
+
DEBUG=1
|
413
|
+
export DEBUG
|
414
|
+
rake
|
415
|
+
</pre> in Bourne shell or
|
416
|
+
<pre>
|
417
|
+
setenv DEBUG 1
|
418
|
+
rake
|
419
|
+
</pre> in C shell.
|
420
|
+
<% end %>
|
616
421
|
|
617
|
-
<% example "Generating a test with specification in rSpec format", "#fig..generate-test.rspec" do %>
|
618
|
-
<pre>
|
619
|
-
$ generate_test.rb counter.v --rspec --name rspec
|
620
422
|
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
create counter_rspec_bench.rb
|
625
|
-
create counter_rspec_design.rb
|
626
|
-
create counter_rspec_proto.rb
|
627
|
-
create counter_rspec_spec.rb
|
628
|
-
</pre>
|
629
|
-
<% end %>
|
423
|
+
<% example "Running a test with environment variables" do %>
|
424
|
+
Below, we enable the prototype and code coverage analysis:
|
425
|
+
<pre>rake -f your_test_runner.rake PROTOTYPE=1 COVERAGE=1</pre>
|
630
426
|
|
631
|
-
|
632
|
-
<pre>
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
create counter_xunit_bench.rb
|
639
|
-
create counter_xunit_design.rb
|
640
|
-
create counter_xunit_proto.rb
|
641
|
-
create counter_xunit_spec.rb
|
642
|
-
</pre>
|
643
|
-
<% end %>
|
427
|
+
Below, we _disable_ the prototype and enable the code coverage analysis. These invocations are equivalent if the @PROTOTYPE@ environment variable is unset.
|
428
|
+
<pre>rake -f your_test_runner.rake PROTOTYPE=0 COVERAGE=1</pre>
|
429
|
+
<pre>rake -f your_test_runner.rake PROTOTYPE= COVERAGE=1</pre>
|
430
|
+
<pre>rake -f your_test_runner.rake COVERAGE=1</pre>
|
431
|
+
<% end %>
|
432
|
+
<% end %>
|
433
|
+
<% end %>
|
644
434
|
|
435
|
+
<% section "Tools", "usage.tools" do %>
|
436
|
+
The *ruby-vpi* command serves as a front-end to the tools provided by Ruby-VPI. You can see its help information (reproduced below) by simply running the command without any arguments.
|
645
437
|
|
646
|
-
|
438
|
+
<pre><%= `ruby ../bin/ruby-vpi` %></pre>
|
647
439
|
|
648
|
-
|
440
|
+
<% section "Automated test generation", "usage.tools.generate" do %>
|
441
|
+
The *generate* tool generates scaffolding for Ruby-VPI tests from Verilog module declarations (written in either Verilog 2001 or Verilog 95 style).
|
649
442
|
|
650
|
-
|
651
|
-
*
|
652
|
-
*
|
653
|
-
*
|
443
|
+
A Ruby-VPI test is composed of the following files:
|
444
|
+
* <tt>runner.rake</tt> runs the test by starting a Verilog simulator and loading Ruby-VPI into it.
|
445
|
+
* <tt>spec.rb</tt> is the executable specification for the design under test.
|
446
|
+
* <tt>design.rb</tt> is an optional file that provides convenience methods for controlling the design under test.
|
447
|
+
* <tt>proto.rb</tt> is an optional file that defines a Ruby prototype of the design under test.
|
448
|
+
* <tt>Rakefile</tt> is an optional file that recursively executes all <tt>runner.rake</tt> files found immediately within or beneath the current directory. It lets you simply run <pre>rake ...</pre> instead of having to write <pre>rake -f runner.rake ...</pre> every time.
|
654
449
|
|
655
|
-
|
450
|
+
As <%= xref "fig:generate-test.RSpec" %> shows, the name of each generated file is prefixed with the name of the Verilog module for which the test was generated. This convention helps organize tests within the file system, so that they are readily distinguishable from one another.
|
656
451
|
|
657
|
-
<%
|
658
|
-
|
659
|
-
<% end %>
|
452
|
+
<% caution "Do not rename generated files" do %>
|
453
|
+
Ruby-VPI uses the convention described above to dynamically create a direct Ruby interface to the design under test, so _do not_ rename the generated files arbitrarily.
|
454
|
+
<% end %>
|
455
|
+
|
456
|
+
By producing multiple files, the automated test generator physically decouples the various parts of a test. As a result, when the interface of a Verilog module changes, you can simply regenerate the test to incorporate those changes without diverting your focus from the task at hand. Furthermore, the incorporation of changes can be catalyzed by interactive text merging tools, which allow you to selectively accept or reject the merging of changes into your source code. Fully automated text merging tools may also be used for this purpose.
|
457
|
+
|
458
|
+
You can try this tool by running the <pre>ruby-vpi generate --help</pre> command.
|
459
|
+
|
460
|
+
<% tip "Using *kdiff3* with the automated test generator." do %>
|
461
|
+
# Create a file named <tt>merge2</tt> with the following content: <code>
|
462
|
+
#!/bin/sh
|
463
|
+
# args: old file, new file
|
464
|
+
kdiff3 --auto --output "$2" "$@"
|
465
|
+
</code>
|
466
|
+
# Make the file executable by running the <pre>chmod +x merge2</pre> command.
|
467
|
+
# Place the file somewhere accessible by your @PATH@ environment variable.
|
468
|
+
# Assign the value "merge2" to the @MERGER@ environment variable using your shell's *export* or *setenv* command.
|
469
|
+
|
470
|
+
From now on, *kdiff3* will be invoked to help you transfer your changes between generated files. When you are finished transferring changes, simply issue the "save the file" command and quit *kdiff3*. Or, if you do not want to transfer any changes, simply quit *kdiff3* _without_ saving the file.
|
471
|
+
<% end %>
|
472
|
+
<% end %>
|
473
|
+
|
474
|
+
<% section "Verilog to Ruby conversion", "usage.tools.convert" do %>
|
475
|
+
The *convert* tool can be used to convert Verilog header files into Ruby. You can try it by running the <pre>ruby-vpi convert --help</pre> command.
|
476
|
+
|
477
|
+
By converting Verilog header files into Ruby, your test can utilize the same @`define@ constants that are used in the Verilog design.
|
478
|
+
<% end %>
|
479
|
+
<% end %>
|
480
|
+
|
481
|
+
<% section "Sample tests", "usage.examples" do %>
|
482
|
+
The <tt>samp</tt> directory contains several sample tests which illustrate how Ruby-VPI can be used. Each sample has an associated <tt>Rakefile</tt> which simplifies the process of running it. Therefore, simply navigate into an example directory and run the <pre>rake</pre> command to get started.
|
483
|
+
<% end %>
|
484
|
+
|
485
|
+
<% section "Tutorial", "usage.tutorial" do %>
|
486
|
+
# <%= xref "usage.tutorial.declare-design", "Declare a design" %> using Verilog 2001 syntax.
|
487
|
+
# <%= xref "usage.tutorial.generate-test", "Generate a test" %> for the design using the <%= xref "usage.tools.generate", "automated test generator" %> tool.
|
488
|
+
# <%= xref "usage.tutorial.specification", "Identify your expectations" %> for the design and implement them in the specification.
|
489
|
+
# (Optional) <%= xref "usage.tutorial.implement-proto", "Implement the prototype" %> of the design in Ruby.
|
490
|
+
# (Optional) <%= xref "usage.tutorial.test-proto", "Verify the prototype" %> against the specification.
|
491
|
+
# <%= xref "usage.tutorial.implement-design", "Implement the design" %> in Verilog once the prototype has been verified.
|
492
|
+
# <%= xref "usage.tutorial.test-design", "Verify the design" %> against the specification.
|
493
|
+
|
494
|
+
|
495
|
+
<% section "Start with a Verilog design", "usage.tutorial.declare-design" do %>
|
496
|
+
First, we need a Verilog design to test. In this tutorial, <%= xref "fig:counter.v_decl" %> will serve as our design under test. Its interface is composed of the following parts:
|
497
|
+
|
498
|
+
* @Size@ defines the number of bits used to represent the counter's value.
|
499
|
+
* @clock@ causes the @count@ register to increment whenever it reaches a positive edge.
|
500
|
+
* @reset@ causes the @count@ register to become zero when asserted.
|
501
|
+
* @count@ is a register that contains the counter's value.
|
502
|
+
|
503
|
+
<% example "Declaration of a simple up-counter with synchronous reset", "fig:counter.v_decl" do %>
|
504
|
+
<code lang="verilog">
|
505
|
+
module counter #(parameter Size = 5) (
|
506
|
+
input clock,
|
507
|
+
input reset,
|
508
|
+
output reg [Size-1 : 0] count
|
509
|
+
);
|
510
|
+
endmodule
|
511
|
+
</code>
|
512
|
+
<% end %>
|
513
|
+
|
514
|
+
Before we continue, save the source code shown in <%= xref "fig:counter.v_decl" %> into a file named <tt>counter.v</tt>.
|
515
|
+
<% end %>
|
516
|
+
|
517
|
+
|
518
|
+
<% section "Generate a test", "usage.tutorial.generate-test" do %>
|
519
|
+
Now that we have a Verilog design to test, we shall use the <%= xref "usage.tools.generate", "generate" %> tool to generate some scaffolding for our test. This tool allows us to implement our specification using RSpec, xUnit, or any other format.
|
660
520
|
|
661
|
-
|
662
|
-
|
663
|
-
|
521
|
+
Each format represents a different software development methodology:
|
522
|
+
* RSpec represents <%= xref "glossary.BDD", "BDD" %>
|
523
|
+
* xUnit represents <%= xref "glossary.TDD", "TDD" %>
|
524
|
+
* our own format can represent another methodology
|
525
|
+
|
526
|
+
In this tutorial, you will see how both RSpec and xUnit formats are used. So let us make separate directories for both formats to avoid generated tests from overwriting each other:
|
527
|
+
<pre>
|
528
|
+
$ mkdir RSpec xUnit
|
529
|
+
$ cp counter.v RSpec
|
530
|
+
$ cp counter.v xUnit
|
531
|
+
</pre>
|
532
|
+
|
533
|
+
Once we have decided how we want to implement our specification, we can proceed to generate a test for our design. This process is illustrated by <%= xref "fig:generate-test.RSpec" %> and <%= xref "fig:generate-test.xUnit" %>.
|
664
534
|
|
665
|
-
<%
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
535
|
+
<% example "Generating a test with specification in RSpec format", "fig:generate-test.RSpec" do %>
|
536
|
+
<pre>
|
537
|
+
$ ruby-vpi generate counter.v --RSpec
|
538
|
+
|
539
|
+
module counter
|
540
|
+
create counter_runner.rake
|
541
|
+
create counter_design.rb
|
542
|
+
create counter_proto.rb
|
543
|
+
create counter_spec.rb
|
544
|
+
create Rakefile
|
545
|
+
</pre>
|
546
|
+
<% end %>
|
670
547
|
|
548
|
+
<% example "Generating a test with specification in xUnit format", "fig:generate-test.xUnit" do %>
|
549
|
+
<pre>
|
550
|
+
$ ruby-vpi generate counter.v --xUnit
|
671
551
|
|
672
|
-
|
552
|
+
module counter
|
553
|
+
create counter_runner.rake
|
554
|
+
create counter_design.rb
|
555
|
+
create counter_proto.rb
|
556
|
+
create counter_spec.rb
|
557
|
+
create Rakefile
|
558
|
+
</pre>
|
559
|
+
<% end %>
|
560
|
+
<% end %>
|
673
561
|
|
674
|
-
Now that we have a "specification":#glossary.specification against which to verify our "design":#glossary.design, let us build a prototype of our design. By doing so, we exercise our specification, experience potential problems that may arise when we later implement our design in Verilog, and gain confidence in our work. The result of this proceess is illustrated by <xref #fig..counter_proto.rb>.
|
675
562
|
|
676
|
-
<%
|
677
|
-
|
678
|
-
<% end %>
|
563
|
+
<% section "Specify your expectations", "usage.tutorial.specification" do %>
|
564
|
+
So far, the test generation tool has created a basic foundation for our test Now we must build upon this foundation by identifying our <%= xref "glossary.expectation", "expectation" %> of the design under test. That is, how do we expect the design to _behave_ under certain conditions?
|
679
565
|
|
680
|
-
|
681
|
-
|
682
|
-
|
566
|
+
Here are some reasonable expectations for our simple counter:
|
567
|
+
* A resetted counter's value should be zero.
|
568
|
+
* A resetted counter's value should increment by one count upon each rising clock edge.
|
569
|
+
* A counter with the maximum value should overflow upon increment.
|
683
570
|
|
571
|
+
Now that we have identified a set of expectations for our design, we are ready to implement them in our specification. This process is illustrated by <%= xref "fig:RSpec/counter_spec.rb" %> and <%= xref "fig:xUnit/counter_spec.rb" %>.
|
684
572
|
|
685
|
-
|
573
|
+
<% example "Specification implemented in RSpec format", "fig:RSpec/counter_spec.rb" do %>
|
574
|
+
<code><%= File.read '../samp/counter/RSpec/counter_spec.rb' %></code>
|
575
|
+
<% end %>
|
686
576
|
|
687
|
-
|
577
|
+
<% example "Specification implemented in xUnit format", "fig:xUnit/counter_spec.rb" do %>
|
578
|
+
<code><%= File.read '../samp/counter/xUnit/counter_spec.rb' %></code>
|
579
|
+
<% end %>
|
688
580
|
|
689
|
-
|
581
|
+
Before we continue,
|
582
|
+
# Replace the contents of the file named <tt>RSpec/counter_spec.rb</tt> with the source code shown in <%= xref "fig:RSpec/counter_spec.rb" %>.
|
583
|
+
# Replace the contents of the file named <tt>xUnit/counter_spec.rb</tt> with the source code shown in <%= xref "fig:xUnit/counter_spec.rb" %>.
|
584
|
+
# Replace the contents of the files named <tt>RSpec/counter_design.rb</tt> and <tt>xUnit/counter_design.rb</tt> with the following code. <code><%= File.read '../samp/counter/RSpec/counter_design.rb' %></code>
|
585
|
+
<% end %>
|
690
586
|
|
691
|
-
<% example "Running a test with specification in rSpec format", "#fig..test-proto.rspec" do %>
|
692
|
-
<pre>
|
693
|
-
$ rake -f counter_rspec_runner.rake cver PROTOTYPE=1
|
694
587
|
|
695
|
-
|
588
|
+
<% section "Implement the prototype", "usage.tutorial.implement-proto" do %>
|
589
|
+
Now that we have a specification against which to verify our design let us build a prototype of our design. By doing so, we exercise our specification, experience potential problems that may arise when we later implement our design in Verilog, and gain confidence in our work. The result of this proceess is illustrated by <%= xref "fig:counter_proto.rb" %>.
|
696
590
|
|
697
|
-
|
698
|
-
|
699
|
-
|
591
|
+
<% example "Ruby prototype of our Verilog design", "fig:counter_proto.rb" do %>
|
592
|
+
<code><%= File.read '../samp/counter/RSpec/counter_proto.rb' %></code>
|
593
|
+
<% end %>
|
700
594
|
|
701
|
-
|
702
|
-
|
595
|
+
Before we continue, replace the contents of the files named <tt>RSpec/counter_proto.rb</tt> and <tt>xUnit/counter_proto.rb</tt> with the source code shown in <%= xref "fig:counter_proto.rb" %>.
|
596
|
+
<% end %>
|
703
597
|
|
704
|
-
Finished in 0.018199 seconds
|
705
598
|
|
706
|
-
|
707
|
-
|
708
|
-
<% end %>
|
599
|
+
<% section "Verify the prototype", "usage.tutorial.test-proto" do %>
|
600
|
+
Now that we have implemented our prototype, we are ready to verify it against our specification by running the test This process is illustrated by <%= xref "fig:test-proto.RSpec" %> and <%= xref "fig:test-proto.unit-test" %>.
|
709
601
|
|
710
|
-
|
711
|
-
<pre>
|
712
|
-
$ rake -f counter_xunit_runner.rake cver PROTOTYPE=1
|
602
|
+
In these examples, the @PROTOTYPE@ environment variable is assigned the value 1 while running the test so that, instead of our design, our prototype is verified against our specification (see <%= xref "usage.test-runner.env-vars" %> for details). Also, the <%= xref "setup.reqs", "GPL Cver simulator" %> denoted by _cver_, is used to run the simulation.
|
713
603
|
|
714
|
-
|
604
|
+
<% example "Running a test with specification in RSpec format", "fig:test-proto.RSpec" do %>
|
605
|
+
<pre>
|
606
|
+
$ cd RSpec
|
607
|
+
$ rake cver PROTOTYPE=1
|
715
608
|
|
716
|
-
|
717
|
-
|
718
|
-
...
|
719
|
-
Finished in 0.040668 seconds.
|
609
|
+
Ruby-VPI: prototype is enabled
|
610
|
+
...
|
720
611
|
|
721
|
-
|
722
|
-
</pre>
|
723
|
-
<% end %>
|
612
|
+
Finished in 0.05106 seconds
|
724
613
|
|
725
|
-
|
726
|
-
|
727
|
-
|
614
|
+
3 examples, 0 failures
|
615
|
+
cd -
|
616
|
+
</pre>
|
617
|
+
<% end %>
|
728
618
|
|
619
|
+
<% example "Running a test with specification in xUnit format", "fig:test-proto.unit-test" do %>
|
620
|
+
<pre>
|
621
|
+
$ cd xUnit
|
622
|
+
$ rake cver PROTOTYPE=1
|
729
623
|
|
730
|
-
|
624
|
+
Ruby-VPI: prototype is enabled
|
625
|
+
Loaded suite counter
|
626
|
+
Started
|
627
|
+
...
|
628
|
+
Finished in 0.043859 seconds.
|
731
629
|
|
732
|
-
|
630
|
+
3 tests, 35 assertions, 0 failures, 0 errors
|
631
|
+
</pre>
|
632
|
+
<% end %>
|
733
633
|
|
634
|
+
<% tip "What can the test runner do?" do %>
|
635
|
+
If you invoke the test runner (1) without any arguments or (2) with the <tt>--tasks</tt> option, it will show you a list of tasks that it can perform for you.
|
636
|
+
<% end %>
|
637
|
+
<% end %>
|
734
638
|
|
735
|
-
<% example "Implementation of a simple up-counter with synchronous reset", "#fig..counter.v_impl" do %>
|
736
|
-
<code lang="verilog"><%= File.read '../samp/counter/counter.v' %></code>
|
737
|
-
<% end %>
|
738
639
|
|
739
|
-
<%
|
740
|
-
|
741
|
-
<% end %>
|
640
|
+
<% section "Implement the design", "usage.tutorial.implement-design" do %>
|
641
|
+
Now that we have implemented and verified our prototype, we are ready to implement our design This is often quite simple because we translate _existing_ code from Ruby (our prototype) into Verilog (our design). The result of this process is illustrated by <%= xref "fig:counter.v_impl" %>.
|
742
642
|
|
643
|
+
<% example "Implementation of a simple up-counter with synchronous reset", "fig:counter.v_impl" do %>
|
644
|
+
<code lang="verilog"><%= File.read '../samp/counter/counter.v' %></code>
|
645
|
+
<% end %>
|
743
646
|
|
744
|
-
|
647
|
+
Before we continue, replace the contents of the files named <tt>RSpec/counter.v</tt> and <tt>xUnit/counter.v</tt> with the source code shown in <%= xref "fig:counter.v_impl" %>
|
648
|
+
<% end %>
|
745
649
|
|
746
|
-
Now that we have implemented our "design":#glossary.design, we are ready to verify it against our "specification":#glossary.specification by running the "test":#glossary.test. <xref #fig..test-design.rspec> and <xref #fig..test-design.unit-test> illustrate this process.
|
747
650
|
|
748
|
-
|
651
|
+
<% section "Verify the design", "usage.tutorial.test-design" do %>
|
652
|
+
Now that we have implemented our design we are ready to verify it against our specification by running the test <%= xref "fig:test-design.RSpec" %> and <%= xref "fig:test-design.unit-test" %> illustrate this process.
|
749
653
|
|
750
|
-
|
751
|
-
<pre>
|
752
|
-
$ rake -f counter_rspec_runner.rake cver
|
654
|
+
In these examples, the @PROTOTYPE@ environment variable is _not_ specified while running the test, so that our design, instead of our prototype, is verified against our specification. You can also achieve this effect by assigning an empty value to @PROTOTYPE@, or by using your shell's *unset* command. Finally, the <%= xref "setup.reqs", "GPL Cver simulator" %> denoted by _cver_, is used to run the simulation.
|
753
655
|
|
754
|
-
|
755
|
-
|
756
|
-
|
656
|
+
<% example "Running a test with specification in RSpec format", "fig:test-design.RSpec" do %>
|
657
|
+
<pre>
|
658
|
+
$ cd RSpec
|
659
|
+
$ rake cver
|
757
660
|
|
758
|
-
|
759
|
-
- should overflow upon increment
|
661
|
+
...
|
760
662
|
|
761
|
-
Finished in 0.
|
663
|
+
Finished in 0.041198 seconds
|
762
664
|
|
763
|
-
3
|
764
|
-
</pre>
|
765
|
-
<% end %>
|
665
|
+
3 examples, 0 failures
|
666
|
+
</pre>
|
667
|
+
<% end %>
|
766
668
|
|
767
|
-
<% example "Running a test with specification in xUnit format", "
|
768
|
-
<pre>
|
769
|
-
$
|
669
|
+
<% example "Running a test with specification in xUnit format", "fig:test-design.unit-test" do %>
|
670
|
+
<pre>
|
671
|
+
$ cd xUnit
|
672
|
+
$ rake cver
|
770
673
|
|
771
|
-
Loaded suite
|
772
|
-
Started
|
773
|
-
...
|
774
|
-
Finished in 0.
|
674
|
+
Loaded suite counter
|
675
|
+
Started
|
676
|
+
...
|
677
|
+
Finished in 0.040262 seconds.
|
775
678
|
|
776
|
-
3 tests, 35 assertions, 0 failures, 0 errors
|
777
|
-
</pre>
|
679
|
+
3 tests, 35 assertions, 0 failures, 0 errors
|
680
|
+
</pre>
|
681
|
+
<% end %>
|
682
|
+
<% end %>
|
683
|
+
<% end %>
|
778
684
|
<% end %>
|
779
685
|
|
686
|
+
<% chapter "Hacking", "hacking" do %>
|
687
|
+
<% section "Getting the source code", "hacking.scm" do %>
|
688
|
+
Check out the source code using "Darcs":http://darcs.net from the project repository:
|
780
689
|
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
h2(#hacking.scm). Getting the source code
|
785
|
-
|
786
|
-
Check out the source code using "Darcs":http://darcs.net from the project repository:
|
787
|
-
|
788
|
-
darcs get http://ruby-vpi.rubyforge.org/src/ruby-vpi
|
789
|
-
|
790
|
-
h2(#hacking.release-packages). Building release packages
|
690
|
+
darcs get http://ruby-vpi.rubyforge.org/src/ruby-vpi
|
691
|
+
<% end %>
|
791
692
|
|
792
|
-
In addition to the "normal requirements":#setup.reqs, you need the following software to build release packages:
|
793
693
|
|
794
|
-
|
795
|
-
|
796
|
-
* "CodeRay":http://rubyforge.org/projects/coderay/
|
694
|
+
<% section "Building release packages", "hacking.release-packages" do %>
|
695
|
+
In addition to the <%= xref "setup.reqs", "normal requirements" %> you need the following software to build release packages:
|
797
696
|
|
798
|
-
|
697
|
+
* "SWIG":http://www.swig.org/
|
698
|
+
* "RedCloth":http://rubyforge.org/projects/redcloth/
|
699
|
+
* "CodeRay":http://rubyforge.org/projects/coderay/
|
799
700
|
|
701
|
+
Once you have satisfied these requirements, you can run <pre>rake release</pre> to build the release packages. Also, see the output of <pre>rake -T</pre> for more build options.
|
702
|
+
<% end %>
|
800
703
|
|
801
|
-
h1(#problems). Known problems
|
802
704
|
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
h2(#problems.ruby). Ruby
|
807
|
-
|
808
|
-
|
809
|
-
h3(#problems.ruby.SystemStackError). SystemStackError
|
810
|
-
|
811
|
-
<% note "Fixed in 2.0.0." do %>
|
812
|
-
This problem was fixed in release 2.0.0 (2006-04-17).
|
705
|
+
<% section "Editing this manual", "hacking.manual" do %>
|
706
|
+
The "doc" files inside the <tt>doc/</tt> directory are really _plain text_ files that contain the source code of this manual. You can edit these files and run the <pre>rake</pre> command to automatically generate the HTML documentation you are currently viewing.
|
707
|
+
<% end %>
|
813
708
|
<% end %>
|
814
709
|
|
815
|
-
|
710
|
+
<% chapter "Known problems", "problems" do %>
|
711
|
+
This chapter presents known problems and possible solutions.
|
816
712
|
|
713
|
+
<% section "Icarus Verilog", "problem.ivl" do %>
|
714
|
+
<% section "Give full paths to Verilog objects", "problems.ivl.vpi_handle_by_name.absolute-paths" do %>
|
715
|
+
In version 0.8 and snapshot 20061009 of Icarus Verilog, the @vpi_handle_by_name@ function requires an _absolute_ path (including the name of the bench which instantiates the design) to a Verilog object. In addition, @vpi_handle_by_name@ always returns @nil@ when its second parameter is specified.
|
817
716
|
|
818
|
-
|
717
|
+
For example, consider <%= xref "ex:TestFoo" %>. Here, one must write @vpi_handle_by_name("TestFoo.my_foo.clk", nil)@ instead of @vpi_handle_by_name("my_foo.clk", TestFoo)@ in order to access the @clk@ input of the @my_foo@ module instance.
|
819
718
|
|
820
|
-
<%
|
821
|
-
|
822
|
-
|
719
|
+
<% example "Part of a bench which instantiates a Verilog design", "ex:TestFoo" do %>
|
720
|
+
<code lang="verilog">
|
721
|
+
module TestFoo;
|
722
|
+
reg clk_reg;
|
723
|
+
Foo my_foo(.clk(clk_reg));
|
724
|
+
endmodule
|
725
|
+
</code>
|
726
|
+
<% end %>
|
727
|
+
<% end %>
|
823
728
|
|
824
|
-
|
729
|
+
<% section "Registers must be connected", "problems.ivl.vpi_handle_by_name.connect-registers" do %>
|
730
|
+
In version 0.8 of Icarus Verilog, if you want to access a register in a design, then it must be connected to something (either assigned to a wire or passed as a parameter to a module instantiation). Otherwise, you will get a @nil@ value as the result of @vpi_handle_by_name@ method.
|
825
731
|
|
732
|
+
For example, suppose you wanted to access the @clk_reg@ register, from the bench shown in <%= xref "ex:TestFoo_bad" %> If you execute the statement @clk_reg = vpi_handle_by_name("TestFoo.clk_reg", nil)@ in a specification, then you will discover that the @vpi_handle_by_name@ method returns @nil@ instead of a handle to the @clk_reg@ register.
|
826
733
|
|
827
|
-
|
734
|
+
The solution is to change the design such that it appears like the one shown in <%= xref "ex:TestFoo_fix" %> where the register is connected to a wire, or <%= xref "ex:TestFoo" %> where the register is connected to a module instantiation.
|
828
735
|
|
736
|
+
<% example "Bad design with unconnected registers", "ex:TestFoo_bad" do %>
|
737
|
+
Here the @clk_reg@ register is not connected to anything.
|
829
738
|
|
830
|
-
|
739
|
+
<code lang="verilog">
|
740
|
+
module TestFoo;
|
741
|
+
reg clk_reg;
|
742
|
+
endmodule
|
743
|
+
</code>
|
744
|
+
<% end %>
|
831
745
|
|
746
|
+
<% example "Fixed design with wired registers", "ex:TestFoo_fix" do %>
|
747
|
+
Here the @clk_reg@ register is connected to the @clk_wire@ wire.
|
832
748
|
|
833
|
-
|
749
|
+
<code lang="verilog">
|
750
|
+
module TestFoo;
|
751
|
+
reg clk_reg;
|
752
|
+
wire clk_wire;
|
753
|
+
assign clk_wire = clk_reg;
|
754
|
+
endmodule
|
755
|
+
</code>
|
756
|
+
<% end %>
|
757
|
+
<% end %>
|
758
|
+
<% end %>
|
834
759
|
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
<% example "Part of a bench which instantiates a Verilog design", "#ex..TestFoo" do %>
|
840
|
-
<code lang="verilog">
|
841
|
-
module TestFoo;
|
842
|
-
reg clk_reg;
|
843
|
-
Foo my_foo(.clk(clk_reg));
|
844
|
-
endmodule
|
845
|
-
</code>
|
760
|
+
<% section "Vpi::reset", "problems.ivl.vpi_reset" do %>
|
761
|
+
In version 0.8 of Icarus Verilog, the @vpi_control(vpiReset)@ VPI function causes an assertion to fail inside the simulator. As a result, the simulation terminates and a core dump is produced.
|
762
|
+
<% end %>
|
846
763
|
<% end %>
|
847
764
|
|
765
|
+
<% chapter "Glossary", "glossary" do %>
|
766
|
+
<% section "Test", "glossary.test" do %>
|
767
|
+
Something that checks if a <%= xref "glossary.design", "design" %> satisfies a <%= xref "glossary.specification", "specification" %>
|
768
|
+
<% end %>
|
848
769
|
|
849
|
-
|
770
|
+
<% section "Design", "glossary.design" do %>
|
771
|
+
A Verilog module that is verified against a <%= xref "glossary.specification", "specification" %> in order to ensure correctness or soundness of its being. In other words, it is the thing being checked: does it work or not?
|
772
|
+
<% end %>
|
850
773
|
|
851
|
-
|
774
|
+
<% section "Specification", "glossary.specification" do %>
|
775
|
+
A set of <%= xref "glossary.expectation", "expectations" %> which define the desired behavior of a <%= xref "glossary.design", "design" %> when it is subjected to certain stimulus.
|
776
|
+
<% end %>
|
852
777
|
|
853
|
-
|
778
|
+
<% section "Expectation", "glossary.expectation" do %>
|
779
|
+
The desired response to some stimulus.
|
780
|
+
<% end %>
|
854
781
|
|
855
|
-
|
782
|
+
<% section "Handle", "glossary.handle" do %>
|
783
|
+
A reference to an object inside the Verilog simulation. See <%= xref "vpi.handles" %> for usage instructions.
|
784
|
+
<% end %>
|
856
785
|
|
857
|
-
<%
|
858
|
-
|
859
|
-
module TestFoo;
|
860
|
-
reg clk_reg;
|
861
|
-
endmodule
|
862
|
-
</code>
|
786
|
+
<% section "Rake", "glossary.rake" do %>
|
787
|
+
bq. Rake is a build tool, written in Ruby, using Ruby as a build language. Rake is similar to *make* in scope and purpose.
|
863
788
|
|
864
|
-
|
865
|
-
<% end %>
|
789
|
+
p>. --"Rake documentation":http://docs.rubyrake.org
|
790
|
+
<% end %>
|
866
791
|
|
867
|
-
<%
|
868
|
-
|
869
|
-
module TestFoo;
|
870
|
-
reg clk_reg;
|
871
|
-
wire clk_wire;
|
872
|
-
assign clk_wire = clk_reg;
|
873
|
-
endmodule
|
874
|
-
</code>
|
875
|
-
|
876
|
-
Here the @clk_reg@ register is connected to the @clk_wire@ wire.
|
877
|
-
<% end %>
|
792
|
+
<% section "RSpec", "glossary.RSpec" do %>
|
793
|
+
The <%= xref "glossary.BDD", "BDD" %> framework for Ruby.
|
878
794
|
|
795
|
+
See the "RSpec website":http://rspec.rubyforge.org and "tutorial":http://rspec.rubyforge.org/tutorials/index.html for more information.
|
796
|
+
<% end %>
|
879
797
|
|
880
|
-
|
798
|
+
<% section "Test driven development", "glossary.TDD" do %>
|
799
|
+
An "agile software development methodology":http://agilemanifesto.org/ which emphasizes (1) testing functionality before implementing it and (2) refactoring.
|
881
800
|
|
882
|
-
|
801
|
+
See "this introductory article":http://www.agiledata.org/essays/tdd.html for more information.
|
802
|
+
<% end %>
|
883
803
|
|
804
|
+
<% section "Behavior driven development", "glossary.BDD" do %>
|
805
|
+
An "agile software development methodology":http://agilemanifesto.org/ which emphasizes thinking in terms of behavior when designing, implementing, and verifying software.
|
884
806
|
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
h3(#problems.vsim.ruby_run). ruby_run();
|
889
|
-
|
890
|
-
<% note "Fixed in 2.0.0." do %>
|
891
|
-
This problem was fixed in release 2.0.0 (2006-04-17).
|
807
|
+
See the "official wiki":http://behaviour-driven.org/ for more information.
|
808
|
+
<% end %>
|
892
809
|
<% end %>
|
893
|
-
|
894
|
-
Version 6.1b of Mentor Modelsim doesn't play nicely with either an embedded Ruby interpreter or POSIX threads in a PLI application. When Ruby-VPI invokes the ruby_run function (which starts the Ruby interpreter), the simulator terminates immediately with an exit status of 0.
|
895
|
-
|
896
|
-
|
897
|
-
h1(#glossary). Glossary
|
898
|
-
|
899
|
-
|
900
|
-
h2(#glossary.bench). Bench
|
901
|
-
|
902
|
-
An environment in which a "design":#glossary.design is verified against a "specification":#glossary.specification. Often, it is used to emulate conditions in which the design will be eventually deployed.
|
903
|
-
|
904
|
-
|
905
|
-
h2(#glossary.BDD). Behavior driven development (BDD)
|
906
|
-
|
907
|
-
An "agile software development methodology":http://agilemanifesto.org/ which emphasizes thinking in terms of behavior when designing, implementing, and verifying software.
|
908
|
-
|
909
|
-
See the "official wiki":http://behaviour-driven.org/ for more information.
|
910
|
-
|
911
|
-
|
912
|
-
h2(#glossary.design). Design
|
913
|
-
|
914
|
-
A Verilog module that is verified against a "specification":#glossary.specification in order to ensure correctness or soundness of its being. In other words, it is the thing being checked: does it work or not?
|
915
|
-
|
916
|
-
|
917
|
-
h2(#glossary.expectation). Expectation
|
918
|
-
|
919
|
-
The desired response to some stimulus.
|
920
|
-
|
921
|
-
|
922
|
-
h2(#glossary.handle). Handle
|
923
|
-
|
924
|
-
A reference to an object inside the Verilog simulation that was obtained through the @vpi_handle_by_name@ function.
|
925
|
-
|
926
|
-
|
927
|
-
h2(#glossary.rake). Rake
|
928
|
-
|
929
|
-
bq. Rake is a build tool, written in Ruby, using Ruby as a build language. Rake is similar to *make* in scope and purpose.
|
930
|
-
|
931
|
-
p>. --"Rake documentation":http://docs.rubyrake.org
|
932
|
-
|
933
|
-
|
934
|
-
h2(#glossary.rspec). rSpec
|
935
|
-
|
936
|
-
The "BDD":#glossary.BDD framework for Ruby.
|
937
|
-
|
938
|
-
See the "rSpec website":http://rspec.rubyforge.org and "tutorial":http://rspec.rubyforge.org/tutorials/index.html for more information.
|
939
|
-
|
940
|
-
|
941
|
-
h2(#glossary.specification). Specification
|
942
|
-
|
943
|
-
A set of "expectations":#glossary.expectations which define the desired behavior of a "design":#glossary.design when it is subjected to certain stimulus.
|
944
|
-
|
945
|
-
|
946
|
-
h2(#glossary.TDD). Test driven development (TDD)
|
947
|
-
|
948
|
-
An "agile software development methodology":http://agilemanifesto.org/ which emphasizes (1) testing functionality before implementing it and (2) refactoring.
|
949
|
-
|
950
|
-
See "this introductory article":http://www.agiledata.org/essays/tdd.html for more information.
|
951
|
-
|
952
|
-
|
953
|
-
h2(#glossary.test). Test
|
954
|
-
|
955
|
-
Something that checks if a "design":#glossary.design satisfies a "specification":#glossary.specification.
|
956
|
-
|
957
|
-
|
958
|
-
h2(#glossary.test_bench). Test bench
|
959
|
-
|
960
|
-
An allusion to "a bench in an electronics laboratory":#background.vocab, or so it seems.
|