aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDamien George2019-08-05 16:32:10 +1000
committerDamien George2019-08-06 15:58:23 +1000
commitcd35dd9d9a29836906acdce60c931f6352b536d0 (patch)
tree7fe4f06cceb784bafb26794c847babd34e90d162 /tests
parent2d3d4f74830eddaba8e13ca9a860a5cb7fb2f163 (diff)
py: Allow to pass in read-only buffers to viper and inline-asm funcs.
Fixes #4936.
Diffstat (limited to 'tests')
-rw-r--r--tests/inlineasm/asmsum.py4
-rw-r--r--tests/inlineasm/asmsum.py.exp1
-rw-r--r--tests/micropython/viper_addr.py10
-rw-r--r--tests/micropython/viper_addr.py.exp1
4 files changed, 16 insertions, 0 deletions
diff --git a/tests/inlineasm/asmsum.py b/tests/inlineasm/asmsum.py
index 07e71c738..9cbd8418e 100644
--- a/tests/inlineasm/asmsum.py
+++ b/tests/inlineasm/asmsum.py
@@ -55,3 +55,7 @@ print(b, n)
b = array.array('b', (10, 20, 30, 40, 50, 60, 70, 80))
n = asm_sum_bytes(len(b), b)
print(b, n)
+
+b = b'\x01\x02\x03\x04'
+n = asm_sum_bytes(len(b), b)
+print(b, n)
diff --git a/tests/inlineasm/asmsum.py.exp b/tests/inlineasm/asmsum.py.exp
index d50a94c8d..3c83da367 100644
--- a/tests/inlineasm/asmsum.py.exp
+++ b/tests/inlineasm/asmsum.py.exp
@@ -1,2 +1,3 @@
array('l', [100, 200, 300, 400]) 1000
array('b', [10, 20, 30, 40, 50, 60, 70, 80]) 360
+b'\x01\x02\x03\x04' 10
diff --git a/tests/micropython/viper_addr.py b/tests/micropython/viper_addr.py
index cd953ce07..0d8efb90b 100644
--- a/tests/micropython/viper_addr.py
+++ b/tests/micropython/viper_addr.py
@@ -9,6 +9,13 @@ def memset(dest:ptr8, c:int, n:int):
for i in range(n):
dest[i] = c
+@micropython.viper
+def memsum(src:ptr8, n:int) -> int:
+ s = 0
+ for i in range(n):
+ s += src[i]
+ return s
+
# create array and get its address
ar = bytearray('0000')
addr = get_addr(ar)
@@ -27,3 +34,6 @@ print(ar)
# pass direct pointer to array buffer, with offset
memset(addr + 2, ord('3'), len(ar) - 2)
print(ar)
+
+# pass a read-only bytes object in
+print(memsum(b'\x01\x02\x03\x04', 4))
diff --git a/tests/micropython/viper_addr.py.exp b/tests/micropython/viper_addr.py.exp
index 87a18e1e2..8e08db9a5 100644
--- a/tests/micropython/viper_addr.py.exp
+++ b/tests/micropython/viper_addr.py.exp
@@ -4,3 +4,4 @@ bytearray(b'0000')
bytearray(b'1111')
bytearray(b'2222')
bytearray(b'2233')
+10