Testing my ignorance with dejagnu - part one

Well, this post is not like the title :). This post is about overcoming my ignorance about dejagnu and  understand what it is, how it works, and how to configure it. I am going to write this as a series of posts, and this is the first.

Simply Dejagnu

First we will try to see what it is, by doing this quick 2 minute exercise.

  1. Install Dejagnu from official repository. For debian its apt-get install dejagnu. For arch linux it's pacman -S dejagnu, and for fedora/redhat based it's yum install dejagnu, or you can simply download the source and configure, build, install it.
Now run the following commands
sh-4.2# mkdir ~/test && cd ~/test && vi test1.exp
In test1.exp write the following
set result [exec echo "Hello"]
if { $result == "Hello" } {
    pass "echo printed the result correctly"
if { $result != "Hello" } {
    fail "echo malfunction"
Save the above file, and from the ~/test folder run
sh-4.2#runtest test1.exp
and you should see some output ending as follows(Am purposefully skipping other messages/warnings in the output for now)
        ===  Summary ===

of expected passes 1

This is what dejagnu does !. i.e It provides a syntax to write test scripts (Tcl based), it gives a library (Expect based) to assert tests i.e pass or fail, and finally it gives you a frontend to execute the tests i.e runtest.

The test script you saw above tests if the command "echo" in linux outputs "Hello" correctly. I understand dejagnu as a sort of black box testing, since we launch the application and interact with it from the command line and not calling some API's in it and testing it.

In a simplistic sense this is what dejagnu does. But wait, we hear a lot of other things, like board, tool, sourcedir, builddir, objdir blah ! blah ! blah !. Yes, they are there for specific to server specific needs. To understand all of them we should first go over what are the expected features of a test framework and how dejagnu supports them.

We now know that Dejagnu is a test framework. A test framework is a set of assumptions, concepts and tools that provide support for software testing. The Testing framework (Dejagnu) is responsible for:

  1. defining the format in which to express expectations
  2. creating a mechanism to hook into or drive the application under test
  3. executing the tests
  4. reporting results
I conclude this post with this information. We have so far seen what dejagnu is and how to write a simple testcase out of it. We will get into more of dejagnu in the next post.