summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2022-03-07 12:29:17 +1100
committerDamien George <damien@micropython.org>2022-03-07 15:25:11 +1100
commit7cd166ff9244a720a6e72e651215db891dc1f85e (patch)
tree7a5317ff4e6667bc8f576f7e73330045ff1330ed
parentbb2bd071f74c04237618958521e58d48d2dc35d4 (diff)
tests/basics: Add test for creating small-ints in nan-box builds.
Signed-off-by: Damien George <damien@micropython.org>
-rw-r--r--tests/basics/nanbox_smallint.py42
-rw-r--r--tests/basics/nanbox_smallint.py.exp5
2 files changed, 47 insertions, 0 deletions
diff --git a/tests/basics/nanbox_smallint.py b/tests/basics/nanbox_smallint.py
new file mode 100644
index 000000000..642ca77b3
--- /dev/null
+++ b/tests/basics/nanbox_smallint.py
@@ -0,0 +1,42 @@
+# Test creating small integers without heap allocation in nan-boxing mode.
+
+import micropython
+
+try:
+ # Test for nan-box build by allocating a float while heap is locked.
+ # This should pass on nan-box builds.
+ micropython.heap_lock()
+ float(123)
+ micropython.heap_unlock()
+except:
+ print("SKIP")
+ raise SystemExit
+
+# Check that nan-boxing uses 64-bit floats (eg it's not object representation C).
+if float("1e100") == float("inf"):
+ print("SKIP")
+ raise SystemExit
+
+micropython.heap_lock()
+print(int("0x80000000"))
+micropython.heap_unlock()
+
+# This is the most positive small integer.
+micropython.heap_lock()
+print(int("0x3fffffffffff"))
+micropython.heap_unlock()
+
+# This is the most negative small integer.
+micropython.heap_lock()
+print(int("-0x3fffffffffff") - 1)
+micropython.heap_unlock()
+
+x = 1
+micropython.heap_lock()
+print((x << 31) + 1)
+micropython.heap_unlock()
+
+x = 1
+micropython.heap_lock()
+print((x << 45) + 1)
+micropython.heap_unlock()
diff --git a/tests/basics/nanbox_smallint.py.exp b/tests/basics/nanbox_smallint.py.exp
new file mode 100644
index 000000000..aad1f7b8b
--- /dev/null
+++ b/tests/basics/nanbox_smallint.py.exp
@@ -0,0 +1,5 @@
+2147483648
+70368744177663
+-70368744177664
+2147483649
+35184372088833