Skip to content

Commit d3b32ca

Browse files
committed
unix: Add special function to improve coverage.
The function and corresponding command-line option are only enabled for the coverage build. They are used to exercise uPy features that can't be properly tested by Python scripts.
1 parent 0589c19 commit d3b32ca

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ script:
3535
- make -C unix CC=gcc-4.7 coverage
3636
- (cd tests && MICROPY_CPYTHON3=python3.4 MICROPY_MICROPYTHON=../unix/micropython_coverage ./run-tests)
3737
- (cd tests && MICROPY_CPYTHON3=python3.4 MICROPY_MICROPYTHON=../unix/micropython_coverage ./run-tests --emit native)
38+
# TODO the output of this extra coverage test is not checked
39+
- unix/micropython_coverage --coverage
3840

3941
after_success:
4042
- (cd unix && coveralls --root .. --build-root . --gcov $(which gcov-4.7) --gcov-options '\-o build-coverage/' --include py --include extmod)

unix/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ SRC_C = \
9494
file.c \
9595
modos.c \
9696
alloc.c \
97+
coverage.c \
9798
$(SRC_MOD)
9899

99100

@@ -133,9 +134,11 @@ minimal:
133134

134135
# build an interpreter for coverage testing and do the testing
135136
coverage:
136-
$(MAKE) COPT="-O0" CFLAGS_EXTRA='-fprofile-arcs -ftest-coverage -Wdouble-promotion -Wformat -Wmissing-declarations -Wmissing-prototypes -Wold-style-definition -Wpointer-arith -Wshadow -Wsign-compare -Wuninitialized -Wunused-parameter' LDFLAGS_EXTRA='-fprofile-arcs -ftest-coverage' BUILD=build-coverage PROG=micropython_coverage
137+
$(MAKE) COPT="-O0" CFLAGS_EXTRA='-fprofile-arcs -ftest-coverage -Wdouble-promotion -Wformat -Wmissing-declarations -Wmissing-prototypes -Wold-style-definition -Wpointer-arith -Wshadow -Wsign-compare -Wuninitialized -Wunused-parameter -DMICROPY_UNIX_COVERAGE' LDFLAGS_EXTRA='-fprofile-arcs -ftest-coverage' BUILD=build-coverage PROG=micropython_coverage
137138

138139
coverage_test: coverage
139140
$(eval DIRNAME=$(notdir $(CURDIR)))
140141
cd ../tests && MICROPY_MICROPYTHON=../$(DIRNAME)/micropython_coverage ./run-tests
142+
cd ../tests && MICROPY_MICROPYTHON=../$(DIRNAME)/micropython_coverage ./run-tests --emit native
141143
gcov -o build-coverage/py ../py/*.c
144+
gcov -o build-coverage/extmod ../extmod/*.c

unix/coverage.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <stdio.h>
2+
3+
#include "py/obj.h"
4+
#include "py/runtime.h"
5+
#include "py/repl.h"
6+
7+
#if defined(MICROPY_UNIX_COVERAGE)
8+
9+
// function to run extra tests for things that can't be checked by scripts
10+
void run_extra_coverage_tests(void);
11+
12+
void run_extra_coverage_tests(void) {
13+
// repl autocomplete
14+
{
15+
const char *str;
16+
mp_uint_t len = mp_repl_autocomplete("__", 2, &mp_plat_print, &str);
17+
printf("%.*s\n", (int)len, str);
18+
19+
mp_store_global(MP_QSTR_sys, mp_import_name(MP_QSTR_sys, mp_const_none, MP_OBJ_NEW_SMALL_INT(0)));
20+
mp_repl_autocomplete("sys.", 4, &mp_plat_print, &str);
21+
len = mp_repl_autocomplete("sys.impl", 8, &mp_plat_print, &str);
22+
printf("%.*s\n", (int)len, str);
23+
}
24+
}
25+
26+
#endif

unix/main.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,12 @@ int main(int argc, char **argv) {
434434
MP_STATE_VM(mp_optimise_value) = 0;
435435
for (char *p = argv[a] + 1; *p && *p == 'O'; p++, MP_STATE_VM(mp_optimise_value)++);
436436
}
437+
#if defined(MICROPY_UNIX_COVERAGE)
438+
} else if (strcmp(argv[a], "--coverage") == 0) {
439+
void run_extra_coverage_tests(void);
440+
run_extra_coverage_tests();
441+
ret = 0;
442+
#endif
437443
} else {
438444
return usage(argv);
439445
}

0 commit comments

Comments
 (0)