DejaGnu: The GNU Testing Framework | ||
---|---|---|
<<< Previous | Getting DejaGnu up and running | Next >>> |
In this section you will to start a small project, using the sample application calc, which is part of your DejaGnu distribution
The runtest program can be run standalone. All the autoconf/automake support is just cause those programs are commonly used for other GNU applications. The key to running runtest standalone is having the local site.exp file setup correctly, which automake does.
The generated site.exp should like like:
set tool calc set srcdir . set objdir /home/dgt/dejagnu.test |
We have to prepare some input file in order to run autocon and automake. There is book “GNU autoconf, automake and libtool” by Garry V. Vaughan, et al. NewRider, ISBN 1-57870-190-2 which describes this process thoroughly.
From the calc example distributed with the DejaGnu documentation you should copy the program file itself (calc.c) and some additional files, which you might examine a little bit close to derive their meanings.
dgt:~/dejagnu.test$ cp -r /usr/share/doc/dejagnu/examples/calc/\ {configure.in,Makefile.am,calc.c,testsuite} . |
In Makemake.am note the presence of the AUTOMAKE_OPTIONS = dejagnu. This option is needed.
Run aclocal to generate aclocal.m4, which is a collection of macros needed by configure.in
dgt:~/dejagnu.test$ aclocal |
autoconf is another part of the auto-tools. Run it to generate configure based on information contained in configure.in.
dgt:~/dejagnu.test$ autoconf |
autoheader is another part of the auto-tools. Run it to generate calc.h.in.
dgt:~/dejagnu.test$ autoheader |
The Makefile.am of this example was developed as port of the DejaGnu distribution. Adapt Makefile.am for this test. Replace the line “#noinst_PROGRAMS = calc” to “bin_PROGRAMS = calc”. Change the RUNTESTDEFAULTFLAGS from “$$srcdir/testsuite” to “./testsuite”.
Running automake at this point contains a series of warning in its output as shown in the following example:
Example 2. Sample output of automake with missing files
dgt:~/dejagnu.test$ automake --add-missing automake: configure.in: installing `./install-sh' automake: configure.in: installing `./mkinstalldirs' automake: configure.in: installing `./missing' automake: Makefile.am: installing `./INSTALL' automake: Makefile.am: required file `./NEWS' not found automake: Makefile.am: required file `./README' not found automake: Makefile.am: installing `./COPYING' automake: Makefile.am: required file `./AUTHORS' not found automake: Makefile.am: required file `./ChangeLog' not found configure.in: 4: required file `./calc.h.in' not found Makefile.am:6: required directory ./doc does not exist |
Create a empty directory doc and empty files INSTALL, NEWS, README, AUTHORS, ChangeLog and COPYING. The default COPYING will point to the GNU Public License (GPL). In a real project it would be time to add some meaningfull text in each file.
Adapt calc to your environment by calling configure.
Example 3. Sample output of configure
dgt:~/dejagnu.test$ ./configure creating cache ./config.cache checking whether to enable maintainer-specific portions of Makefiles... no checking for a BSD compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking whether make sets ${MAKE}... yes checking for working aclocal... found checking for working autoconf... found checking for working automake... found checking for working autoheader... found checking for working makeinfo... found checking for gcc... gcc checking whether the C compiler (gcc ) works... yes checking whether the C compiler (gcc ) is a cross-compiler... no checking whether we are using GNU C... yes checking whether gcc accepts -g... yes checking for a BSD compatible install... /usr/bin/install -c checking how to run the C preprocessor... gcc -E checking for stdlib.h... yes checking for strcmp... yes updating cache ./config.cache creating ./config.status creating Makefile creating calc.h |
If you are familiar with GNU software, this output should not contain any surprise to you. Any errors should be easy to fix for such a simple program.
Build the calc executable:
Example 4. Sample output building calc
dgt:~/dejagnu.test$ make gcc -DHAVE_CONFIG_H -I. -I. -I. -g -O2 -c calc.c gcc -g -O2 -o calc calc.o |
You prepared a few files and then called some commands. Respecting the right order assures a automatic and correctly compiled calc program. The following example resumes the correct order.
Example 5. Creating the calc program using the GNU autotools
dgt:~/dejagnu.test$ aclocal dgt:~/dejagnu.test$ autoconf dgt:~/dejagnu.test$ autoheader dgt:~/dejagnu.test$ automake --add-missing dgt:~/dejagnu.test$ ./configure dgt:~/dejagnu.test$ make |
Play with calc and verify whether it works correctly. A sample session might look like this:
dgt:~/dejagnu.test$ ./calc calc: version Version: 1.1 calc: add 3 4 7 calc: multiply 3 4 12 calc: multiply 2 4 12 calc: quit |
Look at the intentional bug that 2 times 4 equals 12.
The tests run by DejaGnu need a file called site.exp, which is automatically generated if we call “make site.exp”. This was the purpose of the “AUTOMAKE_OPTIONS = dejagnu” in Makefile.am.
<<< Previous | Home | Next >>> |
Getting DejaGnu up and running | Up | Our first automated tests |