From d10cda66dcff1b760ebc550c7f9352220fe4163f Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 18 Dec 2024 10:15:01 +1100 Subject: [PATCH] tests/extmod: Add test for uctypes.addressof function. Signed-off-by: Damien George --- tests/extmod/uctypes_addressof.py | 16 ++++++++++++++++ tests/extmod/uctypes_addressof.py.exp | 9 +++++++++ 2 files changed, 25 insertions(+) create mode 100644 tests/extmod/uctypes_addressof.py create mode 100644 tests/extmod/uctypes_addressof.py.exp diff --git a/tests/extmod/uctypes_addressof.py b/tests/extmod/uctypes_addressof.py new file mode 100644 index 000000000..c83089d0f --- /dev/null +++ b/tests/extmod/uctypes_addressof.py @@ -0,0 +1,16 @@ +# Test uctypes.addressof(). + +try: + from sys import maxsize + import uctypes +except ImportError: + print("SKIP") + raise SystemExit + +# Test small addresses. +for i in range(8): + print(uctypes.addressof(uctypes.bytearray_at(1 << i, 8))) + +# Test address that is bigger than the greatest small-int but still within the address range. +large_addr = maxsize + 1 +print(uctypes.addressof(uctypes.bytearray_at(large_addr, 8)) == large_addr) diff --git a/tests/extmod/uctypes_addressof.py.exp b/tests/extmod/uctypes_addressof.py.exp new file mode 100644 index 000000000..5b48569d0 --- /dev/null +++ b/tests/extmod/uctypes_addressof.py.exp @@ -0,0 +1,9 @@ +1 +2 +4 +8 +16 +32 +64 +128 +True