mirror of
https://github.com/micropython/micropython.git
synced 2026-01-07 12:40:15 +01:00
tests: Format all Python code with black, except tests in basics subdir.
This adds the Python files in the tests/ directory to be formatted with ./tools/codeformat.py. The basics/ subdirectory is excluded for now so we aren't changing too much at once. In a few places `# fmt: off`/`# fmt: on` was used where the code had special formatting for readability or where the test was actually testing the specific formatting.
This commit is contained in:
committed by
Damien George
parent
488613bca6
commit
3dc324d3f1
@@ -1,29 +1,44 @@
|
||||
# test passing arguments
|
||||
|
||||
|
||||
@micropython.asm_thumb
|
||||
def arg0():
|
||||
mov(r0, 1)
|
||||
|
||||
|
||||
print(arg0())
|
||||
|
||||
|
||||
@micropython.asm_thumb
|
||||
def arg1(r0):
|
||||
add(r0, r0, 1)
|
||||
|
||||
|
||||
print(arg1(1))
|
||||
|
||||
|
||||
@micropython.asm_thumb
|
||||
def arg2(r0, r1):
|
||||
add(r0, r0, r1)
|
||||
|
||||
|
||||
print(arg2(1, 2))
|
||||
|
||||
|
||||
@micropython.asm_thumb
|
||||
def arg3(r0, r1, r2):
|
||||
add(r0, r0, r1)
|
||||
add(r0, r0, r2)
|
||||
|
||||
|
||||
print(arg3(1, 2, 3))
|
||||
|
||||
|
||||
@micropython.asm_thumb
|
||||
def arg4(r0, r1, r2, r3):
|
||||
add(r0, r0, r1)
|
||||
add(r0, r0, r2)
|
||||
add(r0, r0, r3)
|
||||
|
||||
|
||||
print(arg4(1, 2, 3, 4))
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# test bcc instructions
|
||||
# at the moment only tests beq, narrow and wide versions
|
||||
|
||||
|
||||
@micropython.asm_thumb
|
||||
def f(r0):
|
||||
mov(r1, r0)
|
||||
@@ -21,6 +22,7 @@ def f(r0):
|
||||
|
||||
label(end)
|
||||
|
||||
|
||||
print(f(0))
|
||||
print(f(1))
|
||||
print(f(2))
|
||||
|
||||
@@ -2,12 +2,15 @@
|
||||
def clz(r0):
|
||||
clz(r0, r0)
|
||||
|
||||
print(clz(0xf0))
|
||||
|
||||
print(clz(0xF0))
|
||||
print(clz(0x8000))
|
||||
|
||||
|
||||
@micropython.asm_thumb
|
||||
def rbit(r0):
|
||||
rbit(r0, r0)
|
||||
|
||||
print(hex(rbit(0xf0)))
|
||||
|
||||
print(hex(rbit(0xF0)))
|
||||
print(hex(rbit(0x8000)))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# test bl and bx instructions
|
||||
|
||||
|
||||
@micropython.asm_thumb
|
||||
def f(r0):
|
||||
# jump over the internal functions
|
||||
@@ -17,5 +18,6 @@ def f(r0):
|
||||
bl(func1)
|
||||
bl(func2)
|
||||
|
||||
|
||||
print(f(0))
|
||||
print(f(1))
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
# test constants in assembler
|
||||
|
||||
|
||||
@micropython.asm_thumb
|
||||
def c1():
|
||||
movwt(r0, 0xffffffff)
|
||||
movwt(r1, 0xf0000000)
|
||||
movwt(r0, 0xFFFFFFFF)
|
||||
movwt(r1, 0xF0000000)
|
||||
sub(r0, r0, r1)
|
||||
|
||||
|
||||
print(hex(c1()))
|
||||
|
||||
@@ -2,15 +2,17 @@
|
||||
def sdiv(r0, r1):
|
||||
sdiv(r0, r0, r1)
|
||||
|
||||
|
||||
@micropython.asm_thumb
|
||||
def udiv(r0, r1):
|
||||
udiv(r0, r0, r1)
|
||||
|
||||
|
||||
print(sdiv(1234, 3))
|
||||
print(sdiv(-1234, 3))
|
||||
print(sdiv(1234, -3))
|
||||
print(sdiv(-1234, -3))
|
||||
|
||||
print(udiv(1234, 3))
|
||||
print(udiv(0xffffffff, 0x7fffffff))
|
||||
print(udiv(0xffffffff, 0xffffffff))
|
||||
print(udiv(0xFFFFFFFF, 0x7FFFFFFF))
|
||||
print(udiv(0xFFFFFFFF, 0xFFFFFFFF))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@micropython.asm_thumb # r0 = r0+r1-r2
|
||||
@micropython.asm_thumb # r0 = r0+r1-r2
|
||||
def add_sub(r0, r1, r2):
|
||||
vmov(s0, r0)
|
||||
vcvt_f32_s32(s0, s0)
|
||||
@@ -11,5 +11,5 @@ def add_sub(r0, r1, r2):
|
||||
vcvt_s32_f32(s31, s0)
|
||||
vmov(r0, s31)
|
||||
|
||||
print(add_sub(100, 20, 30))
|
||||
|
||||
print(add_sub(100, 20, 30))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@micropython.asm_thumb # test vcmp, vmrs
|
||||
@micropython.asm_thumb # test vcmp, vmrs
|
||||
def f(r0, r1):
|
||||
vmov(s0, r0)
|
||||
vcvt_f32_s32(s0, s0)
|
||||
@@ -9,6 +9,7 @@ def f(r0, r1):
|
||||
mov(r1, 28)
|
||||
lsr(r0, r1)
|
||||
|
||||
print(f(0,1))
|
||||
print(f(1,1))
|
||||
print(f(1,0))
|
||||
|
||||
print(f(0, 1))
|
||||
print(f(1, 1))
|
||||
print(f(1, 0))
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import uarray as array
|
||||
@micropython.asm_thumb # test vldr, vstr
|
||||
|
||||
|
||||
@micropython.asm_thumb # test vldr, vstr
|
||||
def arrayadd(r0):
|
||||
vldr(s0, [r0, 0])
|
||||
vldr(s1, [r0, 4])
|
||||
vadd(s2, s0, s1)
|
||||
vstr(s2, [r0, 8])
|
||||
|
||||
|
||||
z = array.array("f", [2, 4, 10])
|
||||
arrayadd(z)
|
||||
print(z[2])
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@micropython.asm_thumb # r0 = (int)(r0*r1/r2)
|
||||
@micropython.asm_thumb # r0 = (int)(r0*r1/r2)
|
||||
def muldiv(r0, r1, r2):
|
||||
vmov(s0, r0)
|
||||
vcvt_f32_s32(s0, s0)
|
||||
@@ -11,5 +11,5 @@ def muldiv(r0, r1, r2):
|
||||
vcvt_s32_f32(s31, s8)
|
||||
vmov(r0, s31)
|
||||
|
||||
print(muldiv(100, 10, 50))
|
||||
|
||||
print(muldiv(100, 10, 50))
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# test vsqrt, vneg
|
||||
@micropython.asm_thumb # r0 = -(int)(sqrt(r0)*r1)
|
||||
@micropython.asm_thumb # r0 = -(int)(sqrt(r0)*r1)
|
||||
def sqrt_test(r0, r1):
|
||||
vmov(s1, r0)
|
||||
vcvt_f32_s32(s1, s1)
|
||||
@@ -11,5 +11,5 @@ def sqrt_test(r0, r1):
|
||||
vcvt_s32_f32(s31, s7)
|
||||
vmov(r0, s31)
|
||||
|
||||
print(sqrt_test(256, 10))
|
||||
|
||||
print(sqrt_test(256, 10))
|
||||
|
||||
@@ -1,16 +1,22 @@
|
||||
# test it instruction
|
||||
|
||||
|
||||
@micropython.asm_thumb
|
||||
def f(r0, r1):
|
||||
cmp(r0, r1)
|
||||
it(eq)
|
||||
mov(r0, 100)
|
||||
|
||||
|
||||
print(f(0, 0), f(1, 2))
|
||||
|
||||
|
||||
@micropython.asm_thumb
|
||||
def g(r0, r1):
|
||||
cmp(r0, r1)
|
||||
ite(eq)
|
||||
mov(r0, 100)
|
||||
mov(r0, 200)
|
||||
|
||||
|
||||
print(g(0, 0), g(0, 1))
|
||||
|
||||
@@ -5,4 +5,5 @@ def f(r0, r1, r2):
|
||||
pop({r0})
|
||||
pop({r1, r2})
|
||||
|
||||
|
||||
print(f(0, 1, 2))
|
||||
|
||||
@@ -1,21 +1,33 @@
|
||||
# test return type of inline asm
|
||||
|
||||
|
||||
@micropython.asm_thumb
|
||||
def ret_obj(r0) -> object:
|
||||
pass
|
||||
|
||||
|
||||
ret_obj(print)(1)
|
||||
|
||||
|
||||
@micropython.asm_thumb
|
||||
def ret_bool(r0) -> bool:
|
||||
pass
|
||||
|
||||
|
||||
print(ret_bool(0), ret_bool(1))
|
||||
|
||||
|
||||
@micropython.asm_thumb
|
||||
def ret_int(r0) -> int:
|
||||
lsl(r0, r0, 29)
|
||||
|
||||
|
||||
print(ret_int(0), hex(ret_int(1)), hex(ret_int(2)), hex(ret_int(4)))
|
||||
|
||||
|
||||
@micropython.asm_thumb
|
||||
def ret_uint(r0) -> uint:
|
||||
lsl(r0, r0, 29)
|
||||
|
||||
|
||||
print(ret_uint(0), hex(ret_uint(1)), hex(ret_uint(2)), hex(ret_uint(4)))
|
||||
|
||||
@@ -1,29 +1,46 @@
|
||||
@micropython.asm_thumb
|
||||
def lsl1(r0):
|
||||
lsl(r0, r0, 1)
|
||||
|
||||
|
||||
print(hex(lsl1(0x123)))
|
||||
|
||||
|
||||
@micropython.asm_thumb
|
||||
def lsl23(r0):
|
||||
lsl(r0, r0, 23)
|
||||
|
||||
|
||||
print(hex(lsl23(1)))
|
||||
|
||||
|
||||
@micropython.asm_thumb
|
||||
def lsr1(r0):
|
||||
lsr(r0, r0, 1)
|
||||
|
||||
|
||||
print(hex(lsr1(0x123)))
|
||||
|
||||
|
||||
@micropython.asm_thumb
|
||||
def lsr31(r0):
|
||||
lsr(r0, r0, 31)
|
||||
|
||||
|
||||
print(hex(lsr31(0x80000000)))
|
||||
|
||||
|
||||
@micropython.asm_thumb
|
||||
def asr1(r0):
|
||||
asr(r0, r0, 1)
|
||||
|
||||
|
||||
print(hex(asr1(0x123)))
|
||||
|
||||
|
||||
@micropython.asm_thumb
|
||||
def asr31(r0):
|
||||
asr(r0, r0, 31)
|
||||
|
||||
|
||||
print(hex(asr31(0x80000000)))
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
def getIPSR():
|
||||
mrs(r0, IPSR)
|
||||
|
||||
|
||||
@micropython.asm_thumb
|
||||
def getBASEPRI():
|
||||
mrs(r0, BASEPRI)
|
||||
|
||||
|
||||
print(getBASEPRI())
|
||||
print(getIPSR())
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ def asm_sum_words(r0, r1):
|
||||
|
||||
mov(r0, r2)
|
||||
|
||||
|
||||
@micropython.asm_thumb
|
||||
def asm_sum_bytes(r0, r1):
|
||||
|
||||
@@ -46,16 +47,17 @@ def asm_sum_bytes(r0, r1):
|
||||
|
||||
mov(r0, r2)
|
||||
|
||||
|
||||
import uarray as array
|
||||
|
||||
b = array.array('l', (100, 200, 300, 400))
|
||||
b = array.array("l", (100, 200, 300, 400))
|
||||
n = asm_sum_words(len(b), b)
|
||||
print(b, n)
|
||||
|
||||
b = array.array('b', (10, 20, 30, 40, 50, 60, 70, 80))
|
||||
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'
|
||||
b = b"\x01\x02\x03\x04"
|
||||
n = asm_sum_bytes(len(b), b)
|
||||
print(b, n)
|
||||
|
||||
Reference in New Issue
Block a user