Skip to content

Commit af0670c

Browse files
mralephCommit Queue
authored and
Commit Queue
committed
[tests] Tweak ffi/unaligned_test to reflect decision made in #45009
Skip float and double access tests on ARM because they will always trigger alignment traps. These traps might or might not be hidden from the user depending on the specific OS configuration, e.g. many Linux distrubutions choose to perform fixup in the kernel, but Android disables that. Similarly there is a difference in QEMU behavior depending on QEMU version. Change-Id: Idca9553486e0f479ec1a32c25131d3d1bd4ef74d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/338140 Reviewed-by: Daco Harkes <[email protected]> Commit-Queue: Slava Egorov <[email protected]> Commit-Queue: Daco Harkes <[email protected]> Auto-Submit: Slava Egorov <[email protected]>
1 parent 2534859 commit af0670c

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

tests/ffi/unaligned_test.dart

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,36 @@ import 'dart:io';
1212
import 'package:expect/expect.dart';
1313
import 'package:ffi/ffi.dart';
1414

15+
final bool isUnalignedFloatingPointAccessSupported = switch (Abi.current()) {
16+
// ARMv7-A in [Unaligned Access][1] specifies that VSTR and VLDR will trigger
17+
// alignment trap if address is not word aligned irrespective of SCTLR.A
18+
// state. Some operating systems (e.g. Linux via [`/proc/cpu/alignment`][2])
19+
// can be configured to catch alignment trap, perform unaligned read in
20+
// kernel and resume the execution. Android on the other hand configures
21+
// `/proc/cpu/alignment` to always forward alignment trap to the application
22+
// as a SIGBUS. Finally, different version of QEMU implement different
23+
// behavior for unaligned accesses: older versions ignored ARMv7-A
24+
// requirements while newer versions will correctly trigger alignment trap.
25+
//
26+
// We have decided in https://dartbug.com/45009 that we are not going to
27+
// support unaligned accesses in FFI in a special way (e.g. it is on user
28+
// to be aware of potential problems with unaligned accesses). Consequently
29+
// we simply ignore double and float unaligned tests in configurations
30+
// where they cause alignment traps (irrespective of whether OS will fixup
31+
// and hide the trap from the user or not).
32+
//
33+
// [1]: https://developer.arm.com/documentation/ddi0406/c/Application-Level-Architecture/Application-Level-Memory-Model/Alignment-support/Unaligned-data-access?lang=en
34+
// [2]: https://docs.kernel.org/arch/arm/mem_alignment.html
35+
Abi.androidArm || Abi.linuxArm || Abi.iosArm => false,
36+
_ => true,
37+
};
38+
1539
void main() {
1640
print("hello");
1741
testUnalignedInt16(); //# 01: ok
1842
testUnalignedInt32(); //# 02: ok
1943
testUnalignedInt64(); //# 03: ok
20-
if (!Platform.isAndroid || sizeOf<Pointer>() == 8) {
21-
// TODO(http://dartbug.com/45009): Support unaligned reads/writes on
22-
// Android arm32.
44+
if (isUnalignedFloatingPointAccessSupported) {
2345
testUnalignedFloat(); //# 04: ok
2446
testUnalignedDouble(); //# 05: ok
2547
}

0 commit comments

Comments
 (0)