mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 09:43:57 +00:00
[test/ffi] Split generated files on isLeaf
Splits up tests/ffi/function_structs_by_value_generated_test.dart in - compounds - non-leaf calls - leaf calls We could also consider splitting on chunks from the `functions` from tests/ffi/generator/structs_by_value_tests_configuration.dart as a follow up. TEST=This only splits up the tests, please reapprove failures. Expected failures: https://dart-ci.firebaseapp.com/current_results/#/filter=ffi - windows precompiled https://github.com/dart-lang/sdk/issues/40564 - mac arm64 https://github.com/dart-lang/sdk/issues/46349 Bug: https://github.com/dart-lang/sdk/issues/45007 Change-Id: Id3d9987cbc1e09f579b8cc68ce72fe5d36348b80 Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-nnbd-win-release-x64-try,vm-kernel-precomp-win-release-x64-try,vm-kernel-precomp-win-debug-x64c-try,pkg-mac-release-arm64-try,vm-kernel-mac-release-arm64-try,vm-kernel-nnbd-mac-debug-arm64-try,vm-kernel-nnbd-mac-release-arm64-try,vm-kernel-precomp-nnbd-mac-release-arm64-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/216666 Reviewed-by: Clement Skau <cskau@google.com>
This commit is contained in:
parent
e512402b05
commit
8516cdc587
|
@ -18,8 +18,12 @@ import "package:ffi/ffi.dart";
|
|||
|
||||
import 'callback_tests_utils.dart';
|
||||
|
||||
// Reuse the struct classes.
|
||||
import 'function_structs_by_value_generated_test.dart';
|
||||
import 'dylib_utils.dart';
|
||||
|
||||
// Reuse the compound classes.
|
||||
import 'function_structs_by_value_generated_compounds.dart';
|
||||
|
||||
final ffiTestFunctions = dlopenPlatformSpecific("ffi_test_functions");
|
||||
|
||||
void main() {
|
||||
testCases.forEach((t) {
|
||||
|
|
|
@ -11,8 +11,12 @@ import 'dart:ffi';
|
|||
import "package:expect/expect.dart";
|
||||
import "package:ffi/ffi.dart";
|
||||
|
||||
import 'dylib_utils.dart';
|
||||
|
||||
// Reuse the struct classes.
|
||||
import 'function_structs_by_value_generated_test.dart';
|
||||
import 'function_structs_by_value_generated_compounds.dart';
|
||||
|
||||
final ffiTestFunctions = dlopenPlatformSpecific("ffi_test_functions");
|
||||
|
||||
void main() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
|
|
1210
tests/ffi/function_structs_by_value_generated_compounds.dart
Normal file
1210
tests/ffi/function_structs_by_value_generated_compounds.dart
Normal file
File diff suppressed because it is too large
Load diff
7683
tests/ffi/function_structs_by_value_generated_leaf_test.dart
Normal file
7683
tests/ffi/function_structs_by_value_generated_leaf_test.dart
Normal file
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -478,14 +478,14 @@ extension on List<Member> {
|
|||
}
|
||||
|
||||
extension on CompositeType {
|
||||
String dartClass(bool nnbd) {
|
||||
String dartClass({required bool isNnbd}) {
|
||||
final self = this;
|
||||
final packingAnnotation = (self is StructType) && self.hasPacking
|
||||
? "@Packed(${self.packing})"
|
||||
: "";
|
||||
String dartFields = "";
|
||||
for (final member in members) {
|
||||
dartFields += "${member.dartStructField(nnbd)}\n\n";
|
||||
dartFields += "${member.dartStructField(isNnbd)}\n\n";
|
||||
}
|
||||
String toStringBody = members.map((m) {
|
||||
if (m.type is FixedLengthArrayType) {
|
||||
|
@ -585,7 +585,7 @@ extension on FunctionType {
|
|||
""";
|
||||
}
|
||||
|
||||
String dartCallbackCode(bool nnbd) {
|
||||
String dartCallbackCode({required bool isNnbd}) {
|
||||
final argumentss =
|
||||
arguments.map((a) => "${a.type.dartType} ${a.name}").join(", ");
|
||||
|
||||
|
@ -652,7 +652,7 @@ extension on FunctionType {
|
|||
}
|
||||
|
||||
String returnNull = "";
|
||||
if (!nnbd) {
|
||||
if (!isNnbd) {
|
||||
returnNull = """
|
||||
if (${arguments.firstArgumentName()} == $returnNullValue) {
|
||||
print("returning null!");
|
||||
|
@ -861,16 +861,55 @@ const dart2dot9 = '''
|
|||
// @dart = 2.9
|
||||
''';
|
||||
|
||||
headerDartCallTest(bool nnbd) {
|
||||
final dartVersion = nnbd ? '' : dart2dot9;
|
||||
|
||||
headerCommon({required int copyrightYear}) {
|
||||
final year = copyrightYear;
|
||||
return """
|
||||
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
|
||||
// Copyright (c) $year, 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.
|
||||
//
|
||||
// This file has been automatically generated. Please do not edit it manually.
|
||||
// Generated by tests/ffi/generator/structs_by_value_tests_generator.dart.
|
||||
// Generated by tests/ffi/generator/structs_by_value_tests_generator.dart.""";
|
||||
}
|
||||
|
||||
headerDartCompound({required bool isNnbd, required int copyrightYear}) {
|
||||
final dartVersion = isNnbd ? '' : dart2dot9;
|
||||
|
||||
return """
|
||||
${headerCommon(copyrightYear: copyrightYear)}
|
||||
|
||||
$dartVersion
|
||||
|
||||
import 'dart:ffi';
|
||||
""";
|
||||
}
|
||||
|
||||
String compoundsPath({required bool isNnbd}) {
|
||||
final folder = isNnbd ? 'ffi' : 'ffi_2';
|
||||
return Platform.script
|
||||
.resolve(
|
||||
"../../$folder/function_structs_by_value_generated_compounds.dart")
|
||||
.path;
|
||||
}
|
||||
|
||||
Future<void> writeDartCompounds() async {
|
||||
await Future.wait([true, false].map((isNnbd) async {
|
||||
final StringBuffer buffer = StringBuffer();
|
||||
buffer.write(headerDartCompound(isNnbd: isNnbd, copyrightYear: 2021));
|
||||
|
||||
buffer.writeAll(compounds.map((e) => e.dartClass(isNnbd: isNnbd)));
|
||||
|
||||
final path = compoundsPath(isNnbd: isNnbd);
|
||||
await File(path).writeAsString(buffer.toString());
|
||||
await runProcess("dart", ["format", path]);
|
||||
}));
|
||||
}
|
||||
|
||||
headerDartCallTest({required bool isNnbd, required int copyrightYear}) {
|
||||
final dartVersion = isNnbd ? '' : dart2dot9;
|
||||
|
||||
return """
|
||||
${headerCommon(copyrightYear: copyrightYear)}
|
||||
//
|
||||
// SharedObjects=ffi_test_functions
|
||||
// VMOptions=
|
||||
|
@ -887,50 +926,49 @@ import "package:ffi/ffi.dart";
|
|||
|
||||
import 'dylib_utils.dart';
|
||||
|
||||
// Reuse the compound classes.
|
||||
import 'function_structs_by_value_generated_compounds.dart';
|
||||
|
||||
final ffiTestFunctions = dlopenPlatformSpecific("ffi_test_functions");
|
||||
""";
|
||||
}
|
||||
|
||||
Future<void> writeDartCallTest() async {
|
||||
await Future.wait([true, false].map((nnbd) async {
|
||||
Future<void> writeDartCallTest({required bool isLeaf}) async {
|
||||
await Future.wait([true, false].map((isNnbd) async {
|
||||
final StringBuffer buffer = StringBuffer();
|
||||
buffer.write(headerDartCallTest(nnbd));
|
||||
buffer.write(headerDartCallTest(
|
||||
isNnbd: isNnbd, copyrightYear: isLeaf ? 2021 : 2020));
|
||||
|
||||
final suffix = isLeaf ? 'Leaf' : '';
|
||||
buffer.write("""
|
||||
void main() {
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
${functions.map((e) => "${e.dartTestName}();").join("\n")}
|
||||
${functions.map((e) => "${e.dartTestName}Leaf();").join("\n")}
|
||||
${functions.map((e) => "${e.dartTestName}$suffix();").join("\n")}
|
||||
}
|
||||
}
|
||||
""");
|
||||
buffer.writeAll(compounds.map((e) => e.dartClass(nnbd)));
|
||||
buffer.writeAll(functions.map((e) => e.dartCallCode(isLeaf: false)));
|
||||
buffer.writeAll(functions.map((e) => e.dartCallCode(isLeaf: true)));
|
||||
buffer.writeAll(functions.map((e) => e.dartCallCode(isLeaf: isLeaf)));
|
||||
|
||||
final path = callTestPath(nnbd);
|
||||
final path = callTestPath(isNnbd: isNnbd, isLeaf: isLeaf);
|
||||
await File(path).writeAsString(buffer.toString());
|
||||
await runProcess("dart", ["format", path]);
|
||||
}));
|
||||
}
|
||||
|
||||
String callTestPath(bool nnbd) {
|
||||
final folder = nnbd ? "ffi" : "ffi_2";
|
||||
String callTestPath({required bool isNnbd, required bool isLeaf}) {
|
||||
final folder = isNnbd ? 'ffi' : 'ffi_2';
|
||||
final suffix = isLeaf ? '_leaf' : '';
|
||||
return Platform.script
|
||||
.resolve("../../$folder/function_structs_by_value_generated_test.dart")
|
||||
.resolve(
|
||||
"../../$folder/function_structs_by_value_generated${suffix}_test.dart")
|
||||
.path;
|
||||
}
|
||||
|
||||
headerDartCallbackTest(bool nnbd) {
|
||||
final dartVersion = nnbd ? '' : dart2dot9;
|
||||
headerDartCallbackTest({required bool isNnbd, required int copyrightYear}) {
|
||||
final dartVersion = isNnbd ? '' : dart2dot9;
|
||||
|
||||
return """
|
||||
// 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.
|
||||
//
|
||||
// This file has been automatically generated. Please do not edit it manually.
|
||||
// Generated by tests/ffi/generator/structs_by_value_tests_generator.dart.
|
||||
${headerCommon(copyrightYear: copyrightYear)}
|
||||
//
|
||||
// SharedObjects=ffi_test_functions
|
||||
// VMOptions=
|
||||
|
@ -947,9 +985,12 @@ import "package:ffi/ffi.dart";
|
|||
|
||||
import 'callback_tests_utils.dart';
|
||||
|
||||
// Reuse the struct classes.
|
||||
import 'function_structs_by_value_generated_test.dart';
|
||||
import 'dylib_utils.dart';
|
||||
|
||||
// Reuse the compound classes.
|
||||
import 'function_structs_by_value_generated_compounds.dart';
|
||||
|
||||
final ffiTestFunctions = dlopenPlatformSpecific("ffi_test_functions");
|
||||
|
||||
void main() {
|
||||
testCases.forEach((t) {
|
||||
|
@ -963,9 +1004,9 @@ void main() {
|
|||
}
|
||||
|
||||
Future<void> writeDartCallbackTest() async {
|
||||
await Future.wait([true, false].map((nnbd) async {
|
||||
await Future.wait([true, false].map((isNnbd) async {
|
||||
final StringBuffer buffer = StringBuffer();
|
||||
buffer.write(headerDartCallbackTest(nnbd));
|
||||
buffer.write(headerDartCallbackTest(isNnbd: isNnbd, copyrightYear: 2020));
|
||||
|
||||
buffer.write("""
|
||||
final testCases = [
|
||||
|
@ -973,29 +1014,25 @@ Future<void> writeDartCallbackTest() async {
|
|||
];
|
||||
""");
|
||||
|
||||
buffer.writeAll(functions.map((e) => e.dartCallbackCode(nnbd)));
|
||||
buffer.writeAll(functions.map((e) => e.dartCallbackCode(isNnbd: isNnbd)));
|
||||
|
||||
final path = callbackTestPath(nnbd);
|
||||
final path = callbackTestPath(isNnbd: isNnbd);
|
||||
await File(path).writeAsString(buffer.toString());
|
||||
await runProcess("dart", ["format", path]);
|
||||
}));
|
||||
}
|
||||
|
||||
String callbackTestPath(bool nnbd) {
|
||||
final folder = nnbd ? "ffi" : "ffi_2";
|
||||
String callbackTestPath({required bool isNnbd}) {
|
||||
final folder = isNnbd ? "ffi" : "ffi_2";
|
||||
return Platform.script
|
||||
.resolve(
|
||||
"../../$folder/function_callbacks_structs_by_value_generated_test.dart")
|
||||
.path;
|
||||
}
|
||||
|
||||
const headerC = """
|
||||
// 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.
|
||||
//
|
||||
// This file has been automatically generated. Please do not edit it manually.
|
||||
// Generated by tests/ffi/generator/structs_by_value_tests_generator.dart.
|
||||
headerC({required int copyrightYear}) {
|
||||
return """
|
||||
${headerCommon(copyrightYear: copyrightYear)}
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -1028,6 +1065,7 @@ namespace dart {
|
|||
((EXPECTED * 0.99) >= (ACTUAL) && (EXPECTED * 1.01) <= (ACTUAL)))
|
||||
|
||||
""";
|
||||
}
|
||||
|
||||
const footerC = """
|
||||
|
||||
|
@ -1036,7 +1074,7 @@ const footerC = """
|
|||
|
||||
Future<void> writeC() async {
|
||||
final StringBuffer buffer = StringBuffer();
|
||||
buffer.write(headerC);
|
||||
buffer.write(headerC(copyrightYear: 2020));
|
||||
|
||||
buffer.writeAll(compounds.map((e) => e.cDefinition));
|
||||
buffer.writeAll(functions.map((e) => e.cCallCode));
|
||||
|
@ -1058,10 +1096,14 @@ Generates structs by value tests.
|
|||
|
||||
Generates:
|
||||
- $ccPath
|
||||
- ${callbackTestPath(true)}
|
||||
- ${callTestPath(true)}
|
||||
- ${callbackTestPath(false)}
|
||||
- ${callTestPath(false)}
|
||||
- ${compoundsPath(isNnbd: true)}
|
||||
- ${callbackTestPath(isNnbd: true)}
|
||||
- ${callTestPath(isNnbd: true, isLeaf: false)}
|
||||
- ${callTestPath(isNnbd: true, isLeaf: true)}
|
||||
- ${compoundsPath(isNnbd: false)}
|
||||
- ${callbackTestPath(isNnbd: false)}
|
||||
- ${callTestPath(isNnbd: false, isLeaf: false)}
|
||||
- ${callTestPath(isNnbd: false, isLeaf: true)}
|
||||
""");
|
||||
}
|
||||
|
||||
|
@ -1072,7 +1114,9 @@ void main(List<String> arguments) async {
|
|||
}
|
||||
|
||||
await Future.wait([
|
||||
writeDartCallTest(),
|
||||
writeDartCompounds(),
|
||||
writeDartCallTest(isLeaf: false),
|
||||
writeDartCallTest(isLeaf: true),
|
||||
writeDartCallbackTest(),
|
||||
writeC(),
|
||||
]);
|
||||
|
|
|
@ -9,8 +9,8 @@ import 'dart:ffi';
|
|||
import "package:expect/expect.dart";
|
||||
import 'package:ffi/ffi.dart';
|
||||
|
||||
// Reuse struct definitions.
|
||||
import 'function_structs_by_value_generated_test.dart';
|
||||
// Reuse compound definitions.
|
||||
import 'function_structs_by_value_generated_compounds.dart';
|
||||
|
||||
void main() {
|
||||
testSizeOf();
|
||||
|
|
|
@ -9,8 +9,8 @@ import 'dart:ffi';
|
|||
import "package:expect/expect.dart";
|
||||
import 'package:ffi/ffi.dart';
|
||||
|
||||
// Reuse struct definitions.
|
||||
import 'function_structs_by_value_generated_test.dart';
|
||||
// Reuse compound definitions.
|
||||
import 'function_structs_by_value_generated_compounds.dart';
|
||||
|
||||
void main() {
|
||||
testSizeOf();
|
||||
|
|
|
@ -10,8 +10,8 @@ import "package:expect/expect.dart";
|
|||
|
||||
import 'dylib_utils.dart';
|
||||
|
||||
// Reuse struct definitions.
|
||||
import 'function_structs_by_value_generated_test.dart';
|
||||
// Reuse compound definitions.
|
||||
import 'function_structs_by_value_generated_compounds.dart';
|
||||
|
||||
void main() {
|
||||
testSizeOfC();
|
||||
|
|
|
@ -20,8 +20,12 @@ import "package:ffi/ffi.dart";
|
|||
|
||||
import 'callback_tests_utils.dart';
|
||||
|
||||
// Reuse the struct classes.
|
||||
import 'function_structs_by_value_generated_test.dart';
|
||||
import 'dylib_utils.dart';
|
||||
|
||||
// Reuse the compound classes.
|
||||
import 'function_structs_by_value_generated_compounds.dart';
|
||||
|
||||
final ffiTestFunctions = dlopenPlatformSpecific("ffi_test_functions");
|
||||
|
||||
void main() {
|
||||
testCases.forEach((t) {
|
||||
|
|
|
@ -13,8 +13,12 @@ import 'dart:ffi';
|
|||
import "package:expect/expect.dart";
|
||||
import "package:ffi/ffi.dart";
|
||||
|
||||
import 'dylib_utils.dart';
|
||||
|
||||
// Reuse the struct classes.
|
||||
import 'function_structs_by_value_generated_test.dart';
|
||||
import 'function_structs_by_value_generated_compounds.dart';
|
||||
|
||||
final ffiTestFunctions = dlopenPlatformSpecific("ffi_test_functions");
|
||||
|
||||
void main() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
|
|
1212
tests/ffi_2/function_structs_by_value_generated_compounds.dart
Normal file
1212
tests/ffi_2/function_structs_by_value_generated_compounds.dart
Normal file
File diff suppressed because it is too large
Load diff
7685
tests/ffi_2/function_structs_by_value_generated_leaf_test.dart
Normal file
7685
tests/ffi_2/function_structs_by_value_generated_leaf_test.dart
Normal file
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -11,8 +11,8 @@ import 'dart:ffi';
|
|||
import "package:expect/expect.dart";
|
||||
import 'package:ffi/ffi.dart';
|
||||
|
||||
// Reuse struct definitions.
|
||||
import 'function_structs_by_value_generated_test.dart';
|
||||
// Reuse compound definitions.
|
||||
import 'function_structs_by_value_generated_compounds.dart';
|
||||
|
||||
void main() {
|
||||
testSizeOf();
|
||||
|
|
|
@ -11,8 +11,8 @@ import 'dart:ffi';
|
|||
import "package:expect/expect.dart";
|
||||
import 'package:ffi/ffi.dart';
|
||||
|
||||
// Reuse struct definitions.
|
||||
import 'function_structs_by_value_generated_test.dart';
|
||||
// Reuse compound definitions.
|
||||
import 'function_structs_by_value_generated_compounds.dart';
|
||||
|
||||
void main() {
|
||||
testSizeOf();
|
||||
|
|
|
@ -12,8 +12,8 @@ import "package:expect/expect.dart";
|
|||
|
||||
import 'dylib_utils.dart';
|
||||
|
||||
// Reuse struct definitions.
|
||||
import 'function_structs_by_value_generated_test.dart';
|
||||
// Reuse compound definitions.
|
||||
import 'function_structs_by_value_generated_compounds.dart';
|
||||
|
||||
void main() {
|
||||
testSizeOfC();
|
||||
|
|
Loading…
Reference in a new issue