Abstract
Casacore has an advanced testing framework on top of the CMake environment. It makes it possible to do regression testing and use tools like valgrind in an automatic way.
Casacore comes with an extensive set of test programs. The tests can be run in the cmake/ctest environment used by casacore. A few scripts are doing the actual execution of a test.
A test can use a script for optional preprocessing or postprocessing of a test or to run a test in multiple ways. For regression testing purposes the standard output of a test run can be compared with the expected output.
Casacore consists of several modules (e.g. scimath, tables), where a module can consists of several packages (e.g. casa/IO, casa/OS). Each package contains one or more classes, usually one class per file. Test programs should be creaed in the test directory of a package.
Usually a test for a class X (in source file X.cc) 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 a build directory that is different from the source directory.
Besides the .cc file, a few more files can optionally be created for a test. They need to reside in the source test directory and will be copied automatically to the build test directory.
Note that to run test tX, the test system will only copy files/directories as named above to the build trest directory. If test input files are named differently, they can be used in one of the two following ways.
to get the file copied to the working directory. An entire directory cannot be done in a single line; each individual file has to be mentioned.
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 program 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 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 indicates success.
- 3 indicates that the test is skipped. This might be used if an expected 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 test 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 though a check tool can take too much time. 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.