1# keep target around, since it's referenced in the modules' Makefiles
2clean-local-check:
3	@echo
4
5if HAVE_VALGRIND
6# hangs spectacularly on some machines, so let's not do this by default yet
7check-valgrind:
8	$(MAKE) valgrind
9else
10check-valgrind:
11	@true
12endif
13
14LOOPS ?= 10
15AM_TESTS_ENVIRONMENT = CK_DEFAULT_TIMEOUT=20
16
17# run any given test by running make test.check
18# if the test fails, run it again at at least debug level 2
19%.check: %
20	@$(AM_TESTS_ENVIRONMENT)					\
21	$* ||							\
22	$(AM_TESTS_ENVIRONMENT)					\
23	GST_DEBUG=$$GST_DEBUG,*:2				\
24	$*
25
26# just like 'check', but don't run it again if it fails (useful for debugging)
27%.check-norepeat: %
28	@$(AM_TESTS_ENVIRONMENT)					\
29	$*
30
31# run any given test in a loop
32%.torture: %
33	@for i in `seq 1 $(LOOPS)`; do				\
34	$(AM_TESTS_ENVIRONMENT)					\
35	$*; done
36
37# run any given test in an infinite loop
38%.forever: %
39	@while true; do						\
40	$(AM_TESTS_ENVIRONMENT)					\
41	$* || break; done
42
43# valgrind any given test by running make test.valgrind
44%.valgrind: %
45	@valgrind_log=$(subst /,-,$*-valgrind.log);		\
46	$(AM_TESTS_ENVIRONMENT)					\
47	CK_DEFAULT_TIMEOUT=360					\
48	G_SLICE=always-malloc					\
49	$(LIBTOOL) --mode=execute				\
50	$(VALGRIND_PATH) -q					\
51	$(foreach s,$(SUPPRESSIONS),--suppressions=$(s))	\
52	--tool=memcheck --leak-check=full --trace-children=yes	\
53	--show-possibly-lost=no                                 \
54	--leak-resolution=high --num-callers=20			\
55	./$* 2>&1 | tee $$valgrind_log ;			\
56	if grep "^==" $$valgrind_log > /dev/null 2>&1; then	\
57	    rm $$valgrind_log;					\
58	    exit 1;						\
59	fi ;							\
60	rm $$valgrind_log
61
62# valgrind any given test and generate suppressions for it
63%.valgrind.gen-suppressions: %
64	@$(AM_TESTS_ENVIRONMENT)					\
65	CK_DEFAULT_TIMEOUT=360					\
66	G_SLICE=always-malloc					\
67	$(LIBTOOL) --mode=execute				\
68	$(VALGRIND_PATH) -q 					\
69	$(foreach s,$(SUPPRESSIONS),--suppressions=$(s))	\
70	--tool=memcheck --leak-check=full --trace-children=yes	\
71	--show-possibly-lost=no                                 \
72	--leak-resolution=high --num-callers=20			\
73	--gen-suppressions=all					\
74	./$* 2>&1 | tee suppressions.log
75
76# valgrind torture any given test
77%.valgrind-torture: %
78	@for i in `seq 1 $(LOOPS)`; do				\
79		$(MAKE) $*.valgrind ||				\
80		(echo "Failure after $$i runs"; exit 1) ||	\
81		exit 1;						\
82	done
83	@banner="All $(LOOPS) loops passed";			\
84	dashes=`echo "$$banner" | sed s/./=/g`;			\
85	echo $$dashes; echo $$banner; echo $$dashes
86
87# valgrind any given test until failure by running make test.valgrind-forever
88%.valgrind-forever: %
89	@while $(MAKE) $*.valgrind; do				\
90	  true; done
91
92# gdb any given test by running make test.gdb
93%.gdb: %
94	@$(AM_TESTS_ENVIRONMENT)					\
95	CK_FORK=no						\
96	$(LIBTOOL) --mode=execute				\
97	gdb $(GDB_ARGS) $*
98
99%.gdb-forever: %
100	@while $(MAKE) GDB_ARGS="-ex run -ex quit" $*.gdb ; do	\
101	  sleep 1; done
102
103%.lcov-reset:
104	$(MAKE) $*.lcov-run
105	$(MAKE) $*.lcov-report
106
107%.lcov: %
108	$(MAKE) $*.lcov-reset
109
110if GST_GCOV_ENABLED
111%.lcov-clean:
112	$(MAKE) -C $(top_builddir) lcov-clean
113
114%.lcov-run:
115	$(MAKE) $*.lcov-clean
116	$(MAKE) $*.check
117
118%.lcov-report:
119	$(MAKE) -C $(top_builddir) lcov-report
120else
121%.lcov-run:
122	echo "Need to reconfigure with --enable-gcov"
123
124%.lcov-report:
125	echo "Need to reconfigure with --enable-gcov"
126endif
127
128# torture tests
129torture: $(TESTS)
130	-rm test-registry.*
131	@echo "Torturing tests ..."
132	@for i in `seq 1 $(LOOPS)`; do				\
133		$(MAKE) check ||				\
134		(echo "Failure after $$i runs"; exit 1) ||	\
135		exit 1;						\
136	done
137	@banner="All $(LOOPS) loops passed";			\
138	dashes=`echo "$$banner" | sed s/./=/g`;			\
139	echo $$dashes; echo $$banner; echo $$dashes
140
141# forever tests
142forever: $(TESTS)
143	-rm test-registry.*
144	@echo "Forever tests ..."
145	@while true; do						\
146		$(MAKE) check ||				\
147		(echo "Failure"; exit 1) ||			\
148		exit 1;						\
149	done
150
151# valgrind all tests
152valgrind: $(TESTS)
153	@echo "Valgrinding tests ..."
154	@failed=0; valgrind_targets="";					\
155	for t in $(filter-out $(VALGRIND_TESTS_DISABLE),$(TESTS)); do	\
156	  valgrind_targets="$$valgrind_targets $$t.valgrind";		\
157	done;								\
158	if ! $(MAKE) $$valgrind_targets ; then				\
159	  echo "Some tests had leaks or errors under valgrind";		\
160	  false;							\
161	fi
162
163# valgrind all tests until failure
164valgrind-forever: $(TESTS)
165	-rm test-registry.*
166	@echo "Forever valgrinding tests ..."
167	@while true; do						\
168		$(MAKE) valgrind ||				\
169		(echo "Failure"; exit 1) ||			\
170		exit 1;						\
171	done
172
173# valgrind torture all tests
174valgrind-torture: $(TESTS)
175	-rm test-registry.*
176	@echo "Torturing and valgrinding tests ..."
177	@for i in `seq 1 $(LOOPS)`; do				\
178		$(MAKE) valgrind ||				\
179		(echo "Failure after $$i runs"; exit 1) ||	\
180		exit 1;						\
181	done
182	@banner="All $(LOOPS) loops passed";			\
183	dashes=`echo "$$banner" | sed s/./=/g`;			\
184	echo $$dashes; echo $$banner; echo $$dashes
185
186# valgrind all tests and generate suppressions
187valgrind.gen-suppressions: $(TESTS)
188	@echo "Valgrinding tests ..."
189	@failed=0;							\
190	for t in $(filter-out $(VALGRIND_TESTS_DISABLE),$(TESTS)); do	\
191		$(MAKE) $$t.valgrind.gen-suppressions;			\
192		if test "$$?" -ne 0; then                               \
193			echo "Valgrind error for test $$t";		\
194			failed=`expr $$failed + 1`;			\
195			whicht="$$whicht $$t";				\
196		fi;							\
197	done;								\
198	if test "$$failed" -ne 0; then					\
199		echo "$$failed tests had leaks or errors under valgrind:";	\
200		echo "$$whicht";					\
201		false;							\
202	fi
203
204# inspect every plugin feature
205GST_INSPECT = $(GST_TOOLS_DIR)/gst-inspect-$(GST_API_VERSION)
206inspect:
207	@echo "Inspecting features ..."
208	@for e in `$(AM_TESTS_ENVIRONMENT) $(GST_INSPECT) | head -n -2 	\
209	  | cut -d: -f2`;						\
210	  do echo Inspecting $$e;					\
211	     $(GST_INSPECT) $$e > /dev/null 2>&1; done
212
213# build all tests
214build-checks: $(TESTS)
215
216help:
217	@echo
218	@echo "make check                         -- run all checks"
219	@echo "make torture                       -- run all checks $(LOOPS) times"
220	@echo "make (dir)/(test).check            -- run the given check once, repeat with GST_DEBUG=*:2 if it fails"
221	@echo "make (dir)/(test).check-norepeat   -- run the given check once, but don't run it again if it fails"
222	@echo "make (dir)/(test).forever          -- run the given check forever"
223	@echo "make (dir)/(test).torture          -- run the given check $(LOOPS) times"
224	@echo
225	@echo "make (dir)/(test).gdb              -- start up gdb for the given test"
226	@echo
227	@echo "make valgrind                      -- valgrind all tests"
228	@echo "make valgrind-forever              -- valgrind all tests forever"
229	@echo "make valgrind-torture              -- valgrind all tests $(LOOPS) times"
230	@echo "make valgrind.gen-suppressions     -- generate suppressions for all tests"
231	@echo "                                      and save to suppressions.log"
232	@echo "make (dir)/(test).valgrind         -- valgrind the given test"
233	@echo "make (dir)/(test).valgrind-forever -- valgrind the given test forever"
234	@echo "make (dir)/(test).valgrind-torture -- valgrind the given test $(LOOPS) times"
235	@echo "make (dir)/(test).valgrind.gen-suppressions -- generate suppressions"
236	@echo "                                               and save to suppressions.log"
237	@echo "make inspect                       -- inspect all plugin features"
238	@echo "make build-checks                  -- build all checks (but don't run them)"
239	@echo
240	@echo
241	@echo "Additionally, you can use the GST_CHECKS environment variable to"
242	@echo "specify which test(s) should be run. This is useful if you are"
243	@echo "debugging a failure in one particular test, or want to reproduce"
244	@echo "a race condition in a single test."
245	@echo
246	@echo "Examples:"
247	@echo
248	@echo "  GST_CHECKS=test_this,test_that  make element/foobar.check"
249	@echo "  GST_CHECKS=test_many_threads    make element/foobar.forever"
250	@echo
251
252