Skip to content
Snippets Groups Projects
Commit c638d866 authored by Paul Sokolovsky's avatar Paul Sokolovsky Committed by Damien George
Browse files

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.
parent 2411f42c
No related branches found
No related tags found
No related merge requests found
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")
True
True
TypeError
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment