9f96aeda6f
This CL introduces unit tests for the Native* classes in compiler/ffi that can run for all supported target ABIs on any host architecture. The unit tests are compiled for all target ABIs with `tools/build.py run_ffi_unit_tests` and run for all target ABIs with `tools/test.py ffi_unit`. The unit test and tested code do not conceptually depend on having a DartVM. The tests are compiled with a custom `dart::Zone` and `platform/`. This enables compiling for all `TARGET_ARCH_*` and `TARGET_OS_*` on any host, and running unit tests for all target ABIs on any host. Because the `run_ffi_unit_tests` executables do not include the DartVM their build is quick (<10seconds) and they are small (~6MB) when compared to `run_vm_tests` (~250MB). The tests are added to the existing FFI QEMU bot to prevent adding an extra bot which would add checkout overhead. The unit tests themselves are set up to be fairly similar to vm/cc tests. The only difference is the NativeCallingConvention tests which are set up with `.expect` files for easy inspection and updating. TEST=runtime/vm/compiler/ffi/native_calling_convention_test.cc TEST=runtime/vm/compiler/ffi/native_location_test.cc TEST=runtime/vm/compiler/ffi/native_type_test.cc Change-Id: I7b8bf4de9ef070e7546472217e571a60362b9639 Cq-Include-Trybots: luci.dart.try:vm-precomp-ffi-qemu-linux-release-arm-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/171725 Commit-Queue: Daco Harkes <dacoharkes@google.com> Reviewed-by: Clement Skau <cskau@google.com> Reviewed-by: Alexander Thomas <athom@google.com>
46 lines
1.3 KiB
C++
46 lines
1.3 KiB
C++
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
#include "vm/compiler/ffi/unit_test_custom_zone.h"
|
|
|
|
#include "vm/compiler/runtime_api.h"
|
|
|
|
// Directly compile cc files into the custom zone, so that we do not get linker
|
|
// errors from object files compiled against the DartVM Zone.
|
|
#include "vm/compiler/ffi/native_calling_convention.cc" // NOLINT
|
|
#include "vm/compiler/ffi/native_location.cc" // NOLINT
|
|
#include "vm/compiler/ffi/native_type.cc" // NOLINT
|
|
#include "vm/zone_text_buffer.cc" // NOLINT
|
|
|
|
namespace dart {
|
|
|
|
void* ZoneAllocated::operator new(uintptr_t size, dart::Zone* zone) {
|
|
return reinterpret_cast<void*>(zone->AllocUnsafe(size));
|
|
}
|
|
|
|
Zone::~Zone() {
|
|
while (buffers_.size() > 0) {
|
|
free(buffers_.back());
|
|
buffers_.pop_back();
|
|
}
|
|
}
|
|
|
|
void* Zone::AllocUnsafe(intptr_t size) {
|
|
void* memory = malloc(size);
|
|
buffers_.push_back(memory);
|
|
return memory;
|
|
}
|
|
|
|
DART_EXPORT void Dart_PrepareToAbort() {
|
|
fprintf(stderr, "Dart_PrepareToAbort() not implemented!\n");
|
|
exit(1);
|
|
}
|
|
|
|
DART_EXPORT void Dart_DumpNativeStackTrace(void* context) {
|
|
fprintf(stderr, "Dart_DumpNativeStackTrace() not implemented!\n");
|
|
exit(1);
|
|
}
|
|
|
|
} // namespace dart
|