[dart2wasm] Small improvements in FFI native tests:

- Document which target needs to be built for the test
  `web/wasm/ffi/ffi_native`.

- Add tests that passes and expects `double` and `float`s.
  (The `sqrt` native function was previous unused)

- Define inputs in `wasm_module` gn template so that the
  `ffi_native_test_wasm_module` target will rebuild the Wasm file when
  `tests/web/wasm/ffi/ffi_native_test_module.c` changes.

Change-Id: Iff642ff2cdee48a617e8f2cf4cca4053122a7e05
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384263
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
This commit is contained in:
Ömer Sinan Ağacan
2024-09-10 09:51:41 +00:00
committed by Commit Queue
parent a5baf4e15b
commit 0e58775986
3 changed files with 22 additions and 1 deletions
+10 -1
View File
@@ -5,6 +5,9 @@
// dart2wasmOptions=--extra-compiler-option=--enable-experimental-ffi
// SharedObjects=ffi_native_test_module
// Build target `ffi_native_test_wasm_module` for the FFI module used in this
// test.
import 'dart:ffi';
import 'dart:nativewrappers';
@@ -46,8 +49,11 @@ external bool boolReturn(int b);
@Native<Void Function()>()
external void toggleBool();
@Native<Float Function(Float)>()
external double sqrtFloat(double d);
@Native<Double Function(Double)>()
external double sqrt(double d);
external double sqrtDouble(double d);
@Native<Char Function(Char)>()
external int incrementChar(int a);
@@ -173,6 +179,9 @@ void main() {
Expect.equals(incrementUintPtr(25), 26);
Expect.equals(incrementSize(27), 28);
Expect.equals(incrementWchar(29), 30);
Expect.equals(sqrtDouble(1e300), 1e150);
Expect.equals(sqrtFloat(1e10), 1e5);
}
// Don't crash on an unused `Native.addressOf`.
@@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
#include <emscripten.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
@@ -163,3 +164,13 @@ EMSCRIPTEN_KEEPALIVE
wchar_t incrementWchar(wchar_t a) {
return a + 1;
}
EMSCRIPTEN_KEEPALIVE
double sqrtDouble(double d) {
return sqrt(d);
}
EMSCRIPTEN_KEEPALIVE
float sqrtFloat(float d) {
return sqrtf(d);
}
+1
View File
@@ -19,6 +19,7 @@ template("wasm_module") {
rebase_path("$root_out_dir/wasm/${invoker.module_name}.wasm"),
"-O",
]
inputs = [ "//tests/web/wasm/ffi/${invoker.module_name}.c" ]
outputs = [ "$root_out_dir/wasm/${invoker.module_name}.wasm" ]
}
}