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