Skip to content

Commit 81e464e

Browse files
authored
[native_test_helpers] Allow skipping dumpbin on Dart SDK CI (dart-lang#3442)
1 parent 981c689 commit 81e464e

6 files changed

Lines changed: 72 additions & 48 deletions

File tree

pkgs/native_test_helpers/lib/src/skip_local.dart

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,25 @@ import 'dart:io';
88
///
99
/// Returns `null` (forcing the test or expectation to run) if running on CI
1010
/// (detected by the `GITHUB_ACTIONS` environment variable).
11-
// ignore: avoid_positional_boolean_parameters
12-
Object? skipLocal(bool condition, String reason) {
11+
Object? skipLocal(
12+
// ignore: avoid_positional_boolean_parameters
13+
bool condition,
14+
String reason, {
15+
bool skipDartSdkCI = false,
16+
}) {
1317
// Disallow skips when running in CI environments, where all toolchains and
1418
// dependencies must be present.
1519
final isGithubActions = Platform.environment.containsKey('GITHUB_ACTIONS');
1620

17-
// The Dart SDK's internal CI infrastructure (Buildbot / Swarming).
21+
// Note: The Dart SDK's internal CI infrastructure (Buildbot / Swarming)
22+
// does not always have all tools (e.g. `dumpbin` is missing on Windows).
23+
// We allow skipping there only when `allowSkipDartSdk` is true.
1824
final isDartSdkCI =
1925
Platform.environment.containsKey('BUILDBOT_BUILDERNAME') ||
2026
Platform.environment.containsKey('SWARMING_TASK_ID');
2127

22-
final isCI = isGithubActions || isDartSdkCI;
23-
if (isCI) return null;
28+
if (isGithubActions) return null;
29+
if (isDartSdkCI && !skipDartSdkCI) return null;
30+
2431
return condition ? reason : null;
2532
}

pkgs/native_toolchain_c/test/clinker/objects_helper.dart

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import 'dart:io';
66

77
import 'package:code_assets/code_assets.dart';
88
import 'package:hooks/hooks.dart';
9-
import 'package:native_test_helpers/native_test_helpers.dart';
109
import 'package:native_toolchain_c/native_toolchain_c.dart';
1110
import 'package:test/test.dart';
1211

@@ -96,14 +95,10 @@ void runObjectsTests(
9695
expect(codeAssets, hasLength(1));
9796
final asset = codeAssets.first;
9897
expect(asset, isA<CodeAsset>());
99-
final symbols = await readSymbols(asset, targetOS);
100-
expect(
101-
symbols,
102-
stringContainsInOrder(['my_func', 'my_other_func']),
103-
skip: skipLocal(
104-
symbols == null,
105-
'tool to extract symbols unavailable',
106-
),
98+
await expectSymbols(
99+
asset: asset,
100+
targetOS: targetOS,
101+
symbols: ['my_func', 'my_other_func'],
107102
);
108103
});
109104
}

pkgs/native_toolchain_c/test/clinker/rust_test.dart

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import 'dart:io';
66

77
import 'package:code_assets/code_assets.dart';
88
import 'package:hooks/hooks.dart';
9-
import 'package:native_test_helpers/native_test_helpers.dart';
109
import 'package:native_toolchain_c/native_toolchain_c.dart';
1110
import 'package:test/test.dart';
1211

@@ -60,20 +59,20 @@ Future<void> main() async {
6059
final treeshakeOption = LinkerOptions.treeshake(
6160
symbolsToKeep: ['my_other_func'],
6261
);
63-
final symbols = await _link(
62+
final asset = await _link(
6463
staticLib,
6564
treeshakeOption,
6665
linkInput,
6766
linkOutputBuilder,
6867
targetArchitecture,
6968
targetOS,
7069
);
71-
final skip = skipLocal(
72-
symbols == null,
73-
'tool to extract symbols unavailable',
70+
await expectSymbols(
71+
asset: asset,
72+
targetOS: targetOS,
73+
symbols: ['my_other_func'],
74+
symbolsNotToContain: ['my_func'],
7475
);
75-
expect(symbols, contains('my_other_func'), skip: skip);
76-
expect(symbols, isNot(contains('my_func')), skip: skip);
7776
});
7877

7978
test('link rust binary without script keeps symbols', () async {
@@ -85,24 +84,23 @@ Future<void> main() async {
8584
stripDebug: true,
8685
gcSections: true,
8786
);
88-
final symbols = await _link(
87+
final asset = await _link(
8988
staticLib,
9089
manualOption,
9190
linkInput,
9291
linkOutputBuilder,
9392
targetArchitecture,
9493
targetOS,
9594
);
96-
final skip = skipLocal(
97-
symbols == null,
98-
'tool to extract symbols unavailable',
95+
await expectSymbols(
96+
asset: asset,
97+
targetOS: targetOS,
98+
symbols: ['my_other_func', 'my_func'],
9999
);
100-
expect(symbols, contains('my_other_func'), skip: skip);
101-
expect(symbols, contains('my_func'), skip: skip);
102100
});
103101
}
104102

105-
Future<String?> _link(
103+
Future<CodeAsset> _link(
106104
Uri staticLib,
107105
LinkerOptions manualOption,
108106
LinkInput linkInput,
@@ -122,5 +120,5 @@ Future<String?> _link(
122120

123121
await expectMachineArchitecture(asset.file!, targetArchitecture, targetOS);
124122

125-
return await readSymbols(asset, targetOS);
123+
return asset;
126124
}

pkgs/native_toolchain_c/test/clinker/treeshake_helper.dart

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import 'dart:io';
66

77
import 'package:code_assets/code_assets.dart';
88
import 'package:hooks/hooks.dart';
9-
import 'package:native_test_helpers/native_test_helpers.dart';
109
import 'package:native_toolchain_c/native_toolchain_c.dart';
1110
import 'package:test/test.dart';
1211

@@ -151,17 +150,19 @@ void runTreeshakeTests(
151150
targetOS,
152151
);
153152

154-
final symbols = await readSymbols(asset, targetOS);
155-
final skip = skipLocal(
156-
symbols == null,
157-
'tool to extract symbols unavailable',
158-
);
159153
if (clinker.linker != linkerAutoKeepAll) {
160-
expect(symbols, contains('my_other_func'), skip: skip);
161-
expect(symbols, isNot(contains('my_func')), skip: skip);
154+
await expectSymbols(
155+
asset: asset,
156+
targetOS: targetOS,
157+
symbols: ['my_other_func'],
158+
symbolsNotToContain: ['my_func'],
159+
);
162160
} else {
163-
expect(symbols, contains('my_other_func'), skip: skip);
164-
expect(symbols, contains('my_func'), skip: skip);
161+
await expectSymbols(
162+
asset: asset,
163+
targetOS: targetOS,
164+
symbols: ['my_other_func', 'my_func'],
165+
);
165166
}
166167

167168
final sizeInBytes = await File.fromUri(asset.file!).length();

pkgs/native_toolchain_c/test/clinker/windows_module_definition_helper.dart

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import 'dart:io';
66

77
import 'package:code_assets/code_assets.dart';
88
import 'package:hooks/hooks.dart';
9-
import 'package:native_test_helpers/native_test_helpers.dart';
109
import 'package:native_toolchain_c/native_toolchain_c.dart';
1110
import 'package:test/test.dart';
1211

@@ -69,16 +68,14 @@ void runWindowsModuleDefinitionTests(List<Architecture> architectures) {
6968
expect(codeAssets, hasLength(1));
7069
final asset = codeAssets.first;
7170
expect(asset, isA<CodeAsset>());
72-
final symbols = await readSymbols(asset, targetOS);
73-
final skip = skipLocal(
74-
symbols == null,
75-
'tool to extract symbols unavailable',
76-
);
77-
expect(symbols, contains('my_func'), skip: skip);
7871
// Module Definition file causes my_unexported_func to be exported even
7972
// though it wasn't marked for export.
80-
expect(symbols, contains('my_unexported_func'), skip: skip);
81-
expect(symbols, isNot(contains('my_other_func')), skip: skip);
73+
await expectSymbols(
74+
asset: asset,
75+
targetOS: targetOS,
76+
symbols: ['my_func', 'my_unexported_func'],
77+
symbolsNotToContain: ['my_other_func'],
78+
);
8279
},
8380
);
8481
}

pkgs/native_toolchain_c/test/helpers.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,30 @@ Future<void> expectSymbolNotUndefined(
258258
);
259259
}
260260

261+
/// Asserts that the library described by [asset] contains [symbols] and does
262+
/// not contain [symbolsNotToContain].
263+
Future<void> expectSymbols({
264+
required CodeAsset asset,
265+
required OS targetOS,
266+
List<String> symbols = const [],
267+
List<String> symbolsNotToContain = const [],
268+
}) async {
269+
final symbolsString = await readSymbols(asset, targetOS);
270+
final skip = skipLocal(
271+
symbolsString == null,
272+
'tool to extract symbols unavailable',
273+
// The Dart SDK CI does not have dumpbin.
274+
skipDartSdkCI: true,
275+
);
276+
expect(symbolsString, isNotNull, skip: skip);
277+
for (final symbol in symbols) {
278+
expect(symbolsString, contains(symbol), skip: skip);
279+
}
280+
for (final symbol in symbolsNotToContain) {
281+
expect(symbolsString, isNot(contains(symbol)), skip: skip);
282+
}
283+
}
284+
261285
/// Returns null if the dumpbin tool is not available.
262286
Future<RunProcessResult?> _runDumpbin(
263287
List<String> arguments,
@@ -449,6 +473,8 @@ Future<void> expectMachineArchitecture(
449473
final skip = skipLocal(
450474
result == null,
451475
'tool to determine binary architecture unavailable',
476+
// The Dart SDK CI does not have dumpbin.
477+
skipDartSdkCI: true,
452478
);
453479
expect(result?.exitCode, 0, skip: skip);
454480
final machine = result?.stdout

0 commit comments

Comments
 (0)