check.mak: fix 'make check-valgrind'
[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 # run any given test in a loop
28 %.torture: %
29         @for i in `seq 1 $(LOOPS)`; do                          \
30         $(TESTS_ENVIRONMENT)                                    \
31         CK_DEFAULT_TIMEOUT=20                                   \
32         $*; done
33
34 # run any given test in an infinite loop
35 %.forever: %
36         @while true; do                                         \
37         $(TESTS_ENVIRONMENT)                                    \
38         CK_DEFAULT_TIMEOUT=20                                   \
39         $* || break; done
40
41 # valgrind any given test by running make test.valgrind
42 %.valgrind: %
43         @$(TESTS_ENVIRONMENT)                                   \
44         CK_DEFAULT_TIMEOUT=360                                  \
45         G_SLICE=always-malloc                                   \
46         $(LIBTOOL) --mode=execute                               \
47         $(VALGRIND_PATH) -q                                     \
48         $(foreach s,$(SUPPRESSIONS),--suppressions=$(s))        \
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=360                                  \
62         G_SLICE=always-malloc                                   \
63         $(LIBTOOL) --mode=execute                               \
64         $(VALGRIND_PATH) -q                                     \
65         $(foreach s,$(SUPPRESSIONS),--suppressions=$(s))        \
66         --tool=memcheck --leak-check=full --trace-children=yes  \
67         --leak-resolution=high --num-callers=20                 \
68         --gen-suppressions=all                                  \
69         ./$* 2>&1 | tee suppressions.log
70         
71 # valgrind any given test until failure by running make test.valgrind-forever
72 %.valgrind-forever: %
73         @while $(MAKE) $*.valgrind; do                          \
74           true; done
75
76 # gdb any given test by running make test.gdb
77 %.gdb: %
78         @$(TESTS_ENVIRONMENT)                                   \
79         CK_FORK=no                                              \
80         $(LIBTOOL) --mode=execute                               \
81         gdb $*
82
83 # torture tests
84 torture: $(TESTS)
85         -rm test-registry.xml
86         @echo "Torturing tests ..."
87         @for i in `seq 1 $(LOOPS)`; do                          \
88                 $(MAKE) check ||                                \
89                 (echo "Failure after $$i runs"; exit 1) ||      \
90                 exit 1;                                         \
91         done
92         @banner="All $(LOOPS) loops passed";                    \
93         dashes=`echo "$$banner" | sed s/./=/g`;                 \
94         echo $$dashes; echo $$banner; echo $$dashes
95
96 # forever tests
97 forever: $(TESTS)
98         -rm test-registry.xml
99         @echo "Forever tests ..."
100         @while true; do                                         \
101                 $(MAKE) check ||                                \
102                 (echo "Failure"; exit 1) ||                     \
103                 exit 1;                                         \
104         done
105
106 # valgrind all tests
107 valgrind: $(TESTS)
108         @echo "Valgrinding tests ..."
109         @failed=0;                                                      \
110         for t in $(filter-out $(VALGRIND_TESTS_DISABLE),$(TESTS)); do   \
111                 $(MAKE) $$t.valgrind;                                   \
112                 if test "$$?" -ne 0; then                               \
113                         echo "Valgrind error for test $$t";             \
114                         failed=`expr $$failed + 1`;                     \
115                         whicht="$$whicht $$t";                          \
116                 fi;                                                     \
117         done;                                                           \
118         if test "$$failed" -ne 0; then                                  \
119                 echo "$$failed tests had leaks or errors under valgrind:";      \
120                 echo "$$whicht";                                        \
121                 false;                                                  \
122         fi
123
124 # inspect every plugin feature
125 GST_INSPECT = $(GST_TOOLS_DIR)/gst-inspect-$(GST_MAJORMINOR)
126 inspect:
127         @echo "Inspecting features ..."
128         @for e in `$(TESTS_ENVIRONMENT) $(GST_INSPECT) | head -n -2     \
129           | cut -d: -f2`;                                               \
130           do echo Inspecting $$e;                                       \
131              $(GST_INSPECT) $$e > /dev/null 2>&1; done
132
133 help:
134         @echo
135         @echo "make check                         -- run all checks"
136         @echo "make torture                       -- run all checks $(LOOPS) times"
137         @echo "make (dir)/(test).check            -- run the given check once"
138         @echo "make (dir)/(test).forever          -- run the given check forever"
139         @echo "make (dir)/(test).torture          -- run the given check $(LOOPS) times"
140         @echo
141         @echo "make (dir)/(test).gdb              -- start up gdb for the given test"
142         @echo
143         @echo "make valgrind                      -- valgrind all tests"
144         @echo "make (dir)/(test).valgrind         -- valgrind the given test"
145         @echo "make (dir)/(test).valgrind-forever -- valgrind the given test forever"
146         @echo "make (dir)/(test).valgrind.gen-suppressions -- generate suppressions"
147         @echo "                                               and save to suppressions.log"
148         @echo "make inspect                       -- inspect all plugin features"
149         @echo
150         @echo
151         @echo "Additionally, you can use the GST_CHECKS environment variable to"
152         @echo "specify which test(s) should be run. This is useful if you are"
153         @echo "debugging a failure in one particular test, or want to reproduce"
154         @echo "a race condition in a single test."
155         @echo
156         @echo "Examples:"
157         @echo
158         @echo "  GST_CHECKS=test_this,test_that  make element/foobar.check"
159         @echo "  GST_CHECKS=test_many_threads    make element/foobar.forever"
160         @echo
161