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