Files
sdk/runtime/tools/embedder_layering_check.py
T
Daco Harkes 9f96aeda6f [test/ffi] Add C++ unit tests for all target ABIs
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>
2020-11-16 16:10:55 +00:00

81 lines
2.6 KiB
Python

#!/usr/bin/env python
#
# Copyright (c) 2019, 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.
# Simple tool for verifying that sources from the standalone embedder do not
# directly include sources from the VM or vice versa.
import glob
import os
import re
import sys
INCLUDE_DIRECTIVE_RE = re.compile(r'^#include "(.*)"')
PLATFORM_LAYER_RE = re.compile(r'^runtime/platform/')
VM_LAYER_RE = re.compile(r'^runtime/(vm|lib)/')
BIN_LAYER_RE = re.compile(r'^runtime/bin/')
# Tests that don't match the simple case of *_test.cc.
EXTRA_TEST_FILES = [
'runtime/bin/run_vm_tests.cc',
'runtime/bin/ffi_unit_test/run_ffi_unit_tests.cc',
'runtime/vm/libfuzzer/dart_libfuzzer.cc'
]
def CheckFile(sdk_root, path):
includes = set()
with open(os.path.join(sdk_root, path)) as file:
for line in file:
m = INCLUDE_DIRECTIVE_RE.match(line)
if m is not None:
header = os.path.join('runtime', m.group(1))
if os.path.isfile(os.path.join(sdk_root, header)):
includes.add(header)
errors = []
for include in includes:
if PLATFORM_LAYER_RE.match(path):
if VM_LAYER_RE.match(include):
errors.append(
'LAYERING ERROR: %s must not include %s' % (path, include))
elif BIN_LAYER_RE.match(include):
errors.append(
'LAYERING ERROR: %s must not include %s' % (path, include))
elif VM_LAYER_RE.match(path):
if BIN_LAYER_RE.match(include):
errors.append(
'LAYERING ERROR: %s must not include %s' % (path, include))
elif BIN_LAYER_RE.match(path):
if VM_LAYER_RE.match(include):
errors.append(
'LAYERING ERROR: %s must not include %s' % (path, include))
return errors
def CheckDir(sdk_root, dir):
errors = []
for file in os.listdir(dir):
path = os.path.join(dir, file)
if os.path.isdir(path):
errors += CheckDir(sdk_root, path)
elif path.endswith('test.cc') or path in EXTRA_TEST_FILES:
None # Tests may violate layering.
elif path.endswith('.cc') or path.endswith('.h'):
errors += CheckFile(sdk_root, os.path.relpath(path, sdk_root))
return errors
def DoCheck(sdk_root):
return CheckDir(sdk_root, 'runtime')
if __name__ == '__main__':
errors = DoCheck('.')
print '\n'.join(errors)
if errors:
sys.exit(-1)