Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1086)

Side by Side Diff: samples/sample_extension/test/sample_extension_test_helper.dart

Issue 2475523002: Reload native extensions when starting from a snapshot. (Closed)
Patch Set: comment Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « samples/sample_extension/test/sample_extension_test.dart ('k') | samples/samples.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4 //
5 // Dart test program for testing native extensions.
6
7 import 'dart:async';
8 import 'dart:io';
9 import 'dart:isolate';
10
11 import "package:expect/expect.dart";
12 import "package:path/path.dart";
13
14 Future copyFileToDirectory(String file, String directory) {
15 String src = file;
16 String dst = directory;
17 switch (Platform.operatingSystem) {
18 case 'linux':
19 case 'macos':
20 return Process.run('cp', [src, dst]);
21 case 'windows':
22 return Process.run('cmd.exe', ['/C', 'copy $src $dst']);
23 default:
24 Expect.fail('Unknown operating system ${Platform.operatingSystem}');
25 }
26 }
27
28 String getNativeLibraryPath(String buildDirectory) {
29 switch (Platform.operatingSystem) {
30 case 'linux':
31 return join(buildDirectory, 'lib.target', 'libsample_extension.so');
32 case 'macos':
33 return join(buildDirectory, 'libsample_extension.dylib');
34 case 'windows':
35 return join(buildDirectory, 'sample_extension.dll');
36 default:
37 Expect.fail('Unknown operating system ${Platform.operatingSystem}');
38 }
39 }
40
41 Future run(String program, List arguments) async {
42 print("+ $program ${arguments.join(' ')}");
43 ProcessResult result = await Process.run(program, arguments);
44 if (result.exitCode != 0) {
45 print('Failing process stdout: ${result.stdout}');
46 print('Failing process stderr: ${result.stderr}');
47 print('End failing process stderr');
48 Expect.fail('Test failed with exit code ${result.exitCode}');
49 }
50 }
51
52 Future testNativeExtensions(String snapshotKind) async {
53 String buildDirectory = dirname(Platform.executable);
54 Directory tempDirectory =
55 Directory.systemTemp.createTempSync('sample_extension_');
56 try {
57 String testDirectory = tempDirectory.path;
58 String sourceDirectory = Platform.script.resolve('..').toFilePath();
59
60 // Copy sample_extension shared library, sample_extension dart files and
61 // sample_extension tests to the temporary test directory.
62 await copyFileToDirectory(getNativeLibraryPath(buildDirectory),
63 testDirectory);
64 for (var file in ['sample_synchronous_extension.dart',
65 'sample_asynchronous_extension.dart',
66 'test_sample_synchronous_extension.dart',
67 'test_sample_asynchronous_extension.dart']) {
68 await copyFileToDirectory(join(sourceDirectory, file), testDirectory);
69 }
70
71 for (var test in ['test_sample_synchronous_extension.dart',
72 'test_sample_asynchronous_extension.dart']) {
73 String script = join(testDirectory, test);
74 String snapshot;
75 if (snapshotKind == null) {
76 snapshot = script;
77 } else {
78 snapshot = join(testDirectory, "$test.snapshot");
79 await run(Platform.executable,
80 ['--snapshot=$snapshot',
81 '--snapshot-kind=$snapshotKind',
82 script]);
83 }
84
85 await run(Platform.executable, [snapshot]);
86 }
87 } finally {
88 await tempDirectory.deleteSync(recursive: true);
89 }
90 }
OLDNEW
« no previous file with comments | « samples/sample_extension/test/sample_extension_test.dart ('k') | samples/samples.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698