diff options
| -rw-r--r-- | stmhal/i2c.c | 24 | ||||
| -rw-r--r-- | tests/basics/memoryerror.py | 17 | ||||
| -rwxr-xr-x | tests/run-tests | 22 |
3 files changed, 35 insertions, 28 deletions
diff --git a/stmhal/i2c.c b/stmhal/i2c.c index 88c22163c..780d4fb49 100644 --- a/stmhal/i2c.c +++ b/stmhal/i2c.c @@ -136,10 +136,10 @@ STATIC mp_obj_t pyb_i2c_scan(mp_obj_t self_in) { STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_i2c_scan_obj, pyb_i2c_scan); -STATIC mp_obj_t pyb_i2c_read(uint n_args, const mp_obj_t *args) { - pyb_i2c_obj_t *self = args[0]; - machine_uint_t i2c_addr = mp_obj_get_int(args[1]) << 1; - machine_uint_t n = mp_obj_get_int(args[2]); +STATIC mp_obj_t pyb_i2c_read(mp_obj_t self_in, mp_obj_t i2c_addr_in, mp_obj_t n_in) { + pyb_i2c_obj_t *self = self_in; + machine_uint_t i2c_addr = mp_obj_get_int(i2c_addr_in) << 1; + machine_uint_t n = mp_obj_get_int(n_in); byte *data; mp_obj_t o = mp_obj_str_builder_start(&mp_type_bytes, n, &data); @@ -153,18 +153,18 @@ STATIC mp_obj_t pyb_i2c_read(uint n_args, const mp_obj_t *args) { return mp_obj_str_builder_end(o); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_i2c_read_obj, 3, 3, pyb_i2c_read); +STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_i2c_read_obj, pyb_i2c_read); -STATIC mp_obj_t pyb_i2c_write(uint n_args, const mp_obj_t *args) { - pyb_i2c_obj_t *self = args[0]; - machine_uint_t i2c_addr = mp_obj_get_int(args[1]) << 1; +STATIC mp_obj_t pyb_i2c_write(mp_obj_t self_in, mp_obj_t i2c_addr_in, mp_obj_t data_in) { + pyb_i2c_obj_t *self = self_in; + machine_uint_t i2c_addr = mp_obj_get_int(i2c_addr_in) << 1; HAL_StatusTypeDef status; - if (MP_OBJ_IS_INT(args[2])) { - uint8_t data[1] = {mp_obj_get_int(args[2])}; + if (MP_OBJ_IS_INT(data_in)) { + uint8_t data[1] = {mp_obj_get_int(data_in)}; status = HAL_I2C_Master_Transmit(self->i2c_handle, i2c_addr, data, 1, 500); } else { buffer_info_t bufinfo; - mp_get_buffer_raise(args[2], &bufinfo); + mp_get_buffer_raise(data_in, &bufinfo); status = HAL_I2C_Master_Transmit(self->i2c_handle, i2c_addr, bufinfo.buf, bufinfo.len, 500); } @@ -176,7 +176,7 @@ STATIC mp_obj_t pyb_i2c_write(uint n_args, const mp_obj_t *args) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_i2c_write_obj, 3, 3, pyb_i2c_write); +STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_i2c_write_obj, pyb_i2c_write); STATIC mp_obj_t pyb_i2c_mem_read(uint n_args, const mp_obj_t *args) { pyb_i2c_obj_t *self = args[0]; diff --git a/tests/basics/memoryerror.py b/tests/basics/memoryerror.py index e9aa97d85..b4be420c3 100644 --- a/tests/basics/memoryerror.py +++ b/tests/basics/memoryerror.py @@ -1,11 +1,6 @@ -# this test for MemoryError can be difficult to reproduce -# on different machine configurations (notably Travis CI) -# so we disable it -# TODO is there a way of testing that we are on Travis CI? -if False: - l = list(range(10000)) - try: - 100000000 * l - except MemoryError: - print('MemoryError') - print(len(l), l[0], l[-1]) +l = list(range(10000)) +try: + 100000000 * l +except MemoryError: + print('MemoryError') +print(len(l), l[0], l[-1]) diff --git a/tests/run-tests b/tests/run-tests index 554f5134c..bd6e50bbd 100755 --- a/tests/run-tests +++ b/tests/run-tests @@ -15,6 +15,9 @@ else: CPYTHON3 = os.getenv('MICROPY_CPYTHON3', 'python3') MP_PY = '../unix/micropython' +# Set of tests that we shouldn't run under Travis CI +skip_travis_tests = set(['basics/memoryerror.py']) + def rm_f(fname): if os.path.exists(fname): os.remove(fname) @@ -36,8 +39,12 @@ if test_on_pyboard: pyb = pyboard.Pyboard('/dev/ttyACM0') pyb.enter_raw_repl() +running_under_travis = os.environ.get('TRAVIS', 'false') == 'true' + for test_file in tests: - test_name = os.path.splitext(os.path.basename(test_file))[0] + if running_under_travis and test_file in skip_travis_tests: + print("skip ", test_file) + continue # run CPython try: @@ -64,15 +71,20 @@ for test_file in tests: testcase_count += len(output_expected.splitlines()) + test_basename = os.path.basename(test_file) + test_name = os.path.splitext(test_basename)[0] + filename_expected = test_basename + ".exp" + filename_mupy = test_basename + ".out" + if output_expected == output_mupy: print("pass ", test_file) passed_count += 1 - rm_f(os.path.basename(test_file + ".exp")) - rm_f(os.path.basename(test_file + ".out")) + rm_f(filename_expected) + rm_f(filename_mupy) else: - with open(os.path.basename(test_file + ".exp"), "w") as f: + with open(filename_expected, "w") as f: f.write(str(output_expected, "ascii")) - with open(os.path.basename(test_file + ".out"), "w") as f: + with open(filename_mupy, "w") as f: f.write(str(output_mupy, "ascii")) print("FAIL ", test_file) failed_tests.append(test_name) |
