diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/micropython/viper_ptr32_load.py | 21 | ||||
-rw-r--r-- | tests/micropython/viper_ptr32_load.py.exp | 3 | ||||
-rw-r--r-- | tests/micropython/viper_ptr32_store.py | 26 | ||||
-rw-r--r-- | tests/micropython/viper_ptr32_store.py.exp | 4 |
4 files changed, 54 insertions, 0 deletions
diff --git a/tests/micropython/viper_ptr32_load.py b/tests/micropython/viper_ptr32_load.py new file mode 100644 index 0000000000..d552b9df67 --- /dev/null +++ b/tests/micropython/viper_ptr32_load.py @@ -0,0 +1,21 @@ +# test loading from ptr32 type + +@micropython.viper +def get(src:ptr32) -> int: + return src[0] + +@micropython.viper +def get1(src:ptr32) -> int: + return src[1] + +@micropython.viper +def memadd(src:ptr32, n:int) -> int: + sum = 0 + for i in range(n): + sum += src[i] + return sum + +b = bytearray(b'\x12\x12\x12\x12\x34\x34\x34\x34') +print(b) +print(hex(get(b)), hex(get1(b))) +print(hex(memadd(b, 2))) diff --git a/tests/micropython/viper_ptr32_load.py.exp b/tests/micropython/viper_ptr32_load.py.exp new file mode 100644 index 0000000000..e7ce2d972d --- /dev/null +++ b/tests/micropython/viper_ptr32_load.py.exp @@ -0,0 +1,3 @@ +bytearray(b'\x12\x12\x12\x124444') +0x12121212 0x34343434 +0x46464646 diff --git a/tests/micropython/viper_ptr32_store.py b/tests/micropython/viper_ptr32_store.py new file mode 100644 index 0000000000..b63bac9ee3 --- /dev/null +++ b/tests/micropython/viper_ptr32_store.py @@ -0,0 +1,26 @@ +# test store to ptr32 type + +@micropython.viper +def set(dest:ptr32, val:int): + dest[0] = val + +@micropython.viper +def set1(dest:ptr32, val:int): + dest[1] = val + +@micropython.viper +def memset(dest:ptr32, val:int, n:int): + for i in range(n): + dest[i] = val + +b = bytearray(8) +print(b) + +set(b, 0x42424242) +print(b) + +set1(b, 0x43434343) +print(b) + +memset(b, 0x44444444, len(b) // 4) +print(b) diff --git a/tests/micropython/viper_ptr32_store.py.exp b/tests/micropython/viper_ptr32_store.py.exp new file mode 100644 index 0000000000..13b9f418f8 --- /dev/null +++ b/tests/micropython/viper_ptr32_store.py.exp @@ -0,0 +1,4 @@ +bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00') +bytearray(b'BBBB\x00\x00\x00\x00') +bytearray(b'BBBBCCCC') +bytearray(b'DDDDDDDD') |