mem-overflow: test malloc and realloc corner cases
[platform/upstream/glib.git] / glib.mk
1 # GLIB - Library of useful C routines
2
3 #GTESTER = gtester                      # for non-GLIB packages
4 GTESTER = $(top_builddir)/glib/gtester                  # for the GLIB package
5 GTESTER_REPORT = $(top_builddir)/glib/gtester-report    # for the GLIB package
6 NULL =
7
8 # initialize variables for unconditional += appending
9 BUILT_SOURCES =
10 BUILT_EXTRA_DIST =
11 CLEANFILES =
12 DISTCLEANFILES =
13 MAINTAINERCLEANFILES =
14 EXTRA_DIST =
15 TEST_PROGS =
16
17 installed_test_LTLIBRARIES =
18 installed_test_PROGRAMS =
19 installed_test_SCRIPTS =
20 nobase_installed_test_DATA =
21
22 noinst_LTLIBRARIES =
23 noinst_PROGRAMS =
24 noinst_SCRIPTS =
25 noinst_DATA =
26
27 check_LTLIBRARIES =
28 check_PROGRAMS =
29 check_SCRIPTS =
30 check_DATA =
31
32 TESTS =
33
34 ### testing rules
35
36 # test: run all tests in cwd and subdirs
37 test: test-nonrecursive
38 if OS_UNIX
39         @ for subdir in $(SUBDIRS) . ; do \
40             test "$$subdir" = "." -o "$$subdir" = "po" || \
41             ( cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $@ ) || exit $? ; \
42           done
43
44 # test-nonrecursive: run tests only in cwd
45 test-nonrecursive: ${TEST_PROGS}
46         @test -z "${TEST_PROGS}" || G_TEST_SRCDIR="$(abs_srcdir)" G_TEST_BUILDDIR="$(abs_builddir)" G_DEBUG=gc-friendly MALLOC_CHECK_=2 MALLOC_PERTURB_=$$(($${RANDOM:-256} % 256)) ${GTESTER} --verbose ${TEST_PROGS}
47 else
48 test-nonrecursive:
49 endif
50
51 # test-report: run tests in subdirs and generate report
52 # perf-report: run tests in subdirs with -m perf and generate report
53 # full-report: like test-report: with -m perf and -m slow
54 test-report perf-report full-report:    ${TEST_PROGS}
55         @test -z "${TEST_PROGS}" || { \
56           case $@ in \
57           test-report) test_options="-k";; \
58           perf-report) test_options="-k -m=perf";; \
59           full-report) test_options="-k -m=perf -m=slow";; \
60           esac ; \
61           if test -z "$$GTESTER_LOGDIR" ; then  \
62             G_TEST_SRCDIR="$(abs_srcdir)" G_TEST_BUILDDIR="$(abs_builddir)" ${GTESTER} --verbose $$test_options -o test-report.xml ${TEST_PROGS} ; \
63           elif test -n "${TEST_PROGS}" ; then \
64             G_TEST_SRCDIR="$(abs_srcdir)" G_TEST_BUILDDIR="$(abs_builddir)" ${GTESTER} --verbose $$test_options -o `mktemp "$$GTESTER_LOGDIR/log-XXXXXX"` ${TEST_PROGS} ; \
65           fi ; \
66         }
67         @ ignore_logdir=true ; \
68           if test -z "$$GTESTER_LOGDIR" ; then \
69             GTESTER_LOGDIR=`mktemp -d "\`pwd\`/.testlogs-XXXXXX"`; export GTESTER_LOGDIR ; \
70             ignore_logdir=false ; \
71           fi ; \
72           if test -d "$(top_srcdir)/.git" ; then \
73             REVISION=`git describe` ; \
74           else \
75             REVISION=$(VERSION) ; \
76           fi ; \
77           for subdir in $(SUBDIRS) . ; do \
78             test "$$subdir" = "." -o "$$subdir" = "po" || \
79             ( cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $@ ) || exit $? ; \
80           done ; \
81           $$ignore_logdir || { \
82             echo '<?xml version="1.0"?>'              > $@.xml ; \
83             echo '<report-collection>'               >> $@.xml ; \
84             echo '<info>'                            >> $@.xml ; \
85             echo '  <package>$(PACKAGE)</package>'   >> $@.xml ; \
86             echo '  <version>$(VERSION)</version>'   >> $@.xml ; \
87             echo "  <revision>$$REVISION</revision>" >> $@.xml ; \
88             echo '</info>'                           >> $@.xml ; \
89             for lf in `ls -L "$$GTESTER_LOGDIR"/.` ; do \
90               sed '1,1s/^<?xml\b[^>?]*?>//' <"$$GTESTER_LOGDIR"/"$$lf" >> $@.xml ; \
91             done ; \
92             echo >> $@.xml ; \
93             echo '</report-collection>' >> $@.xml ; \
94             rm -rf "$$GTESTER_LOGDIR"/ ; \
95             ${GTESTER_REPORT} --version 2>/dev/null 1>&2 ; test "$$?" != 0 || ${GTESTER_REPORT} $@.xml >$@.html ; \
96           }
97 .PHONY: test test-report perf-report full-report test-nonrecursive
98
99 .PHONY: lcov genlcov lcov-clean
100 # use recursive makes in order to ignore errors during check
101 lcov:
102         -$(MAKE) $(AM_MAKEFLAGS) -k check
103         $(MAKE) $(AM_MAKEFLAGS) genlcov
104
105 # we have to massage the lcov.info file slightly to hide the effect of libtool
106 # placing the objects files in the .libs/ directory separate from the *.c
107 # we also have to delete tests/.libs/libmoduletestplugin_*.gcda
108 genlcov:
109         rm -f $(top_builddir)/tests/.libs/libmoduletestplugin_*.gcda
110         $(LTP) --directory $(top_builddir) --capture --output-file glib-lcov.info --test-name GLIB_PERF --no-checksum --compat-libtool
111         LANG=C $(LTP_GENHTML) --prefix $(top_builddir) --output-directory glib-lcov --title "GLib Code Coverage" --legend --show-details glib-lcov.info
112         @echo "file://$(abs_top_builddir)/glib-lcov/index.html"
113
114 lcov-clean:
115         -$(LTP) --directory $(top_builddir) -z
116         -rm -rf glib-lcov.info glib-lcov
117         -find -name '*.gcda' -print | xargs rm
118
119 # run tests in cwd as part of make check
120 check-local: test-nonrecursive
121
122 # We support a fairly large range of possible variables.  It is expected that all types of files in a test suite
123 # will belong in exactly one of the following variables.
124 #
125 # First, we support the usual automake suffixes, but in lowercase, with the customary meaning:
126 #
127 #   test_programs, test_scripts, test_data, test_ltlibraries
128 #
129 # The above are used to list files that are involved in both uninstalled and installed testing.  The
130 # test_programs and test_scripts are taken to be actual testcases and will be run as part of the test suite.
131 # Note that _data is always used with the nobase_ automake variable name to ensure that installed test data is
132 # installed in the same way as it appears in the package layout.
133 #
134 # In order to mark a particular file as being only for one type of testing, use 'installed' or 'uninstalled',
135 # like so:
136 #
137 #   installed_test_programs, uninstalled_test_programs
138 #   installed_test_scripts, uninstalled_test_scripts
139 #   installed_test_data, uninstalled_test_data
140 #   installed_test_ltlibraries, uninstalled_test_ltlibraries
141 #
142 # Additionally, we support 'extra' infixes for programs and scripts.  This is used for support programs/scripts
143 # that should not themselves be run as testcases (but exist to be used from other testcases):
144 #
145 #   test_extra_programs, installed_test_extra_programs, uninstalled_test_extra_programs
146 #   test_extra_scripts, installed_test_extra_scripts, uninstalled_test_extra_scripts
147 #
148 # Additionally, for _scripts and _data, we support the customary dist_ prefix so that the named script or data
149 # file automatically end up in the tarball.
150 #
151 #   dist_test_scripts, dist_test_data, dist_test_extra_scripts
152 #   dist_installed_test_scripts, dist_installed_test_data, dist_installed_test_extra_scripts
153 #   dist_uninstalled_test_scripts, dist_uninstalled_test_data, dist_uninstalled_test_extra_scripts
154 #
155 # Note that no file is automatically disted unless it appears in one of the dist_ variables.  This follows the
156 # standard automake convention of not disting programs scripts or data by default.
157 #
158 # test_programs, test_scripts, uninstalled_test_programs and uninstalled_test_scripts (as well as their disted
159 # variants) will be run as part of the in-tree 'make check'.  These are all assumed to be runnable under
160 # gtester.  That's a bit strange for scripts, but it's possible.
161
162 # we use test -z "$(TEST_PROGS)" above, so make sure we have no extra whitespace...
163 TEST_PROGS += $(strip $(test_programs) $(test_scripts) $(uninstalled_test_programs) $(uninstalled_test_scripts) \
164                       $(dist_test_scripts) $(dist_uninstalled_test_scripts))
165
166 if OS_WIN32
167 TESTS += $(test_programs) $(test_scripts) $(uninstalled_test_programs) $(uninstalled_test_scripts) \
168          $(dist_test_scripts) $(dist_uninstalled_test_scripts)
169 endif
170
171 # Note: build even the installed-only targets during 'make check' to ensure that they still work.
172 # We need to do a bit of trickery here and manage disting via EXTRA_DIST instead of using dist_ prefixes to
173 # prevent automake from mistreating gmake functions like $(wildcard ...) and $(addprefix ...) as if they were
174 # filenames, including removing duplicate instances of the opening part before the space, eg. '$(addprefix'.
175 all_test_programs     = $(test_programs) $(uninstalled_test_programs) $(installed_test_programs) \
176                         $(test_extra_programs) $(uninstalled_test_extra_programs) $(installed_test_extra_programs)
177 all_test_scripts      = $(test_scripts) $(uninstalled_test_scripts) $(installed_test_scripts) \
178                         $(test_extra_scripts) $(uninstalled_test_extra_scripts) $(installed_test_extra_scripts)
179 all_dist_test_scripts = $(dist_test_scripts) $(dist_uninstalled_test_scripts) $(dist_installed_test_scripts) \
180                         $(dist_test_extra_scripts) $(dist_uninstalled_test_extra_scripts) $(dist_installed_test_extra_scripts)
181 all_test_scripts     += $(all_dist_test_scripts)
182 EXTRA_DIST           += $(all_dist_test_scripts)
183 all_test_data         = $(test_data) $(uninstalled_test_data) $(installed_test_data)
184 all_dist_test_data    = $(dist_test_data) $(dist_uninstalled_test_data) $(dist_installed_test_data)
185 all_test_data        += $(all_dist_test_data)
186 EXTRA_DIST           += $(all_dist_test_data)
187 all_test_ltlibs       = $(test_ltlibraries) $(uninstalled_test_ltlibraries) $(installed_test_ltlibraries)
188
189 if ENABLE_ALWAYS_BUILD_TESTS
190 noinst_LTLIBRARIES += $(all_test_ltlibs)
191 noinst_PROGRAMS += $(all_test_programs)
192 noinst_SCRIPTS += $(all_test_scripts)
193 noinst_DATA += $(all_test_data)
194 else
195 check_LTLIBRARIES += $(all_test_ltlibs)
196 check_PROGRAMS += $(all_test_programs)
197 check_SCRIPTS += $(all_test_scripts)
198 check_DATA += $(all_test_data)
199 endif
200
201 if ENABLE_INSTALLED_TESTS
202 installed_test_PROGRAMS += $(test_programs) $(installed_test_programs) \
203                           $(test_extra_programs) $(installed_test_extra_programs)
204 installed_test_SCRIPTS += $(test_scripts) $(installed_test_scripts) \
205                           $(test_extra_scripts) $(test_installed_extra_scripts)
206 installed_test_SCRIPTS += $(dist_test_scripts) $(dist_test_extra_scripts) \
207                           $(dist_installed_test_scripts) $(dist_installed_test_extra_scripts)
208 nobase_installed_test_DATA += $(test_data) $(installed_test_data)
209 nobase_installed_test_DATA += $(dist_test_data) $(dist_installed_test_data)
210 installed_test_LTLIBRARIES += $(test_ltlibraries) $(installed_test_ltlibraries)
211 installed_testcases = $(test_programs) $(installed_test_programs) \
212                       $(test_scripts) $(installed_test_scripts) \
213                       $(dist_test_scripts) $(dist_installed_test_scripts)
214
215 installed_test_meta_DATA = $(installed_testcases:=.test)
216
217 %.test: %$(EXEEXT) Makefile
218         $(AM_V_GEN) (echo '[Test]' > $@.tmp; \
219         echo 'Type=session' >> $@.tmp; \
220         echo 'Exec=$(installed_testdir)/$<' >> $@.tmp; \
221         mv $@.tmp $@)
222
223 CLEANFILES += $(installed_test_meta_DATA)
224 endif