From 75aa7befec5d3afce2c5a970d8644299d367f6fe Mon Sep 17 00:00:00 2001 From: Rami Ali Date: Thu, 29 Dec 2016 18:07:38 +1100 Subject: tests/unix: Improve runtime_utils.c test coverage. --- unix/coverage.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'unix/coverage.c') diff --git a/unix/coverage.c b/unix/coverage.c index 6a1b43fdc..2abfc870f 100644 --- a/unix/coverage.c +++ b/unix/coverage.c @@ -5,6 +5,7 @@ #include "py/runtime.h" #include "py/repl.h" #include "py/mpz.h" +#include "py/builtin.h" #if defined(MICROPY_UNIX_COVERAGE) @@ -114,6 +115,21 @@ STATIC mp_obj_t extra_coverage(void) { mp_printf(&mp_plat_print, "%d\n", mpz_as_uint_checked(&mpz, &value)); } + // runtime utils + { + mp_printf(&mp_plat_print, "# runtime utils\n"); + + // call mp_call_function_1_protected + mp_call_function_1_protected(MP_OBJ_FROM_PTR(&mp_builtin_abs_obj), MP_OBJ_NEW_SMALL_INT(1)); + // call mp_call_function_1_protected with invalid args + mp_call_function_1_protected(MP_OBJ_FROM_PTR(&mp_builtin_abs_obj), mp_obj_new_str("abc", 3, false)); + + // call mp_call_function_2_protected + mp_call_function_2_protected(MP_OBJ_FROM_PTR(&mp_builtin_divmod_obj), MP_OBJ_NEW_SMALL_INT(1), MP_OBJ_NEW_SMALL_INT(1)); + // call mp_call_function_2_protected with invalid args + mp_call_function_2_protected(MP_OBJ_FROM_PTR(&mp_builtin_divmod_obj), mp_obj_new_str("abc", 3, false), mp_obj_new_str("abc", 3, false)); + } + // return a tuple of data for testing on the Python side mp_obj_t items[] = {(mp_obj_t)&str_no_hash_obj, (mp_obj_t)&bytes_no_hash_obj}; return mp_obj_new_tuple(MP_ARRAY_SIZE(items), items); -- cgit v1.2.3 From ec72db8a398f82fb694dc01c7081232286e72c3f Mon Sep 17 00:00:00 2001 From: Rami Ali Date: Wed, 4 Jan 2017 14:23:29 +1100 Subject: tests: Improve warning.c test coverage. --- tests/unix/extra_coverage.py.exp | 1 + unix/coverage.c | 6 ++++++ 2 files changed, 7 insertions(+) (limited to 'unix/coverage.c') diff --git a/tests/unix/extra_coverage.py.exp b/tests/unix/extra_coverage.py.exp index 2b3f68467..12d9e1cb6 100644 --- a/tests/unix/extra_coverage.py.exp +++ b/tests/unix/extra_coverage.py.exp @@ -38,6 +38,7 @@ ementation # runtime utils TypeError: can't convert str to int TypeError: unsupported types for : 'str', 'str' +Warning: test ('0123456789', b'0123456789') 7300 7300 diff --git a/unix/coverage.c b/unix/coverage.c index 2abfc870f..033f09ed3 100644 --- a/unix/coverage.c +++ b/unix/coverage.c @@ -6,6 +6,7 @@ #include "py/repl.h" #include "py/mpz.h" #include "py/builtin.h" +#include "py/emit.h" #if defined(MICROPY_UNIX_COVERAGE) @@ -130,6 +131,11 @@ STATIC mp_obj_t extra_coverage(void) { mp_call_function_2_protected(MP_OBJ_FROM_PTR(&mp_builtin_divmod_obj), mp_obj_new_str("abc", 3, false), mp_obj_new_str("abc", 3, false)); } + // warning + { + mp_emitter_warning(MP_PASS_CODE_SIZE, "test"); + } + // return a tuple of data for testing on the Python side mp_obj_t items[] = {(mp_obj_t)&str_no_hash_obj, (mp_obj_t)&bytes_no_hash_obj}; return mp_obj_new_tuple(MP_ARRAY_SIZE(items), items); -- cgit v1.2.3 From d7e168428bc9fd7524dd83b973c283b3488bfd3b Mon Sep 17 00:00:00 2001 From: Rami Ali Date: Thu, 5 Jan 2017 11:12:05 +1100 Subject: tests/unix: Improve formatfloat.c test coverage using C. --- tests/unix/extra_coverage.py.exp | 4 ++++ unix/coverage.c | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) (limited to 'unix/coverage.c') diff --git a/tests/unix/extra_coverage.py.exp b/tests/unix/extra_coverage.py.exp index 12d9e1cb6..0d7fc1180 100644 --- a/tests/unix/extra_coverage.py.exp +++ b/tests/unix/extra_coverage.py.exp @@ -39,6 +39,10 @@ ementation TypeError: can't convert str to int TypeError: unsupported types for : 'str', 'str' Warning: test +# format float +? ++1e+00 ++1e+00 ('0123456789', b'0123456789') 7300 7300 diff --git a/unix/coverage.c b/unix/coverage.c index 033f09ed3..7140be41b 100644 --- a/unix/coverage.c +++ b/unix/coverage.c @@ -7,6 +7,7 @@ #include "py/mpz.h" #include "py/builtin.h" #include "py/emit.h" +#include "py/formatfloat.h" #if defined(MICROPY_UNIX_COVERAGE) @@ -136,6 +137,26 @@ STATIC mp_obj_t extra_coverage(void) { mp_emitter_warning(MP_PASS_CODE_SIZE, "test"); } + // format float + { + mp_printf(&mp_plat_print, "# format float\n"); + + // format with inadequate buffer size + char buf[5]; + mp_format_float(1, buf, sizeof(buf), 'g', 0, '+'); + mp_printf(&mp_plat_print, "%s\n", buf); + + // format with just enough buffer so that precision must be + // set from 0 to 1 twice + char buf2[8]; + mp_format_float(1, buf2, sizeof(buf2), 'g', 0, '+'); + mp_printf(&mp_plat_print, "%s\n", buf2); + + // format where precision is trimmed to avoid buffer overflow + mp_format_float(1, buf2, sizeof(buf2), 'e', 0, '+'); + mp_printf(&mp_plat_print, "%s\n", buf2); + } + // return a tuple of data for testing on the Python side mp_obj_t items[] = {(mp_obj_t)&str_no_hash_obj, (mp_obj_t)&bytes_no_hash_obj}; return mp_obj_new_tuple(MP_ARRAY_SIZE(items), items); -- cgit v1.2.3