Skip to content

Commit

Permalink
[vm/ffi] Do not use int in tests
Browse files Browse the repository at this point in the history
sizeof(int) on iOS arm64 in Flutter test projects returns 4.

Issue: #36140
Issue: #39637

Change-Id: I7b471fa1da653e9bee169c34d1bd36a96fa6a704
Cq-Include-Trybots: luci.dart.try:vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64-try,app-kernel-linux-debug-x64-try,vm-kernel-linux-debug-ia32-try,vm-kernel-win-debug-x64-try,vm-kernel-win-debug-ia32-try,vm-kernel-precomp-linux-debug-x64-try,vm-dartkb-linux-release-x64-abi-try,vm-kernel-precomp-android-release-arm64-try,vm-kernel-asan-linux-release-x64-try,vm-kernel-linux-release-simarm-try,vm-kernel-linux-release-simarm64-try,vm-kernel-precomp-android-release-arm_x64-try,vm-kernel-precomp-obfuscate-linux-release-x64-try,dart-sdk-linux-try,analyzer-analysis-server-linux-try,analyzer-linux-release-try,front-end-linux-release-x64-try,vm-kernel-precomp-win-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132607
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
  • Loading branch information
dcharkes authored and commit-bot@chromium.org committed Jan 21, 2020
1 parent f910a75 commit ef0c7f1
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 88 deletions.
2 changes: 1 addition & 1 deletion runtime/bin/ffi_test/ffi_test_dynamic_library.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
extern "C" __attribute__((visibility("default"))) __attribute((used))
#endif

DART_EXPORT int return42() {
DART_EXPORT intptr_t return42() {
return 42;
}

Expand Down
156 changes: 78 additions & 78 deletions runtime/bin/ffi_test/ffi_test_functions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ DART_EXPORT int64_t UintComputation(uint8_t a,
return retval;
}

// Multiplies pointer sized int by three.
// Multiplies pointer sized intptr_t by three.
// Used for testing pointer sized parameter and return value.
DART_EXPORT intptr_t Times3(intptr_t a) {
std::cout << "Times3(" << a << ")\n";
Expand Down Expand Up @@ -317,25 +317,25 @@ DART_EXPORT double SumManyDoubles(double a,
// Sums many numbers.
// Used for testing calling conventions. With so many parameters we are using
// both registers and stack slots.
DART_EXPORT double SumManyNumbers(int a,
DART_EXPORT double SumManyNumbers(intptr_t a,
float b,
int c,
intptr_t c,
double d,
int e,
intptr_t e,
float f,
int g,
intptr_t g,
double h,
int i,
intptr_t i,
float j,
int k,
intptr_t k,
double l,
int m,
intptr_t m,
float n,
int o,
intptr_t o,
double p,
int q,
intptr_t q,
float r,
int s,
intptr_t s,
double t) {
std::cout << "SumManyNumbers(" << a << ", " << b << ", " << c << ", " << d
<< ", " << e << ", " << f << ", " << g << ", " << h << ", " << i
Expand Down Expand Up @@ -532,7 +532,7 @@ DART_EXPORT int64_t SumVeryLargeStruct(VeryLargeStruct* vls) {
retval += vls->parent->a;
}
std::cout << "has " << vls->numChildren << " children\n";
for (int i = 0; i < vls->numChildren; i++) {
for (intptr_t i = 0; i < vls->numChildren; i++) {
retval += vls->children[i].a;
}
std::cout << "returning " << retval << "\n";
Expand Down Expand Up @@ -577,7 +577,7 @@ DART_EXPORT void DevNullFloat(float a) {
std::cout << "returning nothing\n";
}

// Invents an elite floating point number.
// Invents an elite floating pointptr_t number.
// Used for testing functions that do not take any arguments.
DART_EXPORT float InventFloatValue() {
std::cout << "InventFloatValue()\n";
Expand All @@ -590,95 +590,95 @@ DART_EXPORT float InventFloatValue() {
// Tests for callbacks.

// Sanity test.
DART_EXPORT int TestSimpleAddition(int (*add)(int, int)) {
DART_EXPORT intptr_t TestSimpleAddition(intptr_t (*add)(int, int)) {
CHECK_EQ(add(10, 20), 30);
return 0;
}

//// Following tests are copied from above, with the role of Dart and C++ code
//// reversed.

DART_EXPORT int TestIntComputation(
int64_t (*fn)(int8_t, int16_t, int32_t, int64_t)) {
DART_EXPORT intptr_t
TestIntComputation(int64_t (*fn)(int8_t, int16_t, int32_t, int64_t)) {
CHECK_EQ(fn(125, 250, 500, 1000), 625);
CHECK_EQ(0x7FFFFFFFFFFFFFFFLL, fn(0, 0, 0, 0x7FFFFFFFFFFFFFFFLL));
CHECK_EQ(((int64_t)-0x8000000000000000LL),
fn(0, 0, 0, -0x8000000000000000LL));
return 0;
}

DART_EXPORT int TestUintComputation(
uint64_t (*fn)(uint8_t, uint16_t, uint32_t, uint64_t)) {
DART_EXPORT intptr_t
TestUintComputation(uint64_t (*fn)(uint8_t, uint16_t, uint32_t, uint64_t)) {
CHECK_EQ(0x7FFFFFFFFFFFFFFFLL, fn(0, 0, 0, 0x7FFFFFFFFFFFFFFFLL));
CHECK_EQ(-0x8000000000000000LL, fn(0, 0, 0, -0x8000000000000000LL));
CHECK_EQ(-1, (int64_t)fn(0, 0, 0, -1));
return 0;
}

DART_EXPORT int TestSimpleMultiply(double (*fn)(double)) {
DART_EXPORT intptr_t TestSimpleMultiply(double (*fn)(double)) {
CHECK_EQ(fn(2.0), 2.0 * 1.337);
return 0;
}

DART_EXPORT int TestSimpleMultiplyFloat(float (*fn)(float)) {
DART_EXPORT intptr_t TestSimpleMultiplyFloat(float (*fn)(float)) {
CHECK(::std::abs(fn(2.0) - 2.0 * 1.337) < 0.001);
return 0;
}

DART_EXPORT int TestManyInts(intptr_t (*fn)(intptr_t,
intptr_t,
intptr_t,
intptr_t,
intptr_t,
intptr_t,
intptr_t,
intptr_t,
intptr_t,
intptr_t)) {
DART_EXPORT intptr_t TestManyInts(intptr_t (*fn)(intptr_t,
intptr_t,
intptr_t,
intptr_t,
intptr_t,
intptr_t,
intptr_t,
intptr_t,
intptr_t,
intptr_t)) {
CHECK_EQ(55, fn(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
return 0;
}

DART_EXPORT int TestManyDoubles(double (*fn)(double,
double,
double,
double,
double,
double,
double,
double,
double,
double)) {
DART_EXPORT intptr_t TestManyDoubles(double (*fn)(double,
double,
double,
double,
double,
double,
double,
double,
double,
double)) {
CHECK_EQ(55, fn(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
return 0;
}

DART_EXPORT int TestManyArgs(double (*fn)(intptr_t a,
float b,
intptr_t c,
double d,
intptr_t e,
float f,
intptr_t g,
double h,
intptr_t i,
float j,
intptr_t k,
double l,
intptr_t m,
float n,
intptr_t o,
double p,
intptr_t q,
float r,
intptr_t s,
double t)) {
DART_EXPORT intptr_t TestManyArgs(double (*fn)(intptr_t a,
float b,
intptr_t c,
double d,
intptr_t e,
float f,
intptr_t g,
double h,
intptr_t i,
float j,
intptr_t k,
double l,
intptr_t m,
float n,
intptr_t o,
double p,
intptr_t q,
float r,
intptr_t s,
double t)) {
CHECK(210.0 == fn(1, 2.0, 3, 4.0, 5, 6.0, 7, 8.0, 9, 10.0, 11, 12.0, 13, 14.0,
15, 16.0, 17, 18.0, 19, 20.0));
return 0;
}

DART_EXPORT int TestStore(int64_t* (*fn)(int64_t* a)) {
DART_EXPORT intptr_t TestStore(int64_t* (*fn)(int64_t* a)) {
int64_t p[2] = {42, 1000};
int64_t* result = fn(p);
CHECK_EQ(*result, 1337);
Expand All @@ -687,56 +687,56 @@ DART_EXPORT int TestStore(int64_t* (*fn)(int64_t* a)) {
return 0;
}

DART_EXPORT int TestReturnNull(int32_t (*fn)()) {
DART_EXPORT intptr_t TestReturnNull(int32_t (*fn)()) {
CHECK_EQ(fn(), 42);
return 0;
}

DART_EXPORT int TestNullPointers(int64_t* (*fn)(int64_t* ptr)) {
DART_EXPORT intptr_t TestNullPointers(int64_t* (*fn)(int64_t* ptr)) {
CHECK_EQ(fn(nullptr), reinterpret_cast<void*>(sizeof(int64_t)));
int64_t p[2] = {0};
CHECK_EQ(fn(p), p + 1);
return 0;
}

DART_EXPORT int TestReturnVoid(int (*return_void)()) {
DART_EXPORT intptr_t TestReturnVoid(intptr_t (*return_void)()) {
CHECK_EQ(return_void(), 0);
return 0;
}

DART_EXPORT int TestThrowExceptionDouble(double (*fn)()) {
DART_EXPORT intptr_t TestThrowExceptionDouble(double (*fn)()) {
CHECK_EQ(fn(), 42.0);
return 0;
}

DART_EXPORT int TestThrowExceptionPointer(void* (*fn)()) {
DART_EXPORT intptr_t TestThrowExceptionPointer(void* (*fn)()) {
CHECK_EQ(fn(), nullptr);
return 0;
}

DART_EXPORT int TestThrowException(int (*fn)()) {
DART_EXPORT intptr_t TestThrowException(intptr_t (*fn)()) {
CHECK_EQ(fn(), 42);
return 0;
}

DART_EXPORT int TestTakeMaxUint8x10(intptr_t (*fn)(uint8_t,
uint8_t,
uint8_t,
uint8_t,
uint8_t,
uint8_t,
uint8_t,
uint8_t,
uint8_t,
uint8_t)) {
DART_EXPORT intptr_t TestTakeMaxUint8x10(intptr_t (*fn)(uint8_t,
uint8_t,
uint8_t,
uint8_t,
uint8_t,
uint8_t,
uint8_t,
uint8_t,
uint8_t,
uint8_t)) {
CHECK_EQ(1, fn(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF));
// Check the argument values are properly truncated.
uint64_t v = 0xabcFF;
CHECK_EQ(1, fn(v, v, v, v, v, v, v, v, v, v));
return 0;
}

DART_EXPORT int TestReturnMaxUint8(uint8_t (*fn)()) {
DART_EXPORT intptr_t TestReturnMaxUint8(uint8_t (*fn)()) {
std::cout << "TestReturnMaxUint8(fn): " << static_cast<int>(fn()) << "\n";
CHECK_EQ(0xFF, fn());
return 0;
Expand Down
18 changes: 9 additions & 9 deletions runtime/bin/ffi_test/ffi_test_functions_vmspecific.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ void ClobberAndCall(void (*fn)()) {
extern "C" void ClobberAndCall(void (*fn)());
#endif

DART_EXPORT int TestGC(void (*do_gc)()) {
DART_EXPORT intptr_t TestGC(void (*do_gc)()) {
ClobberAndCall(do_gc);
return 0;
}

struct CallbackTestData {
int success;
intptr_t success;
void (*callback)();
};

Expand All @@ -189,11 +189,11 @@ void CallbackTestSignalHandler(int) {
siglongjmp(buf, 1);
}

int ExpectAbort(void (*fn)()) {
intptr_t ExpectAbort(void (*fn)()) {
fprintf(stderr, "**** EXPECT STACKTRACE TO FOLLOW. THIS IS OK. ****\n");

struct sigaction old_action = {};
int result = __sigsetjmp(buf, /*savesigs=*/1);
intptr_t result = __sigsetjmp(buf, /*savesigs=*/1);
if (result == 0) {
// Install signal handler.
struct sigaction handler = {};
Expand All @@ -219,10 +219,10 @@ void* TestCallbackOnThreadOutsideIsolate(void* parameter) {
return NULL;
}

int TestCallbackOtherThreadHelper(void* (*tester)(void*), void (*fn)()) {
intptr_t TestCallbackOtherThreadHelper(void* (*tester)(void*), void (*fn)()) {
CallbackTestData data = {1, fn};
pthread_attr_t attr;
int result = pthread_attr_init(&attr);
intptr_t result = pthread_attr_init(&attr);
CHECK_EQ(result, 0);

pthread_t tid;
Expand All @@ -241,13 +241,13 @@ int TestCallbackOtherThreadHelper(void* (*tester)(void*), void (*fn)()) {
}

// Run a callback on another thread and verify that it triggers SIGABRT.
DART_EXPORT int TestCallbackWrongThread(void (*fn)()) {
DART_EXPORT intptr_t TestCallbackWrongThread(void (*fn)()) {
return TestCallbackOtherThreadHelper(&TestCallbackOnThreadOutsideIsolate, fn);
}

// Verify that we get SIGABRT when invoking a native callback outside an
// isolate.
DART_EXPORT int TestCallbackOutsideIsolate(void (*fn)()) {
DART_EXPORT intptr_t TestCallbackOutsideIsolate(void (*fn)()) {
Dart_Isolate current = Dart_CurrentIsolate();

Dart_ExitIsolate();
Expand All @@ -258,7 +258,7 @@ DART_EXPORT int TestCallbackOutsideIsolate(void (*fn)()) {
return data.success;
}

DART_EXPORT int TestCallbackWrongIsolate(void (*fn)()) {
DART_EXPORT intptr_t TestCallbackWrongIsolate(void (*fn)()) {
return ExpectAbort(fn);
}

Expand Down

0 comments on commit ef0c7f1

Please sign in to comment.