|
| 1 | +// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file |
| 2 | +// for details. All rights reserved. Use of this source code is governed by a |
| 3 | +// BSD-style license that can be found in the LICENSE file. |
| 4 | +// |
| 5 | +// Dart test program for testing dart:ffi calls argument passing. |
| 6 | +// |
| 7 | +// VMOptions= |
| 8 | +// VMOptions=--deterministic --optimization-counter-threshold=10 |
| 9 | +// VMOptions=--use-slow-path |
| 10 | +// VMOptions=--use-slow-path --stacktrace-every=100 |
| 11 | +// VMOptions=--write-protect-code --no-dual-map-code |
| 12 | +// VMOptions=--write-protect-code --no-dual-map-code --use-slow-path |
| 13 | +// VMOptions=--write-protect-code --no-dual-map-code --stacktrace-every=100 |
| 14 | +// SharedObjects=ffi_test_functions |
| 15 | + |
| 16 | +import 'dart:ffi'; |
| 17 | + |
| 18 | +import 'dylib_utils.dart'; |
| 19 | + |
| 20 | +import "package:expect/expect.dart"; |
| 21 | + |
| 22 | +void main() { |
| 23 | + for (int i = 0; i < 100; ++i) { |
| 24 | + testSumVeryManySmallInts(); |
| 25 | + testSumVeryManyFloatsDoubles(); |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +final ffiTestFunctions = dlopenPlatformSpecific("ffi_test_functions"); |
| 30 | + |
| 31 | +VeryManyIntsOp sumVeryManySmallInts = |
| 32 | + ffiTestFunctions.lookupFunction<NativeVeryManyIntsOp, VeryManyIntsOp>( |
| 33 | + "SumVeryManySmallInts"); |
| 34 | +// Very many small integers, tests alignment on stack. |
| 35 | +void testSumVeryManySmallInts() { |
| 36 | + Expect.equals( |
| 37 | + 40 * 41 / 2, |
| 38 | + sumVeryManySmallInts( |
| 39 | + 1, |
| 40 | + 2, |
| 41 | + 3, |
| 42 | + 4, |
| 43 | + 5, |
| 44 | + 6, |
| 45 | + 7, |
| 46 | + 8, |
| 47 | + 9, |
| 48 | + 10, |
| 49 | + 11, |
| 50 | + 12, |
| 51 | + 13, |
| 52 | + 14, |
| 53 | + 15, |
| 54 | + 16, |
| 55 | + 17, |
| 56 | + 18, |
| 57 | + 19, |
| 58 | + 20, |
| 59 | + 21, |
| 60 | + 22, |
| 61 | + 23, |
| 62 | + 24, |
| 63 | + 25, |
| 64 | + 26, |
| 65 | + 27, |
| 66 | + 28, |
| 67 | + 29, |
| 68 | + 30, |
| 69 | + 31, |
| 70 | + 32, |
| 71 | + 33, |
| 72 | + 34, |
| 73 | + 35, |
| 74 | + 36, |
| 75 | + 37, |
| 76 | + 38, |
| 77 | + 39, |
| 78 | + 40)); |
| 79 | +} |
| 80 | + |
| 81 | +VeryManyFloatsDoublesOp sumVeryManyFloatsDoubles = ffiTestFunctions |
| 82 | + .lookupFunction<NativeVeryManyFloatsDoublesOp, VeryManyFloatsDoublesOp>( |
| 83 | + "SumVeryManyFloatsDoubles"); |
| 84 | + |
| 85 | +// Very many floating points, tests alignment on stack, and packing in |
| 86 | +// floating point registers in hardfp. |
| 87 | +void testSumVeryManyFloatsDoubles() { |
| 88 | + Expect.approxEquals( |
| 89 | + 40.0 * 41.0 / 2.0, |
| 90 | + sumVeryManyFloatsDoubles( |
| 91 | + 1.0, |
| 92 | + 2.0, |
| 93 | + 3.0, |
| 94 | + 4.0, |
| 95 | + 5.0, |
| 96 | + 6.0, |
| 97 | + 7.0, |
| 98 | + 8.0, |
| 99 | + 9.0, |
| 100 | + 10.0, |
| 101 | + 11.0, |
| 102 | + 12.0, |
| 103 | + 13.0, |
| 104 | + 14.0, |
| 105 | + 15.0, |
| 106 | + 16.0, |
| 107 | + 17.0, |
| 108 | + 18.0, |
| 109 | + 19.0, |
| 110 | + 20.0, |
| 111 | + 21.0, |
| 112 | + 22.0, |
| 113 | + 23.0, |
| 114 | + 24.0, |
| 115 | + 25.0, |
| 116 | + 26.0, |
| 117 | + 27.0, |
| 118 | + 28.0, |
| 119 | + 29.0, |
| 120 | + 30.0, |
| 121 | + 31.0, |
| 122 | + 32.0, |
| 123 | + 33.0, |
| 124 | + 34.0, |
| 125 | + 35.0, |
| 126 | + 36.0, |
| 127 | + 37.0, |
| 128 | + 38.0, |
| 129 | + 39.0, |
| 130 | + 40.0)); |
| 131 | +} |
| 132 | + |
| 133 | +typedef NativeVeryManyIntsOp = Int16 Function( |
| 134 | + Int8, |
| 135 | + Int16, |
| 136 | + Int8, |
| 137 | + Int16, |
| 138 | + Int8, |
| 139 | + Int16, |
| 140 | + Int8, |
| 141 | + Int16, |
| 142 | + Int8, |
| 143 | + Int16, |
| 144 | + Int8, |
| 145 | + Int16, |
| 146 | + Int8, |
| 147 | + Int16, |
| 148 | + Int8, |
| 149 | + Int16, |
| 150 | + Int8, |
| 151 | + Int16, |
| 152 | + Int8, |
| 153 | + Int16, |
| 154 | + Int8, |
| 155 | + Int16, |
| 156 | + Int8, |
| 157 | + Int16, |
| 158 | + Int8, |
| 159 | + Int16, |
| 160 | + Int8, |
| 161 | + Int16, |
| 162 | + Int8, |
| 163 | + Int16, |
| 164 | + Int8, |
| 165 | + Int16, |
| 166 | + Int8, |
| 167 | + Int16, |
| 168 | + Int8, |
| 169 | + Int16, |
| 170 | + Int8, |
| 171 | + Int16, |
| 172 | + Int8, |
| 173 | + Int16); |
| 174 | + |
| 175 | +typedef VeryManyIntsOp = int Function( |
| 176 | + int, |
| 177 | + int, |
| 178 | + int, |
| 179 | + int, |
| 180 | + int, |
| 181 | + int, |
| 182 | + int, |
| 183 | + int, |
| 184 | + int, |
| 185 | + int, |
| 186 | + int, |
| 187 | + int, |
| 188 | + int, |
| 189 | + int, |
| 190 | + int, |
| 191 | + int, |
| 192 | + int, |
| 193 | + int, |
| 194 | + int, |
| 195 | + int, |
| 196 | + int, |
| 197 | + int, |
| 198 | + int, |
| 199 | + int, |
| 200 | + int, |
| 201 | + int, |
| 202 | + int, |
| 203 | + int, |
| 204 | + int, |
| 205 | + int, |
| 206 | + int, |
| 207 | + int, |
| 208 | + int, |
| 209 | + int, |
| 210 | + int, |
| 211 | + int, |
| 212 | + int, |
| 213 | + int, |
| 214 | + int, |
| 215 | + int); |
| 216 | + |
| 217 | +typedef NativeVeryManyFloatsDoublesOp = Double Function( |
| 218 | + Float, |
| 219 | + Double, |
| 220 | + Float, |
| 221 | + Double, |
| 222 | + Float, |
| 223 | + Double, |
| 224 | + Float, |
| 225 | + Double, |
| 226 | + Float, |
| 227 | + Double, |
| 228 | + Float, |
| 229 | + Double, |
| 230 | + Float, |
| 231 | + Double, |
| 232 | + Float, |
| 233 | + Double, |
| 234 | + Float, |
| 235 | + Double, |
| 236 | + Float, |
| 237 | + Double, |
| 238 | + Float, |
| 239 | + Double, |
| 240 | + Float, |
| 241 | + Double, |
| 242 | + Float, |
| 243 | + Double, |
| 244 | + Float, |
| 245 | + Double, |
| 246 | + Float, |
| 247 | + Double, |
| 248 | + Float, |
| 249 | + Double, |
| 250 | + Float, |
| 251 | + Double, |
| 252 | + Float, |
| 253 | + Double, |
| 254 | + Float, |
| 255 | + Double, |
| 256 | + Float, |
| 257 | + Double); |
| 258 | + |
| 259 | +typedef VeryManyFloatsDoublesOp = double Function( |
| 260 | + double, |
| 261 | + double, |
| 262 | + double, |
| 263 | + double, |
| 264 | + double, |
| 265 | + double, |
| 266 | + double, |
| 267 | + double, |
| 268 | + double, |
| 269 | + double, |
| 270 | + double, |
| 271 | + double, |
| 272 | + double, |
| 273 | + double, |
| 274 | + double, |
| 275 | + double, |
| 276 | + double, |
| 277 | + double, |
| 278 | + double, |
| 279 | + double, |
| 280 | + double, |
| 281 | + double, |
| 282 | + double, |
| 283 | + double, |
| 284 | + double, |
| 285 | + double, |
| 286 | + double, |
| 287 | + double, |
| 288 | + double, |
| 289 | + double, |
| 290 | + double, |
| 291 | + double, |
| 292 | + double, |
| 293 | + double, |
| 294 | + double, |
| 295 | + double, |
| 296 | + double, |
| 297 | + double, |
| 298 | + double, |
| 299 | + double); |
0 commit comments