configure: rename BUILD_TESTS to ENABLE_RUNTIME_TESTS
[platform/upstream/libevdev.git] / test / Makefile.am
1 if ENABLE_RUNTIME_TESTS
2 build_tests = test-compile-pedantic test-link test-static-link
3 run_tests = test-libevdev test-kernel
4
5 .NOTPARALLEL:
6
7 noinst_PROGRAMS = $(run_tests) $(build_tests)
8
9 TESTS = $(run_tests)
10
11 libevdev_sources = $(top_srcdir)/libevdev/libevdev.c \
12                    $(top_srcdir)/libevdev/libevdev.h \
13                    $(top_srcdir)/libevdev/libevdev-names.c \
14                    $(top_srcdir)/libevdev/libevdev-uinput.h \
15                    $(top_srcdir)/libevdev/libevdev-uinput.c \
16                    $(top_srcdir)/libevdev/libevdev-uinput-int.h \
17                    $(top_srcdir)/libevdev/libevdev-util.h \
18                    $(top_srcdir)/libevdev/libevdev-int.h
19 common_sources = $(libevdev_sources) \
20                  test-common-uinput.c \
21                  test-common-uinput.h \
22                  test-common.c \
23                  test-common.h
24
25 # include builddir for event-names.h
26 AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/include -I$(top_builddir)/libevdev $(CHECK_CFLAGS) $(GCOV_CFLAGS)
27 AM_LDFLAGS = $(GCOV_LDFLAGS)
28
29 test_libevdev_SOURCES = \
30                         test-main.c \
31                         test-event-names.c \
32                         test-event-codes.c \
33                         test-libevdev-init.c \
34                         test-libevdev-has-event.c \
35                         test-int-queue.c \
36                         test-libevdev-events.c \
37                         test-uinput.c \
38                         $(common_sources)
39
40 test_libevdev_LDADD =  $(CHECK_LIBS)
41
42 test_compile_pedantic_SOURCES = test-compile-pedantic.c
43 test_compile_pedantic_CFLAGS = $(AM_CPPFLAGS) -pedantic -Werror -std=c90
44
45 test_link_SOURCES = test-link.c
46 test_link_CFLAGS = -I$(top_srcdir)
47 test_link_LDADD = $(top_builddir)/libevdev/libevdev.la
48
49 test_static_link_SOURCES = test-link.c
50 test_static_link_CFLAGS = -I$(top_srcdir)
51 test_static_link_LDADD = $(top_builddir)/libevdev/libevdev.la
52 test_static_link_LDFLAGS = $(AM_LDFLAGS) -static
53
54 test_kernel_SOURCES = \
55                       test-kernel.c \
56                       $(common_sources)
57 test_kernel_CFLAGS = -I$(top_srcdir)
58 test_kernel_LDADD = $(CHECK_LIBS)
59
60 check_local_deps =
61
62 if HAVE_VALGRIND
63 VALGRIND_FLAGS=--leak-check=full \
64                 --quiet \
65                 --error-exitcode=3 \
66                 --suppressions=$(srcdir)/valgrind.suppressions
67
68 valgrind:
69                 $(MAKE) check-TESTS LOG_COMPILER="$(VALGRIND)" LOG_FLAGS="$(VALGRIND_FLAGS)"
70
71 check_local_deps += valgrind
72
73 endif
74
75 EXTRA_DIST = valgrind.suppressions
76
77 if GCOV_ENABLED
78
79 CLEANFILES = gcov-report.txt
80
81 gcov-clean:
82         @rm -f *.gcov
83
84 gcov-report.txt: gcov-clean check-TESTS
85         $(AM_V_GEN)(rm -rf $@; \
86                 echo "========== coverage report ========" >> $@; \
87                 for file in `find $(top_srcdir)/libevdev -name "*.c" -printf "%P\n"`; do \
88                         gcov $$file > /dev/null; \
89                         if test -f $$file.gcov; then \
90                                 total=`grep -v " -:" $$file.gcov | wc -l`; \
91                                 missing=`grep "#####" $$file.gcov | wc -l`; \
92                                 hit=$$((total - missing)); \
93                                 echo -e "$$file: total lines: $$total not tested: $$missing ($$((($$hit * 100)/$$total))%)"; \
94                         fi \
95                 done >> $@; \
96                 echo "========== =============== ========" >> $@; \
97         )
98
99 gcov: gcov-report.txt
100         @cat gcov-report.txt
101
102 check_local_deps += gcov
103
104 else
105
106 gcov-report.txt:
107         @true
108
109 gcov:
110         @true
111
112 gcov-clean:
113         @true
114
115 endif
116
117 .PHONY: gcov gcov-clean gcov-report.txt
118
119 clean-local: gcov-clean
120         rm -f *.gcno *.gcda
121
122 if HAVE_NM
123 # Hack to check for leaking symbols in the static library.
124 # See https://bugs.freedesktop.org/show_bug.cgi?id=82785
125 # Note the spaces in the expressions! After the first grep, each line
126 # is " T symbol_name"
127 static-symbol-leaks: test-static-link
128         $(AM_V_GEN)(\
129                 $(NM) --extern-only $(builddir)/test-static-link | \
130                         grep -o -e " T .*" | \
131                         grep -v -e " main$$" \
132                                 -e " atexit" \
133                                 -e " *gcov.*" \
134                                 -e " _.*" \
135                                 -e " libevdev_*" && \
136                                 echo "Leaking symbols found" && \
137                                 exit 1 || exit 0 \
138         )
139
140 check_local_deps += static-symbol-leaks
141 endif
142
143 check-local: $(check_local_deps)
144 endif