check.mak: Set G_SLICE=always-malloc when valgrinding tests (closes #333272)
[platform/upstream/gst-common.git] / check.mak
1 clean-local-check:
2         for i in `find . -name ".libs" -type d`; do \
3           rm -rf $$i; \
4         done
5
6 if HAVE_VALGRIND
7 # hangs spectacularly on some machines, so let's not do this by default yet
8 check-valgrind:
9         make valgrind
10 else
11 check-valgrind:
12         @true
13 endif
14
15 LOOPS = 10
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         @$(TESTS_ENVIRONMENT)                                   \
21         CK_DEFAULT_TIMEOUT=20                                   \
22         $* ||                                                   \
23         $(TESTS_ENVIRONMENT)                                    \
24         GST_DEBUG=$$GST_DEBUG,*:2                               \
25         CK_DEFAULT_TIMEOUT=20                                   \
26         $*
27
28 # run any given test in a loop
29 %.torture: %
30         @for i in `seq 1 $(LOOPS)`; do                          \
31         $(TESTS_ENVIRONMENT)                                    \
32         CK_DEFAULT_TIMEOUT=20                                   \
33         $*; done
34
35 # run any given test in an infinite loop
36 %.forever: %
37         @while true; do                                         \
38         $(TESTS_ENVIRONMENT)                                    \
39         CK_DEFAULT_TIMEOUT=20                                   \
40         $* || break; done
41
42 # valgrind any given test by running make test.valgrind
43 %.valgrind: %
44         $(TESTS_ENVIRONMENT)                                    \
45         CK_DEFAULT_TIMEOUT=60                                   \
46         G_SLICE=always-malloc                                   \
47         libtool --mode=execute                                  \
48         $(VALGRIND_PATH) -q --suppressions=$(SUPPRESSIONS)      \
49         --tool=memcheck --leak-check=full --trace-children=yes  \
50         --leak-resolution=high --num-callers=20                 \
51         $* 2>&1 | tee valgrind.log
52         @if grep "==" valgrind.log > /dev/null 2>&1; then       \
53             rm valgrind.log;                                    \
54             exit 1;                                             \
55         fi
56         @rm valgrind.log
57         
58 # valgrind any given test and generate suppressions for it
59 %.valgrind.gen-suppressions: %
60         $(TESTS_ENVIRONMENT)                                    \
61         CK_DEFAULT_TIMEOUT=60                                   \
62         libtool --mode=execute                                  \
63         $(VALGRIND_PATH) -q --suppressions=$(SUPPRESSIONS)      \
64         --tool=memcheck --leak-check=full --trace-children=yes  \
65         --leak-resolution=high --num-callers=20                 \
66         --gen-suppressions=all                                  \
67         $* 2>&1 | tee suppressions.log
68         
69 # valgrind any given test until failure by running make test.valgrind-forever
70 %.valgrind-forever: %
71         @while make $*.valgrind; do                             \
72           true; done
73
74 # gdb any given test by running make test.gdb
75 %.gdb: %
76         $(TESTS_ENVIRONMENT)                                    \
77         CK_FORK=no                                              \
78         libtool --mode=execute                                  \
79         gdb $*
80
81 # torture tests
82 torture: $(TESTS)
83         -rm test-registry.xml
84         @echo "Torturing tests ..."
85         for i in `seq 1 $(LOOPS)`; do                           \
86                 make check ||                                   \
87                 (echo "Failure after $$i runs"; exit 1) ||      \
88                 exit 1;                                         \
89         done
90         @banner="All $(LOOPS) loops passed";                    \
91         dashes=`echo "$$banner" | sed s/./=/g`;                 \
92         echo $$dashes; echo $$banner; echo $$dashes
93
94 # forever tests
95 forever: $(TESTS)
96         -rm test-registry.xml
97         @echo "Forever tests ..."
98         while true; do                                          \
99                 make check ||                                   \
100                 (echo "Failure"; exit 1) ||                     \
101                 exit 1;                                         \
102         done
103
104 # valgrind all tests
105 valgrind: $(TESTS)
106         @echo "Valgrinding tests ..."
107         @failed=0;                                                      \
108         for t in $(filter-out $(VALGRIND_TESTS_DISABLE),$(TESTS)); do   \
109                 make $$t.valgrind;                                      \
110                 if test "$$?" -ne 0; then                               \
111                         echo "Valgrind error for test $$t";             \
112                         failed=`expr $$failed + 1`;                     \
113                         whicht="$$whicht $$t";                          \
114                 fi;                                                     \
115         done;                                                           \
116         if test "$$failed" -ne 0; then                                  \
117                 echo "$$failed tests had leaks or errors under valgrind:";      \
118                 echo "$$whicht";                                        \
119                 false;                                                  \
120         fi
121
122 help:
123         @echo "make check                         -- run all checks"
124         @echo "make torture                       -- run all checks $(LOOPS) times"
125         @echo "make (dir)/(test).check            -- run the given check once"
126         @echo "make (dir)/(test).forever          -- run the given check forever"
127         @echo "make (dir)/(test).torture          -- run the given check $(LOOPS) times"
128         @echo
129         @echo "make (dir)/(test).gdb              -- start up gdb for the given test"
130         @echo
131         @echo "make valgrind                      -- valgrind all tests"
132         @echo "make (dir)/(test).valgrind         -- valgrind the given test"
133         @echo "make (dir)/(test).valgrind-forever -- valgrind the given test forever"