0606212732d1ca33c355f4b29bca1d983aa6fb83
[apps/agl-service-can-low-level.git] / tests / Makefile
1 CFLAGS=-ansi -Wall -Werror -I .. -g -O0
2 DEPS=../pb_decode.h ../pb_encode.h ../pb.h person.pb.h callbacks2.pb.h callbacks.pb.h unittests.h unittestproto.pb.h alltypes.pb.h missing_fields.pb.h
3 TESTS=test_decode1 test_encode1 decode_unittests encode_unittests test_no_messages
4 TESTS=test_decode1 test_encode1 decode_unittests encode_unittests test_no_messages test_multiple_files
5
6
7 # More strict checks for the core part of nanopb
8 CC_VERSION=$(shell $(CC) -v 2>&1)
9 CFLAGS_CORE=
10 ifneq (,$(findstring gcc,$(CC_VERSION)))
11         CFLAGS_CORE=-pedantic -Wextra -Wcast-qual -Wlogical-op -Wconversion
12         CFLAGS+=--coverage
13         LDFLAGS+=--coverage
14 endif
15 ifneq (,$(findstring clang,$(CC_VERSION)))
16         CFLAGS_CORE=-pedantic -Wextra -Wcast-qual -Wconversion
17 endif
18
19 all: breakpoints $(TESTS) run_unittests
20
21 clean:
22         rm -f $(TESTS) person.pb* alltypes.pb* *.o *.gcda *.gcno
23
24 %.pb.o: %.pb.c %.pb.h
25         $(CC) $(CFLAGS) $(CFLAGS_CORE) -c -o $@ $<
26
27 %.o: %.c
28 %.o: %.c $(DEPS)
29         $(CC) $(CFLAGS) -c -o $@ $<
30
31 pb_encode.o: ../pb_encode.c $(DEPS)
32         $(CC) $(CFLAGS) $(CFLAGS_CORE) -c -o $@ $<
33 pb_decode.o: ../pb_decode.c $(DEPS)
34         $(CC) $(CFLAGS) $(CFLAGS_CORE) -c -o $@ $<
35
36 pb_encode.cxx.o: ../pb_encode.c $(DEPS)
37         $(CXX) $(CFLAGS) $(CFLAGS_CORE) -c -o $@ $<
38 pb_decode.cxx.o: ../pb_decode.c $(DEPS)
39         $(CXX) $(CFLAGS) $(CFLAGS_CORE) -c -o $@ $<
40
41 test_cxxcompile: pb_encode.cxx.o pb_decode.cxx.o
42 test_decode1: test_decode1.o pb_decode.o person.pb.o
43 test_decode2: test_decode2.o pb_decode.o person.pb.o
44 test_decode3: test_decode3.o pb_decode.o alltypes.pb.o
45 test_encode1: test_encode1.o pb_encode.o person.pb.o
46 test_encode2: test_encode2.o pb_encode.o person.pb.o
47 test_encode3: test_encode3.o pb_encode.o alltypes.pb.o
48 test_multiple_files: test_multiple_files.o pb_encode.o callbacks2.pb.o callbacks.pb.o
49 test_decode_callbacks: test_decode_callbacks.o pb_decode.o callbacks.pb.o
50 test_encode_callbacks: test_encode_callbacks.o pb_encode.o callbacks.pb.o
51 test_missing_fields: test_missing_fields.o pb_encode.o pb_decode.o missing_fields.pb.o
52 decode_unittests: decode_unittests.o pb_decode.o unittestproto.pb.o
53 encode_unittests: encode_unittests.o pb_encode.o unittestproto.pb.o
54 test_no_messages: no_messages.pb.h no_messages.pb.c no_messages.pb.o
55
56 %.pb: %.proto
57         protoc -I. -I../generator -I/usr/include -o$@ $<
58
59 %.pb.c %.pb.h: %.pb ../generator/nanopb_generator.py
60         python ../generator/nanopb_generator.py $<
61
62 breakpoints: ../*.c *.c
63         grep -n 'return false;' $^ | cut -d: -f-2 | xargs -n 1 echo b > $@
64
65 coverage: run_unittests
66         gcov pb_encode.gcda
67         gcov pb_decode.gcda
68
69 run_unittests: decode_unittests encode_unittests test_cxxcompile test_multiple_files test_encode1 test_encode2 test_encode3 test_decode1 test_decode2 test_decode3 test_encode_callbacks test_decode_callbacks test_missing_fields test_options
70         rm -f *.gcda
71         
72         ./decode_unittests > /dev/null
73         ./encode_unittests > /dev/null
74         
75         [ "`./test_encode1 | ./test_decode1`" = \
76         "`./test_encode1 | protoc --decode=Person -I. -I../generator -I/usr/include person.proto`" ]
77
78         [ "`./test_encode2 | ./test_decode1`" = \
79         "`./test_encode2 | protoc --decode=Person -I. -I../generator -I/usr/include person.proto`" ]
80
81         [ "`./test_encode2 | ./test_decode2`" = \
82         "`./test_encode2 | protoc --decode=Person -I. -I../generator -I/usr/include person.proto`" ]
83         
84         [ "`./test_decode2 < person_with_extra_field.pb`" = \
85         "`./test_encode2 | ./test_decode2`" ]
86         
87         [ "`./test_encode_callbacks | ./test_decode_callbacks`" = \
88         "`./test_encode_callbacks | protoc --decode=TestMessage callbacks.proto`" ]
89
90         ./test_encode3 | ./test_decode3
91         ./test_encode3 1 | ./test_decode3 1
92         ./test_encode3 1 | protoc --decode=AllTypes -I. -I../generator -I/usr/include alltypes.proto >/dev/null
93         
94         ./test_missing_fields
95
96 test_options: options.pb.h options.expected options.pb.o
97         cat options.expected | while read -r p; do \
98             if ! grep -q "$$p" $<; then \
99                 echo Expected: "$$p"; \
100                 exit 1; \
101             fi \
102         done
103
104 run_fuzztest: test_decode2
105         bash -c 'I=1; while true; do cat /dev/urandom | ./test_decode2 > /dev/null; I=$$(($$I+1)); echo -en "\r$$I"; done'