Browse Source

Add gcov test coverage suppport

Yann Weber 1 year ago
parent
commit
65d2bd32b1
5 changed files with 42 additions and 7 deletions
  1. 6
    0
      .gitignore
  2. 29
    2
      Makefile
  3. 4
    4
      tests/Makefile
  4. 0
    1
      tests/pyrpn.so
  5. 3
    0
      tests/tests_rpniter.py

+ 6
- 0
.gitignore View File

@@ -0,0 +1,6 @@
1
+*.o
2
+*.so
3
+*.gcda
4
+*.gcno
5
+lcov.info
6
+lcov_html

+ 29
- 2
Makefile View File

@@ -27,6 +27,14 @@ ASM_OBJS=$(patsubst %.asm,%.o,$(ASM_SOURCES))
27 27
 OBJS=$(ASM_OBJS) $(C_OBJS)
28 28
 LIB=pyrpn.so
29 29
 
30
+CFLAGS_COV=$(CFLAGS) --coverage
31
+LDFLAGS_COV=$(LDFLAGS)
32
+C_OBJS_COV=$(patsubst %.c,%_cov.o,$(C_SOURCES))
33
+C_GCNO=$(patsubst %.o,%.gcno,$(C_OBJS_COV))
34
+C_GCDA=$(patsubst %.o,%.gcda,$(C_OBJS_COV))
35
+OBJS_COV=$(ASM_OBJS) $(C_OBJS_COV)
36
+LIB_COV=tests/pyrpn.so
37
+
30 38
 all: .deps pyrpn.so
31 39
 
32 40
 $(C_OBJS): %.o: %.c $(HEADERS)
@@ -38,6 +46,14 @@ $(ASM_OBJS): %.o: %.asm $(HEADERS)
38 46
 $(LIB): $(OBJS)
39 47
 	$(LD) $(LDFLAGS) $(PYTHON_LDFLAGS) -o $@ $^
40 48
 
49
+
50
+$(C_OBJS_COV): %_cov.o: %.c $(HEADERS)
51
+	$(CC) $(PYTHON_CFLAGS) $(CFLAGS_COV) -c -o $@ $<
52
+
53
+$(LIB_COV): $(OBJS_COV)
54
+	gcc $(LDFLAGS_COV) $(PYTHON_LDFLAGS) -o $@ $^ --coverage -lgcov
55
+
56
+
41 57
 # Doxygen documentation
42 58
 doc: doc/.doxygen.stamp
43 59
 
@@ -63,8 +79,18 @@ benchmark: $(LIB)
63 79
 		PYTHONPATH=`pwd` $(PYTHON) tests/benchmark.py 0x500 0x4000;
64 80
 		   
65 81
 
66
-unittest: $(LIB)
67
-	PYTHONPATH=`pwd` $(PYTHON) -m unittest -v -f
82
+unittest: $(LIB_COV)
83
+	cd tests;\
84
+		$(PYTHON) -m unittest -v -f
85
+
86
+lcov.info: unittest runtest
87
+	lcov --no-external --base-directory ./ --capture --directory ./ --output-file $@
88
+
89
+lcov_html: lcov.info
90
+	genhtml $< --output-directory $@
91
+
92
+coverage: lcov_html
93
+
68 94
 
69 95
 runtest:
70 96
 	make -C tests
@@ -72,6 +98,7 @@ runtest:
72 98
 clean:
73 99
 	-rm -fv $(OBJS) $(LIB) test;\
74 100
 	rm -fRv doc/.doxygen.stamp doc/* Doxyfile;\
101
+	rm -fRv $(OBJS_COV) $(C_GCNO) $(C_GCDA) $(LIB_COV) lcov_html lcov.info;\
75 102
 	make -C tests clean
76 103
 
77 104
 distclean: clean

+ 4
- 4
tests/Makefile View File

@@ -11,13 +11,13 @@ checks: $(BINARIES) $(SOURCES)
11 11
 	for test_bin in $(BINARIES); do echo "Running $${test_bin}.c"; ./$$test_bin && echo "OK" || echo "fail"; done
12 12
 
13 13
 ../%.o:
14
-	make -C ..
14
+	$(MAKE) -C .. `basename "$@"`
15 15
 
16 16
 %.o: %.c
17
-	$(CC) -I.. $(CFLAGS) -c -o $@ $<
17
+	$(CC) -I .. $(CFLAGS) -c -o $@ $<
18 18
 
19
-test_%: test_%.o ../rpn_lib.o ../rpn_jit.o ../rpn_parse.o ../rpn_if.o ../rpn_if_default.o
20
-	$(CC) -I..  $(CFLAGS) -o $@ $^
19
+test_rpn: test_rpn.o ../rpn_lib.o ../rpn_jit_cov.o ../rpn_parse_cov.o ../rpn_if_cov.o ../rpn_if_default_cov.o
20
+	$(CC) -I..  $(CFLAGS) -o $@ $^ -lgcov
21 21
 	
22 22
 .PHONY: clean
23 23
 

+ 0
- 1
tests/pyrpn.so View File

@@ -1 +0,0 @@
1
-../pyrpn.so

+ 3
- 0
tests/tests_rpniter.py View File

@@ -154,6 +154,8 @@ class TestRPNIterInit(unittest.TestCase):
154 154
                  [pyrpn.const.POS_XY, pyrpn.const.RESULT_CONST_RGBA, (640,480), (255,0,0,255)],
155 155
                  [pyrpn.const.POS_LINEAR, pyrpn.const.RESULT_RGBA, (1024,)],
156 156
                  [pyrpn.const.POS_XDIM, pyrpn.const.RESULT_RGB, (4, 2, 2, 640, 480)],
157
+                 [pyrpn.const.POS_XY, pyrpn.const.RESULT_CONST, (1024,512),
158
+                     (2,)],
157 159
         ]
158 160
         for args in tests:
159 161
             rif = pyrpn.RPNIterExpr(*args)
@@ -166,6 +168,7 @@ class TestRPNIterInit(unittest.TestCase):
166 168
                 expr = pyrpn.RPNExpr(codes[key], argc)
167 169
                 with self.subTest(rif=rif, key=key, orig=orig, clone=expr):
168 170
                     self.assertEqual(orig, expr)
171
+            str_repr = repr(rif)
169 172
 
170 173
 
171 174
 if __name__ == '__main__':

Loading…
Cancel
Save