wiki:pm-test-make

Version 2 (modified by andreasw, 14 years ago) (diff)

cleaned up

Test Directory Makefile.am File

In the test subdirectory, which should provide a unit test, the Makefile has a target test which compiles and runs the unit test.

Beginning of the File

# Copyright (C) 2006 International Business Machines and others.
# All Rights Reserved.
# This file is distributed under the Common Public License.

## $Id: Makefile.am 506 2006-06-01 20:11:24Z andreasw $

# Author:  Andreas Waechter           IBM    2006-04-13

AUTOMAKE_OPTIONS = foreign
  • As usual, we should have some introduction with copyright note, author information, etc.

Compilation of the Unit Test Program

########################################################################
#                      unitTest for CoinUtils                          #
########################################################################

noinst_PROGRAMS = unitTest

unitTest_SOURCES = \
        CoinDenseVectorTest.cpp \
        CoinErrorTest.cpp \
        CoinIndexedVectorTest.cpp \
        CoinModelTest.cpp \
        CoinMpsIOTest.cpp \
        CoinPackedMatrixTest.cpp \
        CoinPackedVectorTest.cpp \
        CoinShallowPackedVectorTest.cpp \
        unitTest.cpp

# List libraries of COIN projects
unitTest_LDADD = $(COINUTILSOBJDIR)/src/libCoinUtils.la

# List additional libraries
LIBS += $(ADDLIBS)

# Here list all include flags, relative to this "srcdir" directory.  This
# "cygpath" stuff is necessary to compile with native compilers on Cygwin
AM_CPPFLAGS = \
        -I`$(CYGPATH_W) $(COINUTILSSRCDIR)/src`

# This line is necessary to allow VPATH compilation with MS compilers
# on Cygwin
DEFAULT_INCLUDES = -I. -I`$(CYGPATH_W) $(srcdir)` -I$(top_builddir)/inc
  • The above example is taken from the CoinUtils project. It follows the same scheme as describe for the source directory Makefile.am file for defining the compilation of a program. Since we don't want to install the unitTest program, we use the noinst_ prefix for the PROGRAMS primary.

The Test Target

test: unitTest$(EXEEXT)
        cd ../../Data/Netlib; make uncompress
        ./unitTest$(EXEEXT)

.PHONY: test
  • The test target above depends on the unitTest executable. Note the addition of the EXEEXT variable to the executable name; this variable is set to the extension of executables on the specific platform. For example, on UNIX systems it is an emply string, and on Windows it is automatically set to ".exe".

For this particular test, the executable will use files in the Data/Netlib directory. If the CoinUtils library has not been compiled with zlib support, the MPS files in that directory first have to be uncompressed. This is done by the Makefile in the Data/Netlib directory (unless the files have already been compressed, or the zlib library is used).

Finally, the unit test executable is run.

House Cleaning

########################################################################
#                          Cleaning stuff                              #
########################################################################

# Here we list everything that is not generated by the compiler, e.g.,
# output files of a program

DISTCLEANFILES = yy.mps xx.mps
  • The unit test program might generate output files. It is a nice guesture to the user to make sure that everything is cleaned up, when (s)he does a make distclean. For this reason, you should list all possibly generated output files in the DISTCLEANFILES Automake variable.