Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've been using <a href="http://www.gnu.org/software/dejagnu" rel="nofollow noreferrer">dejagnu</a> for years and love it.</p> <p>I started using it for embedded development because it supports very well the concept that the machine on which you're running the test program may be different than the machine on which you build the test program. A consequence of this is that testing code on multiple platforms is also well supported. Not sure if that's important. The gcc testsuite uses it. I use it for desktop development as well.</p> <p>The basic idea with dejagnu is that you</p> <ul> <li>copy the test program to the "target" (which for local testing could be the ~/tmp directory)</li> <li>start the test program</li> <li>print stuff to the console (which acts as input to the test program)</li> <li>parse the output from the test program and match it with what you expect</li> <li>decide whether that output means pass or fail</li> </ul> <p>Once you've got the test program and the test scripts written, you end up doing something like this:</p> <pre>$ runtest === foo Summary === &#35; of expected passes 42 foo-test built Thu Jan 15 20:09:19 PST 2009 foo-test version 0.0.0.1 runtest completed at Sun Jan 18 08:29:13 2009</pre> <p>The way I get there for testing a library named foo is:</p> <ul> <li>assume the source and include files for the library are in ~/src/foo</li> <li>create a directory named ~/src/foo/testsuite</li> <li>write a test program named foo-test.c that has a main() that</li> <ul> <li>processes command line args</li> <li>- prints a prompt and sits in a loop processing "commands" where I define a command to test each function in my library. This is sort of like a command shell but specific to the library. For something like my_pow I'd define the command to take 2 args.</li> <li>write a dejagnu (which is another layer on top of Expect (http://expect.nist.gov/, which is itself a layer on top of Tcl (http://www.tcl.tk/) function called my_pow that:</li> <ul> <li>takes two arguments</li> <li>calculates the expected result (in Tcl)</li> <li>sends "my_pow " to the console</li> <li>parses the output of the my_pow command from foo-test</li> <li>determines whether the actual result matches the expected result</li> <li>calls the appropriate dejagnu function (pass or fail)</li> </ul> </ul> </ul> <p>Sounds hard, but it's not. It takes a little while to decide how much work to do in foo-test vs. how much to do in Tcl. I end up using a fair amount of shell (e.g. bash) functionality to do things like copy files to temp directories or look at the log files that my programs generate. So you end up getting good at all this stuff.</p> <p>As far as references, there's one book on Expect that I'd say is a requirement for diving into this: <a href="http://oreilly.com/catalog/9781565920903/index.html" rel="nofollow noreferrer">http://oreilly.com/catalog/9781565920903/index.html</a>.<br> Between that and an online Tcl command reference <a href="http://www.tcl.tk/man/tcl8.4/TclCmd/contents.htm" rel="nofollow noreferrer">http://www.tcl.tk/man/tcl8.4/TclCmd/contents.htm</a> and FAQ (<a href="http://www.psg.com/~joem/tcl/faq.html" rel="nofollow noreferrer">http://www.psg.com/~joem/tcl/faq.html</a>), you're pretty much there.</p> <p>Good luck.</p> <p>-DB</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload