summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2018-08-26 09:52:03 +0300
committerDamien George <damien.p.george@gmail.com>2018-10-23 11:33:35 +1100
commitc638d86660c78037d506f71f1f40a5daea73800f (patch)
tree59589190aac44e09a2ac5da9c15d4c27a45783eb
parent2411f42ccba561affc0882f8983811b9d8c02b94 (diff)
tests/extmod/uctypes_sizeof_layout: Test for sizeof of different layout.
On almost all realistic platforms, native layout should be larger (or equal) than packed layout.
-rw-r--r--tests/extmod/uctypes_sizeof_layout.py27
-rw-r--r--tests/extmod/uctypes_sizeof_layout.py.exp3
2 files changed, 30 insertions, 0 deletions
diff --git a/tests/extmod/uctypes_sizeof_layout.py b/tests/extmod/uctypes_sizeof_layout.py
new file mode 100644
index 000000000..2108e8150
--- /dev/null
+++ b/tests/extmod/uctypes_sizeof_layout.py
@@ -0,0 +1,27 @@
+try:
+ import uctypes
+except ImportError:
+ print("SKIP")
+ raise SystemExit
+
+desc = {
+ "f1": 0 | uctypes.UINT32,
+ "f2": 4 | uctypes.UINT8,
+}
+
+
+# uctypes.NATIVE is default
+print(uctypes.sizeof(desc) == uctypes.sizeof(desc, uctypes.NATIVE))
+
+# Here we assume that that we run on a platform with convential ABI
+# (which rounds up structure size based on max alignment). For platforms
+# where that doesn't hold, this tests should be just disabled in the runner.
+print(uctypes.sizeof(desc, uctypes.NATIVE) > uctypes.sizeof(desc, uctypes.LITTLE_ENDIAN))
+
+# When taking sizeof of instantiated structure, layout type param
+# is prohibited (because structure already has its layout type).
+s = uctypes.struct(0, desc, uctypes.LITTLE_ENDIAN)
+try:
+ uctypes.sizeof(s, uctypes.LITTLE_ENDIAN)
+except TypeError:
+ print("TypeError")
diff --git a/tests/extmod/uctypes_sizeof_layout.py.exp b/tests/extmod/uctypes_sizeof_layout.py.exp
new file mode 100644
index 000000000..281f20856
--- /dev/null
+++ b/tests/extmod/uctypes_sizeof_layout.py.exp
@@ -0,0 +1,3 @@
+True
+True
+TypeError