license
[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.h unittests.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) *.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.o
20 test_encode1: test_encode1.o pb_encode.o person.o
21 decode_unittests: decode_unittests.o pb_decode.o person.o
22 encode_unittests: encode_unittests.o pb_encode.o person.o
23
24 person.c person.h: person.proto
25         protoc -I. -I../generator -I/usr/include -operson.pb $<
26         python ../generator/nanopb_generator.py person.pb
27
28 breakpoints: ../*.c *.c
29         grep -n 'return false;' $^ | cut -d: -f-2 | xargs -n 1 echo b > $@
30
31 coverage: run_unittests
32         gcov pb_encode.gcda
33         gcov pb_decode.gcda
34
35 run_unittests: decode_unittests encode_unittests test_encode1 test_decode1
36         rm -f *.gcda
37         
38         ./decode_unittests > /dev/null
39         ./encode_unittests > /dev/null
40         
41         [ "`./test_encode1 | ./test_decode1`" = \
42         "`./test_encode1 | protoc --decode=Person -I. -I../generator -I/usr/include person.proto`" ]
43
44 run_fuzztest: test_decode1
45         bash -c 'I=1; while cat /dev/urandom | ./test_decode1 > /dev/null; do I=$$(($$I+1)); echo -en "\r$$I"; done'