Skip to content

Commit d792d9e

Browse files
committed
unix: Make extra-coverage function callable from Python scripts.
This allows the output of the extra-coverage tests to be checked using the normal run-tests script.
1 parent d3b32ca commit d792d9e

File tree

5 files changed

+27
-12
lines changed

5 files changed

+27
-12
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ 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
4038

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

tests/unix/extra_coverage.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
try:
2+
extra_coverage
3+
except NameError:
4+
print("SKIP")
5+
import sys
6+
sys.exit()
7+
8+
extra_coverage()

tests/unix/extra_coverage.py.exp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ame__
2+
3+
__name__ path argv version
4+
version_info implementation platform byteorder
5+
maxsize exit stdin stdout
6+
stderr exc_info print_exception
7+
ementation

unix/coverage.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,21 @@
77
#if defined(MICROPY_UNIX_COVERAGE)
88

99
// 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) {
10+
STATIC mp_obj_t extra_coverage(void) {
1311
// repl autocomplete
1412
{
1513
const char *str;
16-
mp_uint_t len = mp_repl_autocomplete("__", 2, &mp_plat_print, &str);
14+
mp_uint_t len = mp_repl_autocomplete("__n", 3, &mp_plat_print, &str);
1715
printf("%.*s\n", (int)len, str);
1816

1917
mp_store_global(MP_QSTR_sys, mp_import_name(MP_QSTR_sys, mp_const_none, MP_OBJ_NEW_SMALL_INT(0)));
2018
mp_repl_autocomplete("sys.", 4, &mp_plat_print, &str);
2119
len = mp_repl_autocomplete("sys.impl", 8, &mp_plat_print, &str);
2220
printf("%.*s\n", (int)len, str);
2321
}
22+
23+
return mp_const_none;
2424
}
25+
MP_DEFINE_CONST_FUN_OBJ_0(extra_coverage_obj, extra_coverage);
2526

2627
#endif

unix/main.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,13 @@ int main(int argc, char **argv) {
356356

357357
mp_obj_list_init(mp_sys_argv, 0);
358358

359+
#if defined(MICROPY_UNIX_COVERAGE)
360+
{
361+
MP_DECLARE_CONST_FUN_OBJ(extra_coverage_obj);
362+
mp_store_global(QSTR_FROM_STR_STATIC("extra_coverage"), (mp_obj_t)&extra_coverage_obj);
363+
}
364+
#endif
365+
359366
// Here is some example code to create a class and instance of that class.
360367
// First is the Python, then the C code.
361368
//
@@ -434,12 +441,6 @@ int main(int argc, char **argv) {
434441
MP_STATE_VM(mp_optimise_value) = 0;
435442
for (char *p = argv[a] + 1; *p && *p == 'O'; p++, MP_STATE_VM(mp_optimise_value)++);
436443
}
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
443444
} else {
444445
return usage(argv);
445446
}

0 commit comments

Comments
 (0)