5035af8fdb5e8a49a0bd3531ea7c0705ab9fbee3
[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 unittests.h unittestproto.pb.h
4 TESTS=test_decode1 test_encode1 decode_unittests encode_unittests
5
6 all: $(TESTS) run_unittests breakpoints
7
8 clean:
9         rm -f $(TESTS) person.pb* *.o *.gcda *.gcno
10
11 %.o: %.c $(DEPS)
12         $(CC) $(CFLAGS) -c -o $@ $<
13
14 pb_encode.o: ../pb_encode.c $(DEPS)
15         $(CC) $(CFLAGS) -c -o $@ $<
16 pb_decode.o: ../pb_decode.c $(DEPS)
17         $(CC) $(CFLAGS) -c -o $@ $<
18
19 test_decode1: test_decode1.o pb_decode.o person.pb.o
20 test_encode1: test_encode1.o pb_encode.o person.pb.o
21 decode_unittests: decode_unittests.o pb_decode.o unittestproto.pb.o
22 encode_unittests: encode_unittests.o pb_encode.o unittestproto.pb.o
23
24 %.pb: %.proto
25         protoc -I. -I../generator -I/usr/include -o$@ $<
26
27 %.pb.c %.pb.h: %.pb
28         python ../generator/nanopb_generator.py $<
29
30 breakpoints: ../*.c *.c
31         grep -n 'return false;' $^ | cut -d: -f-2 | xargs -n 1 echo b > $@
32
33 coverage: run_unittests
34         gcov pb_encode.gcda
35         gcov pb_decode.gcda
36
37 run_unittests: decode_unittests encode_unittests test_encode1 test_decode1
38         rm -f *.gcda
39         
40         ./decode_unittests > /dev/null
41         ./encode_unittests > /dev/null
42         
43         [ "`./test_encode1 | ./test_decode1`" = \
44         "`./test_encode1 | protoc --decode=Person -I. -I../generator -I/usr/include person.proto`" ]
45
46 run_fuzztest: test_decode1
47         bash -c 'I=1; while cat /dev/urandom | ./test_decode1 > /dev/null; do I=$$(($$I+1)); echo -en "\r$$I"; done'