OLD | NEW |
(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 void main() async { |
| 42 String buildDirectory = dirname(Platform.executable); |
| 43 Directory tempDirectory = |
| 44 Directory.systemTemp.createTempSync('sample_extension_'); |
| 45 try { |
| 46 String testDirectory = tempDirectory.path; |
| 47 String sourceDirectory = Platform.script.resolve('..').toFilePath(); |
| 48 |
| 49 // Copy sample_extension shared library, sample_extension dart files and |
| 50 // sample_extension tests to the temporary test directory. |
| 51 await copyFileToDirectory(getNativeLibraryPath(buildDirectory), |
| 52 testDirectory); |
| 53 for (var file in ['sample_synchronous_extension.dart', |
| 54 'sample_asynchronous_extension.dart', |
| 55 'test_sample_synchronous_extension.dart', |
| 56 'test_sample_asynchronous_extension.dart']) { |
| 57 await copyFileToDirectory(join(sourceDirectory, file), testDirectory); |
| 58 } |
| 59 |
| 60 for (var test in ['test_sample_synchronous_extension.dart', |
| 61 'test_sample_asynchronous_extension.dart']) { |
| 62 String script = join(testDirectory, test); |
| 63 String snapshot = join(testDirectory, "$test.snapshot"); |
| 64 ProcessResult result = await Process.run(Platform.executable, |
| 65 ['--snapshot=$snapshot', |
| 66 '--snapshot-kind=app-jit', |
| 67 join(testDirectory, test)]); |
| 68 if (result.exitCode != 0) { |
| 69 print('Failing test: ${join(sourceDirectory, test)}'); |
| 70 print('Failing process stdout: ${result.stdout}'); |
| 71 print('Failing process stderr: ${result.stderr}'); |
| 72 print('End failing process stderr'); |
| 73 Expect.fail('Test failed with exit code ${result.exitCode}'); |
| 74 } |
| 75 |
| 76 result = await Process.run(Platform.executable, [snapshot]); |
| 77 if (result.exitCode != 0) { |
| 78 print('Failing test: ${join(sourceDirectory, test)}'); |
| 79 print('Failing process stdout: ${result.stdout}'); |
| 80 print('Failing process stderr: ${result.stderr}'); |
| 81 print('End failing process stderr'); |
| 82 Expect.fail('Test failed with exit code ${result.exitCode}'); |
| 83 } |
| 84 } |
| 85 } finally { |
| 86 await tempDirectory.deleteSync(recursive: true); |
| 87 } |
| 88 } |
OLD | NEW |