diff options
Diffstat (limited to 'tests/micropython/viper_ptr32_store_boundary.py')
-rw-r--r-- | tests/micropython/viper_ptr32_store_boundary.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/micropython/viper_ptr32_store_boundary.py b/tests/micropython/viper_ptr32_store_boundary.py new file mode 100644 index 000000000..243ff5cd9 --- /dev/null +++ b/tests/micropython/viper_ptr32_store_boundary.py @@ -0,0 +1,35 @@ +# Test boundary conditions for various architectures + +TEST_DATA = ( + (3, (0x04030201, 0x08070605, 0x0C0B0A09)), + (63, (0x100F0E0D, 0x14131211, 0x18171615)), + (1023, (0x1C1B1A19, 0x201F1E1D, 0x24232221)), +) + +SET_TEMPLATE = """ +@micropython.viper +def set{off}(dest: ptr32): + dest[{off}] = {val} & 0x3FFFFFFF +set{off}(b) +print(b[{off} * 4:({off} + 1) * 4]) +""" + + +@micropython.viper +def set_index(dest: ptr32, i: int, val: int): + dest[i] = val + + +b = bytearray(5000) +for start, vals in TEST_DATA: + for i, v in enumerate(vals): + set_index(b, start + i, v) + print(b[(start + i) * 4 : (start + i + 1) * 4]) + +for i in range(len(b)): + b[i] = 0 + + +for start, vals in TEST_DATA: + for i, v in enumerate(vals): + exec(SET_TEMPLATE.format(off=start + i, val=v + 0x01010101)) |