Abstract
Casacore has an advanced testing framework on top of the CMake environment. It makes it possible to do regression testing, coverage testing, and use tools like valgrind in an automatic way.
Casacore comes with an extensive set of test programs. The tests can be built in the cmake environment used by casacore by adding -DBUILD_TESTING=ON to the cmake command. Running the tests can be done using the make test or ctest command. For regression testing purposes the standard output of a test run can be compared with the expected output. Casacore uses a few scripts doing the actual execution of a test.
A test can be embedded in a script for optional preprocessing or postprocessing of a test or to run a
test in multiple ways.
Such a script can also be used to test an application (such as taql).
Casacore uses the cmake system to build the code and test programs. ctest is used to execute the test programs and to check for success or failure.
The casacore source code is divided into modules (e.g. casa, tables). Each module is divided into packages (e.g. casa/IO) containing the source files. Each package should have a test directory containing the test programs. Schematically it is organized like:
The build system creates a library per module (e.g. libcasa_tables). Modules are layered, thus the libraries not mutually dependent. Packages in a module can use each other, also mutually.
It is best to build casacore in a build directory at the same level as the casacore directory. In this way the source and build files are well separated.
The code can be built in various ways (optimized, debug, etc.), so in the build directory a directory should be created telling the build type. The build system makes uses of the name to automatically set the compile options for a build type. It recognizes:
In this directory the source code structure is mirrored, thus it will have directories like casa/IO/test.
Casacore consists of several modules (e.g. scimath, tables). A module can consist of one or more packages (e.g. casa/IO, casa/OS). Each package contains one or more classes, usually one class per file. Test programs should be created in the test directory of a package.
Usually a test for class X is written in C++. The casacore convention is to name such a test tX, thus the source code for a test is in <module>/<package>/test/tX.cc. In order to build the test program, it needs to be added to the tests list in the CMakeLists.txt file in that test directory.
The test executable is created in the build directory build/<type>/<module>/<package>/test.
Besides the .cc file, a few more files can be created for a test. They also need to reside in the source test directory. When using a standard name as in the list below, they will be copied automatically to the build test directory when the test is run.
Note that to run test tX, the test system will only copy files/directories as named above to the build test directory. After the test they will be removed from the build test directory. If test input files are named differently, they can be used in one of the two following ways.
to let the cmake system copy the file to the working directory. An entire directory cannot be done in a single line; each individual file has to be named.
If the test program or script creates output files, it is best to call them tX_tmp<something>. In this way they will be removed automatically after the test is run.
The standard way to run a test is using ctest. It makes it possible to run all or some tests.
If such a command is run in the casacore top build directory, all casacore tests are considered. However, it is also possible to run it in a subdirectory (e.g. casa or casa/IO/test) to execute only tests of a specific module or package.
The system runs a test as follows:
The return of a test program or script can be:
- 0 indicating success.
- 3 indicating that the test is skipped. This might be used if an expected input file is not available or if the
test is run on a platform not supporting it. cmake_assay will change this to 0, because ctest can only deal
with success and failure.
- Any other value indicates a failure.
If the environment variable CASACORE_CHECK has the value 1, the casacore_assay script runs the test of an executable through casacore_memcheck. This script runs the test through valgrind’s memcheck tool and tests for errors, definite and possible leaks, and leaked file descriptors. If any such problem is found, the valgrind output is put into a file tX.checktool.valgrind in the working directory.
If a .run file is used to execute the test, each invocation of the test program in the .run file should be preceeded by $casa_checktool. This environment variable defines the valgrind command. If valgrind is not used, the variable is empty.
The same mechanism can be used to use a check tool different from valgrind’s memcheck.
CASACORE_CHECK can be defined as the name of a script or a command to use. In fact, defining
CASACORE_CHECK as casacore_memcheck would have the same effect as defining it as
1.
Sometimes a test run with a check tool can take too much time and should be omitted. There is no direct way to tell that a specific test should be omitted. However, it can easily be achieved by having a .run file for such a test without the $casa_checktool prefix.
The casacore build system has support for test coverage analysis. By building in the directory build/cov
the code is automatically built this way. Currently, only the g++ compiler is supported. Support for clang
will be added later.
The script casacore_cov (in casacore/scons-tools) should be used to run the tests, analyze the test
output, and generate coverage reports from it using lcov and genhtml. It works as follows: