views:

448

answers:

7

I have looked on the web and the discussions/examples appear to be for traditional software development. Since Verilog and VHDL (used for chip design, e.g. FPGAs and ASICs) are similar to software development C and C++ it would appear to make sense. However they have some differences being fundamentally parallel and requiring hardware to fully tests.

What experiences, good and bad, have you had? Any links you can suggest on this specific application?

Edits/clarifications: 10/28/09: I'm particularly asking about TDD. I'm familiar with doing test benches, including self-checking ones. I'm also aware that SystemVerilog has some particular features for test benches.

10/28/09: The questions implied include 1) writing a test for any functionality, never using waveforms for simulation and 2) writing test/testbenches first.

11/29/09: In Empirical Studies Show Test Driven Development Improves Quality they report for (software) TDD "The pre-release defect density of the four products, measured as defects per thousand lines of code, decreased between 40% and 90% relative to the projects that did not use TDD. The teams' management reported subjectively a 15–35% increase in initial development time for the teams using TDD, though the teams agreed that this was offset by reduced maintenance costs." The reduced bugs reduces risk for tape-out, at the expense of moderate schedule impact. This also has some data.

11/29/09: I'm mainly doing control and datapath code, not DSP code. For DSP, the typical solution involves a Matlab bit-accurate simulation.

03/02/10: The advantage of TDD is you make sure the test fails first. I suppose this could be done with assertions too.

+2  A: 

The SystemVerilog extensions to the IEEE Verilog Standard include a variety of constructs which facilitate creating thorough test suites for verifying complex digital logic designs. SystemVerilog is one of the Hardware Verification Languages (HVL) which is used to verify ASIC chip designs via simulation (as opposed to emulation or using FPGA's).

Significant benefits over a traditional Hardware Design Language (Verilog) are:

  • constrained randomization
  • assertions
  • automatic collection of functional and assertion coverage data

The key is to have access to simulation software which supports this recent (2005) standard. Not all simulators fully support the more advanced features.

In addition to the IEEE standard, there is an open-source SystemVerilog library of verification components available from VMM Central (http://www.vmmcentral.com). It provides a reasonable framework for creating a test environment.

You could also do more research on the topic by searching the Verfication Guild forum.

SystemVerilog is not the only HVL,and VMM is not the only library. But, I would recommend both, if you have access to the appropriate tools. I have found this to be an effective methodology in finding design bugs before becoming silicon.

toolic
I didn't see anything on TDD in the Verification Guild http://verificationguild.com/
Brian Carlton
That's possibly because verification in a simulation environment has been going on for a looong time in the ASIC world, just not called TDD. Mind you, it's often not done as test *driven* development either (as in "write tests before functional code")!
Martin Thompson
+1  A: 

Hi Brian,

I never actively tried TDD on an RTL design, but I had my thoughts on this.

What I think would be interesting is to try out this approach in connection with assertions. You would basically first write down in form of assertions what you assume/expect from your module, write your RTL and later you can verify these assertions using formal tools and/or simulation. In contrast to "normal" testcases (where you probably would need to write directed ones) you should have much better coverage and the assertions/assumptions may be of use later (e.g. on system level) as well.

However I wouldn't fully rely on assertions, this can become very hairy.

Maybe you can express your thoughts on this as well, as you are asking for it I guess you carry some ideas in your head?

danielpoe
+4  A: 

I write code for FPGAs, not ASICS... but TDD is my still my preferred approach. I like to have a full suite of tests for all the functional code I write, and I try (not always successfully) to write testcode first. Staring at waveforms always happens at some point when you're debugging, but it's not a good way of validating your code (IMHO).

Given the difficulty of performing proper tests in the real hardware (stimulating corner cases is particularly hard) and the fact that a VHDL-compile takes seconds (vs a "to hardware" compile that takes many minutes (or even hours)), I don't see how anyone can operate any other way!

I also build assertions into the RTL as I write it to catch things I know shouldn't ever happen. Apparantly this is seen as a bit "weird", as there's a perception that verification engineers write assertions and RTL designers don't. But mostly I'm my own verification engineer, so maybe that's why!

Martin Thompson
Hi Martin, if you happen to have a paper or some article where you give some examples and share your experiences I would be quite interested. What kind of RTL modules do you write, i.e. is it more the JPEG processor, the bus system, ...
danielpoe
Hi Daniel,I'm afraid I have nothing I can refer you to about examples (maybe I ought to write something :). The modules in question are for an image processing system (you can read more here about the system if you want http://www.conekt.net/fpgas-for-ldw.html).I tend to build small test benches operating on tiny (often hand drawn) images, for which I can calculate the "right answers" by hand. Then I have a Matlab simulation of the algorithms (which is used for alg. development), which generates answers for the HDL sim to test against - I iterate until I get bit-accurate results here.
Martin Thompson
+2  A: 

I don't know a lot about hardware/chip design, but I am deeply into TDD, so I can at least discuss suitability of the process with you.

The question I'd call most pertinent is: How quickly can your tests give you feedback on a design? Related to that: How quickly can you add new tests? And how well do your tools support refactoring (changing structure without changing behavior) of your design?

The TDD process depends a great deal on the "softness" of software - good automated unit tests run in seconds (minutes at the outside), and guide short bursts of focused construction and refactoring. Do your tools support this kind of workflow - rapidly cycling between writing and running tests and building the system under test in short iterations?

bradheintz
I wonder is there a unittest verilog equivalent?
Marty
My experience is that the full suite can take many minutes to run... But I can run a compile/test iteration on a particular test in single-digit seconds (usually). The full suite for most of my submodules is a ~10 seconds kind of activity.The time it falls over is if you have to iterate with real hardware, or a synthesis run - usually because you are chasing performance issues, not functional ones. These can take tens of minutes often.
Martin Thompson
By "synthesis run", I'm guessing you mean something akin to what we'd call an "integration test" or "acceptance test" in software - not so useful for driving development, but important once you have the pieces in place.10 seconds isn't bad - that's somewhere around the boundary between productive/unproductive unit tests (i.e., the point at which people will either stop running them at each iteration, or will switch over to reading Metafilter while they run).Are there any facilities for mocking/stubbing submodules?
bradheintz
Unit test is roughly a test bench in Verilog and VHDL. They stimulate the design.
Brian Carlton
A synthesis run is converting the design into a form that can be run on the chip. It is as if simulation was like running the C and compiling the code is synthesis.
Brian Carlton
bradheintz: a synthesis run is more than just another test, is what you do to get to the real hardware. It will flag performance issues and allow testing at full speed. But, yes, it is more of a "pieces in place already" activity. There are (a few) times you iterate that part, which is really painful!Mocking/stubbing, yes. You can build multiple "architectures" of a given submodules, which can be as functional (or not) as you like. They can also be "non-synthesisable" at this sim stage, which means more of the language is available to you.
Martin Thompson
+1  A: 

What is TDD for you? Do you mean having all your code exercised by automatic tests at all times, or do you go further to mean that tests are written before the code and no new code is written unless tests fail?

Whichever approach you prefer, HDL code testing isn't very different from software testing. It has its pluses (much better coverage and depth of testing) and minuses (difficult to set up and cumbersome relatively to software).

I've had very good experience with employing Python and generic HDL transactors for implementing comprehensive and automatic tests for synthesizable HDL modules. The idea is somewhat similar to what Janick Bergeron presents in his books, but instead of SystemVerilog, Python is used to (1) generate VHDL code from test scenarios written in Python and (2) verification of results written by the monitoring transactors that accept waveforms from the design during simulation.

There's much more to be written about this technique, but I'm not sure what you want to focus on.

Eli Bendersky
TDD = both 1. regression tests, ideally run before each checking (or at a minimum nightly) 2. Write test before code. At least that's what I'm looking for.
Brian Carlton
A: 

Hi bradheintz,

With regard to refactoring tools for hardware languages, I'd like to point you to our tool Sigasi HDT. Sigasi provides an IDE with built-in VHDL analyzer and VHDL refactorings.

Philippe Faes, Sigasi

Philippe Faes
A: 

ANVIL– ANother Verilog Interaction Layer talks about this some. I haven't tried it.

Brian Carlton