m4: update comment from 0.10 to 1.0
[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 any given test until failure by running make test.valgrind-forever
78 %.valgrind-forever: %
79         @while $(MAKE) $*.valgrind; do                          \
80           true; done
81
82 # gdb any given test by running make test.gdb
83 %.gdb: %
84         @$(TESTS_ENVIRONMENT)                                   \
85         CK_FORK=no                                              \
86         $(LIBTOOL) --mode=execute                               \
87         gdb $*
88
89 # torture tests
90 torture: $(TESTS)
91         -rm test-registry.xml
92         @echo "Torturing tests ..."
93         @for i in `seq 1 $(LOOPS)`; do                          \
94                 $(MAKE) check ||                                \
95                 (echo "Failure after $$i runs"; exit 1) ||      \
96                 exit 1;                                         \
97         done
98         @banner="All $(LOOPS) loops passed";                    \
99         dashes=`echo "$$banner" | sed s/./=/g`;                 \
100         echo $$dashes; echo $$banner; echo $$dashes
101
102 # forever tests
103 forever: $(TESTS)
104         -rm test-registry.xml
105         @echo "Forever tests ..."
106         @while true; do                                         \
107                 $(MAKE) check ||                                \
108                 (echo "Failure"; exit 1) ||                     \
109                 exit 1;                                         \
110         done
111
112 # valgrind all tests
113 valgrind: $(TESTS)
114         @echo "Valgrinding tests ..."
115         @failed=0;                                                      \
116         for t in $(filter-out $(VALGRIND_TESTS_DISABLE),$(TESTS)); do   \
117                 $(MAKE) $$t.valgrind;                                   \
118                 if test "$$?" -ne 0; then                               \
119                         echo "Valgrind error for test $$t";             \
120                         failed=`expr $$failed + 1`;                     \
121                         whicht="$$whicht $$t";                          \
122                 fi;                                                     \
123         done;                                                           \
124         if test "$$failed" -ne 0; then                                  \
125                 echo "$$failed tests had leaks or errors under valgrind:";      \
126                 echo "$$whicht";                                        \
127                 false;                                                  \
128         fi
129
130 # valgrind all tests and generate suppressions
131 valgrind.gen-suppressions: $(TESTS)
132         @echo "Valgrinding tests ..."
133         @failed=0;                                                      \
134         for t in $(filter-out $(VALGRIND_TESTS_DISABLE),$(TESTS)); do   \
135                 $(MAKE) $$t.valgrind.gen-suppressions;                  \
136                 if test "$$?" -ne 0; then                               \
137                         echo "Valgrind error for test $$t";             \
138                         failed=`expr $$failed + 1`;                     \
139                         whicht="$$whicht $$t";                          \
140                 fi;                                                     \
141         done;                                                           \
142         if test "$$failed" -ne 0; then                                  \
143                 echo "$$failed tests had leaks or errors under valgrind:";      \
144                 echo "$$whicht";                                        \
145                 false;                                                  \
146         fi
147
148 # inspect every plugin feature
149 GST_INSPECT = $(GST_TOOLS_DIR)/gst-inspect-$(GST_API_VERSION)
150 inspect:
151         @echo "Inspecting features ..."
152         @for e in `$(TESTS_ENVIRONMENT) $(GST_INSPECT) | head -n -2     \
153           | cut -d: -f2`;                                               \
154           do echo Inspecting $$e;                                       \
155              $(GST_INSPECT) $$e > /dev/null 2>&1; done
156
157 help:
158         @echo
159         @echo "make check                         -- run all checks"
160         @echo "make torture                       -- run all checks $(LOOPS) times"
161         @echo "make (dir)/(test).check            -- run the given check once, repeat with GST_DEBUG=*:2 if it fails"
162         @echo "make (dir)/(test).check-norepeat   -- run the given check once, but don't run it again if it fails"
163         @echo "make (dir)/(test).forever          -- run the given check forever"
164         @echo "make (dir)/(test).torture          -- run the given check $(LOOPS) times"
165         @echo
166         @echo "make (dir)/(test).gdb              -- start up gdb for the given test"
167         @echo
168         @echo "make valgrind                      -- valgrind all tests"
169         @echo "make valgrind.gen-suppressions     -- generate suppressions for all tests"
170         @echo "                                      and save to suppressions.log"
171         @echo "make (dir)/(test).valgrind         -- valgrind the given test"
172         @echo "make (dir)/(test).valgrind-forever -- valgrind the given test forever"
173         @echo "make (dir)/(test).valgrind.gen-suppressions -- generate suppressions"
174         @echo "                                               and save to suppressions.log"
175         @echo "make inspect                       -- inspect all plugin features"
176         @echo
177         @echo
178         @echo "Additionally, you can use the GST_CHECKS environment variable to"
179         @echo "specify which test(s) should be run. This is useful if you are"
180         @echo "debugging a failure in one particular test, or want to reproduce"
181         @echo "a race condition in a single test."
182         @echo
183         @echo "Examples:"
184         @echo
185         @echo "  GST_CHECKS=test_this,test_that  make element/foobar.check"
186         @echo "  GST_CHECKS=test_many_threads    make element/foobar.forever"
187         @echo
188