[vtk-developers] Testing of CXX files in VTK

Ken Martin ken.martin at kitware.com
Fri Aug 9 13:41:15 EDT 2002


Hello Folk,

I have modified VTK to use CMake's built in test driver command
CREATE_TEST_SOURCELIST. This command creates a single executable for a
series of C++ tests. The main motivation for this is with static
builds. With a static build having many C++ tests means having many
large executables and long link times. An additional benifit is that
the resulting MSDev worspaces have fewer projects in them. With the
test driver one executable is created for each component of VTK (such
as Imaging). It is also an interesting example of using CMake. The
following sample shows the basic CMakeLists.txt I have used:

SET(KIT Common)
CREATE_TEST_SOURCELIST(Tests ${KIT}CxxTests.cxx
  ObjectFactory.cxx
  otherArrays.cxx
  TestString.cxx
)

ADD_EXECUTABLE(${KIT}CxxTests ${Tests})
TARGET_LINK_LIBRARIES(${KIT}CxxTests vtkCommon)
SET (TestsToRun ${Tests})
REMOVE (TestsToRun ${KIT}CxxTests.cxx)

FOREACH (test ${TestsToRun})
  GET_FILENAME_COMPONENT(TName ${test} NAME_WE)
  ADD_TEST(${TName} ${CXX_TEST_PATH}/${KIT}CxxTests ${TName})
ENDFOREACH (test)

I setup KIT on the first line to make it easier to cut and paste
between toolkits. Next comes the CREATE_TEST_SOURCELIST command. The
first argument is the name for the resulting list. The second argument
is the name of the file to put the generated test driver code into.
The remaining arguments are where you list the test source code.
Typically each test is in its own .cxx file. Next I add the executable
to the Makefile and then add any link libraries. I create a list
called TestsToRun that contains all the files in the source list. The
I remove the test driver file from this list. Finally I run the
TestsToRun list through a FOREACH and for each test I compute the name
of the test using the GET_FILENAME_COMPONENT command (to remove the
.cxx) and call ADD_TEST.

The test driver is designed so that its first argument is the name of
the test you want to run. Any additional arguments are passed to the
test. I have put this in place for most of VTK's directories except
parallel which has a bunch of wierd MPI stuff in it :-) It could be
converted as well but I figured it could wait.

Thanks
Ken

--------------------------
Ken Martin, PhD
Kitware Inc.
518 371-3971 x101
469 Clifton Corporate Pkwy.
Clifton Park, NY 12065




More information about the vtk-developers mailing list