Make "make -C test clean" idempotent
[platform/upstream/dbus.git] / test / Makefile.am
1 ## the "name-test" subdir in fact contains a bunch of tests now that need a temporary bus 
2 ## to be running to do stuff with. The directory should be renamed.
3 ## We want to build the current directory first to pick up the testutils lib
4 SUBDIRS= . name-test 
5 DIST_SUBDIRS=name-test
6
7 INCLUDES=-I$(top_srcdir) $(DBUS_TEST_CFLAGS) 
8
9 libdbus_testutils_la_SOURCES = test-utils.h test-utils.c
10
11 noinst_LTLIBRARIES = libdbus-testutils.la
12
13 if DBUS_BUILD_TESTS
14 ## break-loader removed for now
15 ## most of these binaries are used in tests but are not themselves tests
16 TEST_BINARIES = \
17         shell-test \
18         spawn-test \
19         test-exit \
20         test-names \
21         test-segfault \
22         test-service \
23         test-shell-service \
24         test-sleep-forever \
25         $(NULL)
26
27 ## these are the things to run in make check (i.e. they are actual tests)
28 ## (binaries in here must also be in TEST_BINARIES)
29 TESTS = \
30         shell-test \
31         $(NULL)
32
33 ## These are conceptually part of directories that come earlier in SUBDIRS
34 ## order, but we don't want to run them til we arrive in this directory,
35 ## since they depend on stuff from this directory
36 TESTS += \
37         ../bus/bus-test$(EXEEXT) \
38         ../bus/bus-test-system$(EXEEXT) \
39         ../dbus/dbus-test$(EXEEXT) \
40         $(NULL)
41
42 if DBUS_UNIX
43 TESTS += ../bus/bus-test-launch-helper$(EXEEXT)
44 endif
45
46 else !DBUS_BUILD_TESTS
47
48 TEST_BINARIES=
49 TESTS=
50
51 endif !DBUS_BUILD_TESTS
52
53 noinst_PROGRAMS= $(TEST_BINARIES)
54
55 test_service_SOURCES=                           \
56         test-service.c
57
58 test_names_SOURCES=                             \
59         test-names.c
60
61 ##break_loader_SOURCES=                         \
62 ##      break-loader.c
63
64 test_shell_service_SOURCES =                    \
65         test-shell-service.c
66
67 shell_test_SOURCES=                             \
68         shell-test.c
69
70 spawn_test_SOURCES=                             \
71         spawn-test.c
72
73 test_exit_SOURCES =                             \
74         test-exit.c
75
76 test_segfault_SOURCES =                         \
77         test-segfault.c
78
79 test_sleep_forever_SOURCES =                    \
80         test-sleep-forever.c
81
82 # This assumes that most tests will be linked to libdbus-internal;
83 # tests linked to only the public libdbus have their own CPPFLAGS.
84 AM_CPPFLAGS=-DDBUS_STATIC_BUILD
85 TEST_LIBS=$(top_builddir)/dbus/libdbus-internal.la $(DBUS_TEST_LIBS)
86
87 test_service_LDADD=libdbus-testutils.la $(TEST_LIBS)
88 test_service_LDFLAGS=@R_DYNAMIC_LDFLAG@
89 test_names_LDADD=libdbus-testutils.la $(TEST_LIBS)
90 test_names_LDFLAGS=@R_DYNAMIC_LDFLAG@
91 ## break_loader_LDADD= $(TEST_LIBS)
92 ## break_loader_LDFLAGS=@R_DYNAMIC_LDFLAG@
93 test_shell_service_LDADD=libdbus-testutils.la $(TEST_LIBS)
94 test_shell_service_LDFLAGS=@R_DYNAMIC_LDFLAG@
95 shell_test_LDADD=libdbus-testutils.la $(TEST_LIBS)
96 shell_test_LDFLAGS=@R_DYNAMIC_LDFLAG@
97 spawn_test_LDADD=$(TEST_LIBS)
98 spawn_test_LDFLAGS=@R_DYNAMIC_LDFLAG@
99
100 test_refs_SOURCES = internals/refs.c
101 test_refs_CPPFLAGS = -DDBUS_STATIC_BUILD $(GLIB_CFLAGS)
102 test_refs_LDADD = libdbus-testutils.la $(GLIB_LIBS) $(TEST_LIBS)
103
104 EXTRA_DIST = dbus-test-runner
105
106 testexecdir = $(libdir)/dbus-1.0/test
107
108 testexec_PROGRAMS =
109
110 installable_tests = \
111         test-corrupt \
112         test-dbus-daemon \
113         test-loopback \
114         test-marshal \
115         test-refs \
116         test-relay \
117         $(NULL)
118
119 installcheck_tests =
120 installcheck_environment = \
121         DBUS_TEST_DAEMON=$(DESTDIR)$(DBUS_DAEMONDIR)/dbus-daemon$(EXEEXT) \
122         DBUS_TEST_SYSCONFDIR=$(DESTDIR)$(sysconfdir)
123
124 TESTS_ENVIRONMENT = \
125         DBUS_BLOCK_ON_ABORT=1 \
126         DBUS_FATAL_WARNINGS=1 \
127         DBUS_TEST_DAEMON=@abs_top_builddir@/bus/dbus-daemon$(EXEEXT) \
128         DBUS_TEST_DATA=@abs_top_builddir@/test/data \
129         DBUS_TEST_HOMEDIR=@abs_top_builddir@/dbus \
130         $(NULL)
131
132 test_corrupt_SOURCES = corrupt.c
133 test_corrupt_CPPFLAGS = $(GLIB_CFLAGS) $(DBUS_GLIB_CFLAGS)
134 test_corrupt_LDFLAGS = @R_DYNAMIC_LDFLAG@
135 test_corrupt_LDADD = $(top_builddir)/dbus/libdbus-1.la \
136     $(GLIB_LIBS) \
137     $(DBUS_GLIB_LIBS)
138
139 test_loopback_SOURCES = loopback.c
140 test_loopback_CPPFLAGS = $(GLIB_CFLAGS) $(DBUS_GLIB_CFLAGS)
141 test_loopback_LDFLAGS = @R_DYNAMIC_LDFLAG@
142 test_loopback_LDADD = $(top_builddir)/dbus/libdbus-1.la \
143     $(GLIB_LIBS) \
144     $(DBUS_GLIB_LIBS)
145
146 test_relay_SOURCES = relay.c
147 test_relay_CPPFLAGS = $(GLIB_CFLAGS) $(DBUS_GLIB_CFLAGS)
148 test_relay_LDFLAGS = @R_DYNAMIC_LDFLAG@
149 test_relay_LDADD = $(top_builddir)/dbus/libdbus-1.la \
150     $(GLIB_LIBS) \
151     $(DBUS_GLIB_LIBS)
152
153 test_dbus_daemon_SOURCES = dbus-daemon.c
154 test_dbus_daemon_CPPFLAGS = $(GLIB_CFLAGS) $(DBUS_GLIB_CFLAGS)
155 test_dbus_daemon_LDFLAGS = @R_DYNAMIC_LDFLAG@
156 test_dbus_daemon_LDADD = $(top_builddir)/dbus/libdbus-1.la \
157     $(GLIB_LIBS) \
158     $(DBUS_GLIB_LIBS)
159
160 test_marshal_SOURCES = marshal.c
161 test_marshal_CPPFLAGS = $(GLIB_CFLAGS) $(DBUS_GLIB_CFLAGS)
162 test_marshal_LDFLAGS = @R_DYNAMIC_LDFLAG@
163 test_marshal_LDADD = $(top_builddir)/dbus/libdbus-1.la \
164     $(GLIB_LIBS) \
165     $(DBUS_GLIB_LIBS)
166
167 if DBUS_ENABLE_MODULAR_TESTS
168 TESTS += $(installable_tests)
169 installcheck_tests += $(installable_tests)
170
171 if DBUS_ENABLE_INSTALLED_TESTS
172   testexec_PROGRAMS += $(installable_tests)
173 else !DBUS_ENABLE_INSTALLED_TESTS
174   noinst_PROGRAMS += $(installable_tests)
175 endif !DBUS_ENABLE_INSTALLED_TESTS
176
177 endif DBUS_ENABLE_MODULAR_TESTS
178
179 # If we're installing the tests into a DESTDIR we can't run them
180 # again using the installed copy, because we don't know how to
181 # do a portable equivalent of setting LD_LIBRARY_PATH.
182 installcheck-local:
183         $(MAKE) check-TESTS TESTS='$$(installcheck_tests)' \
184                 TESTS_ENVIRONMENT='$$(installcheck_environment)'
185 if DBUS_ENABLE_INSTALLED_TESTS
186         test -n "$(DESTDIR)" || \
187         $(installcheck_environment) \
188                 $(srcdir)/dbus-test-runner \
189                 $(testexecdir) \
190                 $(testexec_PROGRAMS)
191 endif DBUS_ENABLE_INSTALLED_TESTS
192
193 ## keep these in creation order, i.e. uppermost dirs first 
194 TESTDIRS=                                       \
195         data                                    \
196         data/valid-messages                     \
197         data/invalid-messages                   \
198         data/incomplete-messages                \
199         data/auth                               \
200         data/sha-1                              \
201         data/valid-config-files                 \
202         data/valid-config-files-system          \
203         data/valid-config-files/basic.d         \
204         data/valid-config-files/session.d       \
205         data/valid-config-files/system.d        \
206         data/valid-service-files                \
207         data/valid-service-files-system         \
208         data/invalid-service-files-system       \
209         data/invalid-config-files               \
210         data/invalid-config-files-system        \
211         data/equiv-config-files                 \
212         data/equiv-config-files/basic           \
213         data/equiv-config-files/basic/basic.d   \
214         data/equiv-config-files/entities        \
215         data/equiv-config-files/entities/basic.d
216
217
218 FIND_TESTS=find . -type f -a \( -name "*.message" -o -name "*.message-raw" -o -name "*.auth-script" -o -name "*.sha1" -o -name "*.txt" -o -name "*.conf" -o -name "*.service" \)
219
220 dist-hook:
221         for D in $(TESTDIRS); do                                                \
222                 test -d $(distdir)/$$D || mkdir $(distdir)/$$D || exit 1 ;      \
223         done ;                                                                  \
224         FILES=`(cd $(srcdir) && $(FIND_TESTS) -o -name "*.in" -a -not -name Makefile.in | grep -Ev "(.svn|CVS)" )` ;                                    \
225         for F in $$FILES; do                                                    \
226                 B=`basename $$F`; \
227                 if test -e $$F.in; then \
228                         echo "-- Skipping file $$F (.in version exists)"; \
229                 elif test "x$$B" = xrun-with-tmp-session-bus.conf; then \
230                         echo "-- Skipping file $$F (generated)"; \
231                 elif test -e "$(top_srcdir)/bus/$$B"; then \
232                         echo "-- Skipping file $$F (from /bus/)"; \
233                 else \
234                         echo '-- Disting file '$$F ; \
235                         cp -f $(srcdir)/$$F $(distdir)/$$F || exit 1; \
236                 fi; \
237         done
238
239 ## copy tests to builddir so that generated tests and static tests 
240 ## are all in one place.
241 all-local:
242         $(AM_V_at)for D in $(TESTDIRS); do                                                              \
243                 test -d $(top_builddir)/test/$$D || mkdir $(top_builddir)/test/$$D || exit 1 ;  \
244         done ;                                                                                  \
245         if ! (test $(srcdir) = . || test $(srcdir) -ef .) ; then                                                                \
246                 FILES=`(cd $(srcdir) && $(FIND_TESTS) | grep -Ev "(.svn|CVS)" )` ;                                      \
247                 for F in $$FILES; do                                                            \
248                         SRC=$(srcdir)/$$F ;                                                     \
249                         DEST=$(top_builddir)/test/$$F ;                                         \
250                         echo '-- Copying test file '$$F ;                                       \
251                         cp $$SRC $$DEST || exit 1 ;                                             \
252                         chmod u+w $$DEST || exit 1 ;                                            \
253                 done ;                                                                          \
254         else                                                                                    \
255                 echo '-- No need to copy test data as srcdir = builddir' ;                      \
256         fi ;                                                                                    \
257         echo '-- Copying' $(top_builddir)/bus/*.conf 'to test directory' ;                      \
258         cp $(top_builddir)/bus/*.conf $(top_builddir)/test/data/valid-config-files || exit 1 ;  \
259         chmod u+w $(top_builddir)/test/data/valid-config-files/*.conf || exit 1
260
261 ## this doesn't clean generated test data files when srcdir=builddir
262 clean-local:
263         if test $(srcdir) != . ; then                                   \
264                 FILES=`(cd $(top_builddir)/test && $(FIND_TESTS) | grep -Ev "(.svn|CVS)" )` ;   \
265                 for F in $$FILES; do                                    \
266                         DEST=$(top_builddir)/test/$$F ;                 \
267                         echo '-- Deleting test file '$$F ;              \
268                         rm $$DEST || exit 1 ;                           \
269                 done ;                                                  \
270                 REVERSEDIRS= ;                                          \
271                 for D in $(TESTDIRS); do                                \
272                         REVERSEDIRS="$$D $$REVERSEDIRS" ;               \
273                 done ;                                                  \
274                 for D in $$REVERSEDIRS; do                              \
275                         rmdir $(top_builddir)/test/$$D ||               \
276                                 test ! -d $(top_builddir)/test/$$D ||   \
277                                 exit 1 ;        \
278                 done ;                                                  \
279         fi