From 414b59d39c9f37c0da5ee00d270aa630c392c2fd Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 21 Feb 2022 10:36:04 +1100 Subject: [PATCH] qemu-arm: Add tests for freezing viper and asm_thumb code. Signed-off-by: Damien George --- ports/qemu-arm/test-frzmpy/frozen_asm.py | 29 ++++++++++++++++++++++ ports/qemu-arm/test-frzmpy/frozen_viper.py | 8 ++++++ tests/qemu-arm/asm_test.py | 7 ++++++ tests/qemu-arm/asm_test.py.exp | 5 ++++ tests/qemu-arm/viper_test.py | 3 +++ tests/qemu-arm/viper_test.py.exp | 1 + 6 files changed, 53 insertions(+) create mode 100644 ports/qemu-arm/test-frzmpy/frozen_asm.py create mode 100644 ports/qemu-arm/test-frzmpy/frozen_viper.py create mode 100644 tests/qemu-arm/asm_test.py create mode 100644 tests/qemu-arm/asm_test.py.exp create mode 100644 tests/qemu-arm/viper_test.py create mode 100644 tests/qemu-arm/viper_test.py.exp diff --git a/ports/qemu-arm/test-frzmpy/frozen_asm.py b/ports/qemu-arm/test-frzmpy/frozen_asm.py new file mode 100644 index 0000000000..2c7f5c92cd --- /dev/null +++ b/ports/qemu-arm/test-frzmpy/frozen_asm.py @@ -0,0 +1,29 @@ +# Test freezing inline-asm code. + +import micropython + + +@micropython.asm_thumb +def asm_add(r0, r1): + add(r0, r0, r1) + + +@micropython.asm_thumb +def asm_add1(r0) -> object: + lsl(r0, r0, 1) + add(r0, r0, 3) + + +@micropython.asm_thumb +def asm_cast_bool(r0) -> bool: + pass + + +@micropython.asm_thumb +def asm_shift_int(r0) -> int: + lsl(r0, r0, 29) + + +@micropython.asm_thumb +def asm_shift_uint(r0) -> uint: + lsl(r0, r0, 29) diff --git a/ports/qemu-arm/test-frzmpy/frozen_viper.py b/ports/qemu-arm/test-frzmpy/frozen_viper.py new file mode 100644 index 0000000000..71dfe7c3b6 --- /dev/null +++ b/ports/qemu-arm/test-frzmpy/frozen_viper.py @@ -0,0 +1,8 @@ +# Test freezing viper code. + +import micropython + + +@micropython.viper +def viper_add(x, y): + print(x + y) diff --git a/tests/qemu-arm/asm_test.py b/tests/qemu-arm/asm_test.py new file mode 100644 index 0000000000..26c7efe427 --- /dev/null +++ b/tests/qemu-arm/asm_test.py @@ -0,0 +1,7 @@ +import frozen_asm + +print(frozen_asm.asm_add(1, 2)) +print(frozen_asm.asm_add1(3)) +print(frozen_asm.asm_cast_bool(0), frozen_asm.asm_cast_bool(3)) +print(frozen_asm.asm_shift_int(4)) +print(frozen_asm.asm_shift_uint(4)) diff --git a/tests/qemu-arm/asm_test.py.exp b/tests/qemu-arm/asm_test.py.exp new file mode 100644 index 0000000000..b4be8b40e2 --- /dev/null +++ b/tests/qemu-arm/asm_test.py.exp @@ -0,0 +1,5 @@ +3 +4 +False True +-2147483648 +2147483648 diff --git a/tests/qemu-arm/viper_test.py b/tests/qemu-arm/viper_test.py new file mode 100644 index 0000000000..8e38a2b928 --- /dev/null +++ b/tests/qemu-arm/viper_test.py @@ -0,0 +1,3 @@ +import frozen_viper + +frozen_viper.viper_add(1, 2) diff --git a/tests/qemu-arm/viper_test.py.exp b/tests/qemu-arm/viper_test.py.exp new file mode 100644 index 0000000000..00750edc07 --- /dev/null +++ b/tests/qemu-arm/viper_test.py.exp @@ -0,0 +1 @@ +3