Chapter 17
Testing

Matthias Bäsken (baesken@infsn2.informatik.uni-halle.de)

The CGAL test suite is a way to test the compilation and execution of CGAL programs automatically (i.e., without user interaction) on a number of different platforms. Developers should, of course, thoroughly test their code on their own development platform(s) before submitting it. The test suite serves as a way to test on additional platforms not available to the developer.

17.1   What a test suite for a package should contain

The test suite helps the developer(s) of a package to

That does not mean that the test suite is a platform for initial testing of code. New code should be tested on different platforms by the developer before submission.

It is strongly recommended for a test suite of a package to

17.2   Using the code coverage tool gcov

The tool gcov can be used together with the GNU C++ compiler to test for code coverage in your programs and may be helpful when you create your CGAL test suite programs. You can find a complete guide to this tool in the GNU on-line documentation at http://gcc.gnu.org/onlinedocs/gcc-2.95.2/gcc_6.html. If you want to use the code coverage tool gcov, you have to compile your programs with the options -fprofile-arcs and -ftest-coverage. Here is a simple example:

   #include<iostream>

   using namespace std;

   void fu(int val)
   {
    int w,v=0;
    if (val==0) {
     cout << "val == 0!\n";
     for(w=0;w<100;w++) v=v+w;
    }
    else {
     cout << "val != 0!\n";
     for(w=0;w<10;w++) v=v+w;  
    }
 
    cout << "v:" << v << "\n";
   }

   int main()
   {
     fu(0);
     return 0;
   }
First you have to compile the example program test.C with the special options. Then you have to execute it, and, after this, gcov can be used.
   g++ -fprofile-arcs -ftest-coverage -o test test.C
   test
   gcov test.C  
gcov will create a file test.C.gcov containing output from gcov:
                #include<iostream>
                
                using namespace std;
                
                void fu(int val)
           1    {
           1     int w,v=0;
           1     if (val==0) {
           1      cout << "val == 0!\n";
           1      for(w=0;w<100;w++) v=v+w;
                 }
      ######     else {
      ######      cout << "val != 0!\n";
      ######      for(w=0;w<10;w++) v=v+w;  
                }
                 
           1     cout << "v:" << v << "\n";
                }
                
                int main()
           1    {
           1      fu(0);
           1      return 0;
                }
The lines that were not executed will be marked with ######, so you will see what should be added in the (CGAL) test suite programs.

17.3   Test suite directory

The test suite is located in the directory test of the internal releases of CGAL. This directory is not part of external releases. The directory test contains:

The test suite will attempt to compile all the programs in the subdirectories of test and to run all except the demo programs (which usually require user interaction) by using the cgal_test scripts (Sections 4.1 and 5.5) and will save the results in files in the package subdirectories (Section 17.6). Even if a program fails to compile or run, the test suite will continue.

17.4   Test suite input

Input to programs in the test suite can be supplied in three different ways:

data files in the data directory
As described in Section 4.1, a package's test directory may contain a subdirectory data that contains input files for the test programs.
*.cin files
If a test program program.C requires input from standard input (i.e., cin), you should put a file called program.cin in the test directory. The test suite will then execute the program using the command
         ./program < program.cin
         
command-line arguments supplied in the cgal_test script
You are discouraged from using this option to give input values to your programs since it requires you to edit and submit a cgal_test script; see Section 5.5.

However, if a test program program.C absolutely requires command-line parameters, you should do the following. Use create_cgal_test to create the script cgal_test. This file contains an entry of the form

         compile_and_run program 
         
Just put the command-line parameters for program at the end of this line:
         compile_and_run program  arg1 arg2 ..
         
The test suite will then execute the program using the command

         ./program <arg1> <arg2> ...
         

17.5   Running the test suite

The test suite is run using the run_testsuite script that is distributed with every internal release in the test directory. There are several ways you can customize this script to meet you needs:

After these steps you are ready to run the test suite. It can be run in two different ways:

./run_testsuite

The test suite will run the tests from all test directories. This may take a considerable amount of time.

./run_testsuite <dir1> <dir2> ...

The test suite will run only the test programs in the test directories

<dir1> <dir2> ... 

To run an entire CGAL test suite automatically, including downloading of an internal release, configuration, and installation of the library, you can use the autotest_cgal script described in Section 5.6.

17.6   Files generated by the test suite

The testsuite will generate the following output files:

17.7   Test suite results

The results of test suites run on the various supported or soon-to-be-supported platforms are posted on the test suite results page .

17.8   Requirements and recommendations

Requirements:

Recommendations: