check.mak 7.57 KB
Newer Older
1
# keep target around, since it's referenced in the modules' Makefiles
2
clean-local-check:
3
	@echo
4 5 6

if HAVE_VALGRIND
# hangs spectacularly on some machines, so let's not do this by default yet
7
check-valgrind:
8
	$(MAKE) valgrind
9
else
10
check-valgrind:
11 12 13
	@true
endif

14
LOOPS ?= 10
15
AM_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 27
# just like 'check', but don't run it again if it fails (useful for debugging)
%.check-norepeat: %
28
	@$(AM_TESTS_ENVIRONMENT)					\
29 30
	$*

31 32 33
# run any given test in a loop
%.torture: %
	@for i in `seq 1 $(LOOPS)`; do				\
34
	$(AM_TESTS_ENVIRONMENT)					\
35 36 37 38 39
	$*; done

# run any given test in an infinite loop
%.forever: %
	@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 51
	$(VALGRIND_PATH) -q					\
	$(foreach s,$(SUPPRESSIONS),--suppressions=$(s))	\
52
	--tool=memcheck --leak-check=full --trace-children=yes	\
53
	--show-possibly-lost=no                                 \
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
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 60
	fi ;							\
	rm $$valgrind_log
61

62 63
# valgrind any given test and generate suppressions for it
%.valgrind.gen-suppressions: %
64
	@$(AM_TESTS_ENVIRONMENT)					\
65
	CK_DEFAULT_TIMEOUT=360					\
66
	G_SLICE=always-malloc					\
67
	$(LIBTOOL) --mode=execute				\
68 69
	$(VALGRIND_PATH) -q 					\
	$(foreach s,$(SUPPRESSIONS),--suppressions=$(s))	\
70
	--tool=memcheck --leak-check=full --trace-children=yes	\
71
	--show-possibly-lost=no                                 \
72 73
	--leak-resolution=high --num-callers=20			\
	--gen-suppressions=all					\
74
	./$* 2>&1 | tee suppressions.log
75

76 77 78 79 80 81 82 83 84 85 86
# valgrind torture any given test
%.valgrind-torture: %
	@for i in `seq 1 $(LOOPS)`; do				\
		$(MAKE) $*.valgrind ||				\
		(echo "Failure after $$i runs"; exit 1) ||	\
		exit 1;						\
	done
	@banner="All $(LOOPS) loops passed";			\
	dashes=`echo "$$banner" | sed s/./=/g`;			\
	echo $$dashes; echo $$banner; echo $$dashes

87 88
# valgrind any given test until failure by running make test.valgrind-forever
%.valgrind-forever: %
89
	@while $(MAKE) $*.valgrind; do				\
90 91
	  true; done

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 98 99 100 101
	gdb $(GDB_ARGS) $*

%.gdb-forever: %
	@while $(MAKE) GDB_ARGS="-ex run -ex quit" $*.gdb ; do	\
	  sleep 1; done
102

103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
%.lcov-reset:
	$(MAKE) $*.lcov-run
	$(MAKE) $*.lcov-report

%.lcov: %
	$(MAKE) $*.lcov-reset

if GST_GCOV_ENABLED
%.lcov-clean:
	$(MAKE) -C $(top_builddir) lcov-clean

%.lcov-run:
	$(MAKE) $*.lcov-clean
	$(MAKE) $*.check

%.lcov-report:
	$(MAKE) -C $(top_builddir) lcov-report
else
%.lcov-run:
	echo "Need to reconfigure with --enable-gcov"

%.lcov-report:
	echo "Need to reconfigure with --enable-gcov"
endif

128 129
# torture tests
torture: $(TESTS)
130
	-rm test-registry.*
131
	@echo "Torturing tests ..."
132 133
	@for i in `seq 1 $(LOOPS)`; do				\
		$(MAKE) check ||				\
134 135 136
		(echo "Failure after $$i runs"; exit 1) ||	\
		exit 1;						\
	done
137 138 139
	@banner="All $(LOOPS) loops passed";			\
	dashes=`echo "$$banner" | sed s/./=/g`;			\
	echo $$dashes; echo $$banner; echo $$dashes
140

141 142
# forever tests
forever: $(TESTS)
143
	-rm test-registry.*
144
	@echo "Forever tests ..."
145 146
	@while true; do						\
		$(MAKE) check ||				\
147 148 149 150
		(echo "Failure"; exit 1) ||			\
		exit 1;						\
	done

151
# valgrind all tests
152
valgrind: $(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 159 160
	if ! $(MAKE) $$valgrind_targets ; then				\
	  echo "Some tests had leaks or errors under valgrind";		\
	  false;							\
161
	fi
162

163 164
# valgrind all tests until failure
valgrind-forever: $(TESTS)
165
	-rm test-registry.*
166 167 168 169 170 171 172
	@echo "Forever valgrinding tests ..."
	@while true; do						\
		$(MAKE) valgrind ||				\
		(echo "Failure"; exit 1) ||			\
		exit 1;						\
	done

173 174
# valgrind torture all tests
valgrind-torture: $(TESTS)
175
	-rm test-registry.*
176 177 178 179 180 181 182 183 184 185
	@echo "Torturing and valgrinding tests ..."
	@for i in `seq 1 $(LOOPS)`; do				\
		$(MAKE) valgrind ||				\
		(echo "Failure after $$i runs"; exit 1) ||	\
		exit 1;						\
	done
	@banner="All $(LOOPS) loops passed";			\
	dashes=`echo "$$banner" | sed s/./=/g`;			\
	echo $$dashes; echo $$banner; echo $$dashes

186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
# valgrind all tests and generate suppressions
valgrind.gen-suppressions: $(TESTS)
	@echo "Valgrinding tests ..."
	@failed=0;							\
	for t in $(filter-out $(VALGRIND_TESTS_DISABLE),$(TESTS)); do	\
		$(MAKE) $$t.valgrind.gen-suppressions;			\
		if test "$$?" -ne 0; then                               \
			echo "Valgrind error for test $$t";		\
			failed=`expr $$failed + 1`;			\
			whicht="$$whicht $$t";				\
		fi;							\
	done;								\
	if test "$$failed" -ne 0; then					\
		echo "$$failed tests had leaks or errors under valgrind:";	\
		echo "$$whicht";					\
		false;							\
	fi

204
# inspect every plugin feature
205
GST_INSPECT = $(GST_TOOLS_DIR)/gst-inspect-$(GST_API_VERSION)
206 207
inspect:
	@echo "Inspecting features ..."
208
	@for e in `$(AM_TESTS_ENVIRONMENT) $(GST_INSPECT) | head -n -2 	\
209 210 211 212
	  | cut -d: -f2`;						\
	  do echo Inspecting $$e;					\
	     $(GST_INSPECT) $$e > /dev/null 2>&1; done

213 214 215
# build all tests
build-checks: $(TESTS)

216
help:
217
	@echo
218 219
	@echo "make check                         -- run all checks"
	@echo "make torture                       -- run all checks $(LOOPS) times"
220 221
	@echo "make (dir)/(test).check            -- run the given check once, repeat with GST_DEBUG=*:2 if it fails"
	@echo "make (dir)/(test).check-norepeat   -- run the given check once, but don't run it again if it fails"
222 223
	@echo "make (dir)/(test).forever          -- run the given check forever"
	@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 233
	@echo "make (dir)/(test).valgrind         -- valgrind the given test"
	@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 240 241 242 243 244 245 246 247 248 249 250
	@echo
	@echo
	@echo "Additionally, you can use the GST_CHECKS environment variable to"
	@echo "specify which test(s) should be run. This is useful if you are"
	@echo "debugging a failure in one particular test, or want to reproduce"
	@echo "a race condition in a single test."
	@echo
	@echo "Examples:"
	@echo
	@echo "  GST_CHECKS=test_this,test_that  make element/foobar.check"
	@echo "  GST_CHECKS=test_many_threads    make element/foobar.forever"
	@echo
251